-- LotUsage Archive Query
-- Source: QADTA.F4111 (current) + ARCDTAQA.F4111 (archived)
-- Used by: GetLotUsagesArchive() - on-demand historical retrieval
-- Note: Not scheduled, used for historical lookups

SELECT lu.ILUKID AS UniqueID,
       lu.ILDOCO AS WorkOrderNumber,
       TRIM(lu.ILLOTN) AS LotNumber,
       TRIM(lu.ILMCU) AS BranchCode,
       lu.ILITM AS ShortItemNumber,
       lu.ILTRQT AS Quantity,
       lu.ILTRDJ AS DateUpdated,
       lu.ILTDAY AS TimeUpdated
  FROM QADTA.F4111 lu
 WHERE lu.ILDCT = 'IM' AND
       TRIM(lu.ILLOTN) IS NOT NULL

UNION ALL

SELECT lu.ILUKID AS UniqueID,
       lu.ILDOCO AS WorkOrderNumber,
       TRIM(lu.ILLOTN) AS LotNumber,
       TRIM(lu.ILMCU) AS BranchCode,
       lu.ILITM AS ShortItemNumber,
       lu.ILTRQT AS Quantity,
       lu.ILTRDJ AS DateUpdated,
       lu.ILTDAY AS TimeUpdated
  FROM ARCDTAQA.F4111 lu
 WHERE lu.ILDCT = 'IM' AND
       TRIM(lu.ILLOTN) IS NOT NULL
