Преглед изворни кода

inventory setup update

master
kelvin.yau пре 1 дан
родитељ
комит
9562302d30
3 измењених фајлова са 16 додато и 3 уклоњено
  1. +2
    -0
      src/main/java/com/ffii/fpsms/modules/master/entity/ItemUomRespository.kt
  2. +2
    -0
      src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt
  3. +12
    -3
      src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt

+ 2
- 0
src/main/java/com/ffii/fpsms/modules/master/entity/ItemUomRespository.kt Прегледај датотеку

@@ -27,4 +27,6 @@ interface ItemUomRespository : AbstractRepository<ItemUom, Long> {
fun findBaseUnitByItemIdAndStockUnitIsTrueAndDeletedIsFalse(itemId: Long): ItemUom? fun findBaseUnitByItemIdAndStockUnitIsTrueAndDeletedIsFalse(itemId: Long): ItemUom?
fun findFirstByItemIdAndUomIdAndDeletedIsFalse(itemId: Long, uomId: Long): ItemUom? fun findFirstByItemIdAndUomIdAndDeletedIsFalse(itemId: Long, uomId: Long): ItemUom?
fun findByItemIdAndUomIdAndStockUnitAndDeletedIsFalse(itemId: Long, uomId: Long, stockUnit: Boolean): ItemUom? fun findByItemIdAndUomIdAndStockUnitAndDeletedIsFalse(itemId: Long, uomId: Long, stockUnit: Boolean): ItemUom?

fun findFirstByItemIdAndStockUnitIsTrueAndDeletedIsFalseOrderByIdAsc(itemId: Long): ItemUom?
} }

+ 2
- 0
src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryRepository.kt Прегледај датотеку

@@ -29,4 +29,6 @@ interface InventoryRepository: AbstractRepository<Inventory, Long> {


@Query("SELECT i FROM Inventory i WHERE i.item.id = :itemId AND i.deleted = false") @Query("SELECT i FROM Inventory i WHERE i.item.id = :itemId AND i.deleted = false")
fun findAllByItemIdAndDeletedIsFalse(itemId: Long): List<Inventory> fun findAllByItemIdAndDeletedIsFalse(itemId: Long): List<Inventory>

fun findFirstByItemIdAndDeletedIsFalseOrderByIdAsc(itemId: Long): Inventory?
} }

+ 12
- 3
src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt Прегледај датотеку

@@ -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()


Loading…
Откажи
Сачувај