@things-factory/warehouse-base 5.0.14 → 6.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/controllers/ecommerce/ecommerce-controller.js +1 -1
- package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
- package/dist-server/controllers/ecommerce/sellercraft-controller.js +64 -60
- package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
- package/dist-server/controllers/warehouse-controller.js +7 -5
- package/dist-server/controllers/warehouse-controller.js.map +1 -1
- package/dist-server/service/inventory/inventory-mutation.js +6 -6
- package/dist-server/service/inventory/inventory-mutation.js.map +1 -1
- package/dist-server/service/inventory/inventory-query.js +217 -195
- package/dist-server/service/inventory/inventory-query.js.map +1 -1
- package/dist-server/service/inventory/inventory-types.js +14 -15
- package/dist-server/service/inventory/inventory-types.js.map +1 -1
- package/dist-server/service/inventory/inventory.js +62 -42
- package/dist-server/service/inventory/inventory.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change-mutation.js +252 -216
- package/dist-server/service/inventory-change/inventory-change-mutation.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change-query.js +6 -7
- package/dist-server/service/inventory-change/inventory-change-query.js.map +1 -1
- package/dist-server/service/inventory-change/inventory-change.js +7 -7
- package/dist-server/service/inventory-change/inventory-change.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-mutation.js +1 -1
- package/dist-server/service/inventory-history/inventory-history-mutation.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-query.js +89 -99
- package/dist-server/service/inventory-history/inventory-history-query.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history-types.js +3 -3
- package/dist-server/service/inventory-history/inventory-history-types.js.map +1 -1
- package/dist-server/service/inventory-history/inventory-history.js +7 -7
- package/dist-server/service/inventory-history/inventory-history.js.map +1 -1
- package/dist-server/service/inventory-item/inventory-item-mutation.js +10 -10
- package/dist-server/service/inventory-item/inventory-item-mutation.js.map +1 -1
- package/dist-server/service/inventory-item/inventory-item-query.js +18 -17
- package/dist-server/service/inventory-item/inventory-item-query.js.map +1 -1
- package/dist-server/service/inventory-item/inventory-item-type.js +4 -5
- package/dist-server/service/inventory-item/inventory-item-type.js.map +1 -1
- package/dist-server/service/inventory-item/inventory-item.js +5 -5
- package/dist-server/service/inventory-item/inventory-item.js.map +1 -1
- package/dist-server/service/inventory-item-change/inventory-item-change-mutation.js +4 -4
- package/dist-server/service/inventory-item-change/inventory-item-change-mutation.js.map +1 -1
- package/dist-server/service/inventory-item-change/inventory-item-change-query.js +7 -9
- package/dist-server/service/inventory-item-change/inventory-item-change-query.js.map +1 -1
- package/dist-server/service/inventory-item-change/inventory-item-change-type.js +6 -7
- package/dist-server/service/inventory-item-change/inventory-item-change-type.js.map +1 -1
- package/dist-server/service/inventory-item-change/inventory-item-change.js +3 -4
- package/dist-server/service/inventory-item-change/inventory-item-change.js.map +1 -1
- package/dist-server/service/inventory-product/inventory-product-mutation.js +4 -4
- package/dist-server/service/inventory-product/inventory-product-mutation.js.map +1 -1
- package/dist-server/service/inventory-product/inventory-product-query.js +7 -9
- package/dist-server/service/inventory-product/inventory-product-query.js.map +1 -1
- package/dist-server/service/inventory-product/inventory-product-type.js +1 -2
- package/dist-server/service/inventory-product/inventory-product-type.js.map +1 -1
- package/dist-server/service/inventory-product/inventory-product.js +5 -5
- package/dist-server/service/inventory-product/inventory-product.js.map +1 -1
- package/dist-server/service/location/location-mutation.js +5 -5
- package/dist-server/service/location/location-mutation.js.map +1 -1
- package/dist-server/service/location/location-query.js +17 -19
- package/dist-server/service/location/location-query.js.map +1 -1
- package/dist-server/service/location/location-types.js +3 -3
- package/dist-server/service/location/location-types.js.map +1 -1
- package/dist-server/service/location/location.js +14 -14
- package/dist-server/service/location/location.js.map +1 -1
- package/dist-server/service/movement/movement-mutation.js +6 -5
- package/dist-server/service/movement/movement-mutation.js.map +1 -1
- package/dist-server/service/movement/movement-query.js +15 -15
- package/dist-server/service/movement/movement-query.js.map +1 -1
- package/dist-server/service/movement/movement-types.js +4 -5
- package/dist-server/service/movement/movement-types.js.map +1 -1
- package/dist-server/service/movement/movement.js +5 -5
- package/dist-server/service/movement/movement.js.map +1 -1
- package/dist-server/service/pallet/pallet-mutation.js +5 -5
- package/dist-server/service/pallet/pallet-mutation.js.map +1 -1
- package/dist-server/service/pallet/pallet-query.js +9 -11
- package/dist-server/service/pallet/pallet-query.js.map +1 -1
- package/dist-server/service/pallet/pallet-types.js +5 -6
- package/dist-server/service/pallet/pallet-types.js.map +1 -1
- package/dist-server/service/pallet/pallet.js +6 -6
- package/dist-server/service/pallet/pallet.js.map +1 -1
- package/dist-server/service/pallet-count/pallet-count-mutation.js +1 -1
- package/dist-server/service/pallet-count/pallet-count-mutation.js.map +1 -1
- package/dist-server/service/pallet-count/pallet-count-query.js +6 -8
- package/dist-server/service/pallet-count/pallet-count-query.js.map +1 -1
- package/dist-server/service/pallet-count/pallet-count.js +3 -4
- package/dist-server/service/pallet-count/pallet-count.js.map +1 -1
- package/dist-server/service/pallet-history/pallet-history-mutation.js +1 -1
- package/dist-server/service/pallet-history/pallet-history-mutation.js.map +1 -1
- package/dist-server/service/pallet-history/pallet-history-query.js +6 -8
- package/dist-server/service/pallet-history/pallet-history-query.js.map +1 -1
- package/dist-server/service/pallet-history/pallet-history.js +6 -6
- package/dist-server/service/pallet-history/pallet-history.js.map +1 -1
- package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js +1 -1
- package/dist-server/service/reduced-inventory-history/reduced-inventory-history.js.map +1 -1
- package/dist-server/service/tote/tote-mutation.js +4 -4
- package/dist-server/service/tote/tote-mutation.js.map +1 -1
- package/dist-server/service/tote/tote-query.js +12 -13
- package/dist-server/service/tote/tote-query.js.map +1 -1
- package/dist-server/service/tote/tote-types.js +2 -3
- package/dist-server/service/tote/tote-types.js.map +1 -1
- package/dist-server/service/tote/tote.js +5 -5
- package/dist-server/service/tote/tote.js.map +1 -1
- package/dist-server/service/warehouse/warehouse-mutation.js +1 -1
- package/dist-server/service/warehouse/warehouse-mutation.js.map +1 -1
- package/dist-server/service/warehouse/warehouse-query.js +9 -10
- package/dist-server/service/warehouse/warehouse-query.js.map +1 -1
- package/dist-server/service/warehouse/warehouse.js +12 -12
- package/dist-server/service/warehouse/warehouse.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/inventory-util.js +16 -16
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +8 -8
- package/server/controllers/ecommerce/ecommerce-controller.ts +1 -1
- package/server/controllers/ecommerce/sellercraft-controller.ts +75 -65
- package/server/controllers/warehouse-controller.ts +9 -4
- package/server/service/inventory/inventory-mutation.ts +28 -24
- package/server/service/inventory/inventory-query.ts +269 -304
- package/server/service/inventory/inventory.ts +50 -35
- package/server/service/inventory-change/inventory-change-mutation.ts +305 -256
- package/server/service/inventory-change/inventory-change-query.ts +9 -9
- package/server/service/inventory-history/inventory-history-mutation.ts +12 -15
- package/server/service/inventory-history/inventory-history-query.ts +158 -133
- package/server/service/inventory-item/inventory-item-mutation.ts +20 -17
- package/server/service/inventory-item/inventory-item-query.ts +28 -18
- package/server/service/inventory-item-change/inventory-item-change-mutation.ts +12 -9
- package/server/service/inventory-item-change/inventory-item-change-query.ts +10 -8
- package/server/service/inventory-product/inventory-product-mutation.ts +16 -12
- package/server/service/inventory-product/inventory-product-query.ts +7 -8
- package/server/service/location/location-mutation.ts +24 -24
- package/server/service/location/location-query.ts +27 -23
- package/server/service/location/location.ts +11 -10
- package/server/service/movement/movement-mutation.ts +7 -8
- package/server/service/movement/movement-query.ts +18 -16
- package/server/service/pallet/pallet-mutation.ts +18 -20
- package/server/service/pallet/pallet-query.ts +13 -14
- package/server/service/pallet-count/pallet-count-mutation.ts +20 -17
- package/server/service/pallet-count/pallet-count-query.ts +6 -7
- package/server/service/pallet-history/pallet-history-mutation.ts +15 -15
- package/server/service/pallet-history/pallet-history-query.ts +7 -8
- package/server/service/reduced-inventory-history/reduced-inventory-history.ts +1 -1
- package/server/service/tote/tote-mutation.ts +23 -22
- package/server/service/tote/tote-query.ts +18 -14
- package/server/service/warehouse/warehouse-mutation.ts +21 -18
- package/server/service/warehouse/warehouse-query.ts +11 -11
- package/server/service/warehouse/warehouse.ts +7 -7
- package/server/utils/inventory-util.ts +10 -10
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { Arg, Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'
|
|
2
|
-
import { Between, Brackets, EntityManager,
|
|
2
|
+
import { Between, Brackets, EntityManager, In, IsNull, Raw, SelectQueryBuilder } from 'typeorm'
|
|
3
3
|
|
|
4
4
|
import { User } from '@things-factory/auth-base'
|
|
5
5
|
import { Bizplace, getMyBizplace, getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
6
6
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
buildQuery,
|
|
9
|
+
convertListParams,
|
|
10
|
+
Domain,
|
|
11
|
+
Filter,
|
|
12
|
+
getRepository,
|
|
13
|
+
ListParam,
|
|
14
|
+
Pagination,
|
|
15
|
+
Sorting
|
|
16
|
+
} from '@things-factory/shell'
|
|
8
17
|
|
|
9
18
|
import { RawInventoryHistoryList } from '../'
|
|
10
19
|
import { InventoryList } from '../inventory/inventory-types'
|
|
@@ -22,8 +31,8 @@ import {
|
|
|
22
31
|
@Resolver(InventoryHistory)
|
|
23
32
|
export class InventoryHistoryQuery {
|
|
24
33
|
@Query(returns => InventoryHistoryList)
|
|
25
|
-
async inventoryHistories(@Args() params: ListParam, @Ctx() context:
|
|
26
|
-
const { domain, user }
|
|
34
|
+
async inventoryHistories(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<InventoryHistoryList> {
|
|
35
|
+
const { domain, user } = context.state
|
|
27
36
|
|
|
28
37
|
if (!params.filters.find((filter: any) => filter.name === 'bizplace')) {
|
|
29
38
|
params.filters.push({
|
|
@@ -38,6 +47,7 @@ export class InventoryHistoryQuery {
|
|
|
38
47
|
...convertedParams,
|
|
39
48
|
relations: ['domain', 'bizplace', 'product', 'location', 'warehouse', 'creator', 'updater'],
|
|
40
49
|
order: {
|
|
50
|
+
...convertedParams.order,
|
|
41
51
|
palletId: 'DESC',
|
|
42
52
|
createdAt: 'ASC'
|
|
43
53
|
}
|
|
@@ -78,28 +88,29 @@ export class InventoryHistoryQuery {
|
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
@Query(returns => InventoryHistory)
|
|
81
|
-
async inventoryHistory(@Arg('name') name: string, @Ctx() context:
|
|
82
|
-
const { domain }
|
|
91
|
+
async inventoryHistory(@Arg('name') name: string, @Ctx() context: ResolverContext): Promise<InventoryHistory> {
|
|
92
|
+
const { domain } = context.state
|
|
83
93
|
|
|
84
94
|
return await getRepository(InventoryHistory).findOne({
|
|
85
|
-
where: { domain: domain, name
|
|
95
|
+
where: { domain: domain, name },
|
|
96
|
+
relations: ['domain', 'creator', 'updater']
|
|
86
97
|
})
|
|
87
98
|
}
|
|
88
99
|
|
|
89
100
|
@Directive('@transaction')
|
|
90
101
|
@Query(returns => InventoryHistoryList)
|
|
91
102
|
async bizplaceInventoryHistories(
|
|
92
|
-
@Ctx() context:
|
|
103
|
+
@Ctx() context: ResolverContext,
|
|
93
104
|
@Arg('inventoryHistory', type => InventoryHistoryPatch, { nullable: true })
|
|
94
105
|
inventoryHistory?: InventoryHistoryPatch,
|
|
95
106
|
@Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[],
|
|
96
107
|
@Arg('pagination', type => Pagination, { nullable: true }) pagination?: Pagination,
|
|
97
108
|
@Arg('sortings', type => [Sorting], { nullable: true }) sortings?: Sorting[]
|
|
98
109
|
): Promise<InventoryHistoryList> {
|
|
99
|
-
const { domain, user, tx }
|
|
110
|
+
const { domain, user, tx } = context.state
|
|
100
111
|
|
|
101
112
|
const ownerBizplace: Bizplace = await getMyBizplace(domain, user)
|
|
102
|
-
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
113
|
+
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({ id: inventoryHistory.bizplace.id })
|
|
103
114
|
|
|
104
115
|
const productFilters = filters.find(x => x.name == 'product_info')
|
|
105
116
|
filters = filters.filter(x => x.name != 'product_info')
|
|
@@ -129,7 +140,7 @@ export class InventoryHistoryQuery {
|
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
if (inventoryHistory && inventoryHistory.warehouseName) {
|
|
132
|
-
const _warehouses: Warehouse[] = await tx.getRepository(Warehouse).
|
|
143
|
+
const _warehouses: Warehouse[] = await tx.getRepository(Warehouse).findBy({
|
|
133
144
|
domain: domain,
|
|
134
145
|
name: Raw(alias => `LOWER(${alias}) LIKE '${inventoryHistory.warehouseName.toLowerCase()}'`)
|
|
135
146
|
})
|
|
@@ -168,11 +179,14 @@ export class InventoryHistoryQuery {
|
|
|
168
179
|
|
|
169
180
|
@Directive('@transaction')
|
|
170
181
|
@Query(returns => [InventoryHistory])
|
|
171
|
-
async inventoryHistoryReport(
|
|
182
|
+
async inventoryHistoryReport(
|
|
183
|
+
@Args() params: ListParam,
|
|
184
|
+
@Ctx() context: ResolverContext
|
|
185
|
+
): Promise<InventoryHistory[]> {
|
|
172
186
|
try {
|
|
173
|
-
const { domain, tx }
|
|
187
|
+
const { domain, tx } = context.state
|
|
174
188
|
|
|
175
|
-
let bizplaceFilter = { name: '', operator: '', value: '' }
|
|
189
|
+
let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
|
|
176
190
|
let userFilter = params.filters.find(data => data.name === 'user')
|
|
177
191
|
let fromDate = params.filters.find(data => data.name === 'fromDate')
|
|
178
192
|
let toDate = params.filters.find(data => data.name === 'toDate')
|
|
@@ -183,10 +197,10 @@ export class InventoryHistoryQuery {
|
|
|
183
197
|
let tzoffset = params.filters.find(data => data.name === 'tzoffset').value + ' seconds'
|
|
184
198
|
|
|
185
199
|
if (userFilter) {
|
|
186
|
-
const user
|
|
200
|
+
const user = (await tx.getRepository(User).findOne({
|
|
187
201
|
where: { id: userFilter.value },
|
|
188
202
|
relations: ['bizplaces']
|
|
189
|
-
})) as
|
|
203
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
190
204
|
|
|
191
205
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
192
206
|
|
|
@@ -199,7 +213,7 @@ export class InventoryHistoryQuery {
|
|
|
199
213
|
|
|
200
214
|
if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
|
|
201
215
|
|
|
202
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
216
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
|
|
203
217
|
id: bizplaceFilter.value
|
|
204
218
|
})
|
|
205
219
|
|
|
@@ -261,7 +275,7 @@ export class InventoryHistoryQuery {
|
|
|
261
275
|
`
|
|
262
276
|
create temp table temp_data_src AS
|
|
263
277
|
(
|
|
264
|
-
SELECT prd.name AS product_name, prd.description AS product_description, prd.type as product_type, prd.aux_value_1 AS product_aux_value_1, trim(invh.batch_id) as batch_id, invh.product_id,
|
|
278
|
+
SELECT prd.sku as sku, prd.name AS product_name, prd.description AS product_description, prd.type as product_type, prd.aux_value_1 AS product_aux_value_1, trim(invh.batch_id) as batch_id, invh.product_id,
|
|
265
279
|
invh.packing_type, invh.bizplace_id, invh.domain_id,
|
|
266
280
|
invh.ref_order_id, invh.order_no, invh.order_ref_no, invh.transaction_type, invh.status, invh.created_at,
|
|
267
281
|
invh.qty, invh.opening_qty,
|
|
@@ -281,7 +295,7 @@ export class InventoryHistoryQuery {
|
|
|
281
295
|
await tx.query(
|
|
282
296
|
`
|
|
283
297
|
create temp table temp_inv_history as (
|
|
284
|
-
SELECT src.product_name, src.product_description, src.product_type, src.product_aux_value_1, src.batch_id, src.product_id, src.packing_type, src.uom,
|
|
298
|
+
SELECT src.sku, src.product_name, src.product_description, src.product_type, src.product_aux_value_1, src.batch_id, src.product_id, src.packing_type, src.uom,
|
|
285
299
|
src.bizplace_id, src.domain_id,
|
|
286
300
|
SUM(COALESCE(src.qty,0)) AS qty,
|
|
287
301
|
SUM(COALESCE(src.opening_qty,0)) AS opening_qty,
|
|
@@ -294,14 +308,14 @@ export class InventoryHistoryQuery {
|
|
|
294
308
|
$1::date AS created_date
|
|
295
309
|
FROM temp_data_src src
|
|
296
310
|
WHERE src.created_at < $1::timestamp
|
|
297
|
-
GROUP BY src.product_name, src.product_description, src.product_type, src.product_aux_value_1, src.batch_id, src.product_id, src.packing_type, src.uom,
|
|
311
|
+
GROUP BY src.sku, src.product_name, src.product_description, src.product_type, src.product_aux_value_1, src.batch_id, src.product_id, src.packing_type, src.uom,
|
|
298
312
|
src.bizplace_id, src.domain_id
|
|
299
313
|
UNION ALL
|
|
300
|
-
SELECT product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
314
|
+
SELECT sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
301
315
|
domain_id, sum(qty) as qty, sum(opening_qty) as opening_qty, sum(uom_value) as uom_value, sum(opening_uom_value) as opening_uom_value,
|
|
302
316
|
order_name, ref_no, 1 AS rn, MIN(created_at) - $2::interval as created_at, (MIN(created_at) - $2::interval)::DATE as created_date
|
|
303
317
|
FROM (
|
|
304
|
-
SELECT invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.bizplace_id,
|
|
318
|
+
SELECT invh.sku, invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.bizplace_id,
|
|
305
319
|
invh.domain_id,
|
|
306
320
|
invh.qty, invh.opening_qty, invh.uom_value, invh.uom, invh.opening_uom_value,
|
|
307
321
|
COALESCE(order_no, '-') AS order_name,
|
|
@@ -314,14 +328,14 @@ export class InventoryHistoryQuery {
|
|
|
314
328
|
invh.transaction_type <>'NEW'
|
|
315
329
|
AND invh.created_at >= $1::timestamp
|
|
316
330
|
) AS inv_movement
|
|
317
|
-
GROUP BY product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
331
|
+
GROUP BY sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
318
332
|
domain_id, order_name, ref_no, rn
|
|
319
333
|
UNION ALL
|
|
320
|
-
SELECT product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
334
|
+
SELECT sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
321
335
|
domain_id, sum(qty) as qty, sum(opening_qty) as opening_qty, sum(uom_value) as uom_value, sum(opening_uom_value) as opening_uom_value,
|
|
322
336
|
order_name, ref_no, 1 AS rn, created_at - $2::interval as created_at, created_at::date as created_date
|
|
323
337
|
FROM (
|
|
324
|
-
SELECT invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.uom, invh.bizplace_id,
|
|
338
|
+
SELECT invh.sku, invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.uom, invh.bizplace_id,
|
|
325
339
|
invh.domain_id,
|
|
326
340
|
invh.qty, invh.opening_qty, invh.uom_value, invh.opening_uom_value,
|
|
327
341
|
invh.transaction_type AS order_name,
|
|
@@ -334,14 +348,14 @@ export class InventoryHistoryQuery {
|
|
|
334
348
|
invh.transaction_type = 'NEW')
|
|
335
349
|
AND invh.created_at >= $1::timestamp
|
|
336
350
|
) AS inv_movement
|
|
337
|
-
GROUP BY product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
351
|
+
GROUP BY sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
338
352
|
domain_id, order_name, ref_no, rn, created_at
|
|
339
353
|
UNION ALL
|
|
340
|
-
SELECT product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
354
|
+
SELECT sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
341
355
|
domain_id, sum(-opening_qty) as qty, sum(opening_qty) as opening_qty, sum(-opening_uom_value) as uom_value, sum(opening_uom_value) as opening_uom_value,
|
|
342
356
|
order_name, ref_no, 1 AS rn, created_at - $2::interval as created_at, created_at::date as created_date
|
|
343
357
|
FROM (
|
|
344
|
-
SELECT invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.uom, invh.bizplace_id,
|
|
358
|
+
SELECT invh.sku, invh.product_name, invh.product_description, invh.product_type, invh.product_aux_value_1, invh.batch_id, invh.product_id, invh.packing_type, invh.uom, invh.bizplace_id,
|
|
345
359
|
invh.domain_id,
|
|
346
360
|
invh.qty, invh.opening_qty, invh.uom_value, invh.opening_uom_value,
|
|
347
361
|
invh.transaction_type AS order_name,
|
|
@@ -354,7 +368,7 @@ export class InventoryHistoryQuery {
|
|
|
354
368
|
invh.status = 'MISSING'
|
|
355
369
|
AND invh.created_at >= $1::timestamp
|
|
356
370
|
) AS inv_movement
|
|
357
|
-
GROUP BY product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
371
|
+
GROUP BY sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
358
372
|
domain_id, order_name, ref_no, rn, created_at
|
|
359
373
|
|
|
360
374
|
)`,
|
|
@@ -363,18 +377,18 @@ export class InventoryHistoryQuery {
|
|
|
363
377
|
|
|
364
378
|
const result: any = await tx.query(
|
|
365
379
|
`
|
|
366
|
-
select product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
380
|
+
select sku, product_name, product_description, product_type, product_aux_value_1, batch_id, product_id, packing_type, uom, bizplace_id,
|
|
367
381
|
domain_id, qty, opening_qty, round(uom_value::decimal,2) as uom_value, opening_uom_value, order_name, ref_no, created_at::date
|
|
368
382
|
from temp_inv_history invh where
|
|
369
383
|
exists (
|
|
370
384
|
select * from (
|
|
371
|
-
select batch_id, product_name, packing_type, sum(qty) as totalQty, count(*) as totalRow from temp_inv_history ih2
|
|
372
|
-
group by batch_id, product_name, packing_type
|
|
385
|
+
select sku, batch_id, product_name, packing_type, sum(qty) as totalQty, count(*) as totalRow from temp_inv_history ih2
|
|
386
|
+
group by sku, batch_id, product_name, packing_type
|
|
373
387
|
) src
|
|
374
|
-
where src.batch_id = invh.batch_id and src.product_name = invh.product_name and src.packing_type = invh.packing_type
|
|
388
|
+
where src.sku = invh.sku and src.batch_id = invh.batch_id and src.product_name = invh.product_name and src.packing_type = invh.packing_type
|
|
375
389
|
${hasTransactionOrBalanceQuery}
|
|
376
390
|
)
|
|
377
|
-
ORDER BY invh.product_name asc, invh.product_description asc, invh.packing_type asc, invh.batch_id asc, invh.uom asc, invh.rn asc, invh.created_at asc
|
|
391
|
+
ORDER BY invh.sku asc, invh.product_name asc, invh.product_description asc, invh.packing_type asc, invh.batch_id asc, invh.uom asc, invh.rn asc, invh.created_at asc
|
|
378
392
|
`
|
|
379
393
|
)
|
|
380
394
|
|
|
@@ -392,6 +406,7 @@ export class InventoryHistoryQuery {
|
|
|
392
406
|
packingType: item.packing_type,
|
|
393
407
|
product: {
|
|
394
408
|
id: item.product_id,
|
|
409
|
+
sku: item.sku,
|
|
395
410
|
name:
|
|
396
411
|
item.product_name +
|
|
397
412
|
' ( ' +
|
|
@@ -420,18 +435,21 @@ export class InventoryHistoryQuery {
|
|
|
420
435
|
|
|
421
436
|
@Directive('@transaction')
|
|
422
437
|
@Query(returns => [InventoryHistory])
|
|
423
|
-
async inventoryHistoryPalletReport(
|
|
438
|
+
async inventoryHistoryPalletReport(
|
|
439
|
+
@Args() params: ListParam,
|
|
440
|
+
@Ctx() context: ResolverContext
|
|
441
|
+
): Promise<InventoryHistory[]> {
|
|
424
442
|
try {
|
|
425
|
-
const { domain, tx }
|
|
443
|
+
const { domain, tx } = context.state
|
|
426
444
|
let userFilter = params.filters.find(data => data.name === 'user')
|
|
427
445
|
|
|
428
|
-
let bizplaceFilter = { name: '', operator: '', value: '' }
|
|
446
|
+
let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
|
|
429
447
|
|
|
430
448
|
if (userFilter) {
|
|
431
|
-
const user
|
|
449
|
+
const user = (await tx.getRepository(User).findOne({
|
|
432
450
|
where: { id: userFilter.value },
|
|
433
451
|
relations: ['bizplaces']
|
|
434
|
-
})) as
|
|
452
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
435
453
|
|
|
436
454
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
437
455
|
|
|
@@ -450,7 +468,7 @@ export class InventoryHistoryQuery {
|
|
|
450
468
|
|
|
451
469
|
let bizplaceQuery = ''
|
|
452
470
|
if (bizplaceFilter) {
|
|
453
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
471
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
|
|
454
472
|
id: bizplaceFilter.value
|
|
455
473
|
})
|
|
456
474
|
|
|
@@ -582,19 +600,19 @@ export class InventoryHistoryQuery {
|
|
|
582
600
|
@Query(returns => [InventoryHistory])
|
|
583
601
|
async inventoryHistoryPalletDetailReport(
|
|
584
602
|
@Args() params: ListParam,
|
|
585
|
-
@Ctx() context:
|
|
603
|
+
@Ctx() context: ResolverContext
|
|
586
604
|
): Promise<InventoryHistory[]> {
|
|
587
605
|
try {
|
|
588
|
-
const { domain, tx }
|
|
606
|
+
const { domain, tx } = context.state
|
|
589
607
|
let userFilter = params.filters.find(data => data.name === 'user')
|
|
590
608
|
|
|
591
|
-
let bizplaceFilter = { name: '', operator: '', value: '' }
|
|
609
|
+
let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
|
|
592
610
|
|
|
593
611
|
if (userFilter) {
|
|
594
|
-
const user
|
|
612
|
+
const user = (await tx.getRepository(User).findOne({
|
|
595
613
|
where: { id: userFilter.value },
|
|
596
614
|
relations: ['bizplaces']
|
|
597
|
-
})) as
|
|
615
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
598
616
|
|
|
599
617
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
600
618
|
|
|
@@ -613,7 +631,7 @@ export class InventoryHistoryQuery {
|
|
|
613
631
|
|
|
614
632
|
let bizplaceQuery = ''
|
|
615
633
|
if (bizplaceFilter) {
|
|
616
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
634
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
|
|
617
635
|
id: bizplaceFilter.value
|
|
618
636
|
})
|
|
619
637
|
|
|
@@ -745,20 +763,20 @@ export class InventoryHistoryQuery {
|
|
|
745
763
|
@Query(returns => InventoryHistoryPalletReportList)
|
|
746
764
|
async inventoryHistoryPalletStorageReport(
|
|
747
765
|
@Args() params: ListParam,
|
|
748
|
-
@Ctx() context:
|
|
766
|
+
@Ctx() context: ResolverContext
|
|
749
767
|
): Promise<InventoryHistoryPalletReportList> {
|
|
750
768
|
try {
|
|
751
|
-
const { domain, tx }
|
|
769
|
+
const { domain, tx } = context.state
|
|
752
770
|
|
|
753
771
|
let userFilter = params.filters.find(data => data.name === 'user')
|
|
754
772
|
|
|
755
|
-
let bizplaceFilter = { name: '', operator: '', value: '' }
|
|
773
|
+
let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
|
|
756
774
|
|
|
757
775
|
if (userFilter) {
|
|
758
|
-
const user
|
|
776
|
+
const user = (await tx.getRepository(User).findOne({
|
|
759
777
|
where: { id: userFilter.value },
|
|
760
778
|
relations: ['bizplaces']
|
|
761
|
-
})) as
|
|
779
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
762
780
|
|
|
763
781
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
764
782
|
|
|
@@ -774,7 +792,7 @@ export class InventoryHistoryQuery {
|
|
|
774
792
|
|
|
775
793
|
if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
|
|
776
794
|
|
|
777
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
795
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
|
|
778
796
|
id: bizplaceFilter.value
|
|
779
797
|
})
|
|
780
798
|
|
|
@@ -890,12 +908,12 @@ export class InventoryHistoryQuery {
|
|
|
890
908
|
@Query(returns => InventoryHistorySummaryList)
|
|
891
909
|
async inventoryHistorySummaryReport(
|
|
892
910
|
@Args() params: ListParam,
|
|
893
|
-
@Ctx() context:
|
|
911
|
+
@Ctx() context: ResolverContext
|
|
894
912
|
): Promise<InventoryHistorySummaryList> {
|
|
895
913
|
try {
|
|
896
|
-
const { tx }
|
|
914
|
+
const { tx } = context.state
|
|
897
915
|
|
|
898
|
-
let bizplaceFilter = { name: '', operator: '', value: '' }
|
|
916
|
+
let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
|
|
899
917
|
|
|
900
918
|
let userFilter = params.filters.find(data => data.name === 'user')
|
|
901
919
|
let fromDate = params.filters.find(data => data.name === 'fromDate')
|
|
@@ -903,10 +921,10 @@ export class InventoryHistoryQuery {
|
|
|
903
921
|
let byPallet = params.filters.find(data => data.name === 'byPallet')
|
|
904
922
|
|
|
905
923
|
if (userFilter) {
|
|
906
|
-
const user
|
|
924
|
+
const user = (await tx.getRepository(User).findOne({
|
|
907
925
|
where: { id: userFilter.value },
|
|
908
926
|
relations: ['bizplaces']
|
|
909
|
-
})) as
|
|
927
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
910
928
|
|
|
911
929
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
912
930
|
|
|
@@ -919,7 +937,7 @@ export class InventoryHistoryQuery {
|
|
|
919
937
|
|
|
920
938
|
if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
|
|
921
939
|
|
|
922
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
940
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
|
|
923
941
|
id: bizplaceFilter.value
|
|
924
942
|
})
|
|
925
943
|
|
|
@@ -963,14 +981,14 @@ export class InventoryHistoryQuery {
|
|
|
963
981
|
@Directive('@transaction')
|
|
964
982
|
@Query(returns => InventoryList)
|
|
965
983
|
async onhandInventories(
|
|
966
|
-
@Ctx() context:
|
|
984
|
+
@Ctx() context: ResolverContext,
|
|
967
985
|
@Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[],
|
|
968
986
|
@Arg('pagination', type => Pagination, { nullable: true }) pagination?: Pagination,
|
|
969
987
|
@Arg('sortings', type => [Sorting], { nullable: true }) sortings?: Sorting[],
|
|
970
988
|
@Arg('locationSortingRules', type => [Sorting], { nullable: true }) locationSortingRules?: Sorting[],
|
|
971
989
|
@Arg('setPagination', type => Boolean, { defaultValue: true }) setPagination?: Boolean
|
|
972
990
|
): Promise<InventoryList> {
|
|
973
|
-
const { domain, user, tx }
|
|
991
|
+
const { domain, user, tx } = context.state
|
|
974
992
|
|
|
975
993
|
// define all inputs
|
|
976
994
|
let userFilter = filters.find(data => data.name === 'user')
|
|
@@ -992,10 +1010,10 @@ export class InventoryHistoryQuery {
|
|
|
992
1010
|
|
|
993
1011
|
// prepare query filters
|
|
994
1012
|
if (userFilter) {
|
|
995
|
-
const user
|
|
1013
|
+
const user = (await tx.getRepository(User).findOne({
|
|
996
1014
|
where: { id: userFilter.value },
|
|
997
1015
|
relations: ['bizplaces']
|
|
998
|
-
})) as
|
|
1016
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
999
1017
|
|
|
1000
1018
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
1001
1019
|
|
|
@@ -1004,12 +1022,12 @@ export class InventoryHistoryQuery {
|
|
|
1004
1022
|
bizplaceFilter = { name: 'bizplace', operator: 'eq', value: [bizplace.id] }
|
|
1005
1023
|
} else {
|
|
1006
1024
|
bizplaceFilter = !filters.find((filter: any) => filter.name === 'bizplace')
|
|
1007
|
-
? {
|
|
1025
|
+
? ({
|
|
1008
1026
|
name: 'bizplace',
|
|
1009
1027
|
operator: 'in',
|
|
1010
1028
|
value: await getPermittedBizplaceIds(domain, user),
|
|
1011
1029
|
relation: true
|
|
1012
|
-
}
|
|
1030
|
+
} as any)
|
|
1013
1031
|
: {
|
|
1014
1032
|
...filters.find(data => data.name === 'bizplace'),
|
|
1015
1033
|
value: [filters.find(data => data.name === 'bizplace').value]
|
|
@@ -1118,21 +1136,31 @@ export class InventoryHistoryQuery {
|
|
|
1118
1136
|
[domain.id, createdAt.value, timezoneOffset]
|
|
1119
1137
|
)
|
|
1120
1138
|
|
|
1121
|
-
|
|
1122
|
-
|
|
1139
|
+
await tx.query(
|
|
1140
|
+
`
|
|
1141
|
+
CREATE TEMP TABLE tmp_src_group on commit drop AS (
|
|
1142
|
+
select ih.domain_id, ih.pallet_id, sum(ih.qty) as qty, sum(ih.uom_value) as uom_value, max(ih.seq) as last_seq, max(ih.created_at) as created_at,
|
|
1143
|
+
min(ih.created_at) as initial_inbound_at
|
|
1144
|
+
from tmp_src ih
|
|
1145
|
+
group by ih.domain_id, ih.pallet_id
|
|
1146
|
+
);
|
|
1147
|
+
`
|
|
1148
|
+
)
|
|
1149
|
+
|
|
1123
1150
|
await tx.query(
|
|
1124
1151
|
`
|
|
1125
1152
|
create temp table tmp_data on commit drop as (
|
|
1126
1153
|
select dt.*, rih.carton_id, rih.batch_id, rih.batch_id_ref, rih.product_id, rih.packing_type, rih.bizplace_id, rih.location_id, rih.unit_cost,iv.id as inventory_id, iv.uom,
|
|
1127
|
-
iv.expiration_date, iv.manufacture_date, iv.reusable_pallet_id, iv.remark
|
|
1154
|
+
iv.expiration_date, iv.manufacture_date, iv.reusable_pallet_id, iv.remark
|
|
1128
1155
|
from
|
|
1129
1156
|
(
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1157
|
+
SELECT ih.*, ih2.status FROM tmp_src_group ih
|
|
1158
|
+
INNER JOIN inventory_histories ih2
|
|
1159
|
+
ON ih.domain_id = ih2.domain_id
|
|
1160
|
+
AND ih.pallet_id = ih2.pallet_id
|
|
1161
|
+
AND ih.last_seq = ih2.seq
|
|
1134
1162
|
) dt
|
|
1135
|
-
inner join tmp_src rih on dt.domain_id = rih.domain_id and dt.pallet_id = rih.pallet_id and dt.last_seq = rih.seq
|
|
1163
|
+
inner join tmp_src rih on dt.domain_id = rih.domain_id and dt.pallet_id = rih.pallet_id and dt.last_seq = rih.seq and rih.status <> 'TERMINATED'
|
|
1136
1164
|
inner join inventories iv on iv.domain_id = dt.domain_id and iv.pallet_id = dt.pallet_id and iv.status <> 'MISSING'
|
|
1137
1165
|
where exists (
|
|
1138
1166
|
SELECT * FROM tmp_bizfilter bizFilter
|
|
@@ -1144,44 +1172,13 @@ export class InventoryHistoryQuery {
|
|
|
1144
1172
|
`
|
|
1145
1173
|
)
|
|
1146
1174
|
|
|
1147
|
-
await tx.query(
|
|
1148
|
-
`
|
|
1149
|
-
create temp table tmp_result on commit drop as (
|
|
1150
|
-
select
|
|
1151
|
-
rih.domain_id, rih.pallet_id as "palletId", rih.carton_id as "cartonId", rih.qty as "remainQty", rih.uom_value as "uomValue", rih.uom, rih.last_seq, rih.created_at,
|
|
1152
|
-
rih.initial_inbound_at as "initialInboundAt", rih.unit_cost as "unitCost",
|
|
1153
|
-
case when rih.reusable_pallet_id is not null then concat(rih.batch_id, ' (', plt.name, ')') else rih.batch_id end as "batchId",
|
|
1154
|
-
rih.batch_id_ref as "batchIdRef", rih.product_id as "productId", rih.packing_type as "packingType",
|
|
1155
|
-
prd.id as product_id, prd.name as product_name, prd.sku as product_sku, prd.brand as product_brand, prd.description as product_description, prd.volume as product_volume,
|
|
1156
|
-
bz.id as bizplace_id, bz.name as bizplace_name,
|
|
1157
|
-
loc.id as location_id, loc.name as location_name, loc."zone" as location_zone, loc."row" as location_row, loc."column" as location_column, loc.shelf as location_shelf,
|
|
1158
|
-
wh.name as warehouse_name, plt.name as reusable_pallet_name,
|
|
1159
|
-
rih.remark,
|
|
1160
|
-
rih.manufacture_date as "manufactureDate",
|
|
1161
|
-
rih.expiration_date as "expirationDate"
|
|
1162
|
-
,sum(case when oi.status = 'LOADING' or (oi.status = 'SORTING' and oi.type = 'RELEASE_OF_GOODS') then oi.release_qty else 0 end) as "nonLoadedQty"
|
|
1163
|
-
,sum(case when oi.status = 'LOADING' or (oi.status = 'SORTING' and oi.type = 'RELEASE_OF_GOODS') then (oi.release_uom_value / oi.release_qty* oi.release_qty) else 0 end) as "nonLoadedUomValue"
|
|
1164
|
-
from tmp_data rih
|
|
1165
|
-
left join pallets plt on plt.id = rih.reusable_pallet_id
|
|
1166
|
-
inner join products prd on prd.id = rih.product_id
|
|
1167
|
-
inner join bizplaces bz on bz.id = rih.bizplace_id
|
|
1168
|
-
inner join locations loc on loc.id = rih.location_id
|
|
1169
|
-
inner join warehouses wh on wh.id = loc.warehouse_id
|
|
1170
|
-
left join order_inventories oi on oi.inventory_id = rih.inventory_id
|
|
1171
|
-
group by rih.inventory_id,rih.domain_id,rih.pallet_id,rih.carton_id,rih.qty,rih.uom_value,rih.uom,rih.last_seq,rih.created_at, rih.initial_inbound_at,rih.unit_cost,rih.reusable_pallet_id,
|
|
1172
|
-
rih.batch_id,plt.name,rih.batch_id_ref,rih.product_id,rih.packing_type,rih.bizplace_id,rih.location_id,prd.id,bz.id,loc.id,wh.name,rih.remark,rih.expiration_date,rih.manufacture_date,rih.status
|
|
1173
|
-
having 1=1 and (case when rih.status = 'TERMINATED' and SUM(CASE WHEN oi.status = 'LOADING' or (oi.status = 'SORTING' AND oi.type = 'RELEASE_OF_GOODS') THEN oi.release_qty ELSE 0 END) > 0 then rih.status = 'TERMINATED' else rih.status <> 'TERMINATED' end)
|
|
1174
|
-
order by created_at desc
|
|
1175
|
-
);
|
|
1176
|
-
`
|
|
1177
|
-
)
|
|
1178
|
-
|
|
1179
|
-
const total: any = await tx.query(`select count(*) from tmp_result`)
|
|
1175
|
+
const total: any = await tx.query(`select count(*) from tmp_data`)
|
|
1180
1176
|
|
|
1181
1177
|
const result: any = await tx.query(
|
|
1182
1178
|
`
|
|
1183
1179
|
select
|
|
1184
|
-
rih.domain_id, rih.pallet_id as "palletId", rih.carton_id as "cartonId", rih.qty as "remainQty",
|
|
1180
|
+
rih.domain_id, rih.pallet_id as "palletId", rih.carton_id as "cartonId", rih.qty as "remainQty",
|
|
1181
|
+
TRUNC(rih.uom_value::numeric,2) as "uomValue", rih.uom, rih.last_seq, rih.created_at,
|
|
1185
1182
|
rih.initial_inbound_at as "initialInboundAt", rih.unit_cost as "unitCost",
|
|
1186
1183
|
case when rih.reusable_pallet_id is not null then concat(rih.batch_id, ' (', plt.name, ')') else rih.batch_id end as "batchId",
|
|
1187
1184
|
rih.batch_id_ref as "batchIdRef", rih.product_id, rih.packing_type as "packingType", rih.bizplace_id, rih.location_id,
|
|
@@ -1191,24 +1188,36 @@ export class InventoryHistoryQuery {
|
|
|
1191
1188
|
wh.name as warehouse_name, plt.name as reusable_pallet_name,
|
|
1192
1189
|
rih.remark,
|
|
1193
1190
|
rih.manufacture_date as "manufactureDate",
|
|
1194
|
-
rih.expiration_date as "expirationDate"
|
|
1195
|
-
|
|
1196
|
-
|
|
1191
|
+
rih.expiration_date as "expirationDate",
|
|
1192
|
+
coalesce((
|
|
1193
|
+
select sum(oi1.release_qty) as nonLoadedQty from order_inventories oi1
|
|
1194
|
+
inner join release_goods rg1 on rg1.id = oi1.release_good_id
|
|
1195
|
+
where rg1.status in ('PICKING', 'LOADING')
|
|
1196
|
+
and oi1.inventory_id = rih.inventory_id
|
|
1197
|
+
and oi1.status in ('PICKED', 'LOADING')
|
|
1198
|
+
and rg1.domain_id = '${domain.id}'
|
|
1199
|
+
group by oi1.inventory_id
|
|
1200
|
+
),0) as "nonLoadedQty",
|
|
1201
|
+
TRUNC(coalesce((
|
|
1202
|
+
select sum(oi1.release_uom_value) as nonLoadedUomValue from order_inventories oi1
|
|
1203
|
+
inner join release_goods rg1 on rg1.id = oi1.release_good_id
|
|
1204
|
+
where rg1.status in ('PICKING', 'LOADING')
|
|
1205
|
+
and oi1.inventory_id = rih.inventory_id
|
|
1206
|
+
and oi1.status in ('PICKED', 'LOADING')
|
|
1207
|
+
and rg1.domain_id = '${domain.id}'
|
|
1208
|
+
group by oi1.inventory_id
|
|
1209
|
+
),0)::numeric,2) as "nonLoadedUomValue"
|
|
1197
1210
|
from tmp_data rih
|
|
1198
1211
|
left join pallets plt on plt.id = rih.reusable_pallet_id
|
|
1199
1212
|
inner join products prd on prd.id = rih.product_id
|
|
1200
1213
|
inner join bizplaces bz on bz.id = rih.bizplace_id
|
|
1201
1214
|
inner join locations loc on loc.id = rih.location_id
|
|
1202
1215
|
inner join warehouses wh on wh.id = loc.warehouse_id
|
|
1203
|
-
|
|
1204
|
-
group by rih.inventory_id,rih.domain_id,rih.pallet_id,rih.carton_id,rih.qty,rih.uom_value,rih.uom,rih.last_seq,rih.created_at, rih.initial_inbound_at,rih.unit_cost,rih.reusable_pallet_id,
|
|
1205
|
-
rih.batch_id,plt.name,rih.batch_id_ref,rih.product_id,rih.packing_type,rih.bizplace_id,rih.location_id,prd.id,bz.id,loc.id,wh.name,rih.remark,rih.expiration_date,rih.manufacture_date,rih.status
|
|
1206
|
-
having 1=1 and (case when rih.status = 'TERMINATED' and SUM(CASE WHEN oi.status = 'LOADING' or (oi.status = 'SORTING' AND oi.type = 'RELEASE_OF_GOODS') THEN oi.release_qty ELSE 0 END) > 0 then rih.status = 'TERMINATED' else rih.status <> 'TERMINATED' end)
|
|
1216
|
+
WHERE 1 = 1
|
|
1207
1217
|
${queryOrder}
|
|
1208
1218
|
${setPagination ? 'OFFSET ' + (pagination.page - 1) * pagination.limit + ' LIMIT ' + pagination.limit : ''}
|
|
1209
1219
|
`
|
|
1210
1220
|
)
|
|
1211
|
-
//comment end
|
|
1212
1221
|
|
|
1213
1222
|
// map all results
|
|
1214
1223
|
let items = result.map(itm => {
|
|
@@ -1241,14 +1250,14 @@ export class InventoryHistoryQuery {
|
|
|
1241
1250
|
@Directive('@transaction')
|
|
1242
1251
|
@Query(returns => RawInventoryHistoryList)
|
|
1243
1252
|
async bizplaceInventoryHistoriesForExport(
|
|
1244
|
-
@Ctx() context:
|
|
1253
|
+
@Ctx() context: ResolverContext,
|
|
1245
1254
|
@Arg('inventoryHistory', type => InventoryHistoryPatch, { nullable: true })
|
|
1246
1255
|
inventoryHistory?: InventoryHistoryPatch,
|
|
1247
1256
|
@Arg('filters', type => [Filter], { nullable: true }) filters?: Filter[]
|
|
1248
1257
|
): Promise<RawInventoryHistoryList> {
|
|
1249
|
-
const { domain, tx }
|
|
1258
|
+
const { domain, tx } = context.state
|
|
1250
1259
|
|
|
1251
|
-
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
1260
|
+
const customerBizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({ id: inventoryHistory.bizplace.id })
|
|
1252
1261
|
|
|
1253
1262
|
const productFilters = filters.find(x => x.name == 'product_info')
|
|
1254
1263
|
filters = filters.filter(x => x.name != 'product_info')
|
|
@@ -1279,7 +1288,7 @@ export class InventoryHistoryQuery {
|
|
|
1279
1288
|
}
|
|
1280
1289
|
|
|
1281
1290
|
if (inventoryHistory && inventoryHistory.warehouseName) {
|
|
1282
|
-
const _warehouses: Warehouse[] = await tx.getRepository(Warehouse).
|
|
1291
|
+
const _warehouses: Warehouse[] = await tx.getRepository(Warehouse).findBy({
|
|
1283
1292
|
domain: domain,
|
|
1284
1293
|
name: Raw(alias => `LOWER(${alias}) LIKE '${inventoryHistory.warehouseName.toLowerCase()}'`)
|
|
1285
1294
|
})
|
|
@@ -1364,22 +1373,22 @@ export class InventoryHistoryQuery {
|
|
|
1364
1373
|
@Query(returns => InventoryHistoryVolumeSummaryReportList)
|
|
1365
1374
|
async inventoryHistoryVolumeSummaryReport(
|
|
1366
1375
|
@Args() params: ListParam,
|
|
1367
|
-
@Ctx() context:
|
|
1376
|
+
@Ctx() context: ResolverContext
|
|
1368
1377
|
): Promise<InventoryHistoryVolumeSummaryReportList> {
|
|
1369
1378
|
try {
|
|
1370
|
-
const { domain, user, tx }
|
|
1379
|
+
const { domain, user, tx } = context.state
|
|
1371
1380
|
|
|
1372
|
-
let bizplaceFilter = { name: '', operator: '', value: '' }
|
|
1381
|
+
let bizplaceFilter: Filter = { name: '', operator: '', value: '' }
|
|
1373
1382
|
|
|
1374
1383
|
let userFilter = params.filters.find(data => data.name === 'user')
|
|
1375
1384
|
let fromDate = params.filters.find(data => data.name === 'fromDate')
|
|
1376
1385
|
let toDate = params.filters.find(data => data.name === 'toDate')
|
|
1377
1386
|
|
|
1378
1387
|
if (userFilter) {
|
|
1379
|
-
const user
|
|
1388
|
+
const user = (await tx.getRepository(User).findOne({
|
|
1380
1389
|
where: { id: userFilter.value },
|
|
1381
1390
|
relations: ['bizplaces']
|
|
1382
|
-
})) as
|
|
1391
|
+
})) as User & { bizplaces: Bizplace[] }
|
|
1383
1392
|
|
|
1384
1393
|
const bizplace: Bizplace = user.bizplaces[0]
|
|
1385
1394
|
|
|
@@ -1392,7 +1401,7 @@ export class InventoryHistoryQuery {
|
|
|
1392
1401
|
|
|
1393
1402
|
if (!bizplaceFilter || !fromDate || !toDate) throw 'Invalid input'
|
|
1394
1403
|
|
|
1395
|
-
const bizplace: Bizplace = await tx.getRepository(Bizplace).
|
|
1404
|
+
const bizplace: Bizplace = await tx.getRepository(Bizplace).findOneBy({
|
|
1396
1405
|
id: bizplaceFilter.value
|
|
1397
1406
|
})
|
|
1398
1407
|
|
|
@@ -1400,7 +1409,8 @@ export class InventoryHistoryQuery {
|
|
|
1400
1409
|
let foundPermittedBizplace: Bizplace
|
|
1401
1410
|
|
|
1402
1411
|
if (bizplace) {
|
|
1403
|
-
foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(
|
|
1412
|
+
foundPermittedBizplace = await tx.getRepository(Bizplace).findOne({
|
|
1413
|
+
where: { id: bizplace.id },
|
|
1404
1414
|
relations: ['company', 'company.domain']
|
|
1405
1415
|
})
|
|
1406
1416
|
|
|
@@ -1529,21 +1539,26 @@ export class InventoryHistoryQuery {
|
|
|
1529
1539
|
|
|
1530
1540
|
@FieldResolver(type => Domain)
|
|
1531
1541
|
async domain(@Root() inventoryHistory: InventoryHistory) {
|
|
1532
|
-
return await getRepository(Domain).
|
|
1542
|
+
return await getRepository(Domain).findOneBy({ id: inventoryHistory.domainId })
|
|
1533
1543
|
}
|
|
1534
1544
|
|
|
1535
1545
|
@FieldResolver(type => User)
|
|
1536
1546
|
async updater(@Root() inventoryHistory: InventoryHistory) {
|
|
1537
|
-
return await getRepository(User).
|
|
1547
|
+
return await getRepository(User).findOneBy({ id: inventoryHistory.updaterId })
|
|
1538
1548
|
}
|
|
1539
1549
|
|
|
1540
1550
|
@FieldResolver(type => User)
|
|
1541
1551
|
async creator(@Root() inventoryHistory: InventoryHistory) {
|
|
1542
|
-
return await getRepository(User).
|
|
1552
|
+
return await getRepository(User).findOneBy({ id: inventoryHistory.creatorId })
|
|
1543
1553
|
}
|
|
1544
1554
|
}
|
|
1545
1555
|
|
|
1546
|
-
async function massageInventorySummary(
|
|
1556
|
+
async function massageInventorySummary(
|
|
1557
|
+
tx: EntityManager,
|
|
1558
|
+
params: ListParam,
|
|
1559
|
+
bizplace: Bizplace,
|
|
1560
|
+
context: ResolverContext
|
|
1561
|
+
) {
|
|
1547
1562
|
await productsQuery(tx, params, bizplace)
|
|
1548
1563
|
await filterInventoryQuery(tx, params, bizplace, context)
|
|
1549
1564
|
|
|
@@ -1590,7 +1605,12 @@ async function massageInventorySummary(tx: EntityManager, params: ListParam, biz
|
|
|
1590
1605
|
return [result, total]
|
|
1591
1606
|
}
|
|
1592
1607
|
|
|
1593
|
-
async function massageInventoryPalletSummary(
|
|
1608
|
+
async function massageInventoryPalletSummary(
|
|
1609
|
+
tx: EntityManager,
|
|
1610
|
+
params: ListParam,
|
|
1611
|
+
bizplace: Bizplace,
|
|
1612
|
+
context: ResolverContext
|
|
1613
|
+
) {
|
|
1594
1614
|
await productsQuery(tx, params, bizplace)
|
|
1595
1615
|
await filterInventoryQuery(tx, params, bizplace, context)
|
|
1596
1616
|
|
|
@@ -1751,7 +1771,12 @@ async function productsQuery(tx: EntityManager, params: ListParam, bizplace: Biz
|
|
|
1751
1771
|
)
|
|
1752
1772
|
}
|
|
1753
1773
|
|
|
1754
|
-
async function filterInventoryQuery(
|
|
1774
|
+
async function filterInventoryQuery(
|
|
1775
|
+
tx: EntityManager,
|
|
1776
|
+
params: ListParam,
|
|
1777
|
+
bizplace: Bizplace,
|
|
1778
|
+
context: ResolverContext
|
|
1779
|
+
) {
|
|
1755
1780
|
let toDate = params.filters.find(data => data.name === 'toDate')
|
|
1756
1781
|
let batchNo = params.filters.find(data => data.name === 'batchNo')
|
|
1757
1782
|
|
|
@@ -1777,8 +1802,8 @@ async function filterInventoryQuery(tx: EntityManager, params: ListParam, bizpla
|
|
|
1777
1802
|
from inventories i2
|
|
1778
1803
|
inner join reduced_inventory_histories ih on ih.pallet_id = i2.pallet_id and ih.domain_id = i2.domain_id
|
|
1779
1804
|
where
|
|
1780
|
-
|
|
1781
|
-
and
|
|
1805
|
+
ih.domain_id = $1
|
|
1806
|
+
and ih.bizplace_id = $2
|
|
1782
1807
|
and ih.created_at <= $3
|
|
1783
1808
|
${batchNoQuery}
|
|
1784
1809
|
)
|