@things-factory/operato-hub 4.3.265 → 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
|
@@ -447,14 +447,14 @@ async function createReleaseGood(
|
|
|
447
447
|
// standardise country
|
|
448
448
|
let deliveryCountry: GeoCountry = releaseGood?.country
|
|
449
449
|
? await geoCountryRepo.findOne({
|
|
450
|
-
|
|
451
|
-
|
|
450
|
+
where: [{ name: ILike(releaseGood?.country) }, { description: ILike(releaseGood?.country) }]
|
|
451
|
+
})
|
|
452
452
|
: null
|
|
453
453
|
|
|
454
454
|
let platformCountry: GeoCountry = releaseGood?.platformCountry
|
|
455
455
|
? await geoCountryRepo.findOne({
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
where: [{ name: ILike(releaseGood.platformCountry) }, { description: ILike(releaseGood.platformCountry) }]
|
|
457
|
+
})
|
|
458
458
|
: null
|
|
459
459
|
|
|
460
460
|
// assign lmd
|
|
@@ -867,107 +867,106 @@ async function assignToInventory(
|
|
|
867
867
|
|
|
868
868
|
let assignedOrderInventories = []
|
|
869
869
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
let sortings: any = []
|
|
870
|
+
const orderInventory = orderProduct.orderInventories[0]
|
|
871
|
+
let sortings: any = []
|
|
873
872
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
} else {
|
|
883
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
873
|
+
if (worksheetPickingAssignment?.value !== 'true') {
|
|
874
|
+
switch (orderInventory.product.pickingStrategy) {
|
|
875
|
+
case 'LIFO':
|
|
876
|
+
sortings.push({ name: 'iv.created_at', desc: true })
|
|
877
|
+
if (pickingProductSetting?.value) {
|
|
878
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
879
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
884
880
|
}
|
|
881
|
+
} else {
|
|
882
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
883
|
+
}
|
|
885
884
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
}
|
|
893
|
-
} else {
|
|
894
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
885
|
+
break
|
|
886
|
+
case 'FEFO':
|
|
887
|
+
sortings.push({ name: 'iv.expiration_date', desc: false }, { name: 'iv.created_at', desc: false })
|
|
888
|
+
if (pickingProductSetting?.value) {
|
|
889
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
890
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
895
891
|
}
|
|
892
|
+
} else {
|
|
893
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
894
|
+
}
|
|
896
895
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
}
|
|
904
|
-
} else {
|
|
905
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
896
|
+
break
|
|
897
|
+
case 'FMFO':
|
|
898
|
+
sortings.push({ name: 'iv.manufacture_date', desc: false }, { name: 'iv.created_at', desc: false })
|
|
899
|
+
if (pickingProductSetting?.value) {
|
|
900
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
901
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
906
902
|
}
|
|
903
|
+
} else {
|
|
904
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
905
|
+
}
|
|
907
906
|
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
}
|
|
914
|
-
} else {
|
|
915
|
-
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
907
|
+
break
|
|
908
|
+
case 'LOCATION':
|
|
909
|
+
if (pickingProductSetting?.value) {
|
|
910
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
911
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
916
912
|
}
|
|
913
|
+
} else {
|
|
914
|
+
sortings.push({ name: 'loc.name', desc: false }, { name: 'iv.created_at', desc: false })
|
|
915
|
+
}
|
|
917
916
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
}
|
|
926
|
-
} else {
|
|
927
|
-
sortings.push({ name: 'loc.name', desc: false })
|
|
928
|
-
sortings.push({ name: 'iv.pallet_id', desc: false })
|
|
917
|
+
break
|
|
918
|
+
//Every other case includes 'FIFO' will be applicable for this case
|
|
919
|
+
default:
|
|
920
|
+
sortings.push({ name: 'iv.created_at', desc: false })
|
|
921
|
+
if (pickingProductSetting?.value) {
|
|
922
|
+
for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
|
|
923
|
+
sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
|
|
929
924
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
(acc, itm, idx, arr) => {
|
|
937
|
-
acc.values.push(itm.filters)
|
|
938
|
-
|
|
939
|
-
switch (itm?.operator) {
|
|
940
|
-
case 'notin':
|
|
941
|
-
case 'in':
|
|
942
|
-
acc.query.push(
|
|
943
|
-
`${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
|
|
944
|
-
.map((itm, idx) => {
|
|
945
|
-
return `$${acc.values.length + 1}`
|
|
946
|
-
})
|
|
947
|
-
.join(',')})`
|
|
948
|
-
)
|
|
949
|
-
break
|
|
925
|
+
} else {
|
|
926
|
+
sortings.push({ name: 'loc.name', desc: false })
|
|
927
|
+
sortings.push({ name: 'iv.pallet_id', desc: false })
|
|
928
|
+
}
|
|
929
|
+
break
|
|
930
|
+
}
|
|
950
931
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
{
|
|
958
|
-
|
|
959
|
-
|
|
932
|
+
let queryFilters = []
|
|
933
|
+
|
|
934
|
+
let queryStrings = queryFilters.reduce(
|
|
935
|
+
(acc, itm, idx, arr) => {
|
|
936
|
+
acc.values.push(itm.filters)
|
|
937
|
+
|
|
938
|
+
switch (itm?.operator) {
|
|
939
|
+
case 'notin':
|
|
940
|
+
case 'in':
|
|
941
|
+
acc.query.push(
|
|
942
|
+
`${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
|
|
943
|
+
.map((itm, idx) => {
|
|
944
|
+
return `$${acc.values.length + 1}`
|
|
945
|
+
})
|
|
946
|
+
.join(',')})`
|
|
947
|
+
)
|
|
948
|
+
break
|
|
949
|
+
|
|
950
|
+
default:
|
|
951
|
+
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
952
|
+
break
|
|
960
953
|
}
|
|
961
|
-
|
|
954
|
+
acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
query: [],
|
|
958
|
+
values: []
|
|
959
|
+
}
|
|
960
|
+
)
|
|
962
961
|
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
962
|
+
let sortQuery = sortings
|
|
963
|
+
.map(itm => {
|
|
964
|
+
return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`
|
|
965
|
+
})
|
|
966
|
+
.join(`,`)
|
|
968
967
|
|
|
969
|
-
|
|
970
|
-
|
|
968
|
+
let updatedInventories = await tx.getRepository(Inventory).query(
|
|
969
|
+
`
|
|
971
970
|
update inventories tgt set locked_qty = coalesce(locked_qty,0) + src.reserve_qty,
|
|
972
971
|
locked_uom_value = coalesce(locked_uom_value,0) + src.reserve_uom_value,
|
|
973
972
|
updated_at = NOW(),
|
|
@@ -984,16 +983,14 @@ async function assignToInventory(
|
|
|
984
983
|
sum(qty - locked_qty - release_qty - unassigned_qty) over (order by sort_seq asc rows between unbounded preceding and current row) as lock_amount
|
|
985
984
|
from (
|
|
986
985
|
SELECT 0 as sort_seq, null as id, null as pallet_id, null as batch_id, null as batch_id_ref,
|
|
987
|
-
null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${
|
|
988
|
-
|
|
989
|
-
}' as packing_size,
|
|
986
|
+
null as unit, '${orderInventory.uom}' as uom, '${orderInventory.packingType}' as packing_type, '${orderInventory.packingSize
|
|
987
|
+
}' as packing_size,
|
|
990
988
|
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,
|
|
991
989
|
'${orderInventory.releaseQty}' as release_qty, '${orderInventory.releaseUomValue}' as release_uom_value
|
|
992
990
|
UNION
|
|
993
991
|
(
|
|
994
|
-
SELECT ROW_NUMBER() OVER(PARTITION BY iv.domain_id ORDER BY wiar.rank ${
|
|
995
|
-
|
|
996
|
-
}) as sort_seq,
|
|
992
|
+
SELECT ROW_NUMBER() OVER(PARTITION BY iv.domain_id ORDER BY wiar.rank ${sortQuery ? ', ' + sortQuery : ''
|
|
993
|
+
}) as sort_seq,
|
|
997
994
|
iv.id, iv.pallet_id, iv.batch_id, iv.batch_id_ref,
|
|
998
995
|
iv.unit, iv.uom, iv.packing_type, iv.packing_size,
|
|
999
996
|
iv.manufacture_year, iv.carton_id, iv.uom_value,
|
|
@@ -1018,77 +1015,77 @@ async function assignToInventory(
|
|
|
1018
1015
|
tgt."id", tgt."qty", tgt."pallet_id", tgt."carton_id", tgt."batch_id", tgt."batch_id_ref", tgt."unit",
|
|
1019
1016
|
tgt."uom", tgt."packing_type", tgt."packing_size", tgt."manufacture_year",
|
|
1020
1017
|
tgt."locked_qty", tgt."uom_value", tgt."locked_uom_value", src."reserve_qty", src."reserve_uom_value";`,
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1018
|
+
[
|
|
1019
|
+
user.id,
|
|
1020
|
+
domain.id,
|
|
1021
|
+
customerBizplace.id,
|
|
1022
|
+
orderInventory.packingType,
|
|
1023
|
+
orderInventory.packingSize,
|
|
1024
|
+
orderInventory.product.id,
|
|
1025
|
+
INVENTORY_STATUS.STORED,
|
|
1026
|
+
LOCATION_TYPE.QUARANTINE,
|
|
1027
|
+
LOCATION_TYPE.RESERVE,
|
|
1028
|
+
LOCATION_TYPE.STORAGE,
|
|
1029
|
+
...queryStrings.values
|
|
1030
|
+
]
|
|
1031
|
+
)
|
|
1035
1032
|
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1033
|
+
console.log({
|
|
1034
|
+
params: {
|
|
1035
|
+
user: user.id || '',
|
|
1036
|
+
domain: domain.id || '',
|
|
1037
|
+
bizplace: customerBizplace.id || '',
|
|
1038
|
+
packingType: orderInventory.packingType || '',
|
|
1039
|
+
packingSize: orderInventory.packingSize || '',
|
|
1040
|
+
productId: orderInventory.product.id || ''
|
|
1041
|
+
},
|
|
1042
|
+
result: updatedInventories[0] || '',
|
|
1043
|
+
location: 'add-release-order unstable assignInventory',
|
|
1044
|
+
time: new Date()
|
|
1045
|
+
})
|
|
1049
1046
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1047
|
+
let totalAssigned = updatedInventories[0].reduce((acc, inv) => {
|
|
1048
|
+
return acc + inv.reserve_qty
|
|
1049
|
+
}, 0)
|
|
1053
1050
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1051
|
+
if (orderProduct.releaseQty != totalAssigned) {
|
|
1052
|
+
throw new ApiError('E01', 'INSUFFICIENT_STOCK')
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
updatedInventories[0].forEach(inv => {
|
|
1056
|
+
let oi = {
|
|
1057
|
+
...orderInventory,
|
|
1058
|
+
inventory: { id: inv.id },
|
|
1059
|
+
uom: inv.uom,
|
|
1060
|
+
packingType: inv.packing_type,
|
|
1061
|
+
batchId: inv.batch_id,
|
|
1062
|
+
releaseQty: inv.reserve_qty,
|
|
1063
|
+
releaseUomValue: inv.reserve_uom_value,
|
|
1064
|
+
pickedQty: 0,
|
|
1065
|
+
packedQty: 0,
|
|
1066
|
+
type: ORDER_TYPES.RELEASE_OF_GOODS,
|
|
1067
|
+
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET,
|
|
1068
|
+
domain: { id: domain.id },
|
|
1069
|
+
bizplace: { id: customerBizplace.id }
|
|
1056
1070
|
}
|
|
1057
1071
|
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
...orderInventory,
|
|
1061
|
-
inventory: { id: inv.id },
|
|
1062
|
-
uom: inv.uom,
|
|
1063
|
-
packingType: inv.packing_type,
|
|
1064
|
-
batchId: inv.batch_id,
|
|
1065
|
-
releaseQty: inv.reserve_qty,
|
|
1066
|
-
releaseUomValue: inv.reserve_uom_value,
|
|
1067
|
-
pickedQty: 0,
|
|
1068
|
-
packedQty: 0,
|
|
1069
|
-
type: ORDER_TYPES.RELEASE_OF_GOODS,
|
|
1070
|
-
status: ORDER_INVENTORY_STATUS.PENDING_WORKSHEET,
|
|
1071
|
-
domain: { id: domain.id },
|
|
1072
|
-
bizplace: { id: customerBizplace.id }
|
|
1073
|
-
}
|
|
1072
|
+
assignedOrderInventories.push(oi)
|
|
1073
|
+
})
|
|
1074
1074
|
|
|
1075
|
-
|
|
1075
|
+
orderProducts[opIdx].orderInventories = assignedOrderInventories
|
|
1076
|
+
} else {
|
|
1077
|
+
await tx
|
|
1078
|
+
.getRepository(ProductDetailStock)
|
|
1079
|
+
.createQueryBuilder()
|
|
1080
|
+
.update(ProductDetailStock)
|
|
1081
|
+
.set({
|
|
1082
|
+
unassignedQty: () => `"unassigned_qty" + ${orderInventory.releaseQty}`,
|
|
1083
|
+
unassignedUomValue: () => `"unassigned_uom_value" + ${orderInventory.releaseUomValue}`
|
|
1076
1084
|
})
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
} else {
|
|
1080
|
-
await tx
|
|
1081
|
-
.getRepository(ProductDetailStock)
|
|
1082
|
-
.createQueryBuilder()
|
|
1083
|
-
.update(ProductDetailStock)
|
|
1084
|
-
.set({
|
|
1085
|
-
unassignedQty: () => `"unassigned_qty" + ${orderInventory.releaseQty}`,
|
|
1086
|
-
unassignedUomValue: () => `"unassigned_uom_value" + ${orderInventory.releaseUomValue}`
|
|
1087
|
-
})
|
|
1088
|
-
.where({ productDetail: orderInventory.productDetail.id })
|
|
1089
|
-
.execute()
|
|
1090
|
-
}
|
|
1085
|
+
.where({ productDetail: orderInventory.productDetail.id })
|
|
1086
|
+
.execute()
|
|
1091
1087
|
}
|
|
1088
|
+
|
|
1092
1089
|
}
|
|
1093
1090
|
|
|
1094
1091
|
return orderProducts
|