@things-factory/operato-wms 6.1.83 → 6.1.84

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 (94) hide show
  1. package/dist-server/tsconfig.tsbuildinfo +1 -1
  2. package/package.json +39 -39
  3. package/server/graphql/index.ts +0 -7
  4. package/server/graphql/resolvers/board-setting/board-settings.ts +0 -93
  5. package/server/graphql/resolvers/board-setting/index.ts +0 -5
  6. package/server/graphql/resolvers/custom/elccl/elccl-daily-collection-report.ts +0 -92
  7. package/server/graphql/resolvers/custom/elccl/elccl-daily-order-inventory-report.ts +0 -147
  8. package/server/graphql/resolvers/custom/elccl/elccl-inventory-history-pallet-detail-report.ts +0 -135
  9. package/server/graphql/resolvers/custom/elccl/elccl-inventory-history-report.ts +0 -178
  10. package/server/graphql/resolvers/custom/elccl/elccl-inventory-history-summary-report.ts +0 -123
  11. package/server/graphql/resolvers/custom/elccl/elccl-onhand-inventory-counter.ts +0 -36
  12. package/server/graphql/resolvers/custom/elccl/index.ts +0 -15
  13. package/server/graphql/resolvers/custom/kimeda/index.ts +0 -5
  14. package/server/graphql/resolvers/custom/kimeda/kimeda-onhand-inventory-counter.ts +0 -42
  15. package/server/graphql/resolvers/dashboard/arrival-notices-by-status.ts +0 -34
  16. package/server/graphql/resolvers/dashboard/collection-orders-by-status.ts +0 -24
  17. package/server/graphql/resolvers/dashboard/delivery-orders-by-status.ts +0 -24
  18. package/server/graphql/resolvers/dashboard/index.ts +0 -17
  19. package/server/graphql/resolvers/dashboard/inventory-expiry-monitor.ts +0 -60
  20. package/server/graphql/resolvers/dashboard/outbound-order-by-status.ts +0 -126
  21. package/server/graphql/resolvers/dashboard/release-goods-by-status.ts +0 -34
  22. package/server/graphql/resolvers/dashboard/unit-inbounded-outbounded.ts +0 -61
  23. package/server/graphql/resolvers/index.ts +0 -24
  24. package/server/graphql/resolvers/inventory-comparison/index.ts +0 -5
  25. package/server/graphql/resolvers/inventory-comparison/inventory-comparison-list.ts +0 -101
  26. package/server/graphql/resolvers/opa-menu/index.ts +0 -5
  27. package/server/graphql/resolvers/opa-menu/opa-menus.ts +0 -77
  28. package/server/graphql/resolvers/other/add-release-good-products.ts +0 -413
  29. package/server/graphql/resolvers/other/index.ts +0 -10
  30. package/server/graphql/resolvers/other/page-settings.ts +0 -105
  31. package/server/graphql/resolvers/reports/costing-report.ts +0 -194
  32. package/server/graphql/resolvers/reports/inbound-order-details-report.ts +0 -216
  33. package/server/graphql/resolvers/reports/inbound-serial-number-report.ts +0 -156
  34. package/server/graphql/resolvers/reports/index.ts +0 -18
  35. package/server/graphql/resolvers/reports/outbound-order-details-report.ts +0 -250
  36. package/server/graphql/resolvers/reports/outbound-serial-number-report.ts +0 -159
  37. package/server/graphql/resolvers/reports/product-label-report.ts +0 -55
  38. package/server/graphql/resolvers/reports/release-inventory-report.ts +0 -201
  39. package/server/graphql/resolvers/shipping-provider/index.ts +0 -5
  40. package/server/graphql/resolvers/shipping-provider/shipping-providers.ts +0 -18
  41. package/server/graphql/resolvers/warehouse-inventory-adjustment/index.ts +0 -5
  42. package/server/graphql/resolvers/warehouse-inventory-adjustment/warehouse-intentory-adjustment.ts +0 -79
  43. package/server/graphql/types/board-setting/board-setting.ts +0 -10
  44. package/server/graphql/types/board-setting/index.ts +0 -6
  45. package/server/graphql/types/custom/elccl/elccl-daily-collection-report-list.ts +0 -8
  46. package/server/graphql/types/custom/elccl/elccl-daily-collection-report.ts +0 -24
  47. package/server/graphql/types/custom/elccl/elccl-daily-order-inventory-report-list.ts +0 -8
  48. package/server/graphql/types/custom/elccl/elccl-daily-order-inventory-report.ts +0 -19
  49. package/server/graphql/types/custom/elccl/elccl-inventory-report.ts +0 -16
  50. package/server/graphql/types/custom/elccl/elccl-inventory-summary-report-list.ts +0 -8
  51. package/server/graphql/types/custom/elccl/elccl-inventory-summary-report.ts +0 -17
  52. package/server/graphql/types/custom/elccl/elccl-pallet-detail-report.ts +0 -16
  53. package/server/graphql/types/custom/elccl/index.ts +0 -28
  54. package/server/graphql/types/custom/kimeda/index.ts +0 -3
  55. package/server/graphql/types/dashboard/index.ts +0 -14
  56. package/server/graphql/types/dashboard/inventory-expiry-counter.ts +0 -9
  57. package/server/graphql/types/dashboard/inventory-expiry-status.ts +0 -8
  58. package/server/graphql/types/dashboard/order-status-counter.ts +0 -8
  59. package/server/graphql/types/index.ts +0 -38
  60. package/server/graphql/types/inventory-comparison/index.ts +0 -11
  61. package/server/graphql/types/inventory-comparison/inventory-comparison-list.ts +0 -8
  62. package/server/graphql/types/inventory-comparison/inventory-comparison.ts +0 -12
  63. package/server/graphql/types/opa-menu/index.ts +0 -6
  64. package/server/graphql/types/opa-menu/opa-menu.ts +0 -39
  65. package/server/graphql/types/other/index.ts +0 -19
  66. package/server/graphql/types/other/page-setting.ts +0 -33
  67. package/server/graphql/types/reports/costing-report-list.ts +0 -8
  68. package/server/graphql/types/reports/costing-report.ts +0 -13
  69. package/server/graphql/types/reports/inbound-order-details-report-list.ts +0 -8
  70. package/server/graphql/types/reports/inbound-order-details-report.ts +0 -53
  71. package/server/graphql/types/reports/inbound-serial-number-report-list.ts +0 -8
  72. package/server/graphql/types/reports/inbound-serial-number-report.ts +0 -17
  73. package/server/graphql/types/reports/index.ts +0 -43
  74. package/server/graphql/types/reports/outbound-order-details-report-list.ts +0 -8
  75. package/server/graphql/types/reports/outbound-order-details-report.ts +0 -70
  76. package/server/graphql/types/reports/outbound-serial-number-report-list.ts +0 -8
  77. package/server/graphql/types/reports/outbound-serial-number-report.ts +0 -19
  78. package/server/graphql/types/reports/product-label-report-list.ts +0 -8
  79. package/server/graphql/types/reports/product-label-report.ts +0 -10
  80. package/server/graphql/types/reports/release-inventory-report-list.ts +0 -8
  81. package/server/graphql/types/reports/release-inventory-report.ts +0 -23
  82. package/server/graphql/types/shipping-provider/index.ts +0 -8
  83. package/server/graphql/types/shipping-provider/shipping-provider-list.ts +0 -7
  84. package/server/graphql/types/shipping-provider/shipping-provider.ts +0 -7
  85. package/server/graphql/types/warehouse-inventory-adjustment/index.ts +0 -5
  86. package/server/index.ts +0 -4
  87. package/server/migrations/1568858861188-SeedSetting.ts +0 -57
  88. package/server/migrations/1623308919899-SeedLocationRecommendSetting.ts +0 -35
  89. package/server/migrations/1623381200659-SeedStoringRule.ts +0 -33
  90. package/server/migrations/index.ts +0 -9
  91. package/server/opa-app-setting-constants.ts +0 -9
  92. package/server/routes.ts +0 -1
  93. package/server/utils/index.ts +0 -1
  94. package/server/utils/report-query-util.ts +0 -47
@@ -1,194 +0,0 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { Bizplace } from '@things-factory/biz-base'
3
- import { Filter, ListParam } from '@things-factory/shell'
4
-
5
- import { rawProductsQuery } from '../../../utils'
6
-
7
- export const costingReport = {
8
- async costingReport(_: any, params: ListParam, context: ResolverContext) {
9
- try {
10
- const { tx } = context.state
11
- let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
12
- let userFilter = params.filters.find(data => data.name === 'user')
13
- let fromDate = params.filters.find(data => data.name === 'fromDate')
14
- let toDate = params.filters.find(data => data.name === 'toDate')
15
-
16
- if (userFilter) {
17
- const user = (await tx.getRepository(User).findOne({
18
- where: { id: userFilter.value },
19
- relations: ['bizplaces']
20
- })) as User & { bizplaces: Bizplace[] }
21
-
22
- const bizplace: Bizplace = user.bizplaces[0]
23
-
24
- if (!bizplace) throw 'Invalid input'
25
-
26
- bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id }
27
- } else {
28
- bizplaceFilter = params.filters.find(data => data.name === 'bizplace')
29
- }
30
-
31
- if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
32
-
33
- const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
34
- id: bizplaceFilter.value
35
- })
36
-
37
- await rawProductsQuery(tx, params, bizplace)
38
-
39
- await tx.query(
40
- `
41
- create temp table tmp_outbound_ord on commit drop as (
42
- select p.sku, rih.domain_id, rih.bizplace_id, rih.product_id, rih.packing_type, rih.packing_size, coalesce(rih.uom, pd.uom, pd2.uom) as uom,
43
- sum(rih.qty) as total_picked_qty, sum(rih.uom_value) as total_picked_uom_value
44
- from reduced_inventory_histories rih
45
- inner join inventories inv on inv.domain_id = rih.domain_id and inv.pallet_id = rih.pallet_id
46
- left join product_details pd on pd.product_id = rih.product_id and pd.packing_type = rih.packing_type and pd.packing_size = rih.packing_size
47
- left join product_details pd2 on pd2.product_id = rih.product_id and pd2.is_default = true
48
- left join products p on p.id = rih.product_id
49
- where rih.domain_id = $1
50
- and inv.bizplace_id = $2
51
- and rih.created_at >= $3 and rih.created_at <= $4
52
- and rih.transaction_type = 'PICKING'
53
- group by p.sku, rih.domain_id, rih.bizplace_id, rih.product_id, rih.packing_type, rih.packing_size, coalesce(rih.uom, pd.uom, pd2.uom)
54
- );
55
- `,
56
- [context.state.domain.id, bizplace.id, fromDate.value, toDate.value]
57
- )
58
-
59
- await tx.query(
60
- `
61
- create temp table tmp_stored_inv on commit drop as (
62
- select src2.sku, src2.domain_id, src2.bizplace_id, src2.pallet_id, src2.product_id, src2.packing_type, src2.packing_size, src2.uom,
63
- to_char(src2.created_at, 'YYYY-MM') as created_year_month, sum(closing_qty) as closing_qty from (
64
- select distinct on (rih.pallet_id) p.sku, rih.domain_id, rih.bizplace_id, rih.pallet_id, rih.product_id, rih.packing_type, rih.packing_size,
65
- coalesce(rih.uom, pd.uom, pd2.uom) as uom,
66
- rih.created_at, rih.transaction_type, rih.status, rih.opening_qty + rih.qty as closing_qty
67
- from reduced_inventory_histories rih
68
- inner join inventories i on i.domain_id = rih.domain_id and i.pallet_id = rih.pallet_id
69
- left join product_details pd on pd.product_id = rih.product_id and pd.packing_type = rih.packing_type and pd.packing_size = rih.packing_size
70
- left join product_details pd2 on pd2.product_id = rih.product_id and pd2.is_default = true
71
- left join products p on p.id = rih.product_id
72
- where rih.domain_id = $1
73
- and i.bizplace_id = $2
74
- and rih.created_at <= $3
75
- order by rih.pallet_id, rih.seq desc
76
- ) src2 where src2.status <> 'TERMINATED'
77
- and exists (
78
- select * from tmp_outbound_ord outboundOrd
79
- where outboundOrd.domain_id = src2.domain_id
80
- and outboundOrd.bizplace_id = src2.bizplace_id
81
- and outboundOrd.product_id = src2.product_id
82
- and outboundOrd.packing_type = src2.packing_type
83
- and outboundOrd.packing_size = src2.packing_size
84
- and outboundOrd.uom = src2.uom
85
- )
86
- group by src2.sku, src2.domain_id, src2.bizplace_id, src2.pallet_id, src2.product_id, src2.packing_type, src2.packing_size, src2.uom, to_char(src2.created_at, 'YYYY-MM')
87
- );
88
- `,
89
- [context.state.domain.id, bizplace.id, toDate.value]
90
- )
91
-
92
- await tx.query(
93
- `
94
- create temp table temp_costing_report on commit drop as (
95
- WITH RECURSIVE cte_forwarded_cost as (
96
- select src.domain_id, src.bizplace_id, src.product_id, src.packing_type, src.packing_size, src.uom, TO_DATE(src.created_year_month,'YYYY-MM')::timestamp as running_year_month,
97
- sum(src.qty) as qty, sum(src.total_cost)/ sum(src.qty) as monthly_avg_cost,
98
- coalesce(sum(src.qty)) as closing_qty from (
99
- select distinct on (pallet_id)
100
- ih.domain_id, ih.bizplace_id, ih.pallet_id, ih.unit_cost, (ih.unit_cost * (ih.opening_qty + ih.qty)) as total_cost, ih.status, ih.transaction_type, ih.product_id, ih.packing_type, ih.packing_size, coalesce(ih.uom, pd.uom) as uom,
101
- ih.created_at, to_char(ih.created_at, 'YYYY-MM') as created_year_month,
102
- ih.opening_qty,
103
- ih.qty as transaction_qty,
104
- ih.opening_qty + ih.qty as qty,
105
- ih.opening_uom_value,
106
- ih.uom_value as transaction_uom_value,
107
- ih.opening_uom_value + ih.uom_value as uom_value
108
- from reduced_inventory_histories ih
109
- inner join inventories i on i.domain_id = ih.domain_id and i.pallet_id = ih.pallet_id
110
- left join product_details pd on pd.product_id = ih.product_id and pd.packing_type = ih.packing_type and pd.packing_size = ih.packing_size
111
- where ih.domain_id = $1
112
- and i.bizplace_id = $2
113
- and ih.created_at <= $3 and ih.unit_cost is not null
114
- and exists (
115
- select * from tmp_outbound_ord outboundOrd
116
- where outboundOrd.domain_id = ih.domain_id
117
- and outboundOrd.bizplace_id = ih.bizplace_id
118
- and outboundOrd.product_id = ih.product_id
119
- and outboundOrd.packing_type = ih.packing_type
120
- and outboundOrd.packing_size = ih.packing_size
121
- and outboundOrd.uom = ih.uom
122
- )
123
- order by ih.pallet_id, ih.seq
124
- ) src
125
- group by src.domain_id, src.bizplace_id, src.product_id, src.packing_type, src.packing_size, src.uom, src.created_year_month
126
- union all
127
- select dt1.domain_id, dt1.bizplace_id, dt1.product_id, dt1.packing_type, dt1.packing_size, dt1.uom,
128
- dt1.running_year_month + interval '1 month' as running_year_month, dt1.qty, dt1.monthly_avg_cost, dt1.closing_qty
129
- from cte_forwarded_cost dt1
130
- where dt1.running_year_month + interval '1 month' < $3
131
- ) select fc.*, -outboundord.total_picked_qty as "qty", -outboundord.total_picked_uom_value as "uom_value", (-outboundord.total_picked_qty * fc.weighted_avg_unit_cost) as "total_cost" from (
132
- select p.sku as "product_sku", p."name" as "product_name", p.description as "product_description", p."type" as "product_type",
133
- fc.domain_id, fc.bizplace_id, fc.product_id, fc.packing_type, fc.packing_size, fc.uom, fc.running_year_month,
134
- ROUND(cast(sum(fc.monthly_avg_cost * fc.closing_qty) / sum(fc.qty) as numeric),2) as "weighted_avg_unit_cost"
135
- from cte_forwarded_cost fc
136
- left join products p on p.id = fc.product_id
137
- where running_year_month = to_date(to_char($3::date, 'YYYY-MM'),'YYYY-MM')::timestamp
138
- group by p.sku, p."name", p.description, p."type", fc.domain_id, fc.bizplace_id, fc.product_id, fc.packing_type, fc.packing_size, fc.uom, fc.running_year_month
139
- ) fc
140
- left join tmp_outbound_ord outboundord on outboundord.domain_id = fc.domain_id
141
- and outboundord.bizplace_id = fc.bizplace_id
142
- and outboundord.product_id = fc.product_id
143
- and outboundord.packing_type = fc.packing_type
144
- and outboundord.packing_size = fc.packing_size
145
- and outboundord.uom = fc.uom
146
- );
147
- `,
148
- [context.state.domain.id, bizplace.id, toDate.value]
149
- )
150
-
151
- const total: any = await tx.query(`
152
- select count(*) from temp_costing_report
153
- `)
154
-
155
- const result: any = await tx.query(
156
- `
157
- select * from temp_costing_report
158
- offset $1 limit $2
159
- `,
160
- [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]
161
- )
162
-
163
- let items = result.map(itm => {
164
- let data = {
165
- bizplace: {
166
- description: bizplace.description,
167
- name: bizplace.name
168
- },
169
- product: {
170
- id: itm.product_id,
171
- sku: itm.product_sku,
172
- name: itm.product_name,
173
- description: itm.product_description,
174
- type: itm.product_type
175
- },
176
- qty: itm.qty,
177
- uom: itm.uom,
178
- uomValue: itm.uom_value,
179
- weightedAvgUnitCost: itm.weighted_avg_unit_cost,
180
- totalCost: itm.total_cost
181
- }
182
-
183
- return data
184
- })
185
-
186
- return {
187
- items,
188
- total: total[0].count
189
- }
190
- } catch (error) {
191
- throw error
192
- }
193
- }
194
- }
@@ -1,216 +0,0 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { Bizplace } from '@things-factory/biz-base'
3
- import { Filter, ListParam } from '@things-factory/shell'
4
-
5
- import { rawProductsQuery } from '../../../utils'
6
-
7
- export const inboundOrderDetailsReport = {
8
- async inboundOrderDetailsReport(_: any, params: ListParam, context: ResolverContext) {
9
- try {
10
- const { tx } = context.state
11
- let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
12
- let userFilter = params.filters.find(data => data.name === 'user')
13
- let fromDate = params.filters.find(data => data.name === 'fromDate')
14
- let toDate = params.filters.find(data => data.name === 'toDate')
15
- let ganNo = params.filters.find(data => data.name === 'ganNo')
16
- let grnNo = params.filters.find(data => data.name === 'grnNo')
17
- let poNo = params.filters.find(data => data.name === 'poNo')
18
- let doNo = params.filters.find(data => data.name === 'doNo')
19
-
20
- if (userFilter) {
21
- const user = (await tx.getRepository(User).findOne({
22
- where: { id: userFilter.value },
23
- relations: ['bizplaces']
24
- })) as User & { bizplaces: Bizplace[] }
25
-
26
- const bizplace: Bizplace = user.bizplaces[0]
27
-
28
- if (!bizplace) throw 'Invalid input'
29
-
30
- bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id }
31
- } else {
32
- bizplaceFilter = params.filters.find(data => data.name === 'bizplace')
33
- }
34
-
35
- if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
36
-
37
- const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
38
- id: bizplaceFilter.value
39
- })
40
-
41
- await rawProductsQuery(tx, params, bizplace)
42
-
43
- let extraQueryFilters = ''
44
- if (ganNo) {
45
- extraQueryFilters = `${extraQueryFilters} and gan_no like '%${ganNo.value}%' `
46
- }
47
- if (grnNo) {
48
- extraQueryFilters = `${extraQueryFilters} and grn_no like '%${grnNo.value}%' `
49
- }
50
- if (poNo) {
51
- extraQueryFilters = `${extraQueryFilters} and purchase_order_name like '%${poNo.value}%' `
52
- }
53
- if (doNo) {
54
- extraQueryFilters = `${extraQueryFilters} and delivery_order_no like '%${doNo.value}%' `
55
- }
56
-
57
- await tx.query(
58
- `
59
- create temp table temp_inbound_order_report on commit drop as (
60
- select * from (
61
- select b2.id as "bizplace_id", b2.name as "bizplace_name", b2.description as "bizplace_description",
62
- grn.name as "grn_no",
63
- an.name as "gan_no", an.ref_no as "ref_no_1", an.ref_no_2 as "ref_no_2", an.ref_no_3 as "ref_no_3",
64
- an.loose_item, an.import_cargo, an.container_no, an.container_size, an.own_transport,
65
- u.name as "accepted_by", an.accepted_at,
66
- an.created_at as "order_created_at",
67
- w.started_at as "unload_start", w.ended_at as "unload_complete",
68
- w2.started_at as "putaway_start", w2.ended_at as "putaway_complete",
69
- an.delivery_order_no,
70
- cp.id as "supplier_id",
71
- cp.company_name as "supplier_name",
72
- po.id as "purchase_order_id",
73
- po.name as "purchase_order_name",
74
- row_number() over(partition by an.name order by an.name, p.sku, ih.batch_id) as "order_line_item",
75
- p.id as "product_id", p.sku as "product_sku", p.name as "product_name", p.description as "product_description", p.type as "product_type",
76
- ih.packing_type as "pack_type", op.packing_size as "pack_size",
77
- ih.qty, ih.uom_value, ih.uom, ih.pallet_id, ih.carton_id, ih.batch_id, ih.batch_id_ref,
78
- i.expiration_date, i.manufacture_date,
79
- ih.unit_cost,
80
- ih.created_at as "unloaded_at",u2.name as "unloaded_by",
81
- ih2.created_at as "putaway_at", u3.name as "putaway_by",
82
- coalesce((select volume from product_details pd where pd.product_id = i.product_id and pd.packing_type = i.packing_type and pd.packing_size = i.packing_size
83
- order by created_at desc
84
- fetch first 1 rows only),0) as unit_volume,
85
- coalesce((select nett_weight from product_details pd where pd.product_id = i.product_id and pd.packing_type = i.packing_type and pd.packing_size = i.packing_size
86
- order by created_at desc
87
- fetch first 1 rows only),0) as unit_nett_weight,
88
- coalesce((select gross_weight from product_details pd where pd.product_id = i.product_id and pd.packing_type = i.packing_type and pd.packing_size = i.packing_size
89
- order by created_at desc
90
- fetch first 1 rows only),0) as unit_gross_weight,
91
- coalesce((select weight_unit from product_details pd where pd.product_id = i.product_id and pd.packing_type = i.packing_type and pd.packing_size = i.packing_size
92
- order by created_at desc
93
- fetch first 1 rows only),'') as weight_unit
94
- from (
95
- select * from arrival_notices
96
- where domain_id = $1 and bizplace_id = $2 and status ='DONE'
97
- and created_at >= $3 and created_at <= $4) an
98
- left join goods_receival_notes grn on grn.arrival_notice_id = an.id
99
- left join purchase_orders po on po.id = an.purchase_order_id
100
- left join contact_points cp on cp.id = po.supplier_id
101
- inner join bizplaces b2 on b2.id = an.bizplace_id
102
- left join users u on u.id = an.accepted_by_id
103
- inner join order_inventories oi on oi.arrival_notice_id = an.id
104
- inner join inventories i on i.id = oi.inventory_id
105
- left join worksheets w on w.arrival_notice_id = an.id and w."type" ='UNLOADING'
106
- inner join reduced_inventory_histories ih on ih.inventory_id = oi.inventory_id and ih.transaction_type ='UNLOADING' and ih.ref_order_id = an.id::varchar
107
- left join users u2 on u2.id = ih.creator_id
108
- left join worksheets w2 on w2.arrival_notice_id = an.id and w2."type" ='PUTAWAY'
109
- inner join reduced_inventory_histories ih2 on ih2.inventory_id = oi.inventory_id and ih2.transaction_type ='PUTAWAY' and ih2.ref_order_id = an.id::varchar
110
- left join users u3 on u3.id = ih2.creator_id
111
- inner join temp_products p on p.id = ih.product_id
112
- inner join order_products op on op.arrival_notice_id = an.id and op.actual_pack_qty is not null and op.product_id = ih.product_id and
113
- op.batch_id = ih.batch_id and op.packing_type = ih.packing_type
114
- order by an.name, p.sku, ih.batch_id
115
- ) src
116
- where 1=1
117
- ${extraQueryFilters}
118
- )
119
- `,
120
- [context.state.domain.id, bizplace.id, fromDate.value, toDate.value]
121
- )
122
-
123
- const total: any = await tx.query(`
124
- select count(*) from temp_inbound_order_report
125
- `)
126
-
127
- const result: any = await tx.query(
128
- `
129
- select *,
130
- round((qty * unit_volume)::numeric ,4) as total_volume,
131
- round((qty * unit_nett_weight)::numeric ,4) as total_unit_nett_weight,
132
- round((qty * unit_gross_weight)::numeric ,4) as total_unit_gross_weight
133
- from temp_inbound_order_report
134
- offset $1 limit $2
135
- `,
136
- [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]
137
- )
138
-
139
- let items = result.map(itm => {
140
- let data = {
141
- bizplace: {
142
- description: itm.bizplace_description,
143
- name: itm.bizplace_name
144
- },
145
- grnNo: itm.grn_no,
146
- ganNo: itm.gan_no,
147
- deliveryOrderNo: itm.delivery_order_no,
148
- refNo1: itm.ref_no_1,
149
- refNo2: itm.ref_no_2,
150
- refNo3: itm.ref_no_3,
151
- looseItem: itm.loose_item,
152
- importCargo: itm.import_cargo,
153
- containerNo: itm.container_no,
154
- containerSize: itm.container_size,
155
- ownTransport: itm.own_transport,
156
- acceptedBy: itm.accepted_by,
157
- acceptedAt: itm.accepted_at,
158
- orderCreatedAt: itm.order_created_at,
159
- unloadStart: itm.unload_start,
160
- unloadComplete: itm.unload_complete,
161
- putawayStart: itm.putaway_start,
162
- putawayComplete: itm.putaway_complete,
163
- orderLineItem: itm.order_line_item,
164
- product: {
165
- id: itm.product_id,
166
- sku: itm.product_sku,
167
- name: itm.product_name,
168
- description: itm.product_description,
169
- type: itm.product_type
170
- },
171
- purchaseOrderId: itm.purchase_order_id,
172
- purchaseOrderNo: itm.purchase_order_name,
173
- packType: itm.pack_type,
174
- packSize: itm.pack_size,
175
- qty: itm.qty,
176
- uomValue: itm.uom_value,
177
- uom: itm.uom,
178
- unitVolume: itm.unit_volume,
179
- unitCost: itm.unit_cost,
180
- totalVolume: itm.total_volume,
181
- unitNettWeight: itm.unit_nett_weight,
182
- totalUnitNettWeight: itm.total_unit_nett_weight,
183
- unitGrossWeight: itm.unit_gross_weight,
184
- totalUnitGrossWeight: itm.total_unit_gross_weight,
185
- weightUnit: itm.weight_unit,
186
- palletId: itm.pallet_id,
187
- cartonId: itm.carton_id,
188
- batchId: itm.batch_id,
189
- batchIdRef: itm.batch_id_ref,
190
- expirationDate: itm.expiration_date,
191
- manufactureDate: itm.manufacture_date,
192
- unloadedAt: itm.unloaded_at,
193
- unloadedBy: itm.unloaded_by,
194
- putawayAt: itm.putaway_at,
195
- putawayBy: itm.putaway_by
196
- }
197
-
198
- if (itm.supplier_id) {
199
- data['supplier'] = {
200
- id: itm.supplier_id,
201
- name: itm.supplier_name
202
- }
203
- }
204
-
205
- return data
206
- })
207
-
208
- return {
209
- items,
210
- total: total[0].count
211
- }
212
- } catch (error) {
213
- throw error
214
- }
215
- }
216
- }
@@ -1,156 +0,0 @@
1
- import { User } from '@things-factory/auth-base'
2
- import { Bizplace } from '@things-factory/biz-base'
3
- import { Filter, ListParam } from '@things-factory/shell'
4
-
5
- import { rawProductsQuery } from '../../../utils'
6
-
7
- export const inboundSerialNumberReport = {
8
- async inboundSerialNumberReport(_: any, params: ListParam, context: ResolverContext) {
9
- try {
10
- const { tx } = context.state
11
- let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
12
- let userFilter = params.filters.find(data => data.name === 'user')
13
- let fromDate = params.filters.find(data => data.name === 'fromDate')
14
- let toDate = params.filters.find(data => data.name === 'toDate')
15
- let orderNo = params.filters.find(data => data.name === 'orderNo')
16
- let ref = params.filters.find(data => data.name === 'ref')
17
- let palletId = params.filters.find(data => data.name === 'palletId')
18
- let cartonId = params.filters.find(data => data.name === 'cartonId')
19
- let serialNumber = params.filters.find(data => data.name === 'serialNumber')
20
-
21
- if (userFilter) {
22
- const user = (await tx.getRepository(User).findOne({
23
- where: { id: userFilter.value },
24
- relations: ['bizplaces']
25
- })) as User & { bizplaces: Bizplace[] }
26
-
27
- const bizplace: Bizplace = user.bizplaces[0]
28
-
29
- if (!bizplace) throw 'Invalid input'
30
-
31
- bizplaceFilter = { name: 'bizplace', operator: 'eq', value: bizplace.id }
32
- } else {
33
- bizplaceFilter = params.filters.find(data => data.name === 'bizplace')
34
- }
35
-
36
- if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
37
-
38
- const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
39
- id: bizplaceFilter.value
40
- })
41
-
42
- await rawProductsQuery(tx, params, bizplace)
43
-
44
- let extraQueryFilters = ''
45
- if (orderNo) {
46
- extraQueryFilters = `${extraQueryFilters} and order_no like '%${orderNo.value}%' `
47
- }
48
- if (palletId) {
49
- extraQueryFilters = `${extraQueryFilters} and pallet_id like '%${palletId.value}%' `
50
- }
51
- if (cartonId) {
52
- extraQueryFilters = `${extraQueryFilters} and carton_id like '%${cartonId.value}%' `
53
- }
54
- if (serialNumber) {
55
- extraQueryFilters = `${extraQueryFilters} and serial_number like '%${serialNumber.value}%' `
56
- }
57
-
58
- let refNoQueryFilter = ''
59
- if (ref) {
60
- let refValue = ref.value
61
- .toLowerCase()
62
- .split(',')
63
- .map(ref => {
64
- return "'%" + ref.trim().replace(/'/g, "''") + "%'"
65
- })
66
- .join(',')
67
- refNoQueryFilter = `AND (
68
- Lower(an.ref_no) LIKE ANY(ARRAY[${refValue}])
69
- OR Lower(an.ref_no_2) LIKE ANY(ARRAY[${refValue}])
70
- OR Lower(an.ref_no_3) LIKE ANY(ARRAY[${refValue}])
71
- )`
72
- }
73
-
74
- await tx.query(
75
- `
76
- create temp table temp_inbound_serial_number_report on commit drop as (
77
- select * from (
78
- select
79
- row_number() over(partition by an."name" order by coalesce(w.started_at, ii.created_at), p.sku ) as "no",
80
- case when "source" = 'ADJUSTMENT' then 'adjustment' else an."name" end as "order_no",
81
- i.pallet_id, i.carton_id,an.ref_no, an.ref_no_2, an.ref_no_3,
82
- p.id as "product_id", p.sku as "product_sku", p.brand_sku as "product_brand_sku",
83
- p.name as "product_name", p.description as "product_description", p."type" as "product_type",
84
- coalesce(pd.volume, '0') as "product_volume",
85
- ii.serial_number,
86
- coalesce(w.started_at,ii.created_at) as "etd"
87
- from inventory_items ii
88
- inner join inventories i on i.id = ii.inventory_id
89
- inner join temp_products p on p.id = i.product_id
90
- left join product_details pd on pd.product_id = p.id and pd.packing_type = i.packing_type and pd.packing_size = i.packing_size
91
- left join arrival_notices an on an.id = ii.inbound_order_id::uuid
92
- left join worksheets w on w.arrival_notice_id = an.id and w.type = 'UNLOADING'
93
- where
94
- i.domain_id = $1 and i.bizplace_id = $2
95
- and coalesce(w.started_at, ii.created_at) between $3 and $4
96
- ${refNoQueryFilter}
97
- order by coalesce(w.started_at, ii.created_at), p.sku
98
- ) src
99
- where 1=1
100
- ${extraQueryFilters}
101
- )
102
- `,
103
- [context.state.domain.id, bizplace.id, fromDate.value, toDate.value]
104
- )
105
-
106
- const total: any = await tx.query(`
107
- select count(*) from temp_inbound_serial_number_report
108
- `)
109
-
110
- const result: any = await tx.query(
111
- `
112
- select *
113
- from temp_inbound_serial_number_report
114
- offset $1 limit $2
115
- `,
116
- [(params.pagination.page - 1) * params.pagination.limit, params.pagination.limit]
117
- )
118
-
119
- let items = result.map(itm => {
120
- let data = {
121
- no: itm.no,
122
- bizplace: {
123
- description: bizplace.description,
124
- name: bizplace.name
125
- },
126
- palletId: itm.pallet_id,
127
- cartonId: itm.carton_id,
128
- orderNo: itm.order_no,
129
- refNo1: itm.ref_no,
130
- refNo2: itm.ref_no_2,
131
- refNo3: itm.ref_no_3,
132
- product: {
133
- id: itm.product_id,
134
- sku: itm.product_sku,
135
- brandSku: itm.product_brand_sku,
136
- name: itm.product_name,
137
- description: itm.product_description,
138
- type: itm.product_type,
139
- volume: itm.product_volume
140
- },
141
- serialNumber: itm.serial_number,
142
- etd: itm.etd
143
- }
144
-
145
- return data
146
- })
147
-
148
- return {
149
- items,
150
- total: total[0].count
151
- }
152
- } catch (error) {
153
- throw error
154
- }
155
- }
156
- }
@@ -1,18 +0,0 @@
1
- import { inboundSerialNumberReport } from './inbound-serial-number-report'
2
- import { outboundSerialNumberReport } from './outbound-serial-number-report'
3
-
4
- import { costingReport } from './costing-report'
5
- import { inboundOrderDetailsReport } from './inbound-order-details-report'
6
- import { outboundOrderDetailsReport } from './outbound-order-details-report'
7
- import { productLabelReport } from './product-label-report'
8
- import { releaseInventoryReport } from './release-inventory-report'
9
-
10
- export const Query = {
11
- ...inboundSerialNumberReport,
12
- ...outboundSerialNumberReport,
13
- ...costingReport,
14
- ...inboundOrderDetailsReport,
15
- ...outboundOrderDetailsReport,
16
- ...productLabelReport,
17
- ...releaseInventoryReport
18
- }