|
|
|
@@ -1200,6 +1200,7 @@ open class StockTakeRecordService( |
|
|
|
stockTakerName = rec.stockTakerName, |
|
|
|
stockTakeEndTime = rec.stockTakeEndTime, |
|
|
|
approverTime = rec.approverTime, |
|
|
|
pickerReviseCount = rec.pickerReviseCount ?: 0, |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1296,6 +1297,7 @@ open class StockTakeRecordService( |
|
|
|
stockTakerName = stockTakeRecord?.stockTakerName, |
|
|
|
stockTakeEndTime = stockTakeRecord?.stockTakeEndTime, |
|
|
|
approverTime = stockTakeRecord?.approverTime, |
|
|
|
pickerReviseCount = stockTakeRecord?.pickerReviseCount ?: 0, |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
@@ -1342,12 +1344,59 @@ open class StockTakeRecordService( |
|
|
|
.subtract(inventoryLotLine.outQty ?: BigDecimal.ZERO) |
|
|
|
//.subtract(inventoryLotLine.holdQty ?: BigDecimal.ZERO) |
|
|
|
|
|
|
|
if (request.reviseFirstQty && request.stockTakeRecordId == null) { |
|
|
|
throw IllegalArgumentException("Stock take record ID is required") |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 新建、更新預建記錄之第一次盤點、或第二次盤點 |
|
|
|
val stockTakeRecord: StockTakeRecord = if (request.stockTakeRecordId != null) { |
|
|
|
val existingRecord = stockTakeRecordRepository.findByIdAndDeletedIsFalse(request.stockTakeRecordId) |
|
|
|
?: throw IllegalArgumentException("Stock take record not found: ${request.stockTakeRecordId}") |
|
|
|
|
|
|
|
val headerStatus = stockTake.status |
|
|
|
val headerStillOpen = headerStatus == StockTakeStatus.PENDING || |
|
|
|
headerStatus == StockTakeStatus.STOCKTAKING || |
|
|
|
headerStatus == StockTakeStatus.APPROVING |
|
|
|
val revisingOpenPass = existingRecord.pickerFirstStockTakeQty != null && |
|
|
|
existingRecord.pickerSecondStockTakeQty == null && |
|
|
|
existingRecord.approverStockTakeQty == null && |
|
|
|
existingRecord.status.equals("pass", ignoreCase = true) && |
|
|
|
headerStillOpen |
|
|
|
when { |
|
|
|
// 已盤點的列在區域「已完成」前可改第一次數量。列狀態已完成、或區域已完成,不能改。 |
|
|
|
request.reviseFirstQty || revisingOpenPass -> { |
|
|
|
if (!headerStillOpen) { |
|
|
|
throw IllegalArgumentException("Cannot change counted qty after the section is completed") |
|
|
|
} |
|
|
|
if (!existingRecord.status.equals("pass", ignoreCase = true)) { |
|
|
|
throw IllegalArgumentException("Only counted records can be changed") |
|
|
|
} |
|
|
|
if (existingRecord.pickerFirstStockTakeQty == null) { |
|
|
|
throw IllegalArgumentException("No first count to change") |
|
|
|
} |
|
|
|
if (existingRecord.pickerSecondStockTakeQty != null || existingRecord.approverStockTakeQty != null) { |
|
|
|
throw IllegalArgumentException("Cannot change the first count after a later count exists") |
|
|
|
} |
|
|
|
val reviseCount = existingRecord.pickerReviseCount ?: 0 |
|
|
|
if (reviseCount >= 2) { |
|
|
|
throw IllegalArgumentException("This count can only be changed 2 times") |
|
|
|
} |
|
|
|
val varianceQty = availableQty - request.qty - request.badQty |
|
|
|
existingRecord.apply { |
|
|
|
this.pickerFirstStockTakeQty = request.qty |
|
|
|
this.pickerFirstBadQty = request.badQty |
|
|
|
this.bookQty = availableQty |
|
|
|
this.varianceQty = varianceQty |
|
|
|
this.stockTakerId = stockTakerId |
|
|
|
this.stockTakerName = user?.name |
|
|
|
this.status = "pass" |
|
|
|
this.pickerSecondStockTakeQty = null |
|
|
|
this.pickerSecondBadQty = null |
|
|
|
this.stockTakeEndTime = null |
|
|
|
this.pickerReviseCount = reviseCount + 1 |
|
|
|
} |
|
|
|
existingRecord |
|
|
|
} |
|
|
|
existingRecord.pickerFirstStockTakeQty == null -> { |
|
|
|
val isCompled = inventoryLotLine.inQty == inventoryLotLine.outQty |
|
|
|
val varianceQty = availableQty - request.qty - request.badQty |
|
|
|
@@ -1367,7 +1416,8 @@ open class StockTakeRecordService( |
|
|
|
} |
|
|
|
existingRecord |
|
|
|
} |
|
|
|
existingRecord.pickerSecondStockTakeQty == null -> { |
|
|
|
existingRecord.pickerSecondStockTakeQty == null && |
|
|
|
existingRecord.status.equals("notMatch", ignoreCase = true) -> { |
|
|
|
val varianceQty = availableQty - request.qty - request.badQty |
|
|
|
existingRecord.apply { |
|
|
|
this.stockTakeRoundId = this.stockTakeRoundId ?: (stockTake.stockTakeRoundId ?: stockTake.id) |
|
|
|
|