From 4ba583fddd0a7dfbd514e366d5508c6fa1c3de1b Mon Sep 17 00:00:00 2001 From: "Tommy\\2Fi-Staff" Date: Mon, 16 Mar 2026 02:39:47 +0800 Subject: [PATCH] reports update --- .../modules/report/service/ReportService.kt | 8 ++++++-- .../service/StockTakeVarianceReportService.kt | 10 +++++----- .../web/StockTakeVarianceReportController.kt | 16 ++++++++-------- .../jasper/StockItemConsumptionTrendReport.jrxml | 2 +- .../jasper/StockTakeVarianceReport.jrxml | 2 +- 5 files changed, 21 insertions(+), 17 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 dce6b60..5d9d980 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 @@ -876,12 +876,16 @@ fun searchMaterialStockOutTraceabilityReport( CASE WHEN COALESCE(item_agg.totalMisInputAndLost, 0) < 0 THEN CONCAT('(', FORMAT(-item_agg.totalMisInputAndLost, 0), ')') ELSE FORMAT(COALESCE(item_agg.totalMisInputAndLost, 0), 0) END as totalMisInputAndLost, CASE WHEN COALESCE(item_agg.totalVariance, 0) < 0 THEN CONCAT('(', FORMAT(-item_agg.totalVariance, 0), ')') ELSE FORMAT(COALESCE(item_agg.totalVariance, 0), 0) END as totalVariance, CASE WHEN COALESCE(item_agg.totalDefectiveGoods, 0) < 0 THEN CONCAT('(', FORMAT(-item_agg.totalDefectiveGoods, 0), ')') ELSE FORMAT(COALESCE(item_agg.totalDefectiveGoods, 0), 0) END as totalDefectiveGoods, - FORMAT(ROUND(COALESCE(item_agg.total_in_value, 0) - COALESCE(item_agg.total_out_value, 0), 2), 2) as totalStockBalance, CASE WHEN COALESCE(item_agg.totalCurrentBalance, 0) > 0 THEN FORMAT(ROUND((COALESCE(item_agg.total_in_value, 0) - COALESCE(item_agg.total_out_value, 0)) / item_agg.totalCurrentBalance, 2), 2) ELSE '0.00' - END as avgUnitPrice + END as avgUnitPrice, + CASE + WHEN COALESCE(item_agg.totalCurrentBalance, 0) > 0 + THEN FORMAT(ROUND(item_agg.totalCurrentBalance * (COALESCE(item_agg.total_in_value, 0) - COALESCE(item_agg.total_out_value, 0)) / item_agg.totalCurrentBalance, 2), 2) + ELSE '0.00' + END as totalStockBalance FROM ( SELECT agg.itemCode AS itemNo, diff --git a/src/main/java/com/ffii/fpsms/modules/report/service/StockTakeVarianceReportService.kt b/src/main/java/com/ffii/fpsms/modules/report/service/StockTakeVarianceReportService.kt index 2986ec6..c4cdbec 100644 --- a/src/main/java/com/ffii/fpsms/modules/report/service/StockTakeVarianceReportService.kt +++ b/src/main/java/com/ffii/fpsms/modules/report/service/StockTakeVarianceReportService.kt @@ -38,8 +38,8 @@ open class StockTakeVarianceReportService( stockCategory: String?, itemCode: String?, storeLocation: String?, - lastInDateStart: String?, // 前端 startDateStart - lastInDateEnd: String?, // 前端 startDateEnd + stockTakeDateStart: String?, + stockTakeDateEnd: String?, ): List> { val args = mutableMapOf() @@ -64,12 +64,12 @@ open class StockTakeVarianceReportService( } // 1) toDate:有填用傳入,沒填用今天 - val toDate = (lastInDateEnd?.replace("/", "-") + val toDate = (stockTakeDateEnd?.replace("/", "-") ?: LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) // 2) fromDate:有填用傳入,沒填查 stock_ledger 最早日期 - val fromDate = if (!lastInDateStart.isNullOrBlank()) { - lastInDateStart.replace("/", "-") + val fromDate = if (!stockTakeDateStart.isNullOrBlank()) { + stockTakeDateStart.replace("/", "-") } else { val minDateSql = """ SELECT DATE_FORMAT(MIN(sl.date), '%Y-%m-%d') AS firstDate diff --git a/src/main/java/com/ffii/fpsms/modules/report/web/StockTakeVarianceReportController.kt b/src/main/java/com/ffii/fpsms/modules/report/web/StockTakeVarianceReportController.kt index 1a694ab..4bd9159 100644 --- a/src/main/java/com/ffii/fpsms/modules/report/web/StockTakeVarianceReportController.kt +++ b/src/main/java/com/ffii/fpsms/modules/report/web/StockTakeVarianceReportController.kt @@ -28,15 +28,15 @@ class StockTakeVarianceReportController( * - stockCategory * - itemCode * - storeLocation - * - lastInDateStart / lastInDateEnd + * - stockTakeDateStart / stockTakeDateEnd */ @GetMapping("/print-stock-take-variance") fun generateStockTakeVarianceReport( @RequestParam(required = false) stockCategory: String?, @RequestParam(required = false) itemCode: String?, @RequestParam(required = false) storeLocation: String?, - @RequestParam(required = false) lastInDateStart: String?, - @RequestParam(required = false) lastInDateEnd: String?, + @RequestParam(required = false) stockTakeDateStart: String?, + @RequestParam(required = false) stockTakeDateEnd: String?, ): ResponseEntity { val parameters = mutableMapOf() @@ -51,9 +51,9 @@ class StockTakeVarianceReportController( parameters["balanceFilterStart"] = "" parameters["balanceFilterEnd"] = "" - parameters["lastInDateStart"] = lastInDateStart ?: "" - parameters["lastInDateEnd"] = lastInDateEnd ?: "" - parameters["lastOutDateStart"] = "" + parameters["stockTakeDateStart"] = stockTakeDateStart ?: "" + parameters["stockTakeDateEnd"] = stockTakeDateEnd ?: "" + parameters["lastInDateEnd"] = "" parameters["lastOutDateEnd"] = "" @@ -62,8 +62,8 @@ class StockTakeVarianceReportController( stockCategory = stockCategory, itemCode = itemCode, storeLocation = storeLocation, - lastInDateStart = lastInDateStart, - lastInDateEnd = lastInDateEnd, + stockTakeDateStart = stockTakeDateStart, + stockTakeDateEnd = stockTakeDateEnd, ) val stockTakeDateDisplay = dbData .mapNotNull { it["stockTakeDate"] as? String } diff --git a/src/main/resources/jasper/StockItemConsumptionTrendReport.jrxml b/src/main/resources/jasper/StockItemConsumptionTrendReport.jrxml index 51411c0..97e2741 100644 --- a/src/main/resources/jasper/StockItemConsumptionTrendReport.jrxml +++ b/src/main/resources/jasper/StockItemConsumptionTrendReport.jrxml @@ -461,7 +461,7 @@ - + diff --git a/src/main/resources/jasper/StockTakeVarianceReport.jrxml b/src/main/resources/jasper/StockTakeVarianceReport.jrxml index 74b9632..bd69230 100644 --- a/src/main/resources/jasper/StockTakeVarianceReport.jrxml +++ b/src/main/resources/jasper/StockTakeVarianceReport.jrxml @@ -164,7 +164,7 @@ - +