@things-factory/operato-wms 4.3.643 → 4.3.644

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 (64) hide show
  1. package/client/pages/outbound/loading-v2/loading-execution-base.js +625 -153
  2. package/client/pages/outbound/loading-v2/loading-execution.js +239 -139
  3. package/client/pages/outbound/loading-v2/loading.js +297 -179
  4. package/client/pages/outbound/loading-v2/release-good-info.js +8 -8
  5. package/client/pages/outbound/picking-v2/picking.js +4 -0
  6. package/client/pages/outbound/show-ro-list-popup.js +17 -3
  7. package/client/pages/report/billing-module-report.js +421 -0
  8. package/client/route.js +4 -0
  9. package/dist-server/graphql/resolvers/outbound/complete-load.js +6 -1
  10. package/dist-server/graphql/resolvers/outbound/complete-load.js.map +1 -1
  11. package/dist-server/graphql/resolvers/outbound/find-loadable-release-good-by-bin.js +148 -0
  12. package/dist-server/graphql/resolvers/outbound/find-loadable-release-good-by-bin.js.map +1 -0
  13. package/dist-server/graphql/resolvers/outbound/find-loadable-release-good.js +67 -13
  14. package/dist-server/graphql/resolvers/outbound/find-loadable-release-good.js.map +1 -1
  15. package/dist-server/graphql/resolvers/outbound/get-delivery-orders.js +20 -3
  16. package/dist-server/graphql/resolvers/outbound/get-delivery-orders.js.map +1 -1
  17. package/dist-server/graphql/resolvers/outbound/index.js +2 -1
  18. package/dist-server/graphql/resolvers/outbound/index.js.map +1 -1
  19. package/dist-server/graphql/resolvers/outbound/load-by-qty.js +15 -3
  20. package/dist-server/graphql/resolvers/outbound/load-by-qty.js.map +1 -1
  21. package/dist-server/graphql/resolvers/outbound/loading-worksheet-v2.js +36 -15
  22. package/dist-server/graphql/resolvers/outbound/loading-worksheet-v2.js.map +1 -1
  23. package/dist-server/graphql/resolvers/outbound/sort-item.js +53 -52
  24. package/dist-server/graphql/resolvers/outbound/sort-item.js.map +1 -1
  25. package/dist-server/graphql/resolvers/reports/billing-module-report.js +355 -0
  26. package/dist-server/graphql/resolvers/reports/billing-module-report.js.map +1 -0
  27. package/dist-server/graphql/resolvers/reports/index.js +2 -1
  28. package/dist-server/graphql/resolvers/reports/index.js.map +1 -1
  29. package/dist-server/graphql/resolvers/reports/outbound-order-details-report.js +3 -0
  30. package/dist-server/graphql/resolvers/reports/outbound-order-details-report.js.map +1 -1
  31. package/dist-server/graphql/resolvers/reports/pg-udf-query.js +5 -3
  32. package/dist-server/graphql/resolvers/reports/pg-udf-query.js.map +1 -1
  33. package/dist-server/graphql/resolvers/zone-worksheet/zone-picking.js +3 -3
  34. package/dist-server/graphql/types/outbound/index.js +2 -1
  35. package/dist-server/graphql/types/outbound/index.js.map +1 -1
  36. package/dist-server/graphql/types/reports/billing-module-report-list.js +14 -0
  37. package/dist-server/graphql/types/reports/billing-module-report-list.js.map +1 -0
  38. package/dist-server/graphql/types/reports/billing-module-report.js +15 -0
  39. package/dist-server/graphql/types/reports/billing-module-report.js.map +1 -0
  40. package/dist-server/graphql/types/reports/index.js +5 -0
  41. package/dist-server/graphql/types/reports/index.js.map +1 -1
  42. package/package.json +4 -4
  43. package/server/graphql/resolvers/outbound/complete-load.ts +6 -1
  44. package/server/graphql/resolvers/outbound/find-loadable-release-good-by-bin.ts +154 -0
  45. package/server/graphql/resolvers/outbound/find-loadable-release-good.ts +82 -16
  46. package/server/graphql/resolvers/outbound/get-delivery-orders.ts +27 -3
  47. package/server/graphql/resolvers/outbound/index.ts +2 -0
  48. package/server/graphql/resolvers/outbound/load-by-qty.ts +19 -7
  49. package/server/graphql/resolvers/outbound/loading-worksheet-v2.ts +116 -22
  50. package/server/graphql/resolvers/outbound/sort-item.ts +56 -58
  51. package/server/graphql/resolvers/reports/billing-module-report.ts +372 -0
  52. package/server/graphql/resolvers/reports/index.ts +2 -0
  53. package/server/graphql/resolvers/reports/outbound-order-details-report.ts +5 -8
  54. package/server/graphql/resolvers/reports/pg-udf-query.ts +15 -13
  55. package/server/graphql/resolvers/zone-worksheet/zone-picking.ts +3 -3
  56. package/server/graphql/types/outbound/index.ts +2 -1
  57. package/server/graphql/types/reports/billing-module-report-list.ts +8 -0
  58. package/server/graphql/types/reports/billing-module-report.ts +9 -0
  59. package/server/graphql/types/reports/index.ts +6 -0
  60. package/things-factory.config.js +4 -0
  61. package/translations/en.json +7 -0
  62. package/translations/ko.json +2 -0
  63. package/translations/ms.json +2 -0
  64. package/translations/zh.json +2 -0
@@ -1,81 +1,79 @@
1
1
  import { EntityManager } from 'typeorm'
2
+ import { Brackets } from 'typeorm'
2
3
 
3
4
  import { User } from '@things-factory/auth-base'
4
5
  import { Domain } from '@things-factory/shell'
5
- import { ORDER_INVENTORY_STATUS, ORDER_STATUS, ReleaseGood, OrderInventory } from '@things-factory/sales-base'
6
- import { ProductDetail, ProductBarcode } from '@things-factory/product-base'
7
- import { WorksheetController } from '@things-factory/worksheet-base'
6
+ import { ORDER_INVENTORY_STATUS, OrderInventory } from '@things-factory/sales-base'
8
7
 
9
8
  export const sortItem = {
10
9
  async sortItem(_: any, { releaseGoodNo, productBarcode, qty, worksheetDetails }, context: any) {
11
10
  const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
12
11
 
13
- const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
14
- where: { domain, name: releaseGoodNo },
15
- relations: ['orderInventories']
16
- })
17
-
18
- if (!releaseGood) {
19
- throw new Error('Release good not found')
20
- }
21
-
22
- const orderInventories: OrderInventory[] = releaseGood.orderInventories
23
-
24
- //fetch product, product detail
25
- const productDetail: ProductDetail = await tx
26
- .getRepository(ProductDetail)
27
- .createQueryBuilder('pd')
28
- .innerJoinAndSelect('pd.productBarcodes', 'pb')
29
- .innerJoinAndSelect('pd.product', 'p')
30
- .where('p.id In(:...productId)', { productId: orderInventories.map(oi => oi.productId) })
31
- .andWhere('pd.id In(:...productDetailId)', { productDetailId: orderInventories.map(oi => oi.productDetailId) })
32
- .andWhere('pb.gtin = :productBarcode', { productBarcode: productBarcode })
33
- .getOne()
12
+ // Single query to get order inventories based on either releaseGood name or binLocation
13
+ const orderInventories: OrderInventory[] = await tx
14
+ .getRepository(OrderInventory)
15
+ .createQueryBuilder('orderInventory')
16
+ .innerJoinAndSelect('orderInventory.productDetail', 'productDetail')
17
+ .innerJoinAndSelect('productDetail.productBarcodes', 'productBarcode')
18
+ .leftJoinAndSelect('orderInventory.releaseGood', 'releaseGood')
19
+ .leftJoinAndSelect('orderInventory.binLocation', 'binLocation')
20
+ .where('orderInventory.domain_id = :domainId', { domainId: domain.id })
21
+ .andWhere('orderInventory.status IN (:...statuses)', {
22
+ statuses: [
23
+ ORDER_INVENTORY_STATUS.SORTING,
24
+ ORDER_INVENTORY_STATUS.LOADING
25
+ ]
26
+ })
27
+ .andWhere('productBarcode.gtin = :gtin', { gtin: productBarcode })
28
+ .andWhere(new Brackets(qb => {
29
+ qb
30
+ .where('orderInventory.sortedQty < orderInventory.pickedQty')
31
+ .andWhere('orderInventory.sortedQty < orderInventory.releaseQty')
32
+ }))
33
+ .andWhere(
34
+ new Brackets(qb => {
35
+ qb.where('releaseGood.name = :releaseGoodNo', { releaseGoodNo }).orWhere(
36
+ 'binLocation.name = :releaseGoodNo',
37
+ { releaseGoodNo }
38
+ )
39
+ })
40
+ )
41
+ .getMany()
34
42
 
35
- if (!productDetail) throw new Error('Product not found')
43
+ if (!orderInventories.length) throw new Error('No matching product barcode found')
36
44
 
37
- const product = productDetail.product
38
- let matchedOrderInventories
45
+ // Calculate total available quantity (minimum of releaseQty and pickedQty for each order inventory)
46
+ const totalAvailableQty = orderInventories.reduce((sum, oi) => {
47
+ const availableQty = Math.min(oi.releaseQty, oi.pickedQty) - oi.sortedQty
48
+ return sum + (availableQty > 0 ? availableQty : 0)
49
+ }, 0)
39
50
 
40
- if (worksheetDetails?.length > 0) {
41
- //find the respective oi from item that user selected
42
- let selectedOrderInventories = worksheetDetails.map(wsd => wsd.relatedOrderInv)
43
- let id = selectedOrderInventories.map(oi => oi.id)
44
- let foundOrderInventories = orderInventories.filter(oi => id.includes(oi.id))
45
- matchedOrderInventories = foundOrderInventories.filter(
46
- oi => oi.productId === product.id && oi.productDetailId === productDetail.id
47
- )
48
- } else {
49
- matchedOrderInventories = orderInventories.filter(
50
- oi => oi.productId === product.id && oi.productDetailId === productDetail.id
51
- )
51
+ if (qty > totalAvailableQty) {
52
+ throw new Error(`Sort qty (${qty}) exceeds total available quantity (${totalAvailableQty})`)
52
53
  }
53
54
 
54
- if (matchedOrderInventories.length > 1 && !worksheetDetails) {
55
- throw new Error('Please select item to sort')
56
- } else if (matchedOrderInventories.length > 1) {
57
- throw new Error('This barcode matched multiple item')
58
- } else if (matchedOrderInventories.length === 0) {
59
- throw new Error('No matching item found')
60
- }
55
+ // Distribute the sorted quantity across order inventories
56
+ let remainingQty = qty
57
+ for (const orderInventory of orderInventories) {
58
+ if (remainingQty <= 0) break
61
59
 
62
- let matchedOrderInventory = matchedOrderInventories[0]
60
+ const availableQty = Math.min(orderInventory.releaseQty, orderInventory.pickedQty) - orderInventory.sortedQty
61
+ if (availableQty <= 0) continue
63
62
 
64
- let newSortQty = matchedOrderInventory.sortedQty + qty
63
+ const qtyToAdd = Math.min(remainingQty, availableQty)
64
+ const newSortQty = orderInventory.sortedQty + qtyToAdd
65
65
 
66
- if (newSortQty > matchedOrderInventory.releaseQty) {
67
- throw new Error('Sort qty is more than release qty')
68
- }
66
+ // Update the order inventory
67
+ await tx.getRepository(OrderInventory).update(orderInventory.id, {
68
+ sortedQty: newSortQty,
69
+ status: ORDER_INVENTORY_STATUS.LOADING,
70
+ updatedAt: new Date(),
71
+ updater: user
72
+ })
69
73
 
70
- if (newSortQty > matchedOrderInventory.pickedQty) {
71
- throw new Error('Sort qty is more than picked qty')
74
+ remainingQty -= qtyToAdd
72
75
  }
73
76
 
74
- //update oi sorted qty
75
- await tx
76
- .getRepository(OrderInventory)
77
- .update(matchedOrderInventory.id, { sortedQty: parseFloat(newSortQty), updatedAt: new Date(), updater: user })
78
-
79
77
  return true
80
78
  }
81
79
  }
@@ -0,0 +1,372 @@
1
+ import { EntityManager } from 'typeorm'
2
+
3
+ import { User } from '@things-factory/auth-base'
4
+ import { Bizplace } from '@things-factory/biz-base'
5
+ import { ListParam } from '@things-factory/shell'
6
+
7
+ import { rawProductsQuery } from '../../../utils'
8
+
9
+ export const billingModuleReport = {
10
+ async billingModuleReport(_: any, params: ListParam, context: any) {
11
+ try {
12
+ const { tx }: { tx: EntityManager } = context.state
13
+ let bizplaceFilter = { name: '', operator: '', value: '' }
14
+ let userFilter = params.filters.find(data => data.name === 'user')
15
+ let fromDate = params.filters.find(data => data.name === 'fromDate')
16
+ let toDate = params.filters.find(data => data.name === 'toDate')
17
+ let locationType = params.filters.find(data => data.name === 'locationType')
18
+
19
+ if (userFilter) {
20
+ const user: User = await tx.getRepository(User).findOne({
21
+ where: { id: userFilter.value },
22
+ relations: ['bizplaces']
23
+ })
24
+
25
+ const bizplace: Bizplace = user.bizplaces[0]
26
+
27
+ if (!bizplace) throw 'Invalid input'
28
+
29
+ bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id }
30
+ } else {
31
+ bizplaceFilter = params.filters.find(data => data.name === 'bizplace')
32
+ }
33
+
34
+ if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
35
+
36
+ const bizplace: Bizplace = await tx.getRepository(Bizplace).findOne({
37
+ id: bizplaceFilter.value
38
+ })
39
+
40
+ // Prepare dynamic locationType clause and query params
41
+ const queryParams = [context.state.domain.id,bizplace.id]
42
+ let locationTypeClause = ''
43
+
44
+ if (locationType && locationType.value) {
45
+ locationTypeClause = 'AND l.type = $3'
46
+ queryParams.push(locationType.value)
47
+ }
48
+
49
+ console.time('temp')
50
+ await tx.query(
51
+ `
52
+ CREATE TEMP TABLE temp_data_src ON COMMIT DROP AS (
53
+ -- Inventory Histories
54
+ SELECT
55
+ invh.inventory_id,
56
+ UPPER(TRIM(invh.packing_type)) AS packing_type,
57
+ CASE
58
+ WHEN invh.order_no ILIKE 'RTO-%' OR invh.transaction_type = 'RETURN' THEN REPLACE((transaction_type)::text, 'UNLOADING', 'RETURN')
59
+ WHEN invh.transaction_type = 'RETURN' THEN REPLACE((transaction_type)::text, 'RETURN', 'RETURN')
60
+ ELSE invh.transaction_type
61
+ END AS transaction_type,
62
+ invh.status, invh.created_at + INTERVAL '8 hours' AS created_at,
63
+ invh.qty,
64
+ invh.opening_qty,
65
+ pd.volume,
66
+ l."type" as location,
67
+ w."type" as warehouse,
68
+ invh.domain_id,
69
+ invh.bizplace_id
70
+ FROM reduced_inventory_histories invh
71
+ INNER JOIN inventories i on i.id = invh.inventory_id
72
+ INNER JOIN locations l on l.id = i.location_id
73
+ INNER JOIN warehouses w on w.id = l.warehouse_id
74
+ LEFT JOIN product_details pd ON pd.id = i.product_detail_id
75
+ WHERE
76
+ invh.domain_id = $1
77
+ AND invh.bizplace_id = $2
78
+ ${locationTypeClause}
79
+ UNION ALL
80
+
81
+ -- VAS Records
82
+ SELECT
83
+ ov.inventory_id,
84
+ UPPER(TRIM(COALESCE(ov.new_packing_type, ov.packing_type))) AS packing_type,
85
+ 'VAS' AS transaction_type,
86
+ 'VAS' AS status,
87
+ ov.updated_at + interval '8 hours' AS created_at,
88
+ COALESCE(ov.adjusted_output_qty, ov.qty) AS qty,
89
+ '0' as opening_qty,
90
+ COALESCE(p.volume, 0) as volume,
91
+ '-' as location,
92
+ '-' as warehouse,
93
+ ov.domain_id,
94
+ ov.bizplace_id
95
+ FROM order_vass ov
96
+ LEFT JOIN products p ON p.id = ov.target_product_id
97
+ WHERE
98
+ ov.domain_id = $1
99
+ AND ov.bizplace_id = $2
100
+ AND ov.qty IS NOT NULL
101
+ );
102
+ `,
103
+ queryParams
104
+ )
105
+
106
+ console.timeEnd('temp')
107
+
108
+ const result: any = await tx.query(
109
+ `
110
+ WITH RECURSIVE date_series AS (
111
+ SELECT
112
+ CASE
113
+ WHEN $1::DATE < (SELECT MIN(created_at)::DATE FROM temp_data_src)
114
+ THEN (SELECT (MIN(created_at)+ INTERVAL '1 DAY')::DATE FROM temp_data_src)
115
+ ELSE $1 ::DATE
116
+ END AS query_date
117
+ UNION ALL
118
+ SELECT (query_date + INTERVAL '1 DAY')::DATE
119
+ FROM date_series
120
+ WHERE query_date < $2
121
+ ),
122
+ distinct_groups AS (
123
+ SELECT DISTINCT
124
+ UPPER(TRIM(packing_type)) AS packing_type,
125
+ warehouse,
126
+ location
127
+ FROM temp_data_src
128
+ WHERE packing_type IS NOT NULL
129
+ ),
130
+ date_packing_combinations AS (
131
+ SELECT DISTINCT ds.query_date, pt.packing_type
132
+ FROM date_series ds
133
+ CROSS JOIN distinct_groups pt
134
+ ),
135
+ order_number AS(
136
+ SELECT
137
+ rg.name,
138
+ (rg.updated_at + interval '8 hours')::DATE AS query_date
139
+ FROM release_goods rg
140
+ INNER JOIN (SELECT domain_id, bizplace_id FROM temp_data_src src limit 1)src
141
+ ON rg.domain_id = src.domain_id
142
+ AND rg.bizplace_id = src.bizplace_id
143
+ WHERE rg.status = 'DONE'
144
+ ),
145
+ inbound AS (
146
+ SELECT
147
+ dpc.query_date,
148
+ SUM(COALESCE(src.opening_qty, 0)) AS qty,
149
+ 'Inbound ' || '(' || INITCAP(dpc.packing_type) || ')' AS data_type
150
+ FROM date_packing_combinations dpc
151
+ LEFT JOIN temp_data_src src
152
+ ON dpc.query_date = src.created_at::DATE
153
+ AND src.transaction_type = 'PUTAWAY'
154
+ AND dpc.packing_type = src.packing_type
155
+ GROUP BY dpc.query_date, dpc.packing_type
156
+ ORDER BY dpc.query_date
157
+ ),
158
+ outbound AS (
159
+ SELECT
160
+ dpc.query_date,
161
+ SUM(ABS(COALESCE(src.qty, 0))) AS qty,
162
+ 'Outbound ' || '(' || INITCAP(dpc.packing_type) || ')' AS data_type
163
+ FROM date_packing_combinations dpc
164
+ LEFT JOIN temp_data_src src
165
+ ON dpc.query_date = src.created_at::DATE
166
+ AND src.transaction_type = 'PICKING'
167
+ AND dpc.packing_type = src.packing_type
168
+ GROUP BY dpc.query_date, dpc.packing_type
169
+ ORDER BY dpc.query_date
170
+ ),
171
+ return AS (
172
+ SELECT
173
+ dpc.query_date,
174
+ SUM(COALESCE(src.qty, 0)) AS qty,
175
+ 'Return ' || '(' || INITCAP(dpc.packing_type) || ')' AS data_type
176
+ FROM date_packing_combinations dpc
177
+ LEFT JOIN temp_data_src src
178
+ ON dpc.query_date = src.created_at::DATE
179
+ AND src.transaction_type = 'RETURN'
180
+ AND dpc.packing_type = src.packing_type
181
+ GROUP BY dpc.query_date, dpc.packing_type
182
+ ORDER BY dpc.query_date
183
+ ),
184
+ vas AS(
185
+ SELECT
186
+ dpc.query_date,
187
+ SUM(COALESCE(src.qty, 0)) AS qty,
188
+ 'Vas ' || '(' || INITCAP(dpc.packing_type) || ')' AS data_type
189
+ FROM date_packing_combinations dpc
190
+ LEFT JOIN temp_data_src src
191
+ ON dpc.query_date = src.created_at::DATE
192
+ AND src.transaction_type = 'VAS'
193
+ AND dpc.packing_type = src.packing_type
194
+ GROUP BY dpc.query_date, dpc.packing_type
195
+ ORDER BY dpc.query_date
196
+ ),
197
+ orders AS(
198
+ SELECT
199
+ dpc.query_date,
200
+ COUNT(DISTINCT rg.name) AS qty,
201
+ 'Total Order Fulfilled' AS data_type
202
+ FROM date_series dpc
203
+ LEFT JOIN order_number rg ON dpc.query_date = rg.query_date
204
+ GROUP BY dpc.query_date
205
+ ORDER BY dpc.query_date
206
+ ),
207
+ total_unit_processed AS(
208
+ SELECT
209
+ o.query_date,
210
+ SUM(ABS(qty)) as qty,
211
+ 'Total Unit Processed' AS data_type
212
+ FROM outbound o
213
+ GROUP BY o.query_date
214
+ ORDER BY o.query_date
215
+ ),
216
+ inbound_volume AS (
217
+ SELECT
218
+ dpc.query_date,
219
+ SUM(COALESCE(src.qty * src.volume, 0)) AS qty,
220
+ 'Inbound (CBM)' AS data_type
221
+ FROM date_packing_combinations dpc
222
+ LEFT JOIN temp_data_src src
223
+ ON dpc.query_date = src.created_at::DATE
224
+ AND src.transaction_type IN ('UNLOADING', 'RETURN')
225
+ AND dpc.packing_type = src.packing_type
226
+ GROUP BY dpc.query_date
227
+ ),
228
+ outbound_volume AS (
229
+ SELECT
230
+ dpc.query_date,
231
+ SUM(ABS(COALESCE(src.qty * src.volume, 0))) AS qty,
232
+ 'Outbound (CBM)' AS data_type
233
+ FROM date_packing_combinations dpc
234
+ LEFT JOIN temp_data_src src
235
+ ON dpc.query_date = src.created_at::DATE
236
+ AND src.transaction_type = 'PICKING'
237
+ AND dpc.packing_type = src.packing_type
238
+ GROUP BY dpc.query_date
239
+ ),
240
+ vas_volume AS (
241
+ SELECT
242
+ dpc.query_date,
243
+ SUM(COALESCE(src.qty * src.volume, 0)) AS qty,
244
+ 'VAS (CBM)' AS data_type
245
+ FROM date_packing_combinations dpc
246
+ LEFT JOIN temp_data_src src
247
+ ON dpc.query_date = src.created_at::DATE
248
+ AND src.transaction_type = 'VAS'
249
+ AND dpc.packing_type = src.packing_type
250
+ GROUP BY dpc.query_date
251
+ ),
252
+ -- Determine the cutoff date from date_series.
253
+ cutoff AS (
254
+ SELECT MIN(query_date) AS cutoff_date
255
+ FROM date_series
256
+ ),
257
+ -- For each unique inventory_id, return the row with the latest created_at (before cutoff)
258
+ -- and calculate its effective opening using opening_qty + qty.
259
+ latest_opening AS (
260
+ SELECT DISTINCT ON (inventory_id)
261
+ inventory_id,
262
+ packing_type,
263
+ warehouse,
264
+ location,
265
+ (COALESCE(opening_qty, 0) + COALESCE(qty, 0)) AS effective_opening,
266
+ created_at AS last_record_date
267
+ FROM temp_data_src, cutoff
268
+ WHERE created_at::DATE < cutoff.cutoff_date
269
+ ORDER BY inventory_id, created_at DESC
270
+ ),
271
+ ---------------group by locations----------------
272
+ -- Aggregate the effective_opening from the latest record (per inventory_id) by group.
273
+ first_count AS (
274
+ SELECT
275
+ cutoff.cutoff_date AS query_date,
276
+ SUM(effective_opening) AS opening_balance,
277
+ 0 AS closing_qty,
278
+ packing_type,
279
+ warehouse,
280
+ location
281
+ FROM latest_opening, cutoff
282
+ GROUP BY packing_type, warehouse, location, cutoff.cutoff_date
283
+ ),
284
+ day_transaction AS (
285
+ SELECT
286
+ ds.query_date,
287
+ COALESCE(SUM(src.qty), 0) AS qty,
288
+ dg.packing_type, dg.warehouse, dg.location
289
+ FROM date_series ds
290
+ CROSS JOIN distinct_groups dg
291
+ LEFT JOIN temp_data_src src
292
+ ON src.created_at::DATE = ds.query_date
293
+ AND src.packing_type = dg.packing_type
294
+ AND src.warehouse = dg.warehouse
295
+ AND src.location = dg.location
296
+ GROUP BY ds.query_date, dg.packing_type, dg.warehouse, dg.location
297
+ ),
298
+ c_transaction AS (
299
+ SELECT
300
+ dt.query_date,
301
+ dt.qty,
302
+ SUM(dt.qty) OVER (PARTITION BY dt.packing_type, dt.warehouse, dt.location ORDER BY dt.query_date) AS c_qty,
303
+ dt.packing_type, dt.warehouse, dt.location
304
+ FROM day_transaction dt
305
+ ),
306
+ by_day_qty AS(
307
+ SELECT * from first_count
308
+ UNION ALL
309
+ SELECT
310
+ (ct.query_date + interval '1 day')::DATE as query_date,
311
+ fc.opening_balance + ct.c_qty AS opening_balance,
312
+ 0 AS closing_qty,
313
+ ct.packing_type, ct.warehouse, ct.location
314
+ FROM c_transaction ct
315
+ JOIN first_count fc
316
+ ON fc.packing_type = ct.packing_type
317
+ AND ct.warehouse = fc.warehouse
318
+ AND ct.location = fc.location
319
+ WHERE ct.query_date < (SELECT MAX(query_date) FROM date_series)
320
+ ORDER BY packing_type, warehouse, location, query_date
321
+ ),
322
+ by_location AS(
323
+ SELECT
324
+ query_date,
325
+ opening_balance as opening_balance,
326
+ INITCAP(SUBSTRING(warehouse FROM 1 FOR 1)) || LOWER(SUBSTRING(warehouse FROM 2)) || ' ' ||
327
+ INITCAP(SUBSTRING(location FROM 1 FOR 1)) || LOWER(SUBSTRING(location FROM 2)) || ' (' ||
328
+ INITCAP(SUBSTRING(packing_type FROM 1 FOR 1)) || LOWER(SUBSTRING(packing_type FROM 2)) || ')' as data_type
329
+ FROM by_day_qty
330
+ ORDER BY data_type, query_date
331
+ )
332
+
333
+ SELECT * FROM inbound
334
+ UNION ALL
335
+ SELECT * FROM outbound
336
+ UNION ALL
337
+ SELECT * FROM return
338
+ UNION ALL
339
+ SELECT * FROM vas
340
+ UNION ALL
341
+ SELECT * FROM orders
342
+ UNION ALL
343
+ SELECT * FROM total_unit_processed
344
+ UNION ALL
345
+ SELECT * FROM by_location
346
+ UNION ALL
347
+ SELECT * FROM inbound_volume
348
+ UNION ALL
349
+ SELECT * FROM outbound_volume
350
+ UNION ALL
351
+ SELECT * FROM vas_volume
352
+ ORDER BY query_date, data_type;
353
+ `,
354
+ [fromDate.value, toDate.value]
355
+ )
356
+
357
+ let items = result.map(itm => {
358
+ return {
359
+ date: itm.query_date,
360
+ packingType: itm.data_type,
361
+ quantity: itm.qty
362
+ }
363
+ })
364
+
365
+ return {
366
+ items
367
+ }
368
+ } catch (error) {
369
+ throw error
370
+ }
371
+ }
372
+ }
@@ -11,6 +11,7 @@ import { productLabelReport } from './product-label-report'
11
11
  import { releaseInventoryReport } from './release-inventory-report'
12
12
  import { shortageReport } from './shortage-report'
13
13
  import { loadingQcReport } from './tote-loading-qc-report'
14
+ import { billingModuleReport } from './billing-module-report'
14
15
  import {
15
16
  orderVasReport,
16
17
  vasReport
@@ -33,5 +34,6 @@ export const Query = {
33
34
  ...cycleCountReport,
34
35
  ...nonLoadedOrderInventoriesReport,
35
36
  ...manifestReport,
37
+ ...billingModuleReport,
36
38
  ...pgUdfQuery
37
39
  }
@@ -1,12 +1,7 @@
1
1
  import { EntityManager } from 'typeorm'
2
-
3
2
  import { User } from '@things-factory/auth-base'
4
3
  import { Bizplace } from '@things-factory/biz-base'
5
- import {
6
- Domain,
7
- ListParam
8
- } from '@things-factory/shell'
9
-
4
+ import { Domain, ListParam } from '@things-factory/shell'
10
5
  import { rawProductsQuery } from '../../../utils'
11
6
 
12
7
  export const outboundOrderDetailsReport = {
@@ -96,9 +91,11 @@ export const outboundOrderDetailsReport = {
96
91
  where rg.bizplace_id = $2 and rg.domain_id = $1
97
92
  and rg.created_at >= $3 and rg.created_at <= $4
98
93
  and oi.status <> 'REPLACED'
94
+ and oi.release_qty > 0
99
95
  ${status ? `and rg.status = '${status.value}' ` : ``}
100
96
  ${binLocation ? `and l.name ilike '${binLocation.value}' ` : ``}
101
97
  ${priorityDelivery ? `and rg.priority_delivery = ${priorityDelivery.value} ` : ``}
98
+ and oi.release_qty > 0
102
99
  ) src
103
100
  where 1=1
104
101
  ${extraQueryFilters}
@@ -134,6 +131,7 @@ export const outboundOrderDetailsReport = {
134
131
  and rg.assigned_inventory = false
135
132
  ${status ? `and rg.status = '${status.value}' ` : ``}
136
133
  and rg.assigned_inventory = false
134
+ and op.release_qty > 0
137
135
  ) src2
138
136
  where 1=1
139
137
  ${extraQueryFilters}
@@ -213,8 +211,7 @@ export const outboundOrderDetailsReport = {
213
211
  ? `and wpack.ended_at BETWEEN '${fromDate.value}' and '${toDate.value}' and wpack.status = 'DONE'`
214
212
  : ''
215
213
  }
216
- ${
217
- byPackingComplete.value ? `ORDER BY wpack.ended_at DESC` : `ORDER BY order_created_at DESC` }
214
+ ${byPackingComplete.value ? `ORDER BY wpack.ended_at DESC` : `ORDER BY order_created_at DESC`}
218
215
  offset $1 limit $2
219
216
  ) src
220
217
  `,
@@ -3,20 +3,25 @@ import { Domain, ListParam } from '@things-factory/shell'
3
3
 
4
4
  export const pgUdfQuery = {
5
5
  async pgUdfQuery(_: any, params: ListParam, context: any) {
6
- const { domain, tx }: { domain: Domain, tx: EntityManager } = context.state
6
+ const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
7
7
  let udfName = params.filters.find(param => param.name === 'udf')
8
+ let domainParam = params.filters.find(param => param.name === 'domain_id')
8
9
 
9
10
  try {
10
11
  if (!udfName?.value) {
11
12
  throw new Error('UDF name is required')
12
13
  }
13
14
 
15
+ if (!domainParam?.value) {
16
+ params.filters.push({ name: 'domain_id', operator: 'eq', value: domain.id })
17
+ }
18
+
14
19
  // Remove the udf filter and convert remaining filters to an object
15
20
  const parameters = params.filters
16
21
  .filter(f => f.name !== 'udf')
17
22
  .map(filter => ({
18
23
  [filter.name]: filter.value
19
- }));
24
+ }))
20
25
 
21
26
  return { items: JSON.stringify(await callPostgresFunction(udfName.value, tx, parameters)) }
22
27
  } catch (error) {
@@ -27,25 +32,24 @@ export const pgUdfQuery = {
27
32
 
28
33
  /**
29
34
  * Calls a PostgreSQL user-defined function through TypeORM
30
- *
35
+ *
31
36
  * @param functionName - Name of the PostgreSQL UDF to call
32
37
  * @param entityManager - EntityManager instance
33
38
  * @param parameters - Array of parameters or string to pass to the function
34
39
  * @returns Promise with the function result
35
40
  */
36
- async function callPostgresFunction(
37
- functionName: string,
38
- entityManager: EntityManager,
39
- parameters: any[] | string
40
- ) {
41
+ async function callPostgresFunction(functionName: string, entityManager: EntityManager, parameters: any[] | string) {
41
42
  try {
42
- const exists = await entityManager.query(`
43
+ const exists = await entityManager.query(
44
+ `
43
45
  SELECT EXISTS (
44
46
  SELECT 1 FROM pg_proc p
45
47
  JOIN pg_namespace n ON p.pronamespace = n.oid
46
48
  WHERE p.proname = $1
47
49
  AND n.nspname = 'public'
48
- )`, [functionName])
50
+ )`,
51
+ [functionName]
52
+ )
49
53
 
50
54
  if (!exists[0].exists) {
51
55
  throw new Error(`PostgreSQL function '${functionName}' does not exist in the database.`)
@@ -68,9 +72,7 @@ async function callPostgresFunction(
68
72
  const result = await entityManager.query(query, params)
69
73
 
70
74
  // PostgreSQL functions typically return rows, so we handle both single and multiple results
71
- return Array.isArray(result) && result.length === 1
72
- ? result[0]
73
- : result
75
+ return Array.isArray(result) && result.length === 1 ? result[0] : result
74
76
  } catch (error) {
75
77
  throw new Error(`Error calling PostgreSQL function '${functionName}': ${error.message}`)
76
78
  }
@@ -376,13 +376,13 @@ async function completeZonePicking(worksheetId: string, context: any, isPartial:
376
376
  await tx.getRepository(OrderInventory).update(
377
377
  { releaseGood: In(roWithLoadingWorksheet), status: ORDER_INVENTORY_STATUS.PICKED },
378
378
  {
379
- status: ORDER_INVENTORY_STATUS.LOADING,
379
+ status: ORDER_INVENTORY_STATUS.SORTING,
380
380
  updater: user,
381
381
  updatedAt: new Date()
382
382
  }
383
383
  )
384
384
  const loadingOrderInventories: OrderInventory[] = await tx.getRepository(OrderInventory).find({
385
- where: { releaseGood: In(roWithLoadingWorksheet), status: ORDER_INVENTORY_STATUS.LOADING }
385
+ where: { releaseGood: In(roWithLoadingWorksheet), status: ORDER_INVENTORY_STATUS.SORTING }
386
386
  })
387
387
  //update loading wsd deactivated to executing
388
388
  await tx.getRepository(WorksheetDetail).update(
@@ -446,7 +446,7 @@ async function generateLoadingWorksheets(tx: EntityManager, domain: Domain, user
446
446
  await tx.getRepository(OrderInventory).update(
447
447
  { id: In(orderInventories.map(oi => oi.id)), status: ORDER_INVENTORY_STATUS.PICKED },
448
448
  {
449
- status: ORDER_INVENTORY_STATUS.LOADING,
449
+ status: ORDER_INVENTORY_STATUS.SORTING,
450
450
  updater: user,
451
451
  updatedAt: new Date()
452
452
  }
@@ -3,7 +3,8 @@ import { DeliveryOrderInfoList } from './delivery-order-info-list'
3
3
  import { LoadingAssignmentStatus } from './loading-assignment'
4
4
 
5
5
  export const Query = `
6
- findLoadableReleaseGood(orderNo: String!): [ReleaseGood] @transaction
6
+ findLoadableReleaseGood(orderNo: String!, tabName: String!): [ReleaseGood] @transaction
7
+ findLoadableReleaseGoodByBin(orderNo: String!): LoadingWorksheet @transaction
7
8
  loadingWorksheetv2(orderNo: String!, filter: String): LoadingWorksheet @transaction
8
9
  getDeliveryOrders(releaseGoodNo: String!): DeliveryOrderInfoList
9
10
  myLoadingAssignmentStatus: LoadingAssignmentStatus