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

SELECT wo.WADOCO AS WorkOrderNumber,
       TRIM(wo.WAMMCU) AS BranchCode,
       TRIM(wo.WALOTN) AS LotNumber,
       TRIM(wo.WALITM) AS ItemNumber,
       wo.WAITM AS ShortItemNumber,
       TRIM(wo.WAPARS) AS ParentWorkOrderNumber,
       wo.WAUORG AS OrderQuantity,
       wo.WASOBK AS HeldQuantity,
       wo.WASOCN AS ScrappedQuantity,
       wo.WASOQS AS ShippedQuantity,
       TRIM(wo.WASRST) AS StatusCode,
       wo.WADCG AS StatusCodeUpdateDT,
       wo.WATRDJ AS IssueDate,
       wo.WASTRT AS StartDate,
       TRIM(wo.WATRT) AS RoutingType,
       wo.WAUPMJ AS DateUpdated,
       wo.WATDAY AS TimeUpdated
  FROM QADTA.F4801 wo

UNION ALL

SELECT wo.WADOCO AS WorkOrderNumber,
       TRIM(wo.WAMMCU) AS BranchCode,
       TRIM(wo.WALOTN) AS LotNumber,
       TRIM(wo.WALITM) AS ItemNumber,
       wo.WAITM AS ShortItemNumber,
       TRIM(wo.WAPARS) AS ParentWorkOrderNumber,
       wo.WAUORG AS OrderQuantity,
       wo.WASOBK AS HeldQuantity,
       wo.WASOCN AS ScrappedQuantity,
       wo.WASOQS AS ShippedQuantity,
       TRIM(wo.WASRST) AS StatusCode,
       wo.WADCG AS StatusCodeUpdateDT,
       wo.WATRDJ AS IssueDate,
       wo.WASTRT AS StartDate,
       TRIM(wo.WATRT) AS RoutingType,
       wo.WAUPMJ AS DateUpdated,
       wo.WATDAY AS TimeUpdated
  FROM ARCDTAQA.F4801 wo
