@things-factory/operato-wms 4.3.592 → 4.3.595

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.
Files changed (131) hide show
  1. package/client/pages/components/list-view/product-list-view.js +378 -0
  2. package/client/pages/constants/picking-standard.js +1 -0
  3. package/client/pages/constants/worksheet.js +12 -0
  4. package/client/pages/inventory-check/cycle-count-inventory-details-popup.js +12 -12
  5. package/client/pages/inventory-check/cycle-count-report.js +181 -91
  6. package/client/pages/inventory-check/inspecting-product.js +56 -12
  7. package/client/pages/order/release-order/b2b/b2b-order-list.js +91 -39
  8. package/client/pages/outbound/generate-worksheet-popup.js +188 -25
  9. package/client/pages/outbound/loading-v2/delivery-order-info.js +205 -0
  10. package/client/pages/outbound/loading-v2/load-by-qty.js +151 -0
  11. package/client/pages/outbound/loading-v2/loading-execution-base.js +514 -0
  12. package/client/pages/outbound/loading-v2/loading-execution.js +392 -0
  13. package/client/pages/outbound/loading-v2/loading.js +419 -0
  14. package/client/pages/outbound/loading-v2/release-good-info.js +93 -0
  15. package/client/pages/outbound/loading-v2/show-my-loading-worksheet-list-popup.js +93 -0
  16. package/client/pages/outbound/loading-v2/warehouse-return-popup.js +194 -0
  17. package/client/pages/outbound/picking-v2/issue-details-popup.js +163 -0
  18. package/client/pages/outbound/picking-v2/picking-execution-base.js +482 -0
  19. package/client/pages/outbound/picking-v2/picking-execution.js +379 -0
  20. package/client/pages/outbound/picking-v2/picking.js +387 -0
  21. package/client/pages/outbound/picking-v2/report-issue-popup.js +139 -0
  22. package/client/pages/outbound/picking-v2/scan-bin-no-popup.js +126 -0
  23. package/client/pages/outbound/picking-v2/worksheet-info.js +200 -0
  24. package/client/pages/outbound/select-operator-popup.js +6 -3
  25. package/client/pages/outbound/show-my-worksheet-list-popup.js +6 -2
  26. package/client/pages/outbound/worksheet-zone-picking.js +507 -0
  27. package/client/pages/outbound/zone-worksheet.js +574 -0
  28. package/client/route.js +15 -0
  29. package/dist-server/graphql/resolvers/index.js +11 -2
  30. package/dist-server/graphql/resolvers/index.js.map +1 -1
  31. package/dist-server/graphql/resolvers/outbound/complete-load.js +96 -0
  32. package/dist-server/graphql/resolvers/outbound/complete-load.js.map +1 -0
  33. package/dist-server/graphql/resolvers/outbound/find-loadable-release-good.js +58 -0
  34. package/dist-server/graphql/resolvers/outbound/find-loadable-release-good.js.map +1 -0
  35. package/dist-server/graphql/resolvers/outbound/get-delivery-orders.js +29 -0
  36. package/dist-server/graphql/resolvers/outbound/get-delivery-orders.js.map +1 -0
  37. package/dist-server/graphql/resolvers/outbound/get-loading-task.js +86 -0
  38. package/dist-server/graphql/resolvers/outbound/get-loading-task.js.map +1 -0
  39. package/dist-server/graphql/resolvers/outbound/index.js +16 -0
  40. package/dist-server/graphql/resolvers/outbound/index.js.map +1 -0
  41. package/dist-server/graphql/resolvers/outbound/load-by-qty.js +112 -0
  42. package/dist-server/graphql/resolvers/outbound/load-by-qty.js.map +1 -0
  43. package/dist-server/graphql/resolvers/outbound/loading-worksheet-v2.js +122 -0
  44. package/dist-server/graphql/resolvers/outbound/loading-worksheet-v2.js.map +1 -0
  45. package/dist-server/graphql/resolvers/outbound/my-loading-assignment-status.js +32 -0
  46. package/dist-server/graphql/resolvers/outbound/my-loading-assignment-status.js.map +1 -0
  47. package/dist-server/graphql/resolvers/outbound/sort-item.js +65 -0
  48. package/dist-server/graphql/resolvers/outbound/sort-item.js.map +1 -0
  49. package/dist-server/graphql/resolvers/outbound/undo-load.js +72 -0
  50. package/dist-server/graphql/resolvers/outbound/undo-load.js.map +1 -0
  51. package/dist-server/graphql/resolvers/outbound/warehouse-return.js +101 -0
  52. package/dist-server/graphql/resolvers/outbound/warehouse-return.js.map +1 -0
  53. package/dist-server/graphql/resolvers/reports/cycle-count-report.js +119 -86
  54. package/dist-server/graphql/resolvers/reports/cycle-count-report.js.map +1 -1
  55. package/dist-server/graphql/resolvers/warehouse-inventory-adjustment/warehouse-intentory-adjustment.js +53 -25
  56. package/dist-server/graphql/resolvers/warehouse-inventory-adjustment/warehouse-intentory-adjustment.js.map +1 -1
  57. package/dist-server/graphql/resolvers/zone-worksheet/activate-zone-worksheet.js +91 -0
  58. package/dist-server/graphql/resolvers/zone-worksheet/activate-zone-worksheet.js.map +1 -0
  59. package/dist-server/graphql/resolvers/zone-worksheet/assign-sorter.js +36 -0
  60. package/dist-server/graphql/resolvers/zone-worksheet/assign-sorter.js.map +1 -0
  61. package/dist-server/graphql/resolvers/zone-worksheet/generate-zone-worksheet.js +103 -0
  62. package/dist-server/graphql/resolvers/zone-worksheet/generate-zone-worksheet.js.map +1 -0
  63. package/dist-server/graphql/resolvers/zone-worksheet/get-zone-picking-task.js +98 -0
  64. package/dist-server/graphql/resolvers/zone-worksheet/get-zone-picking-task.js.map +1 -0
  65. package/dist-server/graphql/resolvers/zone-worksheet/index.js +12 -0
  66. package/dist-server/graphql/resolvers/zone-worksheet/index.js.map +1 -0
  67. package/dist-server/graphql/resolvers/zone-worksheet/zone-picking.js +327 -0
  68. package/dist-server/graphql/resolvers/zone-worksheet/zone-picking.js.map +1 -0
  69. package/dist-server/graphql/resolvers/zone-worksheet/zone-worksheet.js +146 -0
  70. package/dist-server/graphql/resolvers/zone-worksheet/zone-worksheet.js.map +1 -0
  71. package/dist-server/graphql/types/index.js +11 -3
  72. package/dist-server/graphql/types/index.js.map +1 -1
  73. package/dist-server/graphql/types/outbound/delivery-order-info-list.js +14 -0
  74. package/dist-server/graphql/types/outbound/delivery-order-info-list.js.map +1 -0
  75. package/dist-server/graphql/types/outbound/index.js +23 -0
  76. package/dist-server/graphql/types/outbound/index.js.map +1 -0
  77. package/dist-server/graphql/types/outbound/loading-assignment.js +15 -0
  78. package/dist-server/graphql/types/outbound/loading-assignment.js.map +1 -0
  79. package/dist-server/graphql/types/outbound/loading-worksheet-type.js +25 -0
  80. package/dist-server/graphql/types/outbound/loading-worksheet-type.js.map +1 -0
  81. package/dist-server/graphql/types/reports/cycle-count-report.js +2 -0
  82. package/dist-server/graphql/types/reports/cycle-count-report.js.map +1 -1
  83. package/dist-server/graphql/types/reports/index.js +1 -1
  84. package/dist-server/graphql/types/reports/index.js.map +1 -1
  85. package/dist-server/graphql/types/zone-worksheet/index.js +22 -0
  86. package/dist-server/graphql/types/zone-worksheet/index.js.map +1 -0
  87. package/dist-server/graphql/types/zone-worksheet/zone-picking-worksheet.js +18 -0
  88. package/dist-server/graphql/types/zone-worksheet/zone-picking-worksheet.js.map +1 -0
  89. package/dist-server/graphql/types/zone-worksheet/zone-worksheet-overview-list.js +13 -0
  90. package/dist-server/graphql/types/zone-worksheet/zone-worksheet-overview-list.js.map +1 -0
  91. package/dist-server/graphql/types/zone-worksheet/zone-worksheet-overview.js +16 -0
  92. package/dist-server/graphql/types/zone-worksheet/zone-worksheet-overview.js.map +1 -0
  93. package/helps/release-note.md +20 -12
  94. package/package.json +8 -8
  95. package/server/graphql/resolvers/index.ts +11 -2
  96. package/server/graphql/resolvers/outbound/complete-load.ts +126 -0
  97. package/server/graphql/resolvers/outbound/find-loadable-release-good.ts +61 -0
  98. package/server/graphql/resolvers/outbound/get-delivery-orders.ts +32 -0
  99. package/server/graphql/resolvers/outbound/get-loading-task.ts +105 -0
  100. package/server/graphql/resolvers/outbound/index.ts +26 -0
  101. package/server/graphql/resolvers/outbound/load-by-qty.ts +176 -0
  102. package/server/graphql/resolvers/outbound/loading-worksheet-v2.ts +131 -0
  103. package/server/graphql/resolvers/outbound/my-loading-assignment-status.ts +35 -0
  104. package/server/graphql/resolvers/outbound/sort-item.ts +81 -0
  105. package/server/graphql/resolvers/outbound/undo-load.ts +83 -0
  106. package/server/graphql/resolvers/outbound/warehouse-return.ts +129 -0
  107. package/server/graphql/resolvers/reports/cycle-count-report.ts +125 -87
  108. package/server/graphql/resolvers/warehouse-inventory-adjustment/warehouse-intentory-adjustment.ts +77 -35
  109. package/server/graphql/resolvers/zone-worksheet/activate-zone-worksheet.ts +124 -0
  110. package/server/graphql/resolvers/zone-worksheet/assign-sorter.ts +49 -0
  111. package/server/graphql/resolvers/zone-worksheet/generate-zone-worksheet.ts +133 -0
  112. package/server/graphql/resolvers/zone-worksheet/get-zone-picking-task.ts +118 -0
  113. package/server/graphql/resolvers/zone-worksheet/index.ts +20 -0
  114. package/server/graphql/resolvers/zone-worksheet/zone-picking.ts +458 -0
  115. package/server/graphql/resolvers/zone-worksheet/zone-worksheet.ts +183 -0
  116. package/server/graphql/types/index.ts +11 -3
  117. package/server/graphql/types/outbound/delivery-order-info-list.ts +8 -0
  118. package/server/graphql/types/outbound/index.ts +22 -0
  119. package/server/graphql/types/outbound/loading-assignment.ts +9 -0
  120. package/server/graphql/types/outbound/loading-worksheet-type.ts +20 -0
  121. package/server/graphql/types/reports/cycle-count-report.ts +2 -0
  122. package/server/graphql/types/reports/index.ts +3 -9
  123. package/server/graphql/types/zone-worksheet/index.ts +21 -0
  124. package/server/graphql/types/zone-worksheet/zone-picking-worksheet.ts +12 -0
  125. package/server/graphql/types/zone-worksheet/zone-worksheet-overview-list.ts +7 -0
  126. package/server/graphql/types/zone-worksheet/zone-worksheet-overview.ts +10 -0
  127. package/things-factory.config.js +16 -0
  128. package/translations/en.json +31 -1
  129. package/translations/ko.json +28 -0
  130. package/translations/ms.json +30 -2
  131. package/translations/zh.json +28 -0
@@ -1,14 +1,17 @@
1
1
  import { EntityManager } from 'typeorm'
2
-
3
2
  import { User } from '@things-factory/auth-base'
4
3
  import { InventoryCheck } from '@things-factory/sales-base'
5
4
  import { ListParam, Domain } from '@things-factory/shell'
6
5
 
7
6
  export const cycleCountReport = {
8
- async cycleCountReport(_: any, { name }: { name: string }, context: any) {
7
+ async cycleCountReport(_: any, { filters, name }: { filters: any[]; name: string }, context: any) {
9
8
  try {
10
9
  const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
11
10
 
11
+ const batchNoVarianceFilter = filters?.find(e => e.name === 'batchNoVariance')
12
+ const expirationDateVarianceFilter = filters?.find(e => e.name === 'expirationDateVariance')
13
+ const locationVarianceFilter = filters?.find(e => e.name === 'locationVariance')
14
+
12
15
  const cycleCount: InventoryCheck = await tx.getRepository(InventoryCheck).findOne({
13
16
  where: { domain, name },
14
17
  relations: ['domain']
@@ -19,69 +22,68 @@ export const cycleCountReport = {
19
22
  // Step 1: Create the temp_fixed_columns table
20
23
  await tx.query(
21
24
  `
22
- CREATE TEMP TABLE temp_fixed_columns ON COMMIT DROP AS (
23
- SELECT
24
- d.id as "partner_domain_id",
25
- w.check_count as "check_count",
26
- ic.id as "inventory_check_id",
27
- ici.inventory_id as "inventory_id",
28
- ic.name as "name",
29
- ici.product_id as "product_id",
30
- ici.count_no as "count_no",
31
- ici.product_detail_id as "product_detail_id",
32
- ici.status as "invCheckItemStatus",
33
- b.name as "company",
34
- ic.name as "cycle_count_no",
35
- ic.execution_date as "execution_date",
36
- ic.status as "status",
37
- i.carton_id as "carton_id",
38
- i.pallet_id as "pallet_id",
39
- i.packing_type as "i_packing_type",
40
- i.uom as "i_uom",
41
- p.sku as "product_sku",
42
- p.name as "product_name",
43
- p.brand as "product_brand",
44
- p.description as "product_description",
45
- pd.packing_type as "pd_packing_type",
46
- pd.uom as "pd_uom",
47
- ici.origin_batch_no as "origin_batch_no",
48
- ici.inspected_batch_no as "inspected_batch_no",
49
- ici.origin_uom_value as "origin_uom_value",
50
- ici.inspected_uom_value as "inspected_uom_value",
51
- ici.origin_location_id as "origin_location_id",
52
- ici.origin_expiration_date as "origin_expiration_date",
53
- ici.inspected_expiration_date as "inspected_expiration_date",
54
- l.name as "origin_location_name",
55
- ici.inspected_location_id as "inspected_location_id",
56
- l2.name as "inspected_location_name",
57
- COALESCE(ici.origin_qty, 0) as "origin_qty",
58
- COALESCE(ici.inspected_qty, 0) as "inspected_qty"
59
- FROM
60
- inventory_checks ic
61
- inner join
25
+ CREATE TEMP TABLE temp_fixed_columns ON COMMIT DROP AS (
26
+ SELECT
27
+ d.id as "partner_domain_id",
28
+ w.check_count as "check_count",
29
+ ic.id as "inventory_check_id",
30
+ ici.inventory_id as "inventory_id",
31
+ ic.name as "name",
32
+ ici.product_id as "product_id",
33
+ ici.count_no as "count_no",
34
+ ici.product_detail_id as "product_detail_id",
35
+ ici.status as "invCheckItemStatus",
36
+ b.name as "company",
37
+ ic.name as "cycle_count_no",
38
+ ic.execution_date as "execution_date",
39
+ ic.status as "status",
40
+ i.carton_id as "carton_id",
41
+ i.pallet_id as "pallet_id",
42
+ i.packing_type as "i_packing_type",
43
+ i.uom as "i_uom",
44
+ p.sku as "product_sku",
45
+ p.name as "product_name",
46
+ p.brand as "product_brand",
47
+ p.description as "product_description",
48
+ pd.packing_type as "pd_packing_type",
49
+ pd.uom as "pd_uom",
50
+ ici.origin_batch_no as "origin_batch_no",
51
+ ici.inspected_batch_no as "inspected_batch_no",
52
+ ici.origin_uom_value as "origin_uom_value",
53
+ ici.origin_location_id as "origin_location_id",
54
+ ici.origin_expiration_date as "origin_expiration_date",
55
+ ici.inspected_expiration_date as "inspected_expiration_date",
56
+ l.name as "origin_location_name",
57
+ ici.inspected_location_id as "inspected_location_id",
58
+ l2.name as "inspected_location_name",
59
+ COALESCE(ici.origin_qty, 0) as "origin_qty",
60
+ COALESCE(ici.inspected_qty, 0) as "inspected_qty",
61
+ COALESCE(ici.inspected_uom_value, 0) as "inspected_uom_value"
62
+ FROM
63
+ inventory_checks ic
64
+ INNER JOIN
62
65
  inventory_check_items ici on ici.inventory_check_id = ic.id
63
- left join
66
+ LEFT JOIN
64
67
  inventories i on i.id = ici.inventory_id
65
- inner join
68
+ INNER JOIN
66
69
  products p ON p.id = ici.product_id
67
- inner join
70
+ INNER JOIN
68
71
  product_details pd ON pd.id = ici.product_detail_id
69
- inner join
72
+ INNER JOIN
70
73
  worksheets w on w.inventory_check_id = ic.id
71
- inner join
74
+ INNER JOIN
72
75
  worksheet_details wd on wd.worksheet_id = w.id and wd.target_inventory_check_item_id = ici.id
73
- left join
76
+ LEFT JOIN
74
77
  locations l on l.id = ici.origin_location_id
75
- left join
78
+ LEFT JOIN
76
79
  locations l2 on l2.id = ici.inspected_location_id
77
- inner join
80
+ INNER JOIN
78
81
  bizplaces b on b.id = ic.bizplace_id
79
- inner join
82
+ INNER JOIN
80
83
  domains d on d.id = b.domain_id
81
- WHERE
82
- ic.id = $1
83
-
84
- )`,
84
+ WHERE
85
+ ic.id = $1
86
+ )`,
85
87
  [cycleCount.id]
86
88
  )
87
89
 
@@ -99,30 +101,52 @@ export const cycleCountReport = {
99
101
  )
100
102
 
101
103
  // Step 3: Generate definedCrossColumn for dynamic columns
102
- let definedCrossColumn = await tx.query(`
103
- SELECT string_agg(DISTINCT 'count ' || check_count::text, ',') as columns
104
+ const definedCrossColumn = await tx.query(`
105
+ SELECT string_agg(DISTINCT 'count ' || check_count::text, ',') as count_columns,
106
+ string_agg(DISTINCT 'uom count ' || check_count::text, ',') as uom_columns
104
107
  FROM temp_dynamic_columns
105
108
  `)
106
109
 
107
- let columnList = definedCrossColumn[0].columns
110
+ const countColumns = definedCrossColumn[0].count_columns
111
+ .split(',')
112
+ .map(column => `"${column.trim()}" varchar`)
113
+ .join(', ')
114
+
115
+ const uomColumns = definedCrossColumn[0].uom_columns
108
116
  .split(',')
109
117
  .map(column => `"${column.trim()}" varchar`)
110
118
  .join(', ')
111
119
 
112
- // Step 4: Pivot data and create the pivot table
120
+ // Step 4: Pivot data and create the pivot tables
113
121
  await tx.query(`
114
122
  CREATE TEMP TABLE temp_pivoted_data ON COMMIT DROP AS (
115
123
  SELECT *
116
124
  FROM crosstab(
117
125
  $$
118
- SELECT inventory_id, check_count, inspected_qty
126
+ SELECT inventory_id, 'count ' || check_count, inspected_qty
119
127
  FROM temp_fixed_columns ORDER BY 1,2,3
120
128
  $$,
121
129
  $$
122
- SELECT DISTINCT check_count FROM temp_dynamic_columns ORDER BY 1
130
+ SELECT DISTINCT 'count ' || check_count FROM temp_dynamic_columns ORDER BY 1
123
131
  $$
124
- ) AS ct (inventory_id varchar, ${columnList})
125
- )`)
132
+ ) AS ct (inventory_id varchar, ${countColumns})
133
+ )
134
+ `)
135
+
136
+ await tx.query(`
137
+ CREATE TEMP TABLE temp_pivoted_uom_data ON COMMIT DROP AS (
138
+ SELECT *
139
+ FROM crosstab(
140
+ $$
141
+ SELECT inventory_id, 'uom count ' || check_count, inspected_uom_value
142
+ FROM temp_fixed_columns ORDER BY 1,2,3
143
+ $$,
144
+ $$
145
+ SELECT DISTINCT 'uom count ' || check_count FROM temp_dynamic_columns ORDER BY 1
146
+ $$
147
+ ) AS ct (inventory_id varchar, ${uomColumns})
148
+ )
149
+ `)
126
150
 
127
151
  // Step 5: Create the temp_final_count table
128
152
  await tx.query(
@@ -131,44 +155,40 @@ export const cycleCountReport = {
131
155
  SELECT
132
156
  inventory_id,
133
157
  count_no,
134
- MAX(inspected_qty) as "final_count"
158
+ MAX(inspected_qty) as "final_count",
159
+ MAX(inspected_uom_value) as "final_uom"
135
160
  FROM
136
161
  inventory_check_items ici
137
162
  WHERE
138
- (inventory_id, count_no) IN (
139
- SELECT
140
- inventory_id,
141
- MAX(count_no)
142
- FROM
143
- inventory_check_items
144
- WHERE inventory_check_id = $1
145
- GROUP BY
146
- inventory_id
147
- )
148
- AND inventory_check_id = $1
163
+ inventory_check_id = $1
149
164
  GROUP BY inventory_id, count_no
150
165
  )`,
151
166
  [cycleCount.id]
152
167
  )
153
168
 
154
- let jsonColumnNames = definedCrossColumn[0].columns
169
+ // Step 6: Create the final temp table with combined data
170
+ const jsonColumnNames = definedCrossColumn[0].count_columns
155
171
  .split(',')
156
- .map(column => {
157
- return `p."${column.trim()}" as "${column.trim()}"`
158
- })
172
+ .map(column => `p."${column.trim()}" as "${column.trim()}"`)
173
+ .join(',')
174
+
175
+ const uomJsonColumnNames = definedCrossColumn[0].uom_columns
176
+ .split(',')
177
+ .map(column => `puom."${column.trim()}" as "${column.trim()}"`)
159
178
  .join(',')
160
179
 
161
- // Step 6: Create the final temp table with combined data
162
180
  await tx.query(`
163
181
  CREATE TEMP TABLE temp_final_data ON COMMIT DROP AS (
164
182
  SELECT
165
183
  f.*,
166
184
  fc.final_count,
185
+ fc.final_uom,
167
186
  first_count.origin_qty as "system_qty",
168
187
  first_count.origin_batch_no as "system_batch_no",
169
188
  first_count.origin_location_name as "system_location_name",
170
189
  first_count.origin_uom_value as "system_uom_value",
171
190
  row_to_json((SELECT cn FROM (SELECT ${jsonColumnNames}) cn))::varchar as "count_data",
191
+ row_to_json((SELECT cn FROM (SELECT ${uomJsonColumnNames}) cn))::varchar as "count_uom_data",
172
192
  CASE
173
193
  WHEN (COALESCE(first_count.origin_batch_no, '') <> COALESCE(f.inspected_batch_no, ''))
174
194
  THEN true
@@ -204,16 +224,32 @@ export const cycleCountReport = {
204
224
  WHERE count_no = 1
205
225
  ) first_count ON f.inventory_id = first_count.inventory_id
206
226
  INNER JOIN temp_pivoted_data p ON f.inventory_id::uuid = p.inventory_id::uuid
227
+ INNER JOIN temp_pivoted_uom_data puom ON f.inventory_id::uuid = puom.inventory_id::uuid
207
228
  INNER JOIN temp_final_count fc ON f.inventory_id = fc.inventory_id and f.count_no = fc.count_no
208
- )`)
229
+ )
230
+ `)
231
+
232
+ const whereConditions = []
233
+
234
+ if (batchNoVarianceFilter?.value === true) {
235
+ whereConditions.push('"BatchNoVariance" = true')
236
+ }
237
+ if (expirationDateVarianceFilter?.value === true) {
238
+ whereConditions.push('"ExpirationDateVariance" = true')
239
+ }
240
+ if (locationVarianceFilter?.value === true) {
241
+ whereConditions.push('"LocationVariance" = true')
242
+ }
209
243
 
210
- // Step 7: Select final result
244
+ // Step 7: Select final result
211
245
  const result: any = await tx.query(`
212
- SELECT * FROM temp_final_data`)
246
+ SELECT * FROM temp_final_data
247
+ ${whereConditions.length > 0 ? 'WHERE ' + whereConditions.join(' OR ') : ''}
248
+ `)
213
249
 
214
- // grouping inventory id
215
- let inventoryIds = new Set()
216
- let items = []
250
+ // Step 8: Group inventory id and prepare final response
251
+ const inventoryIds = new Set()
252
+ const items = []
217
253
  result.forEach(itm => {
218
254
  if (!inventoryIds.has(itm.inventory_id)) {
219
255
  inventoryIds.add(itm.inventory_id)
@@ -273,11 +309,13 @@ export const cycleCountReport = {
273
309
  originLocationId: itm.origin_location_id,
274
310
  inspectedLocationId: itm.inspected_location_id,
275
311
  countData: itm.count_data,
312
+ countUomData: itm.count_uom_data,
276
313
  batchNoVariance: itm.BatchNoVariance,
277
314
  locationVariance: itm.LocationVariance,
278
315
  uomValueVariance: itm.UomValueVariance,
279
316
  expirationDateVariance: itm.ExpirationDateVariance,
280
317
  finalCount: itm.final_count,
318
+ finalUom: itm.final_uom,
281
319
  countVariance: itm.final_count - itm.origin_qty,
282
320
  countStatus,
283
321
  company: itm.company,
@@ -287,7 +325,7 @@ export const cycleCountReport = {
287
325
  }
288
326
  })
289
327
 
290
- // Step 8: Count total and return the final object
328
+ // Step 9: Count total and return the final object
291
329
  const finalTotal = inventoryIds.size
292
330
  return {
293
331
  items,
@@ -1,9 +1,9 @@
1
- import { EntityManager } from 'typeorm'
2
- import { InventoryChange, approveInventoryChanges } from '@things-factory/warehouse-base'
3
- import { In, Not, IsNull } from 'typeorm'
4
- import { OrderInventory, ReleaseGood } from '@things-factory/sales-base'
5
- import { WorksheetDetail, Worksheet } from '@things-factory/worksheet-base'
6
- import { webhookHandler,WebhookEventsEnum } from '@things-factory/integration-base'
1
+ import { WebhookEventsEnum, webhookHandler } from '@things-factory/integration-base'
2
+ import { OrderInventory, ReleaseGood, ORDER_STATUS, ORDER_INVENTORY_STATUS } from '@things-factory/sales-base'
3
+ import { INVENTORY_TRANSACTION_TYPE } from '@things-factory/warehouse-base'
4
+ import { Inventory,InventoryChange, approveInventoryChanges, INVENTORY_STATUS } from '@things-factory/warehouse-base'
5
+ import { Worksheet, WorksheetDetail, WORKSHEET_STATUS, WORKSHEET_TYPE } from '@things-factory/worksheet-base'
6
+ import { EntityManager, In, Not } from 'typeorm'
7
7
 
8
8
  export const warehouseInventoryAdjustment = {
9
9
  async warehouseInventoryAdjustment(_: any, { patches }, context: any) {
@@ -37,40 +37,82 @@ export const warehouseInventoryAdjustment = {
37
37
  })
38
38
 
39
39
  if (_inventoryChanges.length > 0) {
40
- const invId: any[] = _inventoryChanges
41
- .filter((ic: any) => ic.transactionType == 'MISSING')
42
- .map((ic: any) => ic.inventory.id)
40
+ if (_inventoryChanges.some(ic => ic.transactionType == INVENTORY_TRANSACTION_TYPE.MISSING)) {
41
+ //handle missing inventory
42
+ const invId: any[] = _inventoryChanges
43
+ .filter((ic: any) => ic.transactionType == INVENTORY_TRANSACTION_TYPE.MISSING)
44
+ .map((ic: any) => ic.inventory.id)
43
45
 
44
- const orderInventory: OrderInventory[] = await tx.getRepository(OrderInventory).find({
45
- where: { inventory: In(invId), status: 'PICKING' }
46
- })
46
+ const orderInventory: OrderInventory[] = await tx.getRepository(OrderInventory).find({
47
+ where: { inventory: In(invId), status: In([ORDER_INVENTORY_STATUS.PICKING, ORDER_INVENTORY_STATUS.PROCESSING]) }
48
+ })
47
49
 
48
- await tx.getRepository(OrderInventory).update(
49
- {
50
- inventory: In(invId),
51
- status: 'PICKING'
52
- },
53
- { status: 'MISSING' }
54
- )
50
+ await tx.getRepository(OrderInventory).update(
51
+ {
52
+ inventory: In(invId),
53
+ status: In([ORDER_INVENTORY_STATUS.PICKING, ORDER_INVENTORY_STATUS.PROCESSING])
54
+ },
55
+ { status: ORDER_INVENTORY_STATUS.MISSING }
56
+ )
55
57
 
56
- const orderInvId: any[] = orderInventory.map((oi: any) => oi.id)
57
- const releaseGoodId: any[] = orderInventory.map((roId: any) => roId.releaseGoodId)
58
+ const orderInvId: any[] = orderInventory.map((oi: any) => oi.id)
59
+ const releaseGoodId: any[] = orderInventory.map((roId: any) => roId.releaseGoodId)
58
60
 
59
- await tx.getRepository(WorksheetDetail).update(
60
- {
61
- targetInventory: In(orderInvId),
62
- status: 'EXECUTING'
63
- },
64
- { status: 'MISSING' }
65
- )
61
+ await tx.getRepository(WorksheetDetail).update(
62
+ {
63
+ targetInventory: In(orderInvId),
64
+ status: In([WORKSHEET_STATUS.EXECUTING, WORKSHEET_STATUS.DEACTIVATED])
65
+ },
66
+ { status: WORKSHEET_STATUS.MISSING }
67
+ )
66
68
 
67
- await tx.getRepository(Worksheet).update(
68
- {
69
- releaseGood: In(releaseGoodId),
70
- status: 'EXECUTING'
71
- },
72
- { status: 'DEACTIVATED' }
73
- )
69
+ await tx.getRepository(Worksheet).update(
70
+ {
71
+ releaseGood: In(releaseGoodId),
72
+ status: WORKSHEET_STATUS.EXECUTING,
73
+ type: Not(In([WORKSHEET_TYPE.ZONE_PICKING, WORKSHEET_TYPE.LOADING]))
74
+ },
75
+ { status: WORKSHEET_STATUS.DEACTIVATED }
76
+ )
77
+ }
78
+
79
+ if (_inventoryChanges.some(ic => ic.transactionType == INVENTORY_TRANSACTION_TYPE.EXPIRED)) {
80
+ //handle expired inventory
81
+ const invId: any[] = _inventoryChanges
82
+ .filter((ic: any) => ic.transactionType == INVENTORY_TRANSACTION_TYPE.EXPIRED)
83
+ .map((ic: any) => ic.inventory.id)
84
+
85
+ const orderInventory: OrderInventory[] = await tx.getRepository(OrderInventory).find({
86
+ where: { inventory: In(invId), status: In([ORDER_INVENTORY_STATUS.PICKING, ORDER_INVENTORY_STATUS.PROCESSING]) }
87
+ })
88
+
89
+ const inventoryId: any[] = orderInventory.map((oi: any) => oi.inventoryId)
90
+ const releaseGoodId: any[] = orderInventory.map((roId: any) => roId.releaseGoodId)
91
+
92
+ await tx.getRepository(ReleaseGood).update(
93
+ {
94
+ id: In(releaseGoodId),
95
+ status: In([ORDER_STATUS.PROCESSING, ORDER_STATUS.PARTIAL_PROCESSING])
96
+ },
97
+ { status: ORDER_STATUS.OBSOLETE }
98
+ )
99
+
100
+ await tx.getRepository(Inventory).update(
101
+ {
102
+ id: In(inventoryId),
103
+ status: INVENTORY_STATUS.STORED
104
+ },
105
+ { obsolete: true }
106
+ )
107
+
108
+ await tx.getRepository(InventoryChange).update(
109
+ {
110
+ inventory: In(inventoryId),
111
+ status: 'PENDING'
112
+ },
113
+ { status: 'APPROVED' }
114
+ )
115
+ }
74
116
 
75
117
  for (const invChange of _inventoryChanges) {
76
118
  webhookHandler(invChange, invChange.inventory.bizplace, WebhookEventsEnum.InventoryAdjusted)
@@ -0,0 +1,124 @@
1
+ import { Worksheet, WorksheetDetail, WORKSHEET_STATUS, WORKSHEET_TYPE } from '@things-factory/worksheet-base'
2
+ import { User } from '@things-factory/auth-base'
3
+ import { Domain } from '@things-factory/biz-base'
4
+ import { ReleaseGood, OrderInventory, ORDER_STATUS } from '@things-factory/sales-base'
5
+ import { EntityManager, In } from 'typeorm'
6
+
7
+ export const activateWorksheetZonePicking = {
8
+ async activateWorksheetZonePicking(_: any, { name }, context: any): Promise<Worksheet> {
9
+ const { user, domain, tx }: { user: User; domain: Domain; tx: EntityManager } = context.state
10
+ const type = WORKSHEET_TYPE.ZONE_PICKING
11
+
12
+ return activateWorksheet({ tx, user, domain, name: [name], type })
13
+ }
14
+ }
15
+
16
+ export const activateBulkWorksheetZonePicking = {
17
+ async activateBulkWorksheetZonePicking(_: any, { names }, context: any): Promise<Worksheet[]> {
18
+ const { user, domain, tx }: { user: User; domain: Domain; tx: EntityManager } = context.state
19
+ const type = WORKSHEET_TYPE.ZONE_PICKING
20
+
21
+ return activateWorksheet({ tx, user, domain, name: names, type })
22
+ }
23
+ }
24
+
25
+ interface WorksheetActivationParams {
26
+ tx: EntityManager
27
+ user: User
28
+ domain: Domain
29
+ name: string[]
30
+ type: string
31
+ }
32
+ async function activateWorksheet(params: WorksheetActivationParams): Promise<Worksheet[]> {
33
+ const { tx, user, domain, name, type } = params
34
+
35
+ try {
36
+ //fetch worksheet(s)
37
+ const worksheets: Worksheet[] = await tx.getRepository(Worksheet).find({
38
+ where: {
39
+ domain,
40
+ status: WORKSHEET_STATUS.DEACTIVATED,
41
+ name: In(name),
42
+ type
43
+ },
44
+ relations: [
45
+ 'worksheetDetails',
46
+ 'worksheetDetails.targetInventory',
47
+ 'worksheetDetails.targetInventory.releaseGood'
48
+ ]
49
+ })
50
+
51
+ if (!worksheets || worksheets.length === 0) {
52
+ throw new Error('Worksheet(s) not found')
53
+ }
54
+
55
+ const updatedWorksheets = await Promise.all(
56
+ worksheets.map(async worksheet => {
57
+ //update worksheet
58
+ await tx.getRepository(Worksheet).update(
59
+ { id: worksheet.id },
60
+ {
61
+ status: WORKSHEET_STATUS.EXECUTING,
62
+ startedAt: new Date(),
63
+ updater: user
64
+ }
65
+ )
66
+
67
+ //update worksheet details
68
+ const wsdIds = worksheet.worksheetDetails.map(item => item.id)
69
+ await tx.getRepository(WorksheetDetail).update(
70
+ { id: In(wsdIds) },
71
+ {
72
+ status: WORKSHEET_STATUS.EXECUTING,
73
+ updater: user,
74
+ updatedAt: new Date()
75
+ }
76
+ )
77
+
78
+ //update oi
79
+ let targetInventoryIds = worksheet.worksheetDetails.map(item => item.targetInventory.id)
80
+ const targetInventory: OrderInventory[] = await tx.getRepository(OrderInventory).find({
81
+ where: { id: In(targetInventoryIds) },
82
+ relations: ['releaseGood']
83
+ })
84
+
85
+ const oiIds = targetInventory.map(item => item.id)
86
+ await tx.getRepository(OrderInventory).update(
87
+ { id: In(oiIds) },
88
+ {
89
+ status: ORDER_STATUS.PROCESSING,
90
+ updater: user,
91
+ updatedAt: new Date()
92
+ }
93
+ )
94
+
95
+ //update ro
96
+ const roIds = [...new Set(targetInventory.map(item => item.releaseGood.id))]
97
+ await tx.getRepository(ReleaseGood).update(
98
+ { id: In(roIds) },
99
+ {
100
+ status: ORDER_STATUS.PROCESSING,
101
+ updater: user,
102
+ updatedAt: new Date()
103
+ }
104
+ )
105
+
106
+ //fetch updated worksheet
107
+ let updatedWorksheet: Worksheet = await tx.getRepository(Worksheet).findOne({
108
+ where: { id: worksheet.id },
109
+ relations: [
110
+ 'worksheetDetails',
111
+ 'worksheetDetails.targetInventory',
112
+ 'worksheetDetails.targetInventory.releaseGood'
113
+ ]
114
+ })
115
+
116
+ return updatedWorksheet
117
+ })
118
+ )
119
+
120
+ return updatedWorksheets
121
+ } catch (error) {
122
+ throw error
123
+ }
124
+ }
@@ -0,0 +1,49 @@
1
+ import { EntityManager, Not, In } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { Domain } from '@things-factory/shell'
5
+
6
+ import { ReleaseGood, ORDER_STATUS } from '@things-factory/sales-base'
7
+
8
+ export const assignSorter = {
9
+ async assignSorter(
10
+ _parentObj: void,
11
+ { releaseGoodId, userId }: { releaseGoodId: [string]; userId: string },
12
+ context: any
13
+ ): Promise<void> {
14
+ const { tx, domain }: { tx: EntityManager; domain: Domain } = context.state
15
+ const sorter: User = await tx.getRepository(User).findOne(userId, { relations: ['domains'] })
16
+
17
+ if ((sorter?.domains || []).every((userDomain: Domain) => userDomain.id !== domain.id)) {
18
+ throw new Error('Target user does not belong to current domain')
19
+ }
20
+ if (!sorter) throw new Error('failed to find target user')
21
+
22
+ await Promise.all(
23
+ releaseGoodId.map(async releaseGoodId => {
24
+ const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne(
25
+ {
26
+ id: releaseGoodId
27
+ },
28
+ {
29
+ where: [
30
+ {
31
+ status: Not(In([ORDER_STATUS.PROCESSING, ORDER_STATUS.DONE]))
32
+ }
33
+ ]
34
+ }
35
+ )
36
+
37
+ if (!releaseGood) throw new Error('failed to find target order')
38
+ await tx.getRepository(ReleaseGood).update(
39
+ {
40
+ id: releaseGoodId
41
+ },
42
+ {
43
+ sortedBy: sorter
44
+ }
45
+ )
46
+ })
47
+ )
48
+ }
49
+ }