| @@ -94,14 +94,6 @@ open class StockTransferRecordService( | |||||
| throw IllegalArgumentException("warehouseId is required for stock in") | throw IllegalArgumentException("warehouseId is required for stock in") | ||||
| } | } | ||||
| // Step 4: Check if existing InventoryLotLine with same lot and warehouse exists | |||||
| val existingInventoryLotLine = inventoryLotLineRepository.findByLotNoAndItemIdAndWarehouseId( | |||||
| lotNo = lotNo, | |||||
| itemId = itemId, | |||||
| warehouseId = request.warehouseId | |||||
| ) | |||||
| // Step 5: Map to StockInRequest | |||||
| val stockInRequest = StockInRequest( | val stockInRequest = StockInRequest( | ||||
| itemId = itemId, | itemId = itemId, | ||||
| itemNo = itemCode, | itemNo = itemCode, | ||||
| @@ -115,25 +107,7 @@ open class StockTransferRecordService( | |||||
| warehouseId = request.warehouseId | warehouseId = request.warehouseId | ||||
| ) | ) | ||||
| return if (existingInventoryLotLine != null) { | |||||
| // Update existing InventoryLotLine's inQty | |||||
| existingInventoryLotLine.apply { | |||||
| val currentInQty = this.inQty ?: BigDecimal.ZERO | |||||
| this.inQty = currentInQty + request.transferredQty | |||||
| // Update status if it was UNAVAILABLE and now has stock | |||||
| if (this.status == InventoryLotLineStatus.UNAVAILABLE) { | |||||
| this.status = InventoryLotLineStatus.AVAILABLE | |||||
| } | |||||
| } | |||||
| inventoryLotLineRepository.saveAndFlush(existingInventoryLotLine) | |||||
| // Create StockIn and StockInLine for record keeping, linking to existing InventoryLotLine | |||||
| stockInLineService.createStockInForExistingInventoryLotLine(stockInRequest, existingInventoryLotLine) | |||||
| } else { | |||||
| // Normal flow: create new InventoryLotLine | |||||
| stockInLineService.createStockIn(stockInRequest) | |||||
| } | |||||
| return stockInLineService.createStockIn(stockInRequest) | |||||
| } | } | ||||
| private fun createStockTransferRecord( | private fun createStockTransferRecord( | ||||