@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.
@@ -523,14 +523,14 @@ async function createReleaseGood(
523
523
  // standardise country
524
524
  let deliveryCountry: GeoCountry = releaseGood?.country
525
525
  ? await geoCountryRepo.findOne({
526
- where: [{ name: ILike(releaseGood?.country) }, { description: ILike(releaseGood?.country) }]
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
- where: [{ name: ILike(releaseGood.platformCountry) }, { description: ILike(releaseGood.platformCountry) }]
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
- for (let oiIdx = 0; oiIdx < orderProducts[opIdx].orderInventories.length; oiIdx++) {
999
- const orderInventory = orderProduct.orderInventories[oiIdx]
1000
- let sortings: any = []
1001
-
1002
- if (worksheetPickingAssignment?.value !== 'true') {
1003
- switch (orderInventory.product.pickingStrategy) {
1004
- case 'LIFO':
1005
- sortings.push({ name: 'iv.created_at', desc: true })
1006
- if (pickingProductSetting?.value) {
1007
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
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
- break
1015
- case 'FEFO':
1016
- sortings.push({ name: 'iv.expiration_date', desc: false }, { name: 'iv.created_at', desc: false })
1017
- if (pickingProductSetting?.value) {
1018
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
1019
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
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
- break
1026
- case 'FMFO':
1027
- sortings.push({ name: 'iv.manufacture_date', desc: false }, { name: 'iv.created_at', desc: false })
1028
- if (pickingProductSetting?.value) {
1029
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
1030
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
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
- break
1037
- case 'LOCATION':
1038
- if (pickingProductSetting?.value) {
1039
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
1040
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
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
- break
1047
- //Every other case includes 'FIFO' will be applicable for this case
1048
- default:
1049
- sortings.push({ name: 'iv.created_at', desc: false })
1050
- if (pickingProductSetting?.value) {
1051
- for (const [key, value] of Object.entries(JSON.parse(pickingProductSetting.value))) {
1052
- sortings.push({ name: `loc.${key}`, desc: value == 'DESC' ? true : false })
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
- break
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
- let queryFilters = []
1062
-
1063
- let queryStrings = queryFilters.reduce(
1064
- (acc, itm, idx, arr) => {
1065
- acc.values.push(itm.filters)
1066
-
1067
- switch (itm?.operator) {
1068
- case 'notin':
1069
- case 'in':
1070
- acc.query.push(
1071
- `${itm.query} ${itm.operator == 'notin' ? 'NOT IN' : 'IN'} (${itm.filtes
1072
- .map((itm, idx) => {
1073
- return `$${acc.values.length + 1}`
1074
- })
1075
- .join(',')})`
1076
- )
1077
- break
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
- default:
1080
- acc.query.push(`${itm.query} ${itm?.operator ? itm.operator : '='} $${acc.values.length + 1}`)
1081
- break
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
- let sortQuery = sortings
1092
- .map(itm => {
1093
- return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`
1094
- })
1095
- .join(`,`)
1090
+ let sortQuery = sortings
1091
+ .map(itm => {
1092
+ return `${itm.name} ${itm.desc ? 'DESC' : 'ASC'}`
1093
+ })
1094
+ .join(`,`)
1096
1095
 
1097
- let updatedInventories = await tx.getRepository(Inventory).query(
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
- orderInventory.packingSize
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
- sortQuery ? ', ' + sortQuery : ''
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
- user.id,
1151
- domain.id,
1152
- customerBizplace.id,
1153
- orderInventory.packingType,
1154
- orderInventory.packingSize,
1155
- orderInventory.product.id,
1156
- INVENTORY_STATUS.STORED,
1157
- LOCATION_TYPE.QUARANTINE,
1158
- LOCATION_TYPE.RESERVE,
1159
- LOCATION_TYPE.STORAGE,
1160
- ...queryStrings.values
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
- console.log({
1165
- params: {
1166
- user: user.id || '',
1167
- domain: domain.id || '',
1168
- bizplace: customerBizplace.id || '',
1169
- packingType: orderInventory.packingType || '',
1170
- packingSize: orderInventory.packingSize || '',
1171
- productId: orderInventory.product.id || ''
1172
- },
1173
- result: updatedInventories[0] || '',
1174
- ro: releaseGood || '',
1175
- orderProducts: orderProducts || '',
1176
- location: 'add-release-order unstable assignInventory',
1177
- time: new Date()
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
- let totalAssigned = updatedInventories[0].reduce((acc, inv) => {
1181
- return acc + inv.reserve_qty
1182
- }, 0)
1183
-
1184
- if (orderInventory.releaseQty != totalAssigned) {
1185
- throw new ValidationError({
1186
- errorCode: 'INSUFFICIENT_STOCK',
1187
- message: 'insufficient stock',
1188
- detail: JSON.stringify({
1189
- code: 'insufficient stock',
1190
- sku: orderInventory.product.sku,
1191
- packingType: orderInventory.packingType,
1192
- packingSize: orderInventory.packingSize,
1193
- uom: orderInventory.uom,
1194
- qty: orderInventory.releaseQty,
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
- updatedInventories[0].forEach(inv => {
1201
- let oi = {
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
- assignedOrderInventories.push(oi)
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
- orderProducts[opIdx].orderInventories = assignedOrderInventories
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