|
|
@@ -50,7 +50,7 @@ open class PickOrderWorkbenchService( |
|
|
/** |
|
|
/** |
|
|
* Workbench assign V2 for consumable pick orders: |
|
|
* Workbench assign V2 for consumable pick orders: |
|
|
* - Assign selected pick orders to user and mark ASSIGNED. |
|
|
* - Assign selected pick orders to user and mark ASSIGNED. |
|
|
* - Build no-hold suggestions + ensure stock_out_line for each pick order. |
|
|
|
|
|
|
|
|
* - Do NOT create suggestion/stock_out_line here (created on Tab3 line select). |
|
|
*/ |
|
|
*/ |
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
open fun assignPickOrdersV2(pickOrderIds: List<Long>, assignTo: Long): MessageResponse { |
|
|
open fun assignPickOrdersV2(pickOrderIds: List<Long>, assignTo: Long): MessageResponse { |
|
|
@@ -73,34 +73,17 @@ open class PickOrderWorkbenchService( |
|
|
pickOrder.status = PickOrderStatus.ASSIGNED |
|
|
pickOrder.status = PickOrderStatus.ASSIGNED |
|
|
} |
|
|
} |
|
|
pickOrderRepository.saveAll(pickOrders) |
|
|
pickOrderRepository.saveAll(pickOrders) |
|
|
|
|
|
|
|
|
val assignedIds = mutableListOf<Long>() |
|
|
|
|
|
var suggestionRows = 0 |
|
|
|
|
|
var stockOutLines = 0 |
|
|
|
|
|
pickOrders.forEach { po -> |
|
|
|
|
|
val poId = po.id ?: return@forEach |
|
|
|
|
|
val suggestSummary = suggestedPickLotWorkbenchService.primeNextSingleLotSuggestionsForPickOrder( |
|
|
|
|
|
pickOrderId = poId, |
|
|
|
|
|
storeId = null, |
|
|
|
|
|
excludeWarehouseCodes = null, |
|
|
|
|
|
) |
|
|
|
|
|
val solSummary = stockOutLineWorkbenchService.ensureStockOutLinesForPickOrderNoHold(poId, assignTo) |
|
|
|
|
|
assignedIds.add(poId) |
|
|
|
|
|
suggestionRows += suggestSummary.created |
|
|
|
|
|
stockOutLines += solSummary.created |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
val assignedIds = pickOrders.mapNotNull { it.id } |
|
|
|
|
|
|
|
|
return MessageResponse( |
|
|
return MessageResponse( |
|
|
id = null, |
|
|
id = null, |
|
|
name = "Workbench assign v2 success", |
|
|
name = "Workbench assign v2 success", |
|
|
code = "SUCCESS", |
|
|
code = "SUCCESS", |
|
|
type = "pickorder_workbench", |
|
|
type = "pickorder_workbench", |
|
|
message = "Assigned and initialized no-hold suggestion/stock-out for workbench", |
|
|
|
|
|
|
|
|
message = "Assigned pick orders for workbench (no suggestion/stock-out at assign stage)", |
|
|
errorPosition = null, |
|
|
errorPosition = null, |
|
|
entity = mapOf( |
|
|
entity = mapOf( |
|
|
"pickOrderIds" to assignedIds, |
|
|
|
|
|
"suggestionRowsCreated" to suggestionRows, |
|
|
|
|
|
"stockOutLinesCreated" to stockOutLines |
|
|
|
|
|
|
|
|
"pickOrderIds" to assignedIds |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
} catch (e: Exception) { |
|
|
} catch (e: Exception) { |
|
|
@@ -342,6 +325,7 @@ open class PickOrderWorkbenchService( |
|
|
lotNo = r["lotNo"]?.toString(), |
|
|
lotNo = r["lotNo"]?.toString(), |
|
|
expiryDate = toLocalDate(r["expiryDate"]), |
|
|
expiryDate = toLocalDate(r["expiryDate"]), |
|
|
location = r["location"]?.toString(), |
|
|
location = r["location"]?.toString(), |
|
|
|
|
|
itemId = pol.item?.id, |
|
|
stockUnit = uomDesc, |
|
|
stockUnit = uomDesc, |
|
|
availableQty = availableQty, |
|
|
availableQty = availableQty, |
|
|
requiredQty = toBigDecimal(r["suggestedQty"]) ?: pol.qty ?: zero, |
|
|
requiredQty = toBigDecimal(r["suggestedQty"]) ?: pol.qty ?: zero, |
|
|
@@ -379,6 +363,7 @@ open class PickOrderWorkbenchService( |
|
|
lotNo = null, |
|
|
lotNo = null, |
|
|
expiryDate = null, |
|
|
expiryDate = null, |
|
|
location = null, |
|
|
location = null, |
|
|
|
|
|
itemId = pol.item?.id, |
|
|
stockUnit = uomDesc, |
|
|
stockUnit = uomDesc, |
|
|
availableQty = null, |
|
|
availableQty = null, |
|
|
requiredQty = pol.qty ?: zero, |
|
|
requiredQty = pol.qty ?: zero, |
|
|
@@ -400,5 +385,60 @@ open class PickOrderWorkbenchService( |
|
|
|
|
|
|
|
|
return withLot + noLot |
|
|
return withLot + noLot |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Workbench suggest V2 for consumable pick orders (first-time suggestion path): |
|
|
|
|
|
* - Create/rebuild no-hold suggestions for this pick order. |
|
|
|
|
|
* - Ensure stock_out_line rows exist for created/reused suggestions. |
|
|
|
|
|
*/ |
|
|
|
|
|
@Transactional(rollbackFor = [Exception::class]) |
|
|
|
|
|
open fun suggestPickOrderV2(pickOrderId: Long, userId: Long): MessageResponse { |
|
|
|
|
|
return try { |
|
|
|
|
|
val pickOrder = pickOrderRepository.findById(pickOrderId).orElse(null) |
|
|
|
|
|
?: return MessageResponse( |
|
|
|
|
|
id = pickOrderId, |
|
|
|
|
|
name = "Workbench suggest v2 failed", |
|
|
|
|
|
code = "ERROR", |
|
|
|
|
|
type = "pickorder_workbench", |
|
|
|
|
|
message = "Pick order not found", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
val suggestSummary = suggestedPickLotWorkbenchService.primeNextSingleLotSuggestionsForPickOrder( |
|
|
|
|
|
pickOrderId = pickOrderId, |
|
|
|
|
|
storeId = null, |
|
|
|
|
|
excludeWarehouseCodes = null, |
|
|
|
|
|
) |
|
|
|
|
|
val stockOutSummary = stockOutLineWorkbenchService.ensureStockOutLinesForPickOrderNoHold( |
|
|
|
|
|
pickOrderId = pickOrderId, |
|
|
|
|
|
userId = userId, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
MessageResponse( |
|
|
|
|
|
id = pickOrder.id, |
|
|
|
|
|
name = "Workbench suggest v2 success", |
|
|
|
|
|
code = "SUCCESS", |
|
|
|
|
|
type = "pickorder_workbench", |
|
|
|
|
|
message = "Workbench suggestion prepared", |
|
|
|
|
|
errorPosition = null, |
|
|
|
|
|
entity = mapOf( |
|
|
|
|
|
"pickOrderId" to pickOrderId, |
|
|
|
|
|
"suggestionRowsCreated" to suggestSummary.created, |
|
|
|
|
|
"suggestionRowsSkippedExisting" to suggestSummary.skippedExisting, |
|
|
|
|
|
"stockOutLinesCreated" to stockOutSummary.created, |
|
|
|
|
|
"stockOutLinesReused" to stockOutSummary.reused, |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
MessageResponse( |
|
|
|
|
|
id = pickOrderId, |
|
|
|
|
|
name = "Workbench suggest v2 failed", |
|
|
|
|
|
code = "ERROR", |
|
|
|
|
|
type = "pickorder_workbench", |
|
|
|
|
|
message = "Failed to prepare workbench suggestion: ${e.message}", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|