Subversion Repositories SmartDukaan

Rev

Rev 37758 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37758 Rev 37761
Line 1... Line 1...
1
package com.spice.profitmandi.dao.model;
1
package com.spice.profitmandi.dao.model;
2
 
2
 
3
import javax.persistence.*;
3
import javax.persistence.*;
4
 
4
 
5
/**
5
/**
6
 * Aging-stock breakdown per item, grouped by (warehouse, vendor). Used by the
6
 * Aging-stock breakdown per item, scoped to a specific vendor and grouped by
7
 * PO stock-cover approval flow to show "if the PO's own warehouse has no aging
7
 * warehouse. Used by the PO stock-cover approval flow to show "does THIS vendor
8
 * stock for this item, WHERE across the network does aging exist" so the
8
 * already have aging stock of this item sitting in any of our warehouses?" so
9
 * approver can see whether to redistribute rather than buy fresh.
9
 * the approver can see whether the same vendor's inventory can be redistributed
-
 
10
 * rather than buying fresh from them.
-
 
11
 *
-
 
12
 * <p><b>Vendor-scoped by design:</b> aging held by a DIFFERENT vendor at a
-
 
13
 * different warehouse is not our accountability against this PO — Green Fortune
-
 
14
 * doesn't own NSSPL's pile, so we don't surface NSSPL's aging when raising a
-
 
15
 * Green Fortune PO. Rule matches the same-vendor decision documented in the
-
 
16
 * project plan.
10
 *
17
 *
11
 * <p>Same trace path as {@link ItemAgingStockByVendorModel}
18
 * <p>Same trace path as {@link ItemAgingStockByVendorModel}
12
 * ({@code inventoryItem.purchaseId -> purchase.poId -> purchaseorder.supplierId}),
19
 * ({@code inventoryItem.purchaseId -> purchase.poId -> purchaseorder.supplierId}).
13
 * but without the vendor / warehouse filters — this query returns every
-
 
14
 * (warehouse, vendor) combination that has aging stock of the flagged items.
-
 
15
 */
20
 */
16
@Entity
21
@Entity
17
@NamedNativeQueries({
22
@NamedNativeQueries({
18
        @NamedNativeQuery(
23
        @NamedNativeQuery(
19
                name = "PoStockApproval.AgingBreakdown",
24
                name = "PoStockApproval.AgingBreakdown",
Line 23... Line 28...
23
                        "       COALESCE(SUM(inv.currentQuantity),0) AS aging_qty" +
28
                        "       COALESCE(SUM(inv.currentQuantity),0) AS aging_qty" +
24
                        " FROM warehouse.inventoryItem  inv" +
29
                        " FROM warehouse.inventoryItem  inv" +
25
                        "   JOIN warehouse.purchase      pr ON pr.id = inv.purchaseId" +
30
                        "   JOIN warehouse.purchase      pr ON pr.id = inv.purchaseId" +
26
                        "   JOIN warehouse.purchaseorder po ON po.id = pr.purchaseOrder_id" +
31
                        "   JOIN warehouse.purchaseorder po ON po.id = pr.purchaseOrder_id" +
27
                        " WHERE inv.itemId IN (:itemIds)" +
32
                        " WHERE inv.itemId IN (:itemIds)" +
-
 
33
                        "   AND po.supplierId = :vendorId" +
28
                        "   AND inv.currentQuantity > 0" +
34
                        "   AND inv.currentQuantity > 0" +
29
                        "   AND pr.receivedOn <= :agingCutoff" +
35
                        "   AND pr.receivedOn <= :agingCutoff" +
30
                        " GROUP BY inv.itemId, inv.currentWarehouseId, po.supplierId" +
36
                        " GROUP BY inv.itemId, inv.currentWarehouseId, po.supplierId" +
31
                        " HAVING SUM(inv.currentQuantity) > 0",
37
                        " HAVING SUM(inv.currentQuantity) > 0",
32
                resultSetMapping = "PoStockApprovalAgingBreakdown")
38
                resultSetMapping = "PoStockApprovalAgingBreakdown")