Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37757 ranu 1
package com.spice.profitmandi.dao.model;
2
 
3
import javax.persistence.*;
4
 
5
/**
6
 * Last-15-day secondary-sales quantity per item, scoped to a specific
7
 * fulfilling warehouse. Used by the PO stock-cover approval check
8
 * alongside {@link ItemAgingStockByVendorModel}: if
9
 * {@code agingQty + poQty > sold15dQty}, the PO waits for approval.
10
 *
11
 * <p>"Secondary sales" = orders billed out of this warehouse to fofo/
12
 * partner customers ({@code transaction.order} joined to
13
 * {@code transaction.lineitem}). Excludes refunded orders. Not filtered
14
 * by vendor — sales exhaust stock regardless of who originally supplied
15
 * it, so the run-rate is a shared denominator across vendors of the
16
 * same SKU.
17
 */
18
@Entity
19
@NamedNativeQueries({
20
        @NamedNativeQuery(
21
                name = "PoStockApproval.Sold15Days",
22
                query = "SELECT li.item_id                        AS item_id," +
23
                        "       COALESCE(SUM(li.quantity), 0)     AS sold_qty" +
24
                        " FROM transaction.order    odr" +
25
                        "   JOIN transaction.lineitem li ON li.order_id = odr.id" +
26
                        " WHERE li.item_id IN (:itemIds)" +
27
                        "   AND odr.warehouse_id     = :warehouseId" +
28
                        "   AND odr.created_timestamp >= :sinceDate" +
29
                        "   AND odr.refund_timestamp IS NULL" +
30
                        " GROUP BY li.item_id",
31
                resultSetMapping = "PoStockApprovalSold15Days")
32
})
33
@SqlResultSetMappings({
34
        @SqlResultSetMapping(
35
                name = "PoStockApprovalSold15Days",
36
                classes = {
37
                        @ConstructorResult(
38
                                targetClass = Item15DaysSoldModel.class,
39
                                columns = {
40
                                        @ColumnResult(name = "item_id", type = Integer.class),
41
                                        @ColumnResult(name = "sold_qty", type = Long.class)
42
                                }
43
                        )
44
                }
45
        )
46
})
47
public class Item15DaysSoldModel {
48
 
49
    private Integer itemId;
50
    private Long soldQty;
51
 
52
    @Id
53
    @GeneratedValue(strategy = GenerationType.IDENTITY)
54
    private Long id;
55
 
56
    public Item15DaysSoldModel() {
57
    }
58
 
59
    public Item15DaysSoldModel(Integer itemId, Long soldQty) {
60
        this.itemId = itemId;
61
        this.soldQty = soldQty;
62
    }
63
 
64
    public Integer getItemId() {
65
        return itemId;
66
    }
67
 
68
    public void setItemId(Integer itemId) {
69
        this.itemId = itemId;
70
    }
71
 
72
    public Long getSoldQty() {
73
        return soldQty;
74
    }
75
 
76
    public void setSoldQty(Long soldQty) {
77
        this.soldQty = soldQty;
78
    }
79
}