Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.model;

import javax.persistence.*;

/**
 * Last-15-day secondary-sales quantity per item, scoped to a specific
 * fulfilling warehouse. Used by the PO stock-cover approval check
 * alongside {@link ItemAgingStockByVendorModel}: if
 * {@code agingQty + poQty > sold15dQty}, the PO waits for approval.
 *
 * <p>"Secondary sales" = orders billed out of this warehouse to fofo/
 * partner customers ({@code transaction.order} joined to
 * {@code transaction.lineitem}). Excludes refunded orders. Not filtered
 * by vendor — sales exhaust stock regardless of who originally supplied
 * it, so the run-rate is a shared denominator across vendors of the
 * same SKU.
 */
@Entity
@NamedNativeQueries({
        @NamedNativeQuery(
                name = "PoStockApproval.Sold15Days",
                query = "SELECT li.item_id                        AS item_id," +
                        "       COALESCE(SUM(li.quantity), 0)     AS sold_qty" +
                        " FROM transaction.order    odr" +
                        "   JOIN transaction.lineitem li ON li.order_id = odr.id" +
                        " WHERE li.item_id IN (:itemIds)" +
                        "   AND odr.warehouse_id     = :warehouseId" +
                        "   AND odr.created_timestamp >= :sinceDate" +
                        "   AND odr.refund_timestamp IS NULL" +
                        " GROUP BY li.item_id",
                resultSetMapping = "PoStockApprovalSold15Days")
})
@SqlResultSetMappings({
        @SqlResultSetMapping(
                name = "PoStockApprovalSold15Days",
                classes = {
                        @ConstructorResult(
                                targetClass = Item15DaysSoldModel.class,
                                columns = {
                                        @ColumnResult(name = "item_id", type = Integer.class),
                                        @ColumnResult(name = "sold_qty", type = Long.class)
                                }
                        )
                }
        )
})
public class Item15DaysSoldModel {

    private Integer itemId;
    private Long soldQty;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    public Item15DaysSoldModel() {
    }

    public Item15DaysSoldModel(Integer itemId, Long soldQty) {
        this.itemId = itemId;
        this.soldQty = soldQty;
    }

    public Integer getItemId() {
        return itemId;
    }

    public void setItemId(Integer itemId) {
        this.itemId = itemId;
    }

    public Long getSoldQty() {
        return soldQty;
    }

    public void setSoldQty(Long soldQty) {
        this.soldQty = soldQty;
    }
}