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 1b8f30b..446e609 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 @@ -524,11 +524,12 @@ open class ProductionScheduleService( private fun saveDetailedScheduleLineToDatabase(parentId: Long, detailedScheduleObj: ProductionScheduleRecord) { try { val prodSchedule = productionScheduleRepository.findById(parentId).get() + val item = detailedScheduleObj.item.id?.let { itemService.findById(it) } ?: Items() var savedItem = ProductionScheduleLine() savedItem.id = -1; // savedItem.prodScheduleId = parentId; savedItem.productionSchedule = prodSchedule; - savedItem.item.id = detailedScheduleObj.item.id ?: -1; + savedItem.item = item; savedItem.lastMonthAvgSales = detailedScheduleObj.lastMonthAvgSales ?: 0.0; savedItem.refScheduleId = detailedScheduleObj.id; savedItem.approverId = null; @@ -869,11 +870,12 @@ open class ProductionScheduleService( for (i in 5 until 12) { try { val prodSchedule = productionScheduleRepository.findById(parentId).get() + val item = roughScheduleObj.fgDetail?.id?.let { itemService.findById(it) } ?: Items() var savedItem = ProductionScheduleLine() savedItem.id = -1; // savedItem.prodScheduleId = parentId; savedItem.productionSchedule = prodSchedule; - savedItem.item.id = roughScheduleObj.fgDetail?.id ?: -1; + savedItem.item = item; savedItem.lastMonthAvgSales = roughScheduleObj.fgDetail?.lastMonthAvgSalesCount ?: 0.0; savedItem.refScheduleId = null; savedItem.approverId = null; diff --git a/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt b/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt index 1349d78..747ee4b 100644 --- a/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt +++ b/src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt @@ -16,7 +16,9 @@ import jakarta.servlet.http.HttpServletRequest import jakarta.validation.Valid import org.springframework.web.bind.annotation.* import java.time.Duration +import java.time.LocalDate import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import java.util.HashMap import kotlin.collections.component1 import kotlin.collections.component2 @@ -34,6 +36,7 @@ class ProductionScheduleController( // return uomConversionService.allItems() // } + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); @GetMapping("/test") fun test(request: HttpServletRequest): Any { val criteriaArgs = CriteriaArgsBuilder.withRequest(request) @@ -76,18 +79,23 @@ class ProductionScheduleController( fun generateDetailSchedule(request: HttpServletRequest?): Int { try { // For test - val genDate = request?.getParameter("genDate")?.let { LocalDateTime.parse(it) } + val genDate = request?.getParameter("genDate")?.let { LocalDate.parse(it).atStartOfDay() } + println(request) val today = LocalDateTime.now() val latestRoughScheduleAt = productionScheduleService.getLatestScheduleAt("rough") - val assignDate = abs(Duration.between(latestRoughScheduleAt, today).toDays() % 7) + 1 + + // assume schedule period is sunday to saturday + val assignDate = (genDate ?: today).dayOfWeek.value + +// val assignDate = abs(Duration.between(latestRoughScheduleAt, today).toDays() % 7) + 1 // val finalAssignDate = if (assignDate.toInt() == 0) { // 1 // } else assignDate.toInt() //TODO: update this to receive selectedDate and assignDate from schedule // productionScheduleService.generateDetailedScheduleByDay(1, LocalDateTime.of(2025,6,25,0,0,0)) - println("today: $today | latestRoughScheduleAty: $latestRoughScheduleAt | assignDate: $assignDate ") - productionScheduleService.generateDetailedScheduleByDay(assignDate.toInt(), genDate ?: LocalDateTime.now()) + println("genDate: $genDate | today: $today | latestRoughScheduleAty: $latestRoughScheduleAt | assignDate: $assignDate ") + productionScheduleService.generateDetailedScheduleByDay(assignDate, genDate ?: LocalDateTime.now()) return 200 } catch (e: Exception) { throw RuntimeException("Error generate schedule: ${e.message}", e)