@things-factory/operato-hub 4.3.266 → 4.3.267
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +124 -141
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js +126 -128
- package/dist-server/routers/api/restful-apis/v1/warehouse/add-release-order.js.map +1 -1
- package/dist-server/routers/xilnex-router.js +109 -111
- package/dist-server/routers/xilnex-router.js.map +1 -1
- package/package.json +11 -11
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +154 -174
- package/server/routers/api/restful-apis/v1/warehouse/add-release-order.ts +157 -160
- package/server/routers/xilnex-router.ts +134 -136
|
@@ -523,14 +523,14 @@ async function createReleaseGood(
|
|
|
523
523
|
// standardise country
|
|
524
524
|
let deliveryCountry: GeoCountry = releaseGood?.country
|
|
525
525
|
? await geoCountryRepo.findOne({
|
|
526
|
-
|
|
527
|
-
|
|
526
|
+
where: [{ name: ILike(releaseGood?.country) }, { description: ILike(releaseGood?.country) }]
|
|
527
|
+
})
|
|
528
528
|
: null
|
|
529
529
|
|
|
530
530
|
let platformCountry: GeoCountry = releaseGood?.platformCountry
|
|
531
531
|
? await geoCountryRepo.findOne({
|
|
532
|
-
|
|
533
|
-
|
|
532
|
+
where: [{ name: ILike(releaseGood.platformCountry) }, { description: ILike(releaseGood.platformCountry) }]
|
|
533
|
+
})
|
|
534
534
|
: null
|
|
535
535
|
|
|
536
536
|
// assign lmd
|
|
@@ -995,107 +995,106 @@ async function assignToInventory(
|
|
|
995
995
|
|
|
996
996
|
let assignedOrderInventories = []
|
|
997
997
|
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1009
|
-
}
|
|
1010
|
-
} else {
|
|
1011
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
998
|
+
const orderInventory = orderProduct.orderInventories[0]
|
|
999
|
+
let sortings: any = []
|
|
1000
|
+
|
|
1001
|
+
if (worksheetPickingAssignment?.value !== 'true') {
|
|
1002
|
+
switch (orderInventory.product.pickingStrategy) {
|
|
1003
|
+
case 'LIFO':
|
|
1004
|
+
sortings.push({ name: 'iv.created_at', desc: true })
|
|
1005
|
+
if (pickingProductSetting?.value) {
|
|
1006
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1007
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1012
1008
|
}
|
|
1009
|
+
} else {
|
|
1010
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1011
|
+
}
|
|
1013
1012
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
} else {
|
|
1022
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1013
|
+
break
|
|
1014
|
+
case 'FEFO':
|
|
1015
|
+
sortings.push({ name: 'iv.expiration_date', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1016
|
+
if (pickingProductSetting?.value) {
|
|
1017
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1018
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1023
1019
|
}
|
|
1020
|
+
} else {
|
|
1021
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1022
|
+
}
|
|
1024
1023
|
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
1032
|
-
} else {
|
|
1033
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1024
|
+
break
|
|
1025
|
+
case 'FMFO':
|
|
1026
|
+
sortings.push({ name: 'iv.manufacture_date', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1027
|
+
if (pickingProductSetting?.value) {
|
|
1028
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1029
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1034
1030
|
}
|
|
1031
|
+
} else {
|
|
1032
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1033
|
+
}
|
|
1035
1034
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
}
|
|
1042
|
-
} else {
|
|
1043
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1035
|
+
break
|
|
1036
|
+
case 'LOCATION':
|
|
1037
|
+
if (pickingProductSetting?.value) {
|
|
1038
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1039
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1044
1040
|
}
|
|
1041
|
+
} else {
|
|
1042
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
1043
|
+
}
|
|
1045
1044
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
}
|
|
1054
|
-
} else {
|
|
1055
|
-
sortings.push({ name: 'loc.name', desc: false })
|
|
1056
|
-
sortings.push({ name: 'iv.pallet_id', desc: false })
|
|
1045
|
+
break
|
|
1046
|
+
//Every other case includes 'FIFO' will be applicable for this case
|
|
1047
|
+
default:
|
|
1048
|
+
sortings.push({ name: 'iv.created_at', desc: false })
|
|
1049
|
+
if (pickingProductSetting?.value) {
|
|
1050
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
1051
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
1057
1052
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1053
|
+
} else {
|
|
1054
|
+
sortings.push({ name: 'loc.name', desc: false })
|
|
1055
|
+
sortings.push({ name: 'iv.pallet_id', desc: false })
|
|
1056
|
+
}
|
|
1057
|
+
break
|
|
1058
|
+
}
|
|
1060
1059
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1060
|
+
let queryFilters = []
|
|
1061
|
+
|
|
1062
|
+
let queryStrings = queryFilters.reduce(
|
|
1063
|
+
(acc, itm, idx, arr) => {
|
|
1064
|
+
acc.values.push(itm.filters)
|
|
1065
|
+
|
|
1066
|
+
switch (itm?.operator) {
|
|
1067
|
+
case 'notin':
|
|
1068
|
+
case 'in':
|
|
1069
|
+
acc.query.push(
|
|
1070
|
+
`${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
|
|
1071
|
+
.map((itm, idx) => {
|
|
1072
|
+
return `$${acc.values.length + 1}`
|
|
1073
|
+
})
|
|
1074
|
+
.join(',')})`
|
|
1075
|
+
)
|
|
1076
|
+
break
|
|
1078
1077
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
}
|
|
1083
|
-
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
1084
|
-
},
|
|
1085
|
-
{
|
|
1086
|
-
query: [],
|
|
1087
|
-
values: []
|
|
1078
|
+
default:
|
|
1079
|
+
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
1080
|
+
break
|
|
1088
1081
|
}
|
|
1089
|
-
|
|
1082
|
+
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
query: [],
|
|
1086
|
+
values: []
|
|
1087
|
+
}
|
|
1088
|
+
)
|
|
1090
1089
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1090
|
+
let sortQuery = sortings
|
|
1091
|
+
.map(itm => {
|
|
1092
|
+
return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`
|
|
1093
|
+
})
|
|
1094
|
+
.join(`,`)
|
|
1096
1095
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1096
|
+
let updatedInventories = await tx.getRepository(Inventory).query(
|
|
1097
|
+
`
|
|
1099
1098
|
update inventories tgt set locked_qty = coalesce(locked_qty,0) + src.reserve_qty,
|
|
1100
1099
|
locked_uom_value = coalesce(locked_uom_value,0) + src.reserve_uom_value,
|
|
1101
1100
|
updated_at = NOW(),
|
|
@@ -1112,16 +1111,14 @@ async function assignToInventory(
|
|
|
1112
1111
|
sum(qty - locked_qty - release_qty - unassigned_qty) over (order by sort_seq asc rows between unbounded preceding and current row) as lock_amount
|
|
1113
1112
|
from (
|
|
1114
1113
|
SELECT 0 as sort_seq, null as id, null as pallet_id, null as batch_id, null as batch_id_ref,
|
|
1115
|
-
null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${
|
|
1116
|
-
|
|
1117
|
-
}' as packing_size,
|
|
1114
|
+
null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${orderInventory.packingSize
|
|
1115
|
+
}' as packing_size,
|
|
1118
1116
|
null as manufacture_year, null as carton_id, 0 as uom_value, 0 as locked_uom_value, 0 as qty, 0 as locked_qty, 0 as unassigned_uom_value, 0 as unassigned_qty, null as created_at,
|
|
1119
1117
|
'${orderInventory.releaseQty}' as release_qty, '${orderInventory.releaseUomValue}' as release_uom_value
|
|
1120
1118
|
UNION
|
|
1121
1119
|
(
|
|
1122
|
-
SELECT ROW_NUMBER() OVER(PARTITION BY iv.domain_id ORDER BY wiar.rank ${
|
|
1123
|
-
|
|
1124
|
-
}) as sort_seq,
|
|
1120
|
+
SELECT ROW_NUMBER() OVER(PARTITION BY iv.domain_id ORDER BY wiar.rank ${sortQuery ? ', ' + sortQuery : ''
|
|
1121
|
+
}) as sort_seq,
|
|
1125
1122
|
iv.id, iv.pallet_id, iv.batch_id, iv.batch_id_ref,
|
|
1126
1123
|
iv.unit, iv.uom, iv.packing_type, iv.packing_size,
|
|
1127
1124
|
iv.manufacture_year, iv.carton_id, iv.uom_value,
|
|
@@ -1146,90 +1143,73 @@ async function assignToInventory(
|
|
|
1146
1143
|
tgt."id", tgt."qty", tgt."pallet_id", tgt."carton_id", tgt."batch_id", tgt."batch_id_ref", tgt."unit",
|
|
1147
1144
|
tgt."uom", tgt."packing_type", tgt."packing_size", tgt."manufacture_year",
|
|
1148
1145
|
tgt."locked_qty", tgt."uom_value", tgt."locked_uom_value", src."reserve_qty", src."reserve_uom_value";`,
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1146
|
+
[
|
|
1147
|
+
user.id,
|
|
1148
|
+
domain.id,
|
|
1149
|
+
customerBizplace.id,
|
|
1150
|
+
orderInventory.packingType,
|
|
1151
|
+
orderInventory.packingSize,
|
|
1152
|
+
orderInventory.product.id,
|
|
1153
|
+
INVENTORY_STATUS.STORED,
|
|
1154
|
+
LOCATION_TYPE.QUARANTINE,
|
|
1155
|
+
LOCATION_TYPE.RESERVE,
|
|
1156
|
+
LOCATION_TYPE.STORAGE,
|
|
1157
|
+
...queryStrings.values
|
|
1158
|
+
]
|
|
1159
|
+
)
|
|
1163
1160
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1161
|
+
let totalAssigned = updatedInventories[0].reduce((acc, inv) => {
|
|
1162
|
+
return acc + inv.reserve_qty
|
|
1163
|
+
}, 0)
|
|
1164
|
+
|
|
1165
|
+
if (orderProduct.releaseQty != totalAssigned) {
|
|
1166
|
+
throw new ValidationError({
|
|
1167
|
+
errorCode: 'INSUFFICIENT_STOCK',
|
|
1168
|
+
message: 'insufficient stock',
|
|
1169
|
+
detail: JSON.stringify({
|
|
1170
|
+
code: 'insufficient stock',
|
|
1171
|
+
sku: orderProduct.product.sku,
|
|
1172
|
+
packingType: orderProduct.packingType,
|
|
1173
|
+
packingSize: orderProduct.packingSize,
|
|
1174
|
+
uom: orderProduct.uom,
|
|
1175
|
+
qty: orderProduct.releaseQty,
|
|
1176
|
+
uom_value: orderProduct.releaseUomValue
|
|
1177
|
+
})
|
|
1178
1178
|
})
|
|
1179
|
+
}
|
|
1179
1180
|
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
uom_value: orderInventory.releaseUomValue
|
|
1196
|
-
})
|
|
1197
|
-
})
|
|
1181
|
+
updatedInventories[0].forEach(inv => {
|
|
1182
|
+
let oi = {
|
|
1183
|
+
...orderInventory,
|
|
1184
|
+
inventory: { id: inv.id },
|
|
1185
|
+
uom: inv.uom,
|
|
1186
|
+
packingType: inv.packing_type,
|
|
1187
|
+
batchId: inv.batch_id,
|
|
1188
|
+
releaseQty: inv.reserve_qty,
|
|
1189
|
+
releaseUomValue: inv.reserve_uom_value,
|
|
1190
|
+
pickedQty: 0,
|
|
1191
|
+
packedQty: 0,
|
|
1192
|
+
type: ORDER_TYPES.RELEASE_OF_GOODS,
|
|
1193
|
+
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET,
|
|
1194
|
+
domain: { id: domain.id },
|
|
1195
|
+
bizplace: { id: customerBizplace.id }
|
|
1198
1196
|
}
|
|
1199
1197
|
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
...orderInventory,
|
|
1203
|
-
inventory: { id: inv.id },
|
|
1204
|
-
uom: inv.uom,
|
|
1205
|
-
packingType: inv.packing_type,
|
|
1206
|
-
batchId: inv.batch_id,
|
|
1207
|
-
releaseQty: inv.reserve_qty,
|
|
1208
|
-
releaseUomValue: inv.reserve_uom_value,
|
|
1209
|
-
pickedQty: 0,
|
|
1210
|
-
packedQty: 0,
|
|
1211
|
-
type: ORDER_TYPES.RELEASE_OF_GOODS,
|
|
1212
|
-
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET,
|
|
1213
|
-
domain: { id: domain.id },
|
|
1214
|
-
bizplace: { id: customerBizplace.id }
|
|
1215
|
-
}
|
|
1198
|
+
assignedOrderInventories.push(oi)
|
|
1199
|
+
})
|
|
1216
1200
|
|
|
1217
|
-
|
|
1201
|
+
orderProducts[opIdx].orderInventories = assignedOrderInventories
|
|
1202
|
+
} else {
|
|
1203
|
+
await tx
|
|
1204
|
+
.getRepository(ProductDetailStock)
|
|
1205
|
+
.createQueryBuilder()
|
|
1206
|
+
.update(ProductDetailStock)
|
|
1207
|
+
.set({
|
|
1208
|
+
unassignedQty: () => `"unassigned_qty" + ${orderInventory.releaseQty}`,
|
|
1209
|
+
unassignedUomValue: () => `"unassigned_uom_value" + ${orderInventory.releaseUomValue}`
|
|
1218
1210
|
})
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
} else {
|
|
1222
|
-
await tx
|
|
1223
|
-
.getRepository(ProductDetailStock)
|
|
1224
|
-
.createQueryBuilder()
|
|
1225
|
-
.update(ProductDetailStock)
|
|
1226
|
-
.set({
|
|
1227
|
-
unassignedQty: () => `"unassigned_qty" + ${orderInventory.releaseQty}`,
|
|
1228
|
-
unassignedUomValue: () => `"unassigned_uom_value" + ${orderInventory.releaseUomValue}`
|
|
1229
|
-
})
|
|
1230
|
-
.where({ productDetail: orderInventory.productDetail.id })
|
|
1231
|
-
.execute()
|
|
1232
|
-
}
|
|
1211
|
+
.where({ productDetail: orderInventory.productDetail.id })
|
|
1212
|
+
.execute()
|
|
1233
1213
|
}
|
|
1234
1214
|
}
|
|
1235
1215
|
|