59 lines
2.5 KiB
JavaScript
59 lines
2.5 KiB
JavaScript
export const CONTAINER_CONVERT_ENDPOINT = '/api/platform/v1/last-leg/inbound-plans/convert'
|
|
export const CONTAINER_CONVERT_EXPECTED_ORDERS = 15
|
|
|
|
export function groupOrdersByCustomer(orders) {
|
|
if (!Array.isArray(orders)) return new Map()
|
|
const result = new Map()
|
|
for (const order of orders) {
|
|
const customerId = String(order?.customerId ?? '').trim()
|
|
if (!customerId) return new Map()
|
|
result.set(customerId, [...(result.get(customerId) || []), order])
|
|
}
|
|
return result
|
|
}
|
|
|
|
export function validContainerBatchResult(result, sourceOrders) {
|
|
const plans = Array.isArray(result?.plans) ? result.plans : []
|
|
if (!Array.isArray(sourceOrders) || !sourceOrders.length || plans.length !== sourceOrders.length) return false
|
|
const sourceIds = new Set(sourceOrders.map((order) => String(order.orderId)))
|
|
const resultIds = plans.flatMap((plan) => Array.isArray(plan?.lines) ? plan.lines : [])
|
|
.map((line) => String(line?.orderId))
|
|
return resultIds.length === sourceIds.size
|
|
&& new Set(resultIds).size === sourceIds.size
|
|
&& resultIds.every((orderId) => sourceIds.has(orderId))
|
|
&& plans.every((plan) => {
|
|
const lines = Array.isArray(plan?.lines) ? plan.lines : []
|
|
const expected = sourceOrders.find((order) => String(order.orderId) === String(lines[0]?.orderId))
|
|
return plan?.status === 'PENDING_ASSIGNMENT'
|
|
&& lines.length === 1 && expected != null
|
|
&& String(plan?.customerId ?? '') === String(expected.customerId)
|
|
&& String(plan?.planNo ?? '').length > 0
|
|
&& Array.isArray(plan?.pallets) && Array.isArray(plan?.allocations)
|
|
})
|
|
}
|
|
|
|
export function validOrderFact(actual, expected) {
|
|
const exact = (field) => (actual?.[field] ?? null) === (expected?.[field] ?? null)
|
|
return ['packageCount', 'volumeCbm', 'productQuantity', 'volumeWeightKg',
|
|
'palletCount', 'estimatedArrivalAt', 'actualArrivalAt', 'estimatedWarehouseAt'].every(exact)
|
|
}
|
|
|
|
export function distinctPhysicalPalletCount(rows) {
|
|
if (!Array.isArray(rows)) return 0
|
|
return new Set(rows.map((row) => String(row?.physicalPalletId ?? '').trim()).filter(Boolean)).size
|
|
}
|
|
|
|
export function zeroDrift(before, after) {
|
|
return JSON.stringify(before) === JSON.stringify(after)
|
|
}
|
|
|
|
export function stableReplay(first, replay) {
|
|
return zeroDrift(first, replay)
|
|
}
|
|
|
|
export function validPdaCandidate(candidate, expected) {
|
|
return String(candidate?.containerNo ?? '') === String(expected?.containerNo ?? '')
|
|
&& Number(candidate?.planCount) === Number(expected?.planCount)
|
|
&& Number(candidate?.inboundCodeCount) === Number(expected?.inboundCodeCount)
|
|
}
|