From a0bf0a79f87cd7009e81453bd5c31ba31ccc3a57 Mon Sep 17 00:00:00 2001 From: "vluk@2fi-solutions.com.hk" Date: Thu, 18 Dec 2025 23:35:54 +0800 Subject: [PATCH] no message --- .../service/ProductionScheduleService.kt | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 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 a8706db..94adeb6 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 @@ -644,8 +644,8 @@ open class ProductionScheduleService( bom.itemId != 16771) AS i WHERE 1 and i.avgQtyLastMonth is not null - and i.onHandQty is not null - and (i.onHandQty -500) * 1.0 / i.avgQtyLastMonth <= 1.9 + and i.onHandQty is not null + -- and (i.onHandQty -500) * 1.0 / i.avgQtyLastMonth <= 1.9 -- and avgQtyLastMonth - (onHandQty - 500) > 0 """.trimIndent() @@ -716,7 +716,7 @@ open class ProductionScheduleService( updatedScheduleRecord.itemPriority = priority; - if (machineCap - prodDifference >= 0) { + if (updatedScheduleRecord.batchNeed.toInt() > 0) { //have enough quoter for adjustment machineCap -= prodDifference; detailedScheduleOutputList.add(updatedScheduleRecord) @@ -738,6 +738,37 @@ open class ProductionScheduleService( } saveDetailedScheduleOutput(sortedOutputList, accProdCount, fgCount, produceAt) + + //do for 7 days to predict + for (i in 1..6) { + fgCount = 0 + accProdCount = 0.0 + sortedOutputList.forEach { record -> + record.stockQty = record.stockQty + (record.outputQty * record.needNoOfJobOrder.toInt()) - record.avgQtyLastMonth + //compare if less than 1.9 days + record.daysLeft = record.stockQty / record.avgQtyLastMonth + + if(record.daysLeft <= 1.9){ + record.needQty = (record.avgQtyLastMonth * 2) - record.stockQty; + + if(record.needQty > 0.0){ + record.batchNeed = ceil(record.needQty / record.outputQty) + record.needNoOfJobOrder = record.batchNeed + + fgCount += 1 + accProdCount += record.outputQty * record.batchNeed.toInt() + }else{ + record.needNoOfJobOrder = 0 + record.batchNeed = 0 + } + } + + logger.info(record.name + " record.batchNeed: " + record.batchNeed + " record.stockQty:" + record.stockQty + " record.daysLeft:" + record.daysLeft) + + } + + saveDetailedScheduleOutputPredict(sortedOutputList, accProdCount, fgCount, produceAt.plusDays(i.toLong())) + } } open fun saveDetailedScheduleOutput( @@ -761,6 +792,27 @@ open class ProductionScheduleService( } } + open fun saveDetailedScheduleOutputPredict( + sortedEntries: List, + accProdCount: Double, + fgCount: Long, + produceAt: LocalDateTime, + ) { + val tempObj = ProductionSchedule() + tempObj.id = -1; + tempObj.scheduleAt = LocalDateTime.now() + tempObj.produceAt = produceAt; + tempObj.totalFGType = fgCount; + tempObj.totalEstProdCount = accProdCount; + tempObj.type = "detailed" + tempObj.id = saveProductionScheduleToDatabase(tempObj); + + for (detailedScheduleRecord in sortedEntries) { + if(detailedScheduleRecord.batchNeed.toInt() > 0) + saveDetailedScheduleLineToDatabase(tempObj.id ?: -1, detailedScheduleRecord) + } + } + private fun saveDetailedScheduleLineToDatabase(parentId: Long, detailedScheduleObj: NeedQtyRecord) { try { val prodSchedule = productionScheduleRepository.findById(parentId).get()