Browse Source

update prod schedule line (button)

master
cyril.tsui 1 month ago
parent
commit
6755a20839
2 changed files with 16 additions and 6 deletions
  1. +4
    -2
      src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt
  2. +12
    -4
      src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt

+ 4
- 2
src/main/java/com/ffii/fpsms/modules/master/service/ProductionScheduleService.kt View File

@@ -524,11 +524,12 @@ open class ProductionScheduleService(
private fun saveDetailedScheduleLineToDatabase(parentId: Long, detailedScheduleObj: ProductionScheduleRecord) { private fun saveDetailedScheduleLineToDatabase(parentId: Long, detailedScheduleObj: ProductionScheduleRecord) {
try { try {
val prodSchedule = productionScheduleRepository.findById(parentId).get() val prodSchedule = productionScheduleRepository.findById(parentId).get()
val item = detailedScheduleObj.item.id?.let { itemService.findById(it) } ?: Items()
var savedItem = ProductionScheduleLine() var savedItem = ProductionScheduleLine()
savedItem.id = -1; savedItem.id = -1;
// savedItem.prodScheduleId = parentId; // savedItem.prodScheduleId = parentId;
savedItem.productionSchedule = prodSchedule; savedItem.productionSchedule = prodSchedule;
savedItem.item.id = detailedScheduleObj.item.id ?: -1;
savedItem.item = item;
savedItem.lastMonthAvgSales = detailedScheduleObj.lastMonthAvgSales ?: 0.0; savedItem.lastMonthAvgSales = detailedScheduleObj.lastMonthAvgSales ?: 0.0;
savedItem.refScheduleId = detailedScheduleObj.id; savedItem.refScheduleId = detailedScheduleObj.id;
savedItem.approverId = null; savedItem.approverId = null;
@@ -869,11 +870,12 @@ open class ProductionScheduleService(
for (i in 5 until 12) { for (i in 5 until 12) {
try { try {
val prodSchedule = productionScheduleRepository.findById(parentId).get() val prodSchedule = productionScheduleRepository.findById(parentId).get()
val item = roughScheduleObj.fgDetail?.id?.let { itemService.findById(it) } ?: Items()
var savedItem = ProductionScheduleLine() var savedItem = ProductionScheduleLine()
savedItem.id = -1; savedItem.id = -1;
// savedItem.prodScheduleId = parentId; // savedItem.prodScheduleId = parentId;
savedItem.productionSchedule = prodSchedule; savedItem.productionSchedule = prodSchedule;
savedItem.item.id = roughScheduleObj.fgDetail?.id ?: -1;
savedItem.item = item;
savedItem.lastMonthAvgSales = roughScheduleObj.fgDetail?.lastMonthAvgSalesCount ?: 0.0; savedItem.lastMonthAvgSales = roughScheduleObj.fgDetail?.lastMonthAvgSalesCount ?: 0.0;
savedItem.refScheduleId = null; savedItem.refScheduleId = null;
savedItem.approverId = null; savedItem.approverId = null;


+ 12
- 4
src/main/java/com/ffii/fpsms/modules/master/web/ProductionScheduleController.kt View File

@@ -16,7 +16,9 @@ import jakarta.servlet.http.HttpServletRequest
import jakarta.validation.Valid import jakarta.validation.Valid
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
import java.time.Duration import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.HashMap import java.util.HashMap
import kotlin.collections.component1 import kotlin.collections.component1
import kotlin.collections.component2 import kotlin.collections.component2
@@ -34,6 +36,7 @@ class ProductionScheduleController(
// return uomConversionService.allItems() // return uomConversionService.allItems()
// } // }


val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@GetMapping("/test") @GetMapping("/test")
fun test(request: HttpServletRequest): Any { fun test(request: HttpServletRequest): Any {
val criteriaArgs = CriteriaArgsBuilder.withRequest(request) val criteriaArgs = CriteriaArgsBuilder.withRequest(request)
@@ -76,18 +79,23 @@ class ProductionScheduleController(
fun generateDetailSchedule(request: HttpServletRequest?): Int { fun generateDetailSchedule(request: HttpServletRequest?): Int {
try { try {
// For test // 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 today = LocalDateTime.now()
val latestRoughScheduleAt = productionScheduleService.getLatestScheduleAt("rough") 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) { // val finalAssignDate = if (assignDate.toInt() == 0) {
// 1 // 1
// } else assignDate.toInt() // } else assignDate.toInt()
//TODO: update this to receive selectedDate and assignDate from schedule //TODO: update this to receive selectedDate and assignDate from schedule
// productionScheduleService.generateDetailedScheduleByDay(1, LocalDateTime.of(2025,6,25,0,0,0)) // 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 return 200
} catch (e: Exception) { } catch (e: Exception) {
throw RuntimeException("Error generate schedule: ${e.message}", e) throw RuntimeException("Error generate schedule: ${e.message}", e)


Loading…
Cancel
Save