| @@ -644,8 +644,8 @@ open class ProductionScheduleService( | |||||
| bom.itemId != 16771) AS i | bom.itemId != 16771) AS i | ||||
| WHERE 1 | WHERE 1 | ||||
| and i.avgQtyLastMonth is not null | 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 | -- and avgQtyLastMonth - (onHandQty - 500) > 0 | ||||
| """.trimIndent() | """.trimIndent() | ||||
| @@ -716,7 +716,7 @@ open class ProductionScheduleService( | |||||
| updatedScheduleRecord.itemPriority = priority; | updatedScheduleRecord.itemPriority = priority; | ||||
| if (machineCap - prodDifference >= 0) { | |||||
| if (updatedScheduleRecord.batchNeed.toInt() > 0) { | |||||
| //have enough quoter for adjustment | //have enough quoter for adjustment | ||||
| machineCap -= prodDifference; | machineCap -= prodDifference; | ||||
| detailedScheduleOutputList.add(updatedScheduleRecord) | detailedScheduleOutputList.add(updatedScheduleRecord) | ||||
| @@ -738,6 +738,37 @@ open class ProductionScheduleService( | |||||
| } | } | ||||
| saveDetailedScheduleOutput(sortedOutputList, accProdCount, fgCount, produceAt) | 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( | open fun saveDetailedScheduleOutput( | ||||
| @@ -761,6 +792,27 @@ open class ProductionScheduleService( | |||||
| } | } | ||||
| } | } | ||||
| open fun saveDetailedScheduleOutputPredict( | |||||
| sortedEntries: List<NeedQtyRecord>, | |||||
| 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) { | private fun saveDetailedScheduleLineToDatabase(parentId: Long, detailedScheduleObj: NeedQtyRecord) { | ||||
| try { | try { | ||||
| val prodSchedule = productionScheduleRepository.findById(parentId).get() | val prodSchedule = productionScheduleRepository.findById(parentId).get() | ||||