Quellcode durchsuchen

updated stock out ledger record, sync same pattern with stock in one

master
kelvin.yau vor 1 Tag
Ursprung
Commit
3193a0ee3d
1 geänderte Dateien mit 24 neuen und 22 gelöschten Zeilen
  1. +24
    -22
      src/main/java/com/ffii/fpsms/modules/stock/service/StockOutLineService.kt

+ 24
- 22
src/main/java/com/ffii/fpsms/modules/stock/service/StockOutLineService.kt Datei anzeigen

@@ -1329,29 +1329,31 @@ if (submitQty > BigDecimal.ZERO && actualInventoryLotLineId != null) {
)
}
}
@Transactional
private fun createStockLedgerForStockOut(stockOutLine: StockOutLine) {
val item = stockOutLine.item ?: return
val inventory = inventoryRepository.findByItemId(item.id!!).orElse(null) ?: return
val outQty = stockOutLine.qty?.toDouble() ?: 0.0
// 直接使用 inventory.onHandQty 作为 balance(已经是更新后的值)
val newBalance = (inventory.onHandQty ?: BigDecimal.ZERO).toDouble()
val stockLedger = StockLedger().apply {
this.stockOutLine = stockOutLine
this.inventory = inventory
this.inQty = null
this.outQty = outQty
this.balance = newBalance
this.type = stockOutLine.type
this.itemId = item.id
this.itemCode = item.code
this.date = LocalDate.now()
@Transactional
private fun createStockLedgerForStockOut(stockOutLine: StockOutLine) {
val item = stockOutLine.item ?: return
val inventory = inventoryRepository.findByItemId(item.id!!).orElse(null) ?: return

val outQty = stockOutLine.qty?.toDouble() ?: 0.0
// Use latest ledger balance (same pattern as createStockLedgerForStockIn) so balance is correct when multiple actions run in one transaction
val latestLedger = stockLedgerRepository.findLatestByItemId(item.id!!).firstOrNull()
val previousBalance = latestLedger?.balance ?: (inventory.onHandQty ?: BigDecimal.ZERO).toDouble()
val newBalance = previousBalance - outQty

val stockLedger = StockLedger().apply {
this.stockOutLine = stockOutLine
this.inventory = inventory
this.inQty = null
this.outQty = outQty
this.balance = newBalance
this.type = stockOutLine.type
this.itemId = item.id
this.itemCode = item.code
this.date = LocalDate.now()
}

stockLedgerRepository.saveAndFlush(stockLedger)
}
stockLedgerRepository.saveAndFlush(stockLedger)
}

open fun createStockOut(request: StockOutRequest): StockOutLine {



Laden…
Abbrechen
Speichern