From d56c22945feadc84d1fe1b7a19e2bfe405634ce7 Mon Sep 17 00:00:00 2001 From: kelvinsuen Date: Tue, 19 Aug 2025 19:51:27 +0800 Subject: [PATCH] update stock in --- .../service/PurchaseOrderService.kt | 1 + .../qc/web/model/SaveQcResultRequest.kt | 2 +- .../entity/projection/StockInLineInfo.kt | 2 +- .../stock/service/StockInLineService.kt | 289 +++++++++--------- .../stock/web/model/SaveStockInRequest.kt | 2 + 5 files changed, 157 insertions(+), 139 deletions(-) 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 f04f3f7..6e63b51 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 @@ -184,6 +184,7 @@ open class PurchaseOrderService( } val mappedPoLine = pol.map { thisPol -> val inLine = stockInLine.filter { it.purchaseOrderLineId == thisPol.id } + .filter { it.dnDate != null } val categoryCode = thisPol.item?.qcCategory?.code val qcItems = thisPol.item?.qcCategory?.qcItemCategory?.map { QcForPoLine( diff --git a/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt b/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt index 9d395a4..bda1695 100644 --- a/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt +++ b/src/main/java/com/ffii/fpsms/modules/qc/web/model/SaveQcResultRequest.kt @@ -3,7 +3,7 @@ package com.ffii.fpsms.modules.qc.web.model data class SaveQcResultRequest( val id: Long?, val qcItemId: Long, - val itemId: Long, + val itemId: Long?, val stockInLineId: Long?, val stockOutLineId: Long?, val failQty: Double, 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 7ac6281..8bb625a 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 @@ -44,5 +44,5 @@ interface StockInLineInfo { @get:Value("#{target.item?.type}") val itemType: String val dnNo: String - val dnDate: LocalDateTime + val dnDate: LocalDateTime? } \ No newline at end of file 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 892c451..9450014 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 @@ -57,12 +57,12 @@ open class StockInLineService( private val itemRepository: ItemsRepository, private val warehouseRepository: WarehouseRepository, private val itemUomRespository: ItemUomRespository, - ): AbstractBaseEntityService(jdbcDao, stockInLineRepository) { +): AbstractBaseEntityService(jdbcDao, stockInLineRepository) { open fun getStockInLineInfo(stockInLineId: Long): StockInLineInfo { return stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(stockInLineId) } - open fun getReceiveedStockInLineInfo(stockInLineId: Long): StockInLineInfo { + open fun getReceivedStockInLineInfo(stockInLineId: Long): StockInLineInfo { return stockInLineRepository.findStockInLineInfoByIdAndStatusAndDeletedFalse(id = stockInLineId, status = StockInLineStatus.RECEIVED.status).orElseThrow() } @Throws(IOException::class) @@ -144,9 +144,9 @@ open class StockInLineService( itemId = request.itemId ) val convertedBaseQty = if (stockItemUom != null) { - request.acceptedQty * stockItemUom.ratioN!! / stockItemUom.ratioD!! + (request.acceptQty?:request.acceptedQty) * stockItemUom.ratioN!! / stockItemUom.ratioD!! } else { - request.acceptedQty + (request.acceptQty?:request.acceptedQty) } inventoryLotLine.apply { this.inventoryLot = stockInLine.inventoryLot @@ -203,12 +203,12 @@ open class StockInLineService( println(request.status) if (request.status == StockInLineStatus.RECEIVING.status) { val unQcedLines = stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(purchaseOrderLineId = request.purchaseOrderLineId) - .filter { - it.status != StockInLineStatus.RECEIVING.status - && it.status != StockInLineStatus.RECEIVED.status - && it.status != StockInLineStatus.COMPLETE.status - && it.status != StockInLineStatus.REJECT.status - } + .filter { + it.status != StockInLineStatus.RECEIVING.status + && it.status != StockInLineStatus.RECEIVED.status + && it.status != StockInLineStatus.COMPLETE.status + && it.status != StockInLineStatus.REJECT.status + } if (unQcedLines.isEmpty()) { // all stock in lines finished // change status of purchase order line @@ -226,7 +226,7 @@ open class StockInLineService( val unfinishedLines = stockInLineRepository.findStockInLineInfoByPurchaseOrderLineIdAndDeletedFalse(purchaseOrderLineId = request.purchaseOrderLineId) .filter { it.status != StockInLineStatus.COMPLETE.status - && it.status != StockInLineStatus.REJECT.status + && it.status != StockInLineStatus.REJECT.status } println("unfinishedLines") println(unfinishedLines) @@ -247,14 +247,14 @@ open class StockInLineService( @Transactional open fun update(request: SaveStockInLineRequest): MessageResponse { val stockInLine = if (request.id != null) stockInLineRepository.findById(request.id!!).orElseThrow() - else return MessageResponse( - id = null, - code = null, - name = null, - type = "Found Null", - message = "stock in line id is null", - errorPosition = null, - ) + else return MessageResponse( + id = null, + code = null, + name = null, + type = "Found Null", + message = "stock in line id is null", + errorPosition = null, + ) // val allStockInLine = stockInLineRepository.findAllStockInLineInfoByStockInIdAndDeletedFalse(stockInLine!!.stockIn!!.id!!) if (stockInLine.expiryDate != null && request.expiryDate == null) { @@ -263,133 +263,148 @@ open class StockInLineService( } } // TODO: check all status to prevent reverting progress due to multiple users access to the same po? - // return list of stock in line, update data grid with the list - if (request.acceptedQty.compareTo(stockInLine.acceptedQty) == 0) { - var savedInventoryLot: InventoryLot? = null - var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later - saveQcResultWhenStockIn(request, stockInLine) - if (request.status == StockInLineStatus.RECEIVED.status) { - savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) - } - if (request.status == StockInLineStatus.COMPLETE.status) { - savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) - } -// println("checkpoint1") + stockInLine.apply { + this.productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime + this.productLotNo = request.productLotNo + this.dnNo = request.dnNo + this.dnDate = request.dnDate?.atStartOfDay() + this.acceptedQty = request.acceptedQty + this.demandQty = request.acceptQty + this.invoiceNo = request.invoiceNo + this.receiptDate = request.receiptDate?.atStartOfDay() +// this.status = request.status + this.expiryDate = stockInLine.expiryDate ?: request.expiryDate + this.remarks = stockInLine.remarks ?: request.remarks + } + if (request.status == StockInLineStatus.RECEIVED.status) { + // Putaway + var savedInventoryLotLine: InventoryLotLine? = null + + savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) stockInLine.apply { -// user = null - this.productionDate = request.productionDate?.atStartOfDay() // maybe need to change the request to LocalDateTime - this.productLotNo = request.productLotNo - this.dnNo = request.dnNo - this.dnDate = request.dnDate?.atStartOfDay() - this.invoiceNo = request.invoiceNo - this.receiptDate = request.receiptDate?.atStartOfDay() - this.status = request.status - this.expiryDate = stockInLine.expiryDate ?: request.expiryDate - this.inventoryLot = stockInLine.inventoryLot ?: savedInventoryLot + this.status = StockInLineStatus.COMPLETE.status this.inventoryLotLine = savedInventoryLotLine - this.lotNo = stockInLine.lotNo ?: savedInventoryLot?.lotNo - this.remarks = stockInLine.remarks ?: request.remarks - } - val savedStockInLine = saveAndFlush(stockInLine) - // check if all line completed - updatePurchaseOrderLineStatus(request) -// updatePurchaseOrderStatus(request) -// val allLineByStockInId = find - val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) -// println("checkpoint2") - return MessageResponse( - id = savedStockInLine.id, - code = null, - name = null, - type = "update Success", - message = "stock in line update status success", - errorPosition = null, - entity = listOf(lineInfo) - ) - } else { - if (request.acceptedQty <= BigDecimal(0) ) { - return MessageResponse( - id = null, - code = null, - name = null, - type = "acceptedQty == 0", - message = "acceptedQty cannot be 0", - errorPosition = "request.acceptedQty", - ) } + } else if (request.status == StockInLineStatus.PENDING.status) { + // QC + if (request.qcAccept == true) { + // Accepted + if (request.acceptedQty > BigDecimal(0)) { + var savedInventoryLot: InventoryLot? = null -// var newLineAcceptedQty = 0.0 -// if (request.rejectQty != null && request.rejectQty!! > BigDecimal.ZERO) { -// -// } - val newStockInLine = StockInLine() - newStockInLine.apply { - this.item = stockInLine.item - this.itemNo = stockInLine.itemNo - this.purchaseOrder = stockInLine.purchaseOrderLine?.purchaseOrder - this.purchaseOrderLine = stockInLine.purchaseOrderLine - this.productLotNo = stockInLine.productLotNo - this.dnNo = stockInLine.dnNo - this.dnDate = stockInLine.dnDate - this.invoiceNo = stockInLine.invoiceNo - this.remarks = stockInLine.remarks ?: request.remarks - this.receiptDate = stockInLine.receiptDate - this.stockIn = stockInLine.stockIn - this.demandQty = stockInLine.demandQty - this.acceptedQty = stockInLine.acceptedQty!!.minus(request.acceptedQty) - this.price = stockInLine.price - this.priceUnit = stockInLine.priceUnit - this.inventoryLot = stockInLine.inventoryLot - this.lotNo = stockInLine.lotNo - this.productionDate = stockInLine.productionDate - this.expiryDate = stockInLine.expiryDate - this.status = stockInLine.status // this does update status - this.user = stockInLine.user +// if (request.status == StockInLineStatus.RECEIVED.status) { + savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) +// } + // println("checkpoint1") + stockInLine.apply { + this.status = StockInLineStatus.RECEIVED.status; + this.inventoryLot = stockInLine.inventoryLot ?: savedInventoryLot + this.lotNo = stockInLine.lotNo ?: savedInventoryLot?.lotNo + } + } else { + return MessageResponse( + id = null, + code = null, + name = null, + type = "acceptedQty == 0", + message = "acceptedQty cannot be 0", + errorPosition = "request.acceptedQty", + ) + } + // if (request.acceptedQty.compareTo(stockInLine.acceptedQty) != 0) { + // // Partial Accept + // if (request.acceptedQty <= BigDecimal(0)) { + // return MessageResponse( + // id = null, + // code = null, + // name = null, + // type = "acceptedQty == 0", + // message = "acceptedQty cannot be 0", + // errorPosition = "request.acceptedQty", + // ) + // } + // val newStockInLine = StockInLine() + // newStockInLine.apply { + // this.item = stockInLine.item + // this.itemNo = stockInLine.itemNo + // this.purchaseOrder = stockInLine.purchaseOrderLine?.purchaseOrder + // this.purchaseOrderLine = stockInLine.purchaseOrderLine + // this.productLotNo = stockInLine.productLotNo + // this.dnNo = stockInLine.dnNo + // this.invoiceNo = stockInLine.invoiceNo + // this.remarks = stockInLine.remarks ?: request.remarks + // this.receiptDate = stockInLine.receiptDate + // this.stockIn = stockInLine.stockIn + // this.demandQty = stockInLine.demandQty + // this.acceptedQty = stockInLine.acceptedQty!!.minus(request.acceptedQty) + // this.price = stockInLine.price + // this.priceUnit = stockInLine.priceUnit + // this.inventoryLot = stockInLine.inventoryLot + // this.lotNo = stockInLine.lotNo + // this.productionDate = stockInLine.productionDate + // this.expiryDate = stockInLine.expiryDate + // this.status = StockInLineStatus.RECEIVING.status// stockInLine.status // this does update status + // this.user = stockInLine.user + // } + // saveQcResultWhenStockIn(request, stockInLine) + // var savedInventoryLot: InventoryLot? = null + // var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later + // if (request.status == StockInLineStatus.RECEIVED.status) { + // savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) + // } + // if (request.status == StockInLineStatus.COMPLETE.status) { + // savedInventoryLotLine = + // saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) + // } + // stockInLine.apply { + // this.acceptedQty = request.acceptedQty + // this.status = StockInLineStatus.RECEIVED.status//request.status + // this.inventoryLot = savedInventoryLot ?: stockInLine.inventoryLot + // this.inventoryLotLine = savedInventoryLotLine + // this.lotNo = savedInventoryLot?.lotNo ?: stockInLine.lotNo + // } + // + // val stockInLineEntries = listOf(stockInLine, newStockInLine) + // val savedEntries = stockInLineRepository.saveAllAndFlush(stockInLineEntries) + // val ids = savedEntries.map { it.id!! } + // val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) + // // check if all line completed + // updatePurchaseOrderLineStatus(request) + // + // return MessageResponse( + // id = stockInLine.id, + // code = null, + // name = null, + // type = "Save success", + // message = "created 2 stock in line", + // errorPosition = null, + // entity = lineInfoList + // ) + // } + } else if (request.qcAccept == false) { + // Rejected + stockInLine.apply { + this.status = StockInLineStatus.REJECT.status + } } saveQcResultWhenStockIn(request, stockInLine) - var savedInventoryLot: InventoryLot? = null - var savedInventoryLotLine: InventoryLotLine? = null // maybe remove this later - if (request.status == StockInLineStatus.RECEIVED.status) { - savedInventoryLot = saveInventoryLotWhenStockIn(request = request, stockInLine = stockInLine) - } - if (request.status == StockInLineStatus.COMPLETE.status) { - savedInventoryLotLine = saveInventoryLotLineWhenStockIn(request = request, stockInLine = stockInLine) - } - stockInLine.apply { - this.receiptDate = request.receiptDate?.atStartOfDay() - this.productionDate = request.productionDate?.atStartOfDay() - this.acceptedQty = request.acceptedQty - this.status = request.status - this.inventoryLot = savedInventoryLot ?: stockInLine.inventoryLot - this.inventoryLotLine = savedInventoryLotLine - this.lotNo = savedInventoryLot?.lotNo ?: stockInLine.lotNo - this.expiryDate = stockInLine.expiryDate ?: request.expiryDate - this.productLotNo = stockInLine.productLotNo ?: request.productLotNo - this.dnNo = stockInLine.dnNo ?: request.dnNo - this.dnDate = stockInLine.dnDate ?: request.dnDate?.atStartOfDay() - this.invoiceNo = stockInLine.invoiceNo ?: request.invoiceNo - this.remarks = stockInLine.remarks ?: request.remarks - } + } + val savedStockInLine = saveAndFlush(stockInLine) + // check if all line completed + updatePurchaseOrderLineStatus(request) + val lineInfo = stockInLineRepository.findStockInLineInfoByIdAndDeletedFalse(savedStockInLine.id!!) - val stockInLineEntries = listOf(stockInLine, newStockInLine) - val savedEntries = stockInLineRepository.saveAllAndFlush(stockInLineEntries) - val ids = savedEntries.map { it.id!! } - val lineInfoList = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(ids) - // check if all line completed - updatePurchaseOrderLineStatus(request) -// updatePurchaseOrderStatus(request) + return MessageResponse( + id = savedStockInLine.id, + code = null, + name = null, + type = "update Success", + message = "stock in line update status success", + errorPosition = null, + entity = listOf(lineInfo) + ) - return MessageResponse( - id = stockInLine.id, - code = null, - name = null, - type = "Save success", - message = "created 2 stock in line", - errorPosition = null, - entity = lineInfoList - ) - } } @Throws(IOException::class) 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 730bd29..86c6881 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 @@ -40,6 +40,7 @@ data class SaveStockInLineRequest( var purchaseOrderLineId: Long, var itemId: Long, var acceptedQty: BigDecimal, + var acceptQty: BigDecimal?, var acceptedWeight: BigDecimal?, var status: String?, var expiryDate: LocalDate?, @@ -50,6 +51,7 @@ data class SaveStockInLineRequest( var dnDate: LocalDate?, var receiptDate: LocalDate?, var productionDate: LocalDate?, + var qcAccept: Boolean?, var qcResult: List?, var warehouseId: Long?, var rejectQty: BigDecimal?