namespace QMSDAL.DTO
{
// ─────────────────────────────────────────────────────────────────────────
// TMATRIXINPUT — Traceability Input Lines (RM / BO Consumption)
//
// SQL columns (QMS.sql Section 4):
// MATRIXINPUTID, MATRIXID, SLNO,
// ITEMID, SKUID, ITEMCATEGORY,
// LOTID, PLANNEDQTY, ALLOCATEDQTY, CONSUMEDQTY,
// MIXPROPORTION, LINESTATUS, TENANTID
//
// New FK columns to be added via ALTER:
// BOMLINEID → MBOMDETAIL.BOMLINEID
// LOTDETAILID → TLOTDETAIL.LOTDETAILID (populated after consumption posting)
// ─────────────────────────────────────────────────────────────────────────
public class MatrixInputDTO
{
// ====================================================================
// PRIMARY / LINKING KEYS
// ====================================================================
public int MatrixInputId { get; set; }
/// FK → TMATRIX.MATRIXID
public int MatrixId { get; set; }
public short SlNo { get; set; }
// ====================================================================
// ITEM DETAILS (TMATRIXINPUT.ITEMID / SKUID)
// ====================================================================
/// FK → MITEM.ITEMID
public int ItemId { get; set; }
public string? ItemCode { get; set; }
public string? ItemName { get; set; }
/// MITEM.ITEMSHORTNAME
public string? ItemShortName { get; set; }
/// FK → MUOM.UOMID — MITEM.STOCKUOMID (base stocking unit of the component)
public int StockUomId { get; set; } = -1;
/// MITEM.ISBATCHSTOCK — whether this component requires batch/lot tracking
public bool IsBatchStock { get; set; }
/// MITEM.ISSKUTRACKINGAPPLICABLE
public bool IsSkuTrackingApplicable { get; set; }
/// MITEM.CATEGORYID
public int CategoryId { get; set; } = -1;
/// MITEM.SUBCATEGORYID
public int SubCategoryId { get; set; } = -1;
/// MITEM.ITEMGROUPID
public int ItemGroupId { get; set; } = -1;
/// FK → MSKU.SKUID
public int SkuId { get; set; }
public string? SkuCode { get; set; }
public string? SkuName { get; set; }
// ====================================================================
// CLASSIFICATION (TMATRIXINPUT.ITEMCATEGORY)
// ====================================================================
/// 0=RM | 1=BO_Qty | 2=BO_Serial
public byte ItemCategory { get; set; }
public string? ItemCategoryName { get; set; }
// ====================================================================
// BOM DETAIL LINK (MBOMDETAIL columns)
// ====================================================================
/// FK → MBOMDETAIL.BOMLINEID; -1 when not BOM-linked
public int BomLineId { get; set; } = -1;
/// MBOMDETAIL.SLNO — sequence within the BOM
public short BomSlNo { get; set; }
/// FK → MBOM.BOMID
public int BomId { get; set; } = -1;
public string? BomCode { get; set; }
/// MBOM.PRODUCTIONQTY — reference output qty the BOM was designed for
public decimal BomProductionQty { get; set; }
/// MBOMDETAIL.BOMLEVEL — depth in BOM tree (0=root excluded by query)
public byte BomLevel { get; set; }
/// MBOMDETAIL.PRODUCTIONSTAGE
public string? ProductionStage { get; set; }
/// MBOMDETAIL.MATERIALTYPE
public byte? MaterialType { get; set; }
/// MBOMDETAIL.IOTYPE — 1=Input / 2=Output indicator on BOM line
public byte? IoType { get; set; }
/// MBOMDETAIL.CALCULATIONTYPE
public byte? CalculationType { get; set; }
/// FK → MUOM.UOMID — MBOMDETAIL.UOMID (BOM component unit)
public int UomId { get; set; } = -1;
public string? UomName { get; set; }
/// MBOMDETAIL.QUANTITY — raw qty per BOM reference production qty
public decimal QtyPer { get; set; }
/// MBOMDETAIL.PERCENTAGE — formula-based percentage
public decimal BomPercentage { get; set; }
/// MBOMDETAIL.PERPRODUCTIONQUANTITY — per-unit exploded quantity before waste
public decimal PerProductionQuantity { get; set; }
/// MBOMDETAIL.REQUIREDPRODUCTIONQUANTITY — scaled required quantity
public decimal RequiredProductionQuantity { get; set; }
/// MBOMDETAIL.WASTEPERCENTAGE
public decimal WastePercentage { get; set; }
/// MBOMDETAIL.NETQUANTITY — qty after waste % applied
public decimal NetQuantity { get; set; }
/// MBOMDETAIL.FINALQUANTITY — net qty after waste + manual adjustment
public decimal FinalQuantity { get; set; }
// ====================================================================
// LOT / BATCH (TMATRIXINPUT.LOTID → TLOT)
// ====================================================================
///
/// FK → TLOT.LOTID — assigned RM batch
/// -1 for BO_Qty and BO_Serial items (not yet allocated)
///
public int LotId { get; set; } = -1;
// Display fields joined from TLOT
public string? LotNumber { get; set; }
public string? BatchNo { get; set; }
/// TLOT.LOTDATE
public DateTime? LotDate { get; set; }
/// TLOT.LOTEXPIRYDATE
public DateTime? LotExpiryDate { get; set; }
/// TLOT.LOTTYPEID
public int LotTypeId { get; set; } = -1;
// ====================================================================
// LOT DETAIL LINK — new column LOTDETAILID added to TMATRIXINPUT
// Populated after the consumption issue is posted to TLOTDETAIL
// ====================================================================
/// FK → TLOTDETAIL.LOTDETAILID; -1 before consumption is posted
public int LotDetailId { get; set; } = -1;
// Display fields joined from TLOTDETAIL
/// TLOTDETAIL.OUID
public int OuId { get; set; } = -1;
/// TLOTDETAIL.STOREID
public int StoreId { get; set; } = -1;
public string? StoreName { get; set; }
/// TLOTDETAIL.BINID
public int BinId { get; set; } = -1;
public string? BinName { get; set; }
/// TLOTDETAIL.LOCATIONTYPE
public byte? LocationType { get; set; }
/// TLOTDETAIL.PARTYBRANCHID
public int PartyBranchId { get; set; } = -1;
/// TLOTDETAIL.REFERENCENUMBER
public string? ReferenceNumber { get; set; }
/// TLOTDETAIL.REFERENCEDATE
public DateTime? ReferenceDate { get; set; }
/// TLOTDETAIL.STOCKLEDGERNUMBER
public string? StockLedgerNumber { get; set; }
/// TLOTDETAIL.STOCKLEDGERDATE
public DateTime? StockLedgerDate { get; set; }
// ====================================================================
// QUANTITIES (TMATRIXINPUT)
// ====================================================================
/// BOM-exploded total — planning snapshot (same as RequiredQty)
public decimal PlannedQty { get; set; }
/// Total required quantity for the set range — MBOMDETAIL.FINALQUANTITY × SetCount
public decimal RequiredQty { get; set; }
/// Quantity per production unit — MBOMDETAIL.QUANTITY
public decimal QuantityPer { get; set; }
/// Unit of measure code — MUOM.UOMCODE via MITEM.STOCKUOMID
public string? UomCode { get; set; }
/// Confirmed qty reserved from this batch
public decimal AllocatedQty { get; set; }
/// Running total maintained from actual issues
public decimal ConsumedQty { get; set; }
///
/// Available stock from stock engine
/// Populated by CHECK_STOCK_POSITION only
///
public decimal FreeQty { get; set; }
///
/// AllocatedQty - FreeQty
/// Populated by CHECK_STOCK_POSITION only
///
public decimal ShortageQty { get; set; }
// ====================================================================
// MIX / TRACEABILITY CONTROL (TMATRIXINPUT)
// ====================================================================
/// Blend % for OpenMix mode; 0 for Product / FGItem modes
public decimal MixProportion { get; set; }
// ====================================================================
// STATUS (TMATRIXINPUT.LINESTATUS)
// ====================================================================
/// 0=Open | 1=Partial | 2=Consumed | 3=Cancelled
public byte LineStatus { get; set; }
public string? LineStatusName { get; set; }
// ====================================================================
// RESERVATION FLAG
// ====================================================================
///
/// True when a TRESERVATION row already exists for this input line.
/// Populated on GET from a LEFT JOIN to TRESERVATION
/// (FOROBJECTID = MatrixInputId, FOROBJECTTYPEID = ENTITY_TMATRIXINPUT).
/// On Save: BLL skips reservation creation when this is true.
///
public bool IsReservation { get; set; }
// ====================================================================
// STANDARD FIELDS
// ====================================================================
public int TenantId { get; set; }
public DateTime? CreatedOn { get; set; }
public DateTime? ModifiedOn { get; set; }
}
}