From 037f5aa288a74c3eb236b607ec945d29ea5dcf31 Mon Sep 17 00:00:00 2001 From: "Tommy\\2Fi-Staff" Date: Tue, 14 Apr 2026 22:54:16 +0800 Subject: [PATCH] DNcartonLabel update, report excels fix --- .../modules/report/service/ReportService.kt | 19 +- .../modules/report/web/ReportController.kt | 48 ++- .../report/web/StockLedgerReportController.kt | 5 +- .../DeliveryNoteCartonLabelsPDF.jrxml | 352 +++++++++--------- 4 files changed, 228 insertions(+), 196 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 26fea5e..ffac33c 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 @@ -236,6 +236,7 @@ FORMAT(ROUND(IFNULL(IFNULL(sol.qty, dol.qty), 0), 0), 0) AS qty, WHERE dpolr.deleted = 0 AND (dpor.id IS NULL OR dpor.ticket_status = 'completed') + AND COALESCE(sol.qty, dol.qty, 0) <> 0 $stockCategorySql $stockSubCategorySql $itemCodeSql @@ -250,24 +251,6 @@ FORMAT(ROUND(IFNULL(IFNULL(sol.qty, dol.qty), 0), 0), 0) AS qty, """.trimIndent() val result = jdbcDao.queryForList(sql, args) - -// 打印查询结果(前 10 行) -println("=== Query Result (Total: ${result.size} rows) ===") -result.take(50).forEachIndexed { index, row -> - println("Row $index:") - println(" deliveryDate: ${row["deliveryDate"]}") - println(" itemNo: ${row["itemNo"]}") - println(" itemName: ${row["itemName"]}") - println(" qty: ${row["qty"]}") - println(" qtyNumeric: ${row["qtyNumeric"]}") - println(" deliveryOrderNo: ${row["deliveryOrderNo"]}") - println(" dnNo: ${row["dnNo"]}") - println(" stockSubCategory: ${row["stockSubCategory"]}") - println(" ---") -} -if (result.size > 50) { - println("... (showing first 10 rows, total ${result.size} rows)") -} return result 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 4e45548..dd3b9af 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 @@ -773,7 +773,46 @@ class ReportController( r.createCell(c).apply { setCellValue("-"); cellStyle = styles.text } } } else { - dbData.forEach { m -> + fun addDeliveryOrderTotalRow(totalQty: Double) { + val r = sheet.createRow(rowIndex++) + for (c in 0 until totalColumns) { + r.createCell(c).apply { + setCellValue("") + cellStyle = styles.sumEmpty + } + } + r.getCell(6).apply { + setCellValue("每單交貨總數:") + cellStyle = styles.sumLabel + } + r.getCell(7).apply { + setCellValue(totalQty) + cellStyle = styles.sumQty + } + } + + // Jasper `totalDeliveredQtyPerDeliveryOrder` is reset by Group1 = itemNo. + // Keep Excel consistent: sort by itemNo then calculate per-item total. + val sorted = dbData.sortedWith( + compareBy>( + { it["itemNo"]?.toString().orEmpty() }, + { it["deliveryDate"]?.toString().orEmpty() }, + { it["dnNo"]?.toString().orEmpty() }, + { it["deliveryOrderNo"]?.toString().orEmpty() }, + ), + ) + + var currentItemNo: String? = null + var itemTotalQty = 0.0 + + sorted.forEach { m -> + val itemNo = m["itemNo"]?.toString().orEmpty() + if (currentItemNo != null && itemNo != currentItemNo) { + addDeliveryOrderTotalRow(itemTotalQty) + sheet.createRow(rowIndex++) + itemTotalQty = 0.0 + } + val r = sheet.createRow(rowIndex++) setTextCell(r, 0, m["itemNo"], styles.text) setTextCell(r, 1, m["itemName"], styles.text) @@ -784,6 +823,13 @@ class ReportController( setTextCell(r, 6, m["customerName"], styles.text) setNumberCellFromFormatted(r, 7, m["qty"], styles.int, styles.dash, preferInt = true) setTextCell(r, 8, m["truckNo"], styles.center) + + itemTotalQty += parseSignedNumber(m["qty"]) ?: 0.0 + currentItemNo = itemNo + } + + if (!currentItemNo.isNullOrBlank()) { + addDeliveryOrderTotalRow(itemTotalQty) } } diff --git a/src/main/java/com/ffii/fpsms/modules/report/web/StockLedgerReportController.kt b/src/main/java/com/ffii/fpsms/modules/report/web/StockLedgerReportController.kt index bb43295..e7baa83 100644 --- a/src/main/java/com/ffii/fpsms/modules/report/web/StockLedgerReportController.kt +++ b/src/main/java/com/ffii/fpsms/modules/report/web/StockLedgerReportController.kt @@ -373,7 +373,10 @@ fun generateStockLedgerReport( setTextCell(r, 1, itemName, styles.text) setTextCell(r, 2, uom, styles.center) setTextCell(r, 3, m["trnDate"], styles.center) - setTextCell(r, 4, m["trnRefNo"], styles.center) + val typeText = m["trnRefNo"]?.toString()?.trim().orEmpty().let { t -> + if (t.equals("Expiry", ignoreCase = true)) "過期" else t + } + setTextCell(r, 4, typeText, styles.center) setTextCell(r, 5, m["lotNo"], styles.text) setTextCell(r, 6, m["expiryDate"], styles.center) setIntCellFromFormatted(r, 7, m["cumOpeningBal"], styles.int, styles.dash) diff --git a/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml b/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml index 953bdd4..e014b29 100644 --- a/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml +++ b/src/main/resources/DeliveryNote/DeliveryNoteCartonLabelsPDF.jrxml @@ -1,180 +1,180 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +