From ae53c10a6a9e4fadcf9ea0f624cb78cdc5ce1087 Mon Sep 17 00:00:00 2001 From: Fai Luk Date: Sat, 14 Mar 2026 03:57:32 +0800 Subject: [PATCH] fix the prod qty in forecast --- .../master/service/ProductionScheduleService.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt b/src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt index 0975d9b..c23f8c4 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt @@ -432,11 +432,11 @@ open class ProductionScheduleService( val bom = bomService.findByItemId(itemId) ?: throw NoSuchElementException("BOM not found for Item ID $itemId.") - // 4. Update Prod Schedule Line fields + // 4. Update Prod Schedule Line fields (keep prodQty = total = outputQty * batchNeed) + val outputQtyDouble = bom.outputQty?.toDouble() + ?: throw IllegalStateException("BOM output quantity is null for Item ID $itemId.") prodScheduleLine.apply { - // Use bom.outputQty, ensuring it's treated as Double for prodQty - prodQty = bom.outputQty?.toDouble() - ?: throw IllegalStateException("BOM output quantity is null for Item ID $itemId.") + prodQty = outputQtyDouble * batchNeed.toLong().coerceAtLeast(0) approverId = approver?.id } @@ -966,7 +966,8 @@ open class ProductionScheduleService( savedItem.refScheduleId = detailedScheduleObj.id; savedItem.approverId = null; savedItem.estCloseBal = detailedScheduleObj.outputQty; - savedItem.prodQty = detailedScheduleObj.outputQty + // prodQty = total production = batchQty (outputQty per batch) * batchNeed + savedItem.prodQty = detailedScheduleObj.outputQty * detailedScheduleObj.batchNeed.toInt().coerceAtLeast(0) savedItem.type = "detailed" savedItem.assignDate = LocalDateTime.now().dayOfMonth.toLong(); savedItem.weightingRef = detailedScheduleObj.needQty