From 89b8480d5b8d5877b5fba507d4839fb86c6eaa6d Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Thu, 5 Jun 2025 17:55:44 +0800 Subject: [PATCH] update po --- .../enums/PurchaseOrderLineEnum.kt | 2 +- .../service/PurchaseOrderService.kt | 34 ++++++++++++++----- .../web/PurchaseOrderController.kt | 4 +++ .../entity/projection/StockInLineInfo.kt | 2 ++ .../stock/service/StockInLineService.kt | 27 ++++++++++----- .../stock/web/model/SaveStockInRequest.kt | 2 +- 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ffii/fpsms/modules/purchaseOrder/enums/PurchaseOrderLineEnum.kt b/src/main/java/com/ffii/fpsms/modules/purchaseOrder/enums/PurchaseOrderLineEnum.kt index 614b6f1..862df2e 100644 --- a/src/main/java/com/ffii/fpsms/modules/purchaseOrder/enums/PurchaseOrderLineEnum.kt +++ b/src/main/java/com/ffii/fpsms/modules/purchaseOrder/enums/PurchaseOrderLineEnum.kt @@ -2,7 +2,7 @@ package com.ffii.fpsms.modules.purchaseOrder.enums enum class PurchaseOrderLineStatus(val value: String) { PENDING("pending"), - PICKING("picking"), + RECEIVING("receiving"), COMPLETED("completed"); } diff --git a/src/main/java/com/ffii/fpsms/modules/purchaseOrder/service/PurchaseOrderService.kt b/src/main/java/com/ffii/fpsms/modules/purchaseOrder/service/PurchaseOrderService.kt index 9e07a12..1c58289 100644 --- a/src/main/java/com/ffii/fpsms/modules/purchaseOrder/service/PurchaseOrderService.kt +++ b/src/main/java/com/ffii/fpsms/modules/purchaseOrder/service/PurchaseOrderService.kt @@ -22,6 +22,8 @@ import com.ffii.fpsms.modules.stock.entity.StockInLineRepository import com.ffii.fpsms.modules.stock.entity.StockInRepository import com.ffii.fpsms.modules.stock.web.model.StockInLineStatus import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.io.IOException import java.util.HashMap import java.util.Objects import kotlin.jvm.optionals.getOrDefault @@ -31,7 +33,6 @@ import kotlin.jvm.optionals.getOrNull open class PurchaseOrderService( private val jdbcDao: JdbcDao, private val purchaseOrderRepository: PurchaseOrderRepository, - private val purchaseOrderLineRepository: PurchaseOrderLineRepository, private val polRepository: PurchaseOrderLineRepository, private val shopRepository: ShopRepository, private val m18DataLogRepository: M18DataLogRepository, @@ -89,6 +90,8 @@ open class PurchaseOrderService( return purchaseOrderRepository.findTopByM18DataLogIdAndDeletedIsFalseOrderByModifiedDesc(m18DataLogId) } + @Throws(IOException::class) + @Transactional open fun savePurchaseOrder(request: SavePurchaseOrderRequest): SavePurchaseOrderResponse { val purchaseOrder = request.id?.let { purchaseOrderRepository.findById(it).getOrDefault(PurchaseOrder()) } ?: PurchaseOrder() @@ -132,13 +135,28 @@ open class PurchaseOrderService( return savedPurchaseOrder } - - fun checkPolAndCompletePo(id: Long): MessageResponse { - val unfinishedLines = purchaseOrderLineRepository - .findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse( - purchaseOrderId = id, - status = PurchaseOrderLineStatus.COMPLETED - ) + @Throws(IOException::class) + @Transactional + open fun startPo(id: Long): MessageResponse { + val po = purchaseOrderRepository.findById(id).orElseThrow() + po.apply { + status = PurchaseOrderStatus.RECEIVING + } + val savedPo = purchaseOrderRepository.saveAndFlush(po) + return MessageResponse( + id = savedPo.id, + name = savedPo.code, + code = savedPo.code, + type = PurchaseOrderStatus.RECEIVING.value, + message = "Update Success", + errorPosition = null, + entity = savedPo, + ) + } + @Throws(IOException::class) + @Transactional + open fun checkPolAndCompletePo(id: Long): MessageResponse { + val unfinishedLines = polRepository.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(purchaseOrderId = id, status = PurchaseOrderLineStatus.COMPLETED) val po = purchaseOrderRepository.findById(id).orElseThrow() if (unfinishedLines.isEmpty()) { po.apply { diff --git a/src/main/java/com/ffii/fpsms/modules/purchaseOrder/web/PurchaseOrderController.kt b/src/main/java/com/ffii/fpsms/modules/purchaseOrder/web/PurchaseOrderController.kt index c77f4d6..fd1b6d7 100644 --- a/src/main/java/com/ffii/fpsms/modules/purchaseOrder/web/PurchaseOrderController.kt +++ b/src/main/java/com/ffii/fpsms/modules/purchaseOrder/web/PurchaseOrderController.kt @@ -23,6 +23,10 @@ class PurchaseOrderController( return purchaseOrderService.getDetailedPo(id) } + @PostMapping("/start/{id}") // purchaseOrderId + fun startPo(@PathVariable id: Long): MessageResponse { + return purchaseOrderService.startPo(id) + } @PostMapping("/check/{id}") // purchaseOrderId fun checkPolAndCompletePo(@PathVariable id: Long): MessageResponse { return purchaseOrderService.checkPolAndCompletePo(id) diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/StockInLineInfo.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/StockInLineInfo.kt index 9bd87bb..4a31932 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/StockInLineInfo.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/projection/StockInLineInfo.kt @@ -23,6 +23,8 @@ interface StockInLineInfo { val acceptedQty: BigDecimal val price: BigDecimal? val priceUnit: BigDecimal? + @get:Value("#{target.item?.shelfLife}") + val shelfLife: Double? val receiptDate: LocalDateTime? val productionDate: LocalDateTime? val expiryDate: LocalDate? diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt index c2a54cb..9f36ab9 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt @@ -64,8 +64,20 @@ open class StockInLineService( val stockInLine = StockInLine() val item = itemRepository.findById(request.itemId).orElseThrow() val purchaseOrderLine = polRepository.findById(request.purchaseOrderLineId).orElseThrow() - val stockIn = stockInRepository.findByPurchaseOrderIdAndDeletedFalse(request.purchaseOrderId) - ?: stockInService.create(SaveStockInRequest(purchaseOrderId = request.purchaseOrderId)).entity as StockIn + var stockIn = stockInRepository.findByPurchaseOrderIdAndDeletedFalse(request.purchaseOrderId) + purchaseOrderLine.apply { + status = PurchaseOrderLineStatus.RECEIVING + } + polRepository.saveAndFlush(purchaseOrderLine) + if (stockIn == null) { + stockIn = stockInService.create(SaveStockInRequest(purchaseOrderId = request.purchaseOrderId)).entity as StockIn + // update po status to receiving + val po = purchaseOrderRepository.findById(request.purchaseOrderId).orElseThrow() + po.apply { + status = PurchaseOrderStatus.RECEIVING + } + purchaseOrderRepository.save(po) + } stockInLine.apply { this.item = item itemNo = item.code @@ -112,6 +124,7 @@ open class StockInLineService( @Transactional fun saveInventoryLotLineWhenStockIn(request: SaveStockInLineRequest, stockInLine: StockInLine): InventoryLotLine { val inventoryLotLine = InventoryLotLine() + println(request.warehouseId!!) val warehouse = warehouseRepository.findById(request.warehouseId!!).orElseThrow() inventoryLotLine.apply { this.inventoryLot = stockInLine.inventoryLot @@ -148,10 +161,8 @@ open class StockInLineService( @Transactional fun updatePurchaseOrderStatus(request: SaveStockInLineRequest) { if (request.status == StockInLineStatus.COMPLETE.status) { - val unfinishedLines = polRepository.findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse( - purchaseOrderId = request.purchaseOrderId, - status = PurchaseOrderLineStatus.COMPLETED - ) + val unfinishedLines = polRepository + .findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(purchaseOrderId = request.purchaseOrderId, status = PurchaseOrderLineStatus.COMPLETED) if (unfinishedLines.isEmpty()) { val po = purchaseOrderRepository.findById(request.purchaseOrderId).orElseThrow() po.apply { @@ -223,7 +234,7 @@ open class StockInLineService( val savedStockInLine = saveAndFlush(stockInLine) // check if all line completed updatePurchaseOrderLineStatus(request) - updatePurchaseOrderStatus(request) +// updatePurchaseOrderStatus(request) // val allLineByStockInId = find val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) // println("checkpoint2") @@ -297,7 +308,7 @@ open class StockInLineService( val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) // check if all line completed updatePurchaseOrderLineStatus(request) - updatePurchaseOrderStatus(request) +// updatePurchaseOrderStatus(request) return MessageResponse( id = stockInLine.id, diff --git a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt index ea7e453..e93bf6a 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/web/model/SaveStockInRequest.kt @@ -29,7 +29,7 @@ data class SaveStockInRequest( val orderDate: Long? = null, val estimatedCompleteDate: LocalDateTime? = null, val completeDate: LocalDateTime? = null, - val status: LocalDateTime? = null, + val status: String? = null, val stockOutId: Long? = null, // val m18 )