|
|
|
@@ -12,7 +12,6 @@ import com.ffii.fpsms.modules.stock.entity.InventoryLotLine |
|
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryLotLineRepository |
|
|
|
import com.ffii.fpsms.modules.stock.entity.InventoryRepository |
|
|
|
import com.ffii.fpsms.modules.stock.service.StockOutLineService |
|
|
|
import org.springframework.context.annotation.Lazy |
|
|
|
|
|
|
|
import com.ffii.fpsms.modules.pickOrder.enums.PickOrderLineStatus |
|
|
|
import com.ffii.fpsms.modules.stock.service.SuggestedPickLotService |
|
|
|
@@ -32,6 +31,7 @@ import com.ffii.fpsms.modules.jobOrder.entity.JoPickOrderRepository |
|
|
|
import com.ffii.fpsms.modules.jobOrder.entity.JoPickOrderRecordRepository |
|
|
|
import com.ffii.fpsms.modules.pickOrder.enums.PickExecutionIssueEnum |
|
|
|
import com.ffii.fpsms.modules.stock.web.model.StockOutLineStatus |
|
|
|
import com.ffii.fpsms.modules.stock.web.model.StockOutRequest |
|
|
|
import com.ffii.fpsms.modules.stock.web.model.StockOutStatus |
|
|
|
import com.ffii.fpsms.modules.deliveryOrder.entity.DoPickOrderRepository |
|
|
|
import com.ffii.fpsms.modules.pickOrder.enums.PickOrderStatus |
|
|
|
@@ -59,7 +59,7 @@ open class PickExecutionIssueService( |
|
|
|
private val pickOrderRepository: PickOrderRepository, |
|
|
|
private val jdbcDao: JdbcDao, |
|
|
|
private val stockOutRepository: StockOutRepository, |
|
|
|
@Lazy private val stockOutLineService: StockOutLineService, |
|
|
|
private val stockOutLineService: StockOutLineService, |
|
|
|
private val pickOrderLineRepository: PickOrderLineRepository, |
|
|
|
private val doPickOrderService: DoPickOrderService, |
|
|
|
private val joPickOrderRepository: JoPickOrderRepository, |
|
|
|
@@ -1673,15 +1673,6 @@ open fun submitMissItem(request: SubmitIssueRequest): MessageResponse { |
|
|
|
} |
|
|
|
|
|
|
|
val handler = request.handler ?: SecurityUtils.getUser().orElse(null)?.id ?: 0L |
|
|
|
val stockOut = createIssueStockOutHeader("MISS_ITEM", issue.issueRemark, handler) |
|
|
|
|
|
|
|
val pickOrderLine = issue.pickOrderLineId?.let { |
|
|
|
pickOrderLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val lotLine = issue.lotId?.let { |
|
|
|
inventoryLotLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val item = itemsRepository.findById(issue.itemId).orElse(null) |
|
|
|
?: return MessageResponse( |
|
|
|
@@ -1693,50 +1684,18 @@ open fun submitMissItem(request: SubmitIssueRequest): MessageResponse { |
|
|
|
errorPosition = null |
|
|
|
) |
|
|
|
|
|
|
|
// ✅ 修复:在创建和保存 stockOutLine 之前获取 inventory 的当前 onHandQty |
|
|
|
// 必须在任何可能触发数据库触发器更新 inventory 的操作之前获取 |
|
|
|
val inventoryBeforeUpdate = inventoryRepository.findByItemId(issue.itemId).orElse(null) |
|
|
|
val onHandQtyBeforeUpdate = (inventoryBeforeUpdate?.onHandQty ?: BigDecimal.ZERO).toDouble() |
|
|
|
|
|
|
|
println("=== submitMissItem: Before update ===") |
|
|
|
println("Item ID: ${issue.itemId}") |
|
|
|
println("Issue Qty: ${issueQty}") |
|
|
|
println("OnHandQty Before Update: ${onHandQtyBeforeUpdate}") |
|
|
|
println("=====================================") |
|
|
|
|
|
|
|
// 修改:使用 issueQty 创建 stock_out_line |
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = issueQty.toDouble() // 使用 issueQty 而不是 missQty |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.pickOrderLine = pickOrderLine |
|
|
|
this.type = "Miss" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
|
|
|
|
// 修改:使用 issueQty 更新 inventory_lot_line |
|
|
|
// 注意:这会触发数据库触发器更新 inventory,所以必须在获取 onHandQtyBeforeUpdate 之后调用 |
|
|
|
if (issue.lotId != null) { |
|
|
|
updateLotLineAfterIssue(issue.lotId, issueQty, isMissItem = true) // 使用 issueQty |
|
|
|
} |
|
|
|
|
|
|
|
val lotLineId = issue.lotId |
|
|
|
?: throw IllegalArgumentException("Issue ${issue.id} has no lot line id") |
|
|
|
val savedStockOutLine = stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = lotLineId, |
|
|
|
qty = issueQty.toDouble(), |
|
|
|
type = "Miss" |
|
|
|
) |
|
|
|
) |
|
|
|
markIssueHandled(issue, handler) |
|
|
|
|
|
|
|
// ✅ 修复:使用更新前的 onHandQty 计算 balance |
|
|
|
// balance = 更新前的 onHandQty - 本次出库数量 |
|
|
|
val balance = onHandQtyBeforeUpdate - issueQty.toDouble() |
|
|
|
|
|
|
|
println("=== submitMissItem: Creating stock ledger ===") |
|
|
|
println("OnHandQty Before Update: ${onHandQtyBeforeUpdate}") |
|
|
|
println("Issue Qty (OutQty): ${issueQty.toDouble()}") |
|
|
|
println("Calculated Balance: ${balance}") |
|
|
|
println("=============================================") |
|
|
|
|
|
|
|
createStockLedgerForStockOutWithBalance(savedStockOutLine, balance, "Miss") |
|
|
|
return MessageResponse( |
|
|
|
id = stockOut.id, |
|
|
|
id = savedStockOutLine.stockOut?.id, |
|
|
|
name = "Success", |
|
|
|
code = "SUCCESS", |
|
|
|
type = "stock_issue", |
|
|
|
@@ -1781,15 +1740,6 @@ open fun submitBadItem(request: SubmitIssueRequest): MessageResponse { |
|
|
|
} |
|
|
|
|
|
|
|
val handler = request.handler ?: SecurityUtils.getUser().orElse(null)?.id ?: 0L |
|
|
|
val stockOut = createIssueStockOutHeader("BAD_ITEM", issue.issueRemark, handler) |
|
|
|
|
|
|
|
val pickOrderLine = issue.pickOrderLineId?.let { |
|
|
|
pickOrderLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val lotLine = issue.lotId?.let { |
|
|
|
inventoryLotLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val item = itemsRepository.findById(issue.itemId).orElse(null) |
|
|
|
?: return MessageResponse( |
|
|
|
@@ -1801,27 +1751,15 @@ open fun submitBadItem(request: SubmitIssueRequest): MessageResponse { |
|
|
|
errorPosition = null |
|
|
|
) |
|
|
|
|
|
|
|
// ✅ 修复:在创建和保存 stockOutLine 之前获取 inventory 的当前 onHandQty |
|
|
|
val inventoryBeforeUpdate = inventoryRepository.findByItemId(issue.itemId).orElse(null) |
|
|
|
val onHandQtyBeforeUpdate = (inventoryBeforeUpdate?.onHandQty ?: BigDecimal.ZERO).toDouble() |
|
|
|
|
|
|
|
println("=== submitBadItem: Before update ===") |
|
|
|
println("Item ID: ${issue.itemId}") |
|
|
|
println("Issue Qty: ${issueQty}") |
|
|
|
println("OnHandQty Before Update: ${onHandQtyBeforeUpdate}") |
|
|
|
println("====================================") |
|
|
|
|
|
|
|
// 修改:使用 issueQty 创建 stock_out_line |
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = issueQty.toDouble() // 使用 issueQty 而不是 badItemQty |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.pickOrderLine = pickOrderLine |
|
|
|
this.type = "Bad" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
val lotLineId = issue.lotId |
|
|
|
?: throw IllegalArgumentException("Issue ${issue.id} has no lot line id") |
|
|
|
val savedStockOutLine = stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = lotLineId, |
|
|
|
qty = issueQty.toDouble(), |
|
|
|
type = "Bad" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
// ✅ 修复:Bad item 的 issueQty 应该重置为 0,而不是累加/减去 |
|
|
|
// 先重置 issueQty 为 0 |
|
|
|
@@ -1834,25 +1772,9 @@ open fun submitBadItem(request: SubmitIssueRequest): MessageResponse { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 修改:使用 issueQty 更新 inventory_lot_line(更新 outQty) |
|
|
|
if (issue.lotId != null) { |
|
|
|
updateLotLineAfterIssue(issue.lotId, issueQty, isMissItem = false) // 使用 issueQty |
|
|
|
} |
|
|
|
|
|
|
|
markIssueHandled(issue, handler) |
|
|
|
|
|
|
|
// ✅ 修复:使用更新前的 onHandQty 计算 balance |
|
|
|
val balance = onHandQtyBeforeUpdate - issueQty.toDouble() |
|
|
|
|
|
|
|
println("=== submitBadItem: Creating stock ledger ===") |
|
|
|
println("OnHandQty Before Update: ${onHandQtyBeforeUpdate}") |
|
|
|
println("Issue Qty (OutQty): ${issueQty.toDouble()}") |
|
|
|
println("Calculated Balance: ${balance}") |
|
|
|
println("===========================================") |
|
|
|
|
|
|
|
createStockLedgerForStockOutWithBalance(savedStockOutLine, balance, "Bad") |
|
|
|
return MessageResponse( |
|
|
|
id = stockOut.id, |
|
|
|
id = savedStockOutLine.stockOut?.id, |
|
|
|
name = "Success", |
|
|
|
code = "SUCCESS", |
|
|
|
type = "stock_issue", |
|
|
|
@@ -1874,6 +1796,8 @@ open fun submitBadItem(request: SubmitIssueRequest): MessageResponse { |
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
open fun submitExpiryItem(request: SubmitExpiryRequest): MessageResponse { |
|
|
|
try { |
|
|
|
println("=== submitExpiryItem START ===") |
|
|
|
println("Request lotLineId=${request.lotLineId}, handler=${request.handler}") |
|
|
|
val lotLine = inventoryLotLineRepository.findById(request.lotLineId).orElse(null) |
|
|
|
?: return MessageResponse( |
|
|
|
id = null, |
|
|
|
@@ -1901,6 +1825,7 @@ open fun submitExpiryItem(request: SubmitExpiryRequest): MessageResponse { |
|
|
|
val inQty = lotLine.inQty ?: BigDecimal.ZERO |
|
|
|
val outQty = lotLine.outQty ?: BigDecimal.ZERO |
|
|
|
val remainingQty = inQty.subtract(outQty) |
|
|
|
println("LotLine=${lotLine.id}, itemId=${lot?.item?.id}, inQty=$inQty, outQty=$outQty, remainingQty=$remainingQty") |
|
|
|
|
|
|
|
if (remainingQty <= BigDecimal.ZERO) { |
|
|
|
return MessageResponse( |
|
|
|
@@ -1914,7 +1839,6 @@ open fun submitExpiryItem(request: SubmitExpiryRequest): MessageResponse { |
|
|
|
} |
|
|
|
|
|
|
|
val handler = request.handler ?: SecurityUtils.getUser().orElse(null)?.id ?: 0L |
|
|
|
val stockOut = createIssueStockOutHeader("EXPIRY_ITEM", "Expired item removal", handler) |
|
|
|
|
|
|
|
val item = lot.item |
|
|
|
?: return MessageResponse( |
|
|
|
@@ -1926,23 +1850,16 @@ open fun submitExpiryItem(request: SubmitExpiryRequest): MessageResponse { |
|
|
|
errorPosition = null |
|
|
|
) |
|
|
|
|
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = remainingQty.toDouble() |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.type = "Expiry" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateLotLineAfterIssue(lotLine.id ?: 0L, remainingQty, isMissItem = false) |
|
|
|
// Create stock ledger entry |
|
|
|
createStockLedgerForStockOut(savedStockOutLine) |
|
|
|
val savedStockOutLine = stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = lotLine.id!!, |
|
|
|
qty = remainingQty.toDouble(), |
|
|
|
type = "Expiry" |
|
|
|
) |
|
|
|
) |
|
|
|
println("submitExpiryItem createStockOut SUCCESS: stockOutLineId=${savedStockOutLine.id}, qty=$remainingQty") |
|
|
|
return MessageResponse( |
|
|
|
id = stockOut.id, |
|
|
|
id = savedStockOutLine.stockOut?.id, |
|
|
|
name = "Success", |
|
|
|
code = "SUCCESS", |
|
|
|
type = "stock_issue", |
|
|
|
@@ -1950,6 +1867,8 @@ open fun submitExpiryItem(request: SubmitExpiryRequest): MessageResponse { |
|
|
|
errorPosition = null |
|
|
|
) |
|
|
|
} catch (e: Exception) { |
|
|
|
println("submitExpiryItem ERROR: ${e.message}") |
|
|
|
e.printStackTrace() |
|
|
|
return MessageResponse( |
|
|
|
id = null, |
|
|
|
name = "Error", |
|
|
|
@@ -1980,46 +1899,20 @@ open fun batchSubmitMissItem(request: BatchSubmitIssueRequest): MessageResponse |
|
|
|
} |
|
|
|
|
|
|
|
val handler = request.handler ?: SecurityUtils.getUser().orElse(null)?.id ?: 0L |
|
|
|
val stockOut = createIssueStockOutHeader("MISS_ITEM", "Batch miss item submission", handler) |
|
|
|
|
|
|
|
issues.forEach { issue -> |
|
|
|
val issueQty = issue.issueQty ?: BigDecimal.ZERO |
|
|
|
|
|
|
|
val pickOrderLine = issue.pickOrderLineId?.let { |
|
|
|
pickOrderLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val lotLine = issue.lotId?.let { |
|
|
|
inventoryLotLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val item = itemsRepository.findById(issue.itemId).orElse(null) |
|
|
|
|
|
|
|
// 修改:使用 issueQty |
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = issueQty.toDouble() // 使用 issueQty |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.pickOrderLine = pickOrderLine |
|
|
|
this.type = "Miss" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
|
|
|
|
// ✅ 修复:在更新 lot line 之前获取 inventory 的当前 onHandQty,用于计算 balance |
|
|
|
val inventoryBeforeUpdate = item?.let { inventoryRepository.findByItemId(it.id!!).orElse(null) } |
|
|
|
val onHandQtyBeforeUpdate = (inventoryBeforeUpdate?.onHandQty ?: BigDecimal.ZERO).toDouble() |
|
|
|
|
|
|
|
// 修改:使用 issueQty |
|
|
|
if (issue.lotId != null) { |
|
|
|
updateLotLineAfterIssue(issue.lotId, issueQty, isMissItem = true) // 使用 issueQty |
|
|
|
} |
|
|
|
|
|
|
|
val lotLineId = issue.lotId |
|
|
|
?: throw IllegalArgumentException("Issue ${issue.id} has no lot line id") |
|
|
|
stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = lotLineId, |
|
|
|
qty = issueQty.toDouble(), |
|
|
|
type = "Miss" |
|
|
|
) |
|
|
|
) |
|
|
|
markIssueHandled(issue, handler) |
|
|
|
// ✅ 修复:使用更新前的 onHandQty 计算 balance,避免触发器更新后的错误计算 |
|
|
|
val balance = onHandQtyBeforeUpdate - issueQty.toDouble() |
|
|
|
createStockLedgerForStockOutWithBalance(savedStockOutLine, balance, "Miss") |
|
|
|
} |
|
|
|
|
|
|
|
return MessageResponse( |
|
|
|
@@ -2061,37 +1954,19 @@ open fun batchSubmitBadItem(request: BatchSubmitIssueRequest): MessageResponse { |
|
|
|
} |
|
|
|
|
|
|
|
val handler = request.handler ?: SecurityUtils.getUser().orElse(null)?.id ?: 0L |
|
|
|
val stockOut = createIssueStockOutHeader("BAD_ITEM", "Batch bad item submission", handler) |
|
|
|
|
|
|
|
issues.forEach { issue -> |
|
|
|
val issueQty = issue.issueQty ?: BigDecimal.ZERO |
|
|
|
|
|
|
|
val pickOrderLine = issue.pickOrderLineId?.let { |
|
|
|
pickOrderLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val lotLine = issue.lotId?.let { |
|
|
|
inventoryLotLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
|
|
|
|
val item = itemsRepository.findById(issue.itemId).orElse(null) |
|
|
|
|
|
|
|
// 修改:使用 issueQty |
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = issueQty.toDouble() // 使用 issueQty |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.pickOrderLine = pickOrderLine |
|
|
|
this.type = "Bad" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
|
|
|
|
// ✅ 修复:在更新 lot line 之前获取 inventory 的当前 onHandQty,用于计算 balance |
|
|
|
val inventoryBeforeUpdate = item?.let { inventoryRepository.findByItemId(it.id!!).orElse(null) } |
|
|
|
val onHandQtyBeforeUpdate = (inventoryBeforeUpdate?.onHandQty ?: BigDecimal.ZERO).toDouble() |
|
|
|
|
|
|
|
val lotLineId = issue.lotId |
|
|
|
?: throw IllegalArgumentException("Issue ${issue.id} has no lot line id") |
|
|
|
stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = lotLineId, |
|
|
|
qty = issueQty.toDouble(), |
|
|
|
type = "Bad" |
|
|
|
) |
|
|
|
) |
|
|
|
// ✅ 修复:Bad item 的 issueQty 应该重置为 0,而不是累加/减去 |
|
|
|
// 先重置 issueQty 为 0 |
|
|
|
if (issue.lotId != null) { |
|
|
|
@@ -2103,15 +1978,7 @@ open fun batchSubmitBadItem(request: BatchSubmitIssueRequest): MessageResponse { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 修改:使用 issueQty |
|
|
|
if (issue.lotId != null) { |
|
|
|
updateLotLineAfterIssue(issue.lotId, issueQty, isMissItem = false) // 使用 issueQty |
|
|
|
} |
|
|
|
|
|
|
|
markIssueHandled(issue, handler) |
|
|
|
// ✅ 修复:使用更新前的 onHandQty 计算 balance,避免触发器更新后的错误计算 |
|
|
|
val balance = onHandQtyBeforeUpdate - issueQty.toDouble() |
|
|
|
createStockLedgerForStockOutWithBalance(savedStockOutLine, balance, "Bad") |
|
|
|
} |
|
|
|
|
|
|
|
return MessageResponse( |
|
|
|
@@ -2158,32 +2025,16 @@ open fun batchSubmitExpiryItem(request: BatchSubmitExpiryRequest): MessageRespon |
|
|
|
|
|
|
|
val handler = request.handler ?: SecurityUtils.getUser().orElse(null)?.id ?: 0L |
|
|
|
|
|
|
|
// Create single StockOut header for all submissions |
|
|
|
val stockOut = createIssueStockOutHeader("EXPIRY_ITEM", "Batch expiry item removal", handler) |
|
|
|
|
|
|
|
lotLines.forEach { lotLine -> |
|
|
|
val remainingQty = (lotLine.inQty ?: BigDecimal.ZERO).subtract(lotLine.outQty ?: BigDecimal.ZERO) |
|
|
|
|
|
|
|
// Get item from inventoryLot |
|
|
|
val item = lotLine.inventoryLot?.item |
|
|
|
|
|
|
|
// Create StockOutLine |
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = remainingQty.toDouble() |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.type = "Expiry" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
|
|
|
|
// Create stock ledger entry |
|
|
|
|
|
|
|
|
|
|
|
// Update InventoryLotLine |
|
|
|
updateLotLineAfterIssue(lotLine.id ?: 0L, remainingQty, isMissItem = false) |
|
|
|
createStockLedgerForStockOut(savedStockOutLine) |
|
|
|
stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = lotLine.id!!, |
|
|
|
qty = remainingQty.toDouble(), |
|
|
|
type = "Expiry" |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
return MessageResponse( |
|
|
|
@@ -2746,20 +2597,8 @@ open fun submitIssueWithQty(request: SubmitIssueWithQtyRequest): MessageResponse |
|
|
|
println("OnHandQty Before Update: ${onHandQtyBeforeUpdate}") |
|
|
|
println("==========================================") |
|
|
|
|
|
|
|
val stockOut = createIssueStockOutHeader( |
|
|
|
if (isMissItem) "MISS_ITEM" else "BAD_ITEM", |
|
|
|
firstIssue.issueRemark, |
|
|
|
handler |
|
|
|
) |
|
|
|
println("Created stock out header: id=${stockOut.id}, type=${if (isMissItem) "MISS_ITEM" else "BAD_ITEM"}") |
|
|
|
|
|
|
|
val pickOrderLine = firstIssue.pickOrderLineId?.let { |
|
|
|
pickOrderLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
println("Pick order line: id=${pickOrderLine?.id}") |
|
|
|
|
|
|
|
val lotLine = request.lotId.let { |
|
|
|
inventoryLotLineRepository.findById(it).orElse(null) |
|
|
|
val lotLine = request.lotId.let { |
|
|
|
inventoryLotLineRepository.findById(it).orElse(null) |
|
|
|
} |
|
|
|
println("Lot line: id=${lotLine?.id}, lotNo=${lotLine?.inventoryLot?.lotNo}") |
|
|
|
|
|
|
|
@@ -2774,18 +2613,14 @@ open fun submitIssueWithQty(request: SubmitIssueWithQtyRequest): MessageResponse |
|
|
|
) |
|
|
|
println("Item: id=${item.id}, code=${item.code}") |
|
|
|
|
|
|
|
// Create stock_out_line with custom quantity |
|
|
|
val stockOutLine = StockOutLine().apply { |
|
|
|
this.stockOut = stockOut |
|
|
|
this.inventoryLotLine = lotLine |
|
|
|
this.item = item |
|
|
|
this.qty = submitQty.toDouble() // Use custom quantity |
|
|
|
this.status = StockOutLineStatus.COMPLETE.status |
|
|
|
this.pickOrderLine = pickOrderLine |
|
|
|
this.type = if (isMissItem) "Miss" else "Bad" |
|
|
|
} |
|
|
|
val savedStockOutLine = stockOutLineRepository.saveAndFlush(stockOutLine) |
|
|
|
println("Created stock out line: id=${savedStockOutLine.id}, qty=${savedStockOutLine.qty}, status=${savedStockOutLine.status}") |
|
|
|
val savedStockOutLine = stockOutLineService.createStockOut( |
|
|
|
StockOutRequest( |
|
|
|
inventoryLotLineId = request.lotId, |
|
|
|
qty = submitQty.toDouble(), |
|
|
|
type = if (isMissItem) "Miss" else "Bad" |
|
|
|
) |
|
|
|
) |
|
|
|
println("Created stock out line via createStockOut: id=${savedStockOutLine.id}, qty=${savedStockOutLine.qty}, status=${savedStockOutLine.status}") |
|
|
|
|
|
|
|
if (!isMissItem && request.lotId != null) { |
|
|
|
val rejectedLines = stockOutLineRepository |
|
|
|
@@ -2804,32 +2639,15 @@ open fun submitIssueWithQty(request: SubmitIssueWithQtyRequest): MessageResponse |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Update inventory_lot_line with custom quantity - pass isMissItem flag |
|
|
|
if (request.lotId != null) { |
|
|
|
println("Updating lot line after issue: lotId=${request.lotId}, submitQty=$submitQty, isMissItem=$isMissItem") |
|
|
|
updateLotLineAfterIssue(request.lotId, submitQty, isMissItem) |
|
|
|
} |
|
|
|
|
|
|
|
// Mark all issues as handled |
|
|
|
issues.forEach { issue -> |
|
|
|
println(" Marking issue ${issue.id} as handled by handler $handler") |
|
|
|
markIssueHandled(issue, handler) |
|
|
|
} |
|
|
|
|
|
|
|
// ✅ 修复:使用更新前的 onHandQty 计算 balance |
|
|
|
val balance = onHandQtyBeforeUpdate - submitQty.toDouble() |
|
|
|
|
|
|
|
println("=== submitIssueWithQty: Creating stock ledger ===") |
|
|
|
println("OnHandQty Before Update: ${onHandQtyBeforeUpdate}") |
|
|
|
println("Submit Qty (OutQty): ${submitQty.toDouble()}") |
|
|
|
println("Calculated Balance: ${balance}") |
|
|
|
println("===================================================") |
|
|
|
|
|
|
|
createStockLedgerForStockOutWithBalance(savedStockOutLine, balance, if (isMissItem) "Miss" else "Bad") |
|
|
|
|
|
|
|
println("=== submitIssueWithQty: SUCCESS ===") |
|
|
|
return MessageResponse( |
|
|
|
id = stockOut.id, |
|
|
|
id = savedStockOutLine.stockOut?.id, |
|
|
|
name = "Success", |
|
|
|
code = "SUCCESS", |
|
|
|
type = "stock_issue", |
|
|
|
|