Subversion Repositories SmartDukaan

Rev

Rev 33873 | Rev 34256 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33873 Rev 34163
Line 1... Line 1...
1
package com.spice.profitmandi.dao.entity.fofo;
1
package com.spice.profitmandi.dao.entity.fofo;
2
 
2
 
-
 
3
import com.spice.profitmandi.dao.model.HidAllocationModel;
-
 
4
 
3
import javax.persistence.*;
5
import javax.persistence.*;
4
import java.io.Serializable;
6
import java.io.Serializable;
5
import java.time.LocalDate;
7
import java.time.LocalDate;
6
import java.util.Objects;
8
import java.util.Objects;
7
 
9
 
8
@Entity
10
@Entity
9
@Table(name = "fofo.fofo_opening_stock",
11
@Table(name = "fofo.fofo_opening_stock",
10
        uniqueConstraints = {@UniqueConstraint(columnNames = {"fofo_id", "catalog_id"})})
12
        uniqueConstraints = {@UniqueConstraint(columnNames = {"fofo_id", "catalog_id"})})
11
 
13
 
-
 
14
 
-
 
15
@NamedNativeQueries({
-
 
16
        @NamedNativeQuery(name = "Stock.PartnerHidAllocation",
-
 
17
                query = "SELECT" +
-
 
18
                        "    COALESCE(os.fofo_id,0) as fofo_id," +
-
 
19
                        "    cc.catalog_id," +
-
 
20
                        "    c.model_number," +
-
 
21
                        "    c.brand," +
-
 
22
                        "    COALESCE(SUM(os.current_qty), 0) AS available_stock," +
-
 
23
                        "    COALESCE(sale1.last2daysSale, 0) AS last2DaysSoldQtySum," +
-
 
24
                        "    COALESCE(sale2.last3rddaysale, 0) AS lastThirdDaySoldQty," +
-
 
25
                        "   (CASE" +
-
 
26
                        "         WHEN ((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0) = 0)" +
-
 
27
                        "             OR (COALESCE(SUM(os.current_qty), 0) = 0) THEN 2" +
-
 
28
                        "         ELSE ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0))" +
-
 
29
                        "        END) AS allocation ," +
-
 
30
                        "    (CASE" +
-
 
31
                        "         WHEN ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0)) > 0" +
-
 
32
                        "             THEN ROUND((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0))" +
-
 
33
                        "             - COALESCE(SUM(os.current_qty), 0)" +
-
 
34
                        "         WHEN ((COALESCE(sale1.last2daysSale, 0) * :allocationConst) + COALESCE(sale2.last3rddaysale, 0) = 0)" +
-
 
35
                        "             OR (COALESCE(SUM(os.current_qty), 0) = 0) THEN 2" +
-
 
36
                        "         ELSE 0" +
-
 
37
                        "        END) AS purchase_limit" +
-
 
38
                        " FROM catalog.catagoriesd_catalog cc" +
-
 
39
                        "         LEFT JOIN fofo.fofo_opening_stock os ON os.catalog_id = cc.catalog_id AND os.fofo_id = :fofoId" +
-
 
40
                        "         LEFT JOIN (" +
-
 
41
                        "    SELECT o.fofo_id, ci.catalog_item_id, SUM(oi.quantity) AS last2daysSale" +
-
 
42
                        "    FROM fofo.fofo_order o" +
-
 
43
                        "             JOIN fofo.fofo_order_item oi ON o.id = oi.order_id" +
-
 
44
                        "             JOIN catalog.item ci ON oi.item_id = ci.id" +
-
 
45
                        "    WHERE DATE(o.create_timestamp) BETWEEN (CURDATE() - INTERVAL 2 DAY) AND CURDATE()" +
-
 
46
                        "    GROUP BY o.fofo_id, ci.catalog_item_id" +
-
 
47
                        ") sale1 ON sale1.catalog_item_id = os.catalog_id AND os.fofo_id = sale1.fofo_id" +
-
 
48
                        "         LEFT JOIN (" +
-
 
49
                        "    SELECT o.fofo_id, ci.catalog_item_id, SUM(oi.quantity) AS last3rddaysale" +
-
 
50
                        "    FROM fofo.fofo_order o" +
-
 
51
                        "             JOIN fofo.fofo_order_item oi ON o.id = oi.order_id" +
-
 
52
                        "             JOIN catalog.item ci ON oi.item_id = ci.id" +
-
 
53
                        "    WHERE DATE(o.create_timestamp) = CURDATE() - INTERVAL 3 DAY" +
-
 
54
                        "    GROUP BY o.fofo_id, ci.catalog_item_id" +
-
 
55
                        ") sale2 ON sale2.catalog_item_id = os.catalog_id AND os.fofo_id = sale2.fofo_id" +
-
 
56
                        "         JOIN catalog.catalog c ON c.id = cc.catalog_id" +
-
 
57
                        " WHERE cc.end_date IS NULL AND cc.status = 'HID'" +
-
 
58
                        "GROUP BY cc.catalog_id",
-
 
59
                resultSetMapping = "HidAllocation"),
-
 
60
 
-
 
61
})
-
 
62
 
-
 
63
@SqlResultSetMappings({
-
 
64
 
-
 
65
        @SqlResultSetMapping(name = "HidAllocation",
-
 
66
                classes = {@ConstructorResult(targetClass = HidAllocationModel.class,
-
 
67
                        columns = {
-
 
68
                                @ColumnResult(name = "fofo_id", type = Integer.class),
-
 
69
                                @ColumnResult(name = "catalog_id", type = Integer.class),
-
 
70
                                @ColumnResult(name = "model_number", type = String.class),
-
 
71
                                @ColumnResult(name = "brand ", type = String.class),
-
 
72
                                @ColumnResult(name = "available_stock ", type = Integer.class),
-
 
73
                                @ColumnResult(name = "last2DaysSoldQtySum ", type = Integer.class),
-
 
74
                                @ColumnResult(name = "lastThirdDaySoldQty ", type = Integer.class),
-
 
75
                                @ColumnResult(name = "allocation ", type = Integer.class),
-
 
76
                                @ColumnResult(name = "purchase_limit ", type = Integer.class),
-
 
77
                        }
-
 
78
                )}
-
 
79
        )
-
 
80
 
-
 
81
})
-
 
82
 
12
public class FofoOpeningStock implements Serializable {
83
public class FofoOpeningStock implements Serializable {
13
 
84
 
14
    @Id
85
    @Id
15
    @Column(name = "id")
86
    @Column(name = "id")
16
    @GeneratedValue(strategy = GenerationType.IDENTITY)
87
    @GeneratedValue(strategy = GenerationType.IDENTITY)