|
|
@@ -296,6 +296,69 @@ open class PickOrderService( |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
open fun cancelPickOrders(pickOrderIds: List<Long>): MessageResponse { |
|
|
|
|
|
try { |
|
|
|
|
|
if (pickOrderIds.isEmpty()) { |
|
|
|
|
|
return MessageResponse( |
|
|
|
|
|
id = null, |
|
|
|
|
|
name = "No pick orders selected", |
|
|
|
|
|
code = "ERROR", |
|
|
|
|
|
type = "pickorder", |
|
|
|
|
|
message = "No pick orders selected", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val pickOrders = pickOrderRepository.findAllById(pickOrderIds) |
|
|
|
|
|
if (pickOrders.isEmpty()) { |
|
|
|
|
|
return MessageResponse( |
|
|
|
|
|
id = null, |
|
|
|
|
|
name = "Pick orders not found", |
|
|
|
|
|
code = "ERROR", |
|
|
|
|
|
type = "pickorder", |
|
|
|
|
|
message = "Pick orders not found", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val notPending = pickOrders.filter { it.status != PickOrderStatus.PENDING } |
|
|
|
|
|
if (notPending.isNotEmpty()) { |
|
|
|
|
|
val codes = notPending.mapNotNull { it.code }.joinToString(", ") |
|
|
|
|
|
return MessageResponse( |
|
|
|
|
|
id = null, |
|
|
|
|
|
name = "Only pending pick orders can be cancelled", |
|
|
|
|
|
code = "ERROR", |
|
|
|
|
|
type = "pickorder", |
|
|
|
|
|
message = "Only pending pick orders can be cancelled: $codes", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pickOrders.forEach { pickOrder -> |
|
|
|
|
|
pickOrder.deleted = true |
|
|
|
|
|
} |
|
|
|
|
|
pickOrderRepository.saveAll(pickOrders) |
|
|
|
|
|
|
|
|
|
|
|
return MessageResponse( |
|
|
|
|
|
id = null, |
|
|
|
|
|
name = "Pick orders cancelled successfully", |
|
|
|
|
|
code = "SUCCESS", |
|
|
|
|
|
type = "pickorder", |
|
|
|
|
|
message = "Pick orders cancelled successfully", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
return MessageResponse( |
|
|
|
|
|
id = null, |
|
|
|
|
|
name = "Failed to cancel pick orders", |
|
|
|
|
|
code = "ERROR", |
|
|
|
|
|
type = "pickorder", |
|
|
|
|
|
message = "Failed to cancel pick orders: ${e.message}", |
|
|
|
|
|
errorPosition = null |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
open fun releasePickOrders(pickOrderIds: List<Long>, assignTo: Long): MessageResponse { |
|
|
open fun releasePickOrders(pickOrderIds: List<Long>, assignTo: Long): MessageResponse { |
|
|
try { |
|
|
try { |
|
|
val pickOrders = pickOrderRepository.findAllById(pickOrderIds) |
|
|
val pickOrders = pickOrderRepository.findAllById(pickOrderIds) |
|
|
|