|
|
@@ -740,11 +740,17 @@ open class StockInLineService( |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
@Transactional |
|
|
@Transactional |
|
|
|
|
|
<<<<<<< Updated upstream |
|
|
private fun createStockLedgerForStockIn(stockInLine: StockInLine) { |
|
|
private fun createStockLedgerForStockIn(stockInLine: StockInLine) { |
|
|
val item = stockInLine.item ?: return |
|
|
val item = stockInLine.item ?: return |
|
|
val inventory = inventoryRepository.findByItemId(item.id!!).orElse(null) ?: return |
|
|
val inventory = inventoryRepository.findByItemId(item.id!!).orElse(null) ?: return |
|
|
|
|
|
|
|
|
val inQty = stockInLine.acceptedQty?.toDouble() ?: 0.0 |
|
|
val inQty = stockInLine.acceptedQty?.toDouble() ?: 0.0 |
|
|
|
|
|
======= |
|
|
|
|
|
private fun createStockLedgerForStockIn(stockInLine: StockInLine) { |
|
|
|
|
|
val item = stockInLine.item ?: return |
|
|
|
|
|
val inventory = inventoryRepository.findFirstByItemIdAndDeletedIsFalseOrderByIdAsc(item.id!!) ?: return |
|
|
|
|
|
>>>>>>> Stashed changes |
|
|
|
|
|
|
|
|
// ✅ 修复:查询最新的 stock_ledger 记录,基于前一笔 balance 计算 |
|
|
// ✅ 修复:查询最新的 stock_ledger 记录,基于前一笔 balance 计算 |
|
|
val latestLedger = stockLedgerRepository.findLatestByItemId(item.id!!).firstOrNull() |
|
|
val latestLedger = stockLedgerRepository.findLatestByItemId(item.id!!).firstOrNull() |
|
|
@@ -822,9 +828,12 @@ private fun createStockLedgerForStockIn(stockInLine: StockInLine) { |
|
|
savedStockInLine.inventoryLot = savedInventoryLot |
|
|
savedStockInLine.inventoryLot = savedInventoryLot |
|
|
|
|
|
|
|
|
// Step 4: Create a row in inventory_lot_line table |
|
|
// Step 4: Create a row in inventory_lot_line table |
|
|
val stockItemUom = itemUomRepository.findBaseUnitByItemIdAndStockUnitIsTrueAndDeletedIsFalse( |
|
|
|
|
|
itemId = request.itemId |
|
|
|
|
|
) ?: throw IllegalArgumentException("Stock UOM not found for item ${request.itemId}") |
|
|
|
|
|
|
|
|
val stockItemUom = itemUomRepository.findFirstByItemIdAndStockUnitIsTrueAndDeletedIsFalseOrderByIdAsc( |
|
|
|
|
|
request.itemId |
|
|
|
|
|
) ?: throw IllegalArgumentException( |
|
|
|
|
|
"Stock UOM not found for item: id=${request.itemId}, itemNo=${request.itemNo}. " + |
|
|
|
|
|
"Ensure at least one item_uom row has stockUnit=1, deleted=0 for this item." |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
val warehouse = if (request.warehouseId != null) { |
|
|
val warehouse = if (request.warehouseId != null) { |
|
|
warehouseRepository.findById(request.warehouseId).orElseThrow() |
|
|
warehouseRepository.findById(request.warehouseId).orElseThrow() |
|
|
|