|
|
@@ -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, |
|
|
|