|
|
|
@@ -226,7 +226,6 @@ open class StockInLineService( |
|
|
|
val response = request.inventoryLotLines?.let { lines -> |
|
|
|
val saveLines = mutableListOf<InventoryLotLine>(); |
|
|
|
lines.forEach { line -> |
|
|
|
val inventoryLotLine = InventoryLotLine() |
|
|
|
val warehouse = warehouseRepository.findById(line.warehouseId!!).orElseThrow() |
|
|
|
val stockItemUom = itemUomRepository.findBaseUnitByItemIdAndStockUnitIsTrueAndDeletedIsFalse( |
|
|
|
itemId = request.itemId |
|
|
|
@@ -237,17 +236,38 @@ open class StockInLineService( |
|
|
|
} else { |
|
|
|
(line.qty) |
|
|
|
} |
|
|
|
inventoryLotLine.apply { |
|
|
|
this.inventoryLot = stockInLine.inventoryLot |
|
|
|
this.warehouse = warehouse |
|
|
|
this.inQty = convertedBaseQty |
|
|
|
this.status = InventoryLotLineStatus.AVAILABLE |
|
|
|
this.stockUom = stockItemUom |
|
|
|
|
|
|
|
// ✅ Find existing inventory lot line for same warehouse and inventory lot |
|
|
|
val existingLotLine = stockInLine.inventoryLot?.id?.let { inventoryLotId -> |
|
|
|
inventoryLotLineRepository.findByInventoryLotStockInLineIdAndWarehouseId( |
|
|
|
inventoryLotStockInLineId = stockInLine.id!!, |
|
|
|
warehouseId = warehouse.id!! |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if (existingLotLine != null) { |
|
|
|
// ✅ Update existing inventory lot line (add to existing qty) |
|
|
|
existingLotLine.apply { |
|
|
|
this.inQty = (this.inQty ?: BigDecimal.ZERO) + convertedBaseQty |
|
|
|
this.status = InventoryLotLineStatus.AVAILABLE |
|
|
|
} |
|
|
|
saveLines.add(existingLotLine) |
|
|
|
} else { |
|
|
|
// ✅ Create new inventory lot line (first put away for this warehouse) |
|
|
|
val inventoryLotLine = InventoryLotLine() |
|
|
|
inventoryLotLine.apply { |
|
|
|
this.inventoryLot = stockInLine.inventoryLot |
|
|
|
this.warehouse = warehouse |
|
|
|
this.inQty = convertedBaseQty |
|
|
|
this.status = InventoryLotLineStatus.AVAILABLE |
|
|
|
this.stockUom = stockItemUom |
|
|
|
} |
|
|
|
saveLines.add(inventoryLotLine) |
|
|
|
} |
|
|
|
saveLines.add(inventoryLotLine) |
|
|
|
} |
|
|
|
inventoryLotLineRepository.saveAll(saveLines) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return response ?: emptyList(); |
|
|
|
// val inventoryLotLine = InventoryLotLine() |
|
|
|
|