From b573c92b7752d6e74db747c64d0603a478470d8a Mon Sep 17 00:00:00 2001 From: "Tommy\\2Fi-Staff" Date: Mon, 9 Feb 2026 16:19:23 +0800 Subject: [PATCH] TruckScheduleDashboard & StockInTraceability report update --- .../modules/report/service/ReportService.kt | 48 ++- .../modules/report/web/ReportController.kt | 7 - .../jasper/StockInTraceabilityReport.jrxml | 282 ++++++------------ 3 files changed, 114 insertions(+), 223 deletions(-) diff --git a/src/main/java/com/ffii/fpsms/modules/report/service/ReportService.kt b/src/main/java/com/ffii/fpsms/modules/report/service/ReportService.kt index c2138f1..0bce8f6 100644 --- a/src/main/java/com/ffii/fpsms/modules/report/service/ReportService.kt +++ b/src/main/java/com/ffii/fpsms/modules/report/service/ReportService.kt @@ -327,30 +327,20 @@ return result /** * Queries the database for Stock In Traceability Report data. - * Joins stock_in_line, stock_in, items, item_category, qc_result, inventory_lot, inventory_lot_line, warehouse, and shop tables. - * Supports comma-separated values for stockCategory, stockSubCategory, and itemCode. + * Joins stock_in_line, stock_in, items, qc_result, inventory_lot, inventory_lot_line, warehouse, and shop tables. + * Supports comma-separated values for stockCategory (items.type) and itemCode. */ fun searchStockInTraceabilityReport( stockCategory: String?, - stockSubCategory: String?, itemCode: String?, - year: String?, lastInDateStart: String?, lastInDateEnd: String? ): List> { val args = mutableMapOf() - val stockCategorySql = buildMultiValueLikeClause(stockCategory, "ic.parent", "stockCategory", args) - val stockSubCategorySql = buildMultiValueLikeClause(stockSubCategory, "ic.sub", "stockSubCategory", args) + val stockCategorySql = buildMultiValueExactClause(stockCategory, "it.type", "stockCategory", args) val itemCodeSql = buildMultiValueLikeClause(itemCode, "it.code", "itemCode", args) - val yearSql = if (!year.isNullOrBlank()) { - args["year"] = year - "AND YEAR(sil.receiptDate) = :year" - } else { - "" - } - val lastInDateStartSql = if (!lastInDateStart.isNullOrBlank()) { args["lastInDateStart"] = lastInDateStart "AND sil.receiptDate >= :lastInDateStart" @@ -363,51 +353,49 @@ return result val sql = """ SELECT - COALESCE(ic.sub, '') as stockSubCategory, COALESCE(it.code, '') as itemNo, - COALESCE(CONCAT(COALESCE(it.name, ''), ' ', COALESCE(it.description, '')), '') as itemName, + COALESCE(it.name, '') as itemName, COALESCE(uc.code, '') as unitOfMeasure, COALESCE(sil.dnNo, '') as dnNo, COALESCE(sil.lotNo, il.lotNo, '') as lotNo, COALESCE(DATE_FORMAT(COALESCE(sil.expiryDate, il.expiryDate), '%Y-%m-%d'), '') as expiryDate, - CAST(COALESCE(sil.acceptedQty, 0) AS CHAR) as stockInQty, - CAST(COALESCE(sil.acceptedQty, 0) AS CHAR) as iqcSampleQty, - CAST(COALESCE(qr.failQty, 0) AS CHAR) as iqcDefectQty, - CAST(CASE + FORMAT(COALESCE(sil.acceptedQty, 0), 2) as stockInQty, + FORMAT(COALESCE(sil.acceptedQty, 0), 2) as iqcSampleQty, + FORMAT(COALESCE(qr.failQty, 0), 2) as iqcDefectQty, + FORMAT(CASE WHEN COALESCE(sil.acceptedQty, 0) > 0 THEN ROUND((COALESCE(qr.failQty, 0) / sil.acceptedQty) * 100, 2) ELSE 0 - END AS CHAR) as iqcDefectPercentage, + END, 2) as iqcDefectPercentage, CASE WHEN qr.qcPassed = true OR qr.qcPassed IS NULL THEN 'Accept' ELSE 'Reject' END as iqcResult, COALESCE(qr.remarks, '') as iqcRemarks, COALESCE(wh.code, '') as storeLocation, - COALESCE(sp.code, '') as supplierID, - COALESCE(sp.name, '') as supplierName, - CAST(SUM(COALESCE(sil.acceptedQty, 0)) OVER (PARTITION BY it.id) AS CHAR) as totalStockInQty, - CAST(SUM(COALESCE(sil.acceptedQty, 0)) OVER (PARTITION BY it.id) AS CHAR) as totalIqcSampleQty, - CAST(SUM(COALESCE(qr.failQty, 0)) OVER (PARTITION BY it.id) AS CHAR) as totalIqcDefectQty + COALESCE(sp_si.code, sp_po.code, '') as supplierID, + COALESCE(sp_si.name, sp_po.name, '') as supplierName, + FORMAT(SUM(COALESCE(sil.acceptedQty, 0)) OVER (PARTITION BY it.id), 2) as totalStockInQty, + FORMAT(SUM(COALESCE(sil.acceptedQty, 0)) OVER (PARTITION BY it.id), 2) as totalIqcSampleQty, + FORMAT(SUM(COALESCE(qr.failQty, 0)) OVER (PARTITION BY it.id), 2) as totalIqcDefectQty FROM stock_in_line sil LEFT JOIN stock_in si ON sil.stockInId = si.id + LEFT JOIN purchase_order po ON sil.purchaseOrderId = po.id LEFT JOIN items it ON sil.itemId = it.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 uom_conversion uc ON iu.uomId = uc.id LEFT JOIN qc_result qr ON sil.id = qr.stockInLineId LEFT JOIN inventory_lot il ON sil.inventoryLotId = il.id LEFT JOIN inventory_lot_line ill ON il.id = ill.inventoryLotId LEFT JOIN warehouse wh ON ill.warehouseId = wh.id - LEFT JOIN shop sp ON si.supplierId = sp.id + LEFT JOIN shop sp_si ON si.supplierId = sp_si.id + LEFT JOIN shop sp_po ON po.supplierId = sp_po.id WHERE sil.deleted = false $stockCategorySql - $stockSubCategorySql $itemCodeSql - $yearSql $lastInDateStartSql $lastInDateEndSql - ORDER BY ic.sub, it.code, sil.lotNo + ORDER BY it.code, sil.lotNo """.trimIndent() return jdbcDao.queryForList(sql, args) diff --git a/src/main/java/com/ffii/fpsms/modules/report/web/ReportController.kt b/src/main/java/com/ffii/fpsms/modules/report/web/ReportController.kt index 341bb97..997087d 100644 --- a/src/main/java/com/ffii/fpsms/modules/report/web/ReportController.kt +++ b/src/main/java/com/ffii/fpsms/modules/report/web/ReportController.kt @@ -83,19 +83,14 @@ class ReportController( @GetMapping("/print-stock-in-traceability") fun generateStockInTraceabilityReport( @RequestParam(required = false) stockCategory: String?, - @RequestParam(required = false) stockSubCategory: String?, @RequestParam(required = false) itemCode: String?, - @RequestParam(required = false) year: String?, @RequestParam(required = false) lastInDateStart: String?, @RequestParam(required = false) lastInDateEnd: String? ): ResponseEntity { val parameters = mutableMapOf() // Set report header parameters - parameters["stockCategory"] = stockCategory ?: "All" - parameters["stockSubCategory"] = stockSubCategory ?: "All" parameters["itemNo"] = itemCode ?: "All" - parameters["year"] = year ?: LocalDate.now().year.toString() parameters["reportDate"] = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) parameters["reportTime"] = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")) parameters["lastInDateStart"] = lastInDateStart ?: "" @@ -104,9 +99,7 @@ class ReportController( // Query the DB to get a list of data val dbData = reportService.searchStockInTraceabilityReport( stockCategory, - stockSubCategory, itemCode, - year, lastInDateStart, lastInDateEnd ) diff --git a/src/main/resources/jasper/StockInTraceabilityReport.jrxml b/src/main/resources/jasper/StockInTraceabilityReport.jrxml index c0171a7..b1dfa09 100644 --- a/src/main/resources/jasper/StockInTraceabilityReport.jrxml +++ b/src/main/resources/jasper/StockInTraceabilityReport.jrxml @@ -28,21 +28,21 @@ - - + + - - + + - - - + + + @@ -64,38 +64,29 @@ - + - - - - - - - - - - + - + - + - + - + @@ -103,31 +94,20 @@ - + - + - + - - - - - - - - - - - - + @@ -135,10 +115,10 @@ - + - + @@ -146,10 +126,10 @@ - + - + @@ -161,7 +141,7 @@ 缺陷數量]]> - + @@ -172,7 +152,7 @@ - + @@ -184,7 +164,7 @@ 編號]]> - + @@ -196,7 +176,7 @@ 樣品數量]]> - + @@ -207,7 +187,7 @@ - + @@ -218,7 +198,7 @@ - + @@ -226,10 +206,10 @@ - + - + @@ -240,7 +220,7 @@ - + @@ -252,7 +232,7 @@ 檢查結果]]> - + @@ -263,7 +243,7 @@ - + @@ -275,7 +255,7 @@ 檢查備註]]> - + @@ -287,7 +267,7 @@ 缺陷百分比]]> - + @@ -296,12 +276,12 @@ - + - + @@ -310,7 +290,7 @@ - + @@ -319,7 +299,7 @@ - + @@ -328,7 +308,7 @@ - + @@ -351,72 +331,35 @@ - - <band height="85" splitType="Stretch"> - <staticText> - <reportElement x="288" y="0" width="226" height="23" uuid="15ab756b-0e92-466c-be47-112c2ee1aad1"> - <property name="com.jaspersoft.studio.unit.y" value="px"/> - <property name="com.jaspersoft.studio.unit.height" value="px"/> - </reportElement> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="16" isBold="true"/> - </textElement> - <text><![CDATA[Stock In Traceability Report -]]></text> - </staticText> - <staticText> - <reportElement x="0" y="35" width="90" height="23" uuid="7338c712-b4ee-4194-9c37-07af197eee92"> - <property name="com.jaspersoft.studio.unit.y" value="px"/> + <pageHeader> + <band height="71" splitType="Stretch"> + <line> + <reportElement x="0" y="70" width="799" height="1" uuid="8628d83e-856d-44d2-9454-b6d048e6ecae"> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="16" isBold="true"/> - </textElement> - <text><![CDATA[報告日期:]]></text> - </staticText> + </line> <staticText> - <reportElement x="0" y="58" width="90" height="23" uuid="84d51895-1f38-40bc-a2f8-ad5979628d51"> + <reportElement x="760" y="0" width="20" height="18" uuid="c612993d-f309-41f0-bda2-abc0a7d5a3b5"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> - <textElement textAlignment="Left" verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="16" isBold="true"/> + <textElement textAlignment="Center" verticalAlignment="Middle"> + <font fontName="微軟正黑體" size="12"/> </textElement> - <text><![CDATA[貨物分類:]]></text> + <text><![CDATA[/]]></text> </staticText> - <textField> - <reportElement x="90" y="35" width="390" height="23" uuid="ff7dd53c-f505-4615-bed4-107d0f053ffe"/> - <textElement verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="16" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA[$P{reportDate}]]></textFieldExpression> - </textField> - <textField> - <reportElement x="90" y="58" width="708" height="23" uuid="451b69eb-de5f-49e6-b8ba-d579f51e9658"/> - <textElement> - <font fontName="微軟正黑體" size="16" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA[$P{stockCategory}]]></textFieldExpression> - </textField> <staticText> - <reportElement x="480" y="35" width="90" height="23" uuid="465d0d50-d1f6-49e2-966a-86c87294e1c3"> + <reportElement x="335" y="0" width="100" height="23" uuid="15ab756b-0e92-466c-be47-112c2ee1aad1"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <textElement textAlignment="Left" verticalAlignment="Middle"> <font fontName="微軟正黑體" size="16" isBold="true"/> </textElement> - <text><![CDATA[報告時間:]]></text> + <text><![CDATA[入倉記錄報告]]></text> </staticText> - <textField> - <reportElement x="570" y="35" width="228" height="23" uuid="bf131b2e-1da1-411a-b247-97280b89de21"/> - <textElement verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="16" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA[$P{reportTime}]]></textFieldExpression> - </textField> <textField evaluationTime="Report"> - <reportElement x="780" y="12" width="20" height="18" uuid="ad15e154-51b2-4775-8b7e-3cf2d3bc8da9"> + <reportElement x="780" y="0" width="20" height="18" uuid="ad15e154-51b2-4775-8b7e-3cf2d3bc8da9"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> @@ -425,28 +368,25 @@ </textElement> <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression> </textField> - <staticText> - <reportElement x="760" y="12" width="20" height="18" uuid="c612993d-f309-41f0-bda2-abc0a7d5a3b5"> - <property name="com.jaspersoft.studio.unit.y" value="px"/> - <property name="com.jaspersoft.studio.unit.height" value="px"/> - </reportElement> - <textElement textAlignment="Center" verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="12"/> + <textField> + <reportElement x="570" y="23" width="230" height="22" uuid="bf131b2e-1da1-411a-b247-97280b89de21"/> + <textElement verticalAlignment="Middle"> + <font fontName="微軟正黑體" size="14" isBold="true"/> </textElement> - <text><![CDATA[/]]></text> - </staticText> + <textFieldExpression><![CDATA[$P{reportTime}]]></textFieldExpression> + </textField> <staticText> - <reportElement x="700" y="12" width="40" height="18" uuid="375abc61-d5a7-4b06-8f95-b2ce305302c6"> + <reportElement x="0" y="23" width="100" height="22" uuid="7338c712-b4ee-4194-9c37-07af197eee92"> <property name="com.jaspersoft.studio.unit.y" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> - <textElement textAlignment="Center" verticalAlignment="Middle"> - <font fontName="微軟正黑體" size="12"/> + <textElement textAlignment="Left" verticalAlignment="Middle"> + <font fontName="微軟正黑體" size="14" isBold="true"/> </textElement> - <text><![CDATA[頁數]]></text> + <text><![CDATA[報告日期:]]></text> </staticText> <textField> - <reportElement x="740" y="12" width="20" height="18" uuid="c58d1f01-d047-414b-8436-b173dcb58d48"> + <reportElement x="740" y="0" width="20" height="18" uuid="c58d1f01-d047-414b-8436-b173dcb58d48"> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <textElement textAlignment="Center" verticalAlignment="Middle"> @@ -454,89 +394,59 @@ </textElement> <textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression> </textField> - <line> - <reportElement x="0" y="84" width="800" height="1" uuid="51721ea2-ec7b-4532-9e60-4903d8400cc8"> - <property name="com.jaspersoft.studio.unit.height" value="px"/> - </reportElement> - </line> - </band> - - - + + + + + + + - + - - + + - + - - + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - + - - + + - - - - - - - - - - + - + @@ -545,7 +455,7 @@ - + @@ -554,14 +464,14 @@ - + - + @@ -570,7 +480,7 @@ - + @@ -579,7 +489,7 @@ - + @@ -588,7 +498,7 @@ - + @@ -597,7 +507,7 @@ - + @@ -606,7 +516,7 @@ - + @@ -615,7 +525,7 @@ - + @@ -624,7 +534,7 @@ - + @@ -633,7 +543,7 @@ - +