| @@ -59,9 +59,11 @@ class SemiFGProductionAnalysisReportService( | |||||
| * Queries the database for Semi FG Production Analysis Report data. | * Queries the database for Semi FG Production Analysis Report data. | ||||
| * Aligned with [ReportService.searchStockInTraceabilityReport] totals for the same filters: | * Aligned with [ReportService.searchStockInTraceabilityReport] totals for the same filters: | ||||
| * - stock_in_line driven (no stock_ledger gate); INNER JOIN bom so only items that exist as BOM rows appear | * - stock_in_line driven (no stock_ledger gate); INNER JOIN bom so only items that exist as BOM rows appear | ||||
| * - Include only stock_in_line rows with non-null jobOrderId | |||||
| * - Exclude stock_in_line rows with status = 'Pending' | |||||
| * - stockCategory → items.type (exact, comma-separated); itemCode → items.code (LIKE, comma-separated) | * - stockCategory → items.type (exact, comma-separated); itemCode → items.code (LIKE, comma-separated) | ||||
| * - Date range / year on productionDate (with IS NOT NULL when range bound is set) | * - Date range / year on productionDate (with IS NOT NULL when range bound is set) | ||||
| * - Put-away qty: SUM(inventory_lot_line.inQty) by sil.inventoryLotId (same as traceability pa_sil) | |||||
| * - Quantity source: stock_in_line.acceptedQty | |||||
| * - QC any fail → line qty 0 (same as traceability stockInQty) | * - QC any fail → line qty 0 (same as traceability stockInQty) | ||||
| * - One row per stockInLineId per month before pivot; all lines counted (not only job orders) | * - One row per stockInLineId per month before pivot; all lines counted (not only job orders) | ||||
| */ | */ | ||||
| @@ -113,12 +115,6 @@ class SemiFGProductionAnalysisReportService( | |||||
| WHERE qr.deleted = 0 | WHERE qr.deleted = 0 | ||||
| GROUP BY qr.stockInLineId | GROUP BY qr.stockInLineId | ||||
| ), | ), | ||||
| pa_sil AS ( | |||||
| SELECT inventoryLotId, SUM(COALESCE(inQty, 0)) AS putAwayQtySum | |||||
| FROM inventory_lot_line | |||||
| WHERE deleted = false | |||||
| GROUP BY inventoryLotId | |||||
| ), | |||||
| base AS ( | base AS ( | ||||
| SELECT | SELECT | ||||
| COALESCE(it.code, '') AS itemNo, | COALESCE(it.code, '') AS itemNo, | ||||
| @@ -128,18 +124,19 @@ class SemiFGProductionAnalysisReportService( | |||||
| MONTH(si.productionDate) AS mon, | MONTH(si.productionDate) AS mon, | ||||
| si.id AS stockInLineId, | si.id AS stockInLineId, | ||||
| CASE WHEN COALESCE(qr_agg.qcFailed, 0) = 1 THEN 0 | CASE WHEN COALESCE(qr_agg.qcFailed, 0) = 1 THEN 0 | ||||
| ELSE COALESCE(pa_sil.putAwayQtySum, 0) | |||||
| ELSE COALESCE(si.acceptedQty, 0) | |||||
| END AS linePutAwayQty | END AS linePutAwayQty | ||||
| FROM stock_in_line si | FROM stock_in_line si | ||||
| INNER JOIN items it ON si.itemId = it.id | INNER JOIN items it ON si.itemId = it.id | ||||
| INNER JOIN bom b ON b.code = it.code AND b.deleted = false | INNER JOIN bom b ON b.code = it.code AND b.deleted = false | ||||
| LEFT JOIN qr_agg ON qr_agg.stockInLineId = si.id | LEFT JOIN qr_agg ON qr_agg.stockInLineId = si.id | ||||
| LEFT JOIN pa_sil ON pa_sil.inventoryLotId = si.inventoryLotId | |||||
| LEFT JOIN item_category ic ON it.categoryId = ic.id | LEFT JOIN item_category ic ON it.categoryId = ic.id | ||||
| LEFT JOIN item_uom iu ON it.id = iu.itemId AND iu.stockUnit = true | LEFT JOIN item_uom iu ON it.id = iu.itemId AND iu.stockUnit = true | ||||
| LEFT JOIN uom_conversion uc ON iu.uomId = uc.id | LEFT JOIN uom_conversion uc ON iu.uomId = uc.id | ||||
| WHERE si.deleted = false | WHERE si.deleted = false | ||||
| AND si.productionDate IS NOT NULL | AND si.productionDate IS NOT NULL | ||||
| AND si.jobOrderId IS NOT NULL | |||||
| AND (si.status IS NULL OR si.status <> 'Pending') | |||||
| $stockCategorySql | $stockCategorySql | ||||
| $stockSubCategorySql | $stockSubCategorySql | ||||
| $itemCodeSql | $itemCodeSql | ||||