@things-factory/warehouse-base 3.7.1 → 3.7.6
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/graphql/resolvers/inventory/inventories-by-bundle.js +9 -5
- package/dist-server/graphql/resolvers/inventory/inventories-by-bundle.js.map +1 -1
- package/dist-server/graphql/resolvers/inventory/inventories-by-strategy.js +19 -4
- package/dist-server/graphql/resolvers/inventory/inventories-by-strategy.js.map +1 -1
- package/dist-server/graphql/resolvers/inventory/inventories.js +14 -6
- package/dist-server/graphql/resolvers/inventory/inventories.js.map +1 -1
- package/dist-server/graphql/resolvers/inventory-history/index.js +2 -1
- package/dist-server/graphql/resolvers/inventory-history/index.js.map +1 -1
- package/dist-server/graphql/resolvers/inventory-history/onhand-inventories.js +188 -186
- package/dist-server/graphql/resolvers/inventory-history/onhand-inventories.js.map +1 -1
- package/dist-server/graphql/types/inventory/index.js +1 -1
- package/dist-server/graphql/types/inventory/inventory-bundle-group.js +1 -0
- package/dist-server/graphql/types/inventory/inventory-bundle-group.js.map +1 -1
- package/dist-server/index.js +3 -1
- package/dist-server/index.js.map +1 -1
- package/package.json +8 -8
- package/server/graphql/resolvers/inventory/inventories-by-bundle.ts +9 -4
- package/server/graphql/resolvers/inventory/inventories-by-strategy.ts +44 -5
- package/server/graphql/resolvers/inventory/inventories.ts +29 -16
- package/server/graphql/resolvers/inventory-history/index.ts +4 -1
- package/server/graphql/resolvers/inventory-history/onhand-inventories.ts +223 -216
- package/server/graphql/types/inventory/index.ts +1 -1
- package/server/graphql/types/inventory/inventory-bundle-group.ts +1 -0
- package/server/index.ts +1 -0
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityManager } from 'typeorm'
|
|
2
|
+
|
|
2
3
|
import { Setting } from '@things-factory/setting-base'
|
|
3
4
|
import { Domain } from '@things-factory/shell'
|
|
5
|
+
|
|
4
6
|
import { Inventory } from '../../../entities'
|
|
5
7
|
|
|
6
8
|
export const inventoriesByStrategyResolver = {
|
|
7
9
|
async inventoriesByStrategy(
|
|
8
10
|
_: any,
|
|
9
|
-
{
|
|
11
|
+
{
|
|
12
|
+
worksheetId,
|
|
13
|
+
batchId,
|
|
14
|
+
bizplaceId,
|
|
15
|
+
productName,
|
|
16
|
+
productSku,
|
|
17
|
+
packingType,
|
|
18
|
+
packingSize,
|
|
19
|
+
uom,
|
|
20
|
+
pickingStrategy,
|
|
21
|
+
locationSortingRules
|
|
22
|
+
},
|
|
10
23
|
context: any
|
|
11
24
|
) {
|
|
12
25
|
const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
|
|
@@ -24,7 +37,18 @@ export const inventoriesByStrategyResolver = {
|
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
return inventoriesByStrategy(
|
|
27
|
-
{
|
|
40
|
+
{
|
|
41
|
+
worksheetId,
|
|
42
|
+
batchId,
|
|
43
|
+
bizplaceId,
|
|
44
|
+
productName,
|
|
45
|
+
productSku,
|
|
46
|
+
packingType,
|
|
47
|
+
packingSize,
|
|
48
|
+
uom,
|
|
49
|
+
pickingStrategy,
|
|
50
|
+
locationSortingRules
|
|
51
|
+
},
|
|
28
52
|
domain,
|
|
29
53
|
tx
|
|
30
54
|
)
|
|
@@ -32,7 +56,18 @@ export const inventoriesByStrategyResolver = {
|
|
|
32
56
|
}
|
|
33
57
|
|
|
34
58
|
export async function inventoriesByStrategy(
|
|
35
|
-
{
|
|
59
|
+
{
|
|
60
|
+
worksheetId,
|
|
61
|
+
batchId,
|
|
62
|
+
bizplaceId,
|
|
63
|
+
productName,
|
|
64
|
+
productSku,
|
|
65
|
+
packingType,
|
|
66
|
+
packingSize,
|
|
67
|
+
uom,
|
|
68
|
+
pickingStrategy,
|
|
69
|
+
locationSortingRules
|
|
70
|
+
},
|
|
36
71
|
domain: Domain,
|
|
37
72
|
trxMgr: EntityManager
|
|
38
73
|
) {
|
|
@@ -59,12 +94,16 @@ export async function inventoriesByStrategy(
|
|
|
59
94
|
.andWhere('"PROD"."name" = :productName')
|
|
60
95
|
.andWhere('"PROD"."sku" = :productSku')
|
|
61
96
|
.andWhere('"INV"."packing_type" = :packingType')
|
|
97
|
+
.andWhere('"INV"."packing_size" = :packingSize')
|
|
98
|
+
.andWhere('"INV"."uom" = :uom')
|
|
62
99
|
.andWhere('"INV"."status" = :status', { status: 'STORED' })
|
|
63
100
|
.setParameters({
|
|
64
101
|
domainId: domain.id,
|
|
65
102
|
productName,
|
|
66
103
|
productSku,
|
|
67
|
-
packingType
|
|
104
|
+
packingType,
|
|
105
|
+
packingSize,
|
|
106
|
+
uom
|
|
68
107
|
})
|
|
69
108
|
|
|
70
109
|
if (batchId !== '') {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { Brackets, getRepository, SelectQueryBuilder } from 'typeorm'
|
|
2
|
+
|
|
1
3
|
import { User } from '@things-factory/auth-base'
|
|
2
4
|
import { getPermittedBizplaceIds } from '@things-factory/biz-base'
|
|
3
|
-
import { Product } from '@things-factory/product-base'
|
|
5
|
+
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
4
6
|
import { buildQuery, Domain } from '@things-factory/shell'
|
|
5
|
-
|
|
7
|
+
|
|
6
8
|
import { Inventory, InventoryChange } from '../../../entities'
|
|
7
9
|
|
|
8
10
|
export const inventoriesResolver = {
|
|
@@ -12,7 +14,7 @@ export const inventoriesResolver = {
|
|
|
12
14
|
const productFilters = filters.find(x => x.name == 'product_info')
|
|
13
15
|
filters = filters.filter(x => x.name != 'product_info')
|
|
14
16
|
const params = { filters, pagination }
|
|
15
|
-
|
|
17
|
+
|
|
16
18
|
if (!params.filters.find((filter: any) => filter.name === 'bizplace')) {
|
|
17
19
|
params.filters.push({
|
|
18
20
|
name: 'bizplace',
|
|
@@ -67,20 +69,23 @@ export const inventoriesResolver = {
|
|
|
67
69
|
qb.andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END = 0')
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
if(productFilters){
|
|
72
|
+
if (productFilters) {
|
|
71
73
|
let productFilterValue = `%${productFilters.value.toLowerCase()}%`
|
|
72
|
-
qb.andWhere(
|
|
73
|
-
const subQuery = qb
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
qb.andWhere(qb => {
|
|
75
|
+
const subQuery = qb
|
|
76
|
+
.subQuery()
|
|
77
|
+
.select()
|
|
78
|
+
.from(Product, `products`)
|
|
79
|
+
.where(`products.id = iv.product_id`)
|
|
80
|
+
.andWhere(
|
|
81
|
+
new Brackets(qb => {
|
|
82
|
+
qb.where('Lower(products.sku) LIKE :productInfo', { productInfo: productFilterValue })
|
|
83
|
+
.orWhere('Lower(products.name) LIKE :productInfo', { productInfo: productFilterValue })
|
|
84
|
+
.orWhere('Lower(products.description) LIKE :productInfo', { productInfo: productFilterValue })
|
|
85
|
+
})
|
|
86
|
+
)
|
|
87
|
+
.getQuery()
|
|
88
|
+
return `EXISTS ${subQuery}`
|
|
84
89
|
})
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -115,6 +120,14 @@ export const inventoriesResolver = {
|
|
|
115
120
|
const selectedQty = item.lockedQty ? item.lockedQty : 0
|
|
116
121
|
const selectedUomValue = item.lockedUomValue ? item.lockedUomValue : 0
|
|
117
122
|
|
|
123
|
+
item.product['productDetails'] = await getRepository(ProductDetail).find({
|
|
124
|
+
where: {
|
|
125
|
+
product: item.product.id,
|
|
126
|
+
packingType: item.packingType,
|
|
127
|
+
packingSize: item.packingSize
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
118
131
|
return {
|
|
119
132
|
...item,
|
|
120
133
|
changeCount: inventoryChangeCount,
|
|
@@ -11,7 +11,7 @@ import { inventoryHistoryPalletReport } from './inventory-history-pallet-report'
|
|
|
11
11
|
import { inventoryHistoryPalletDetailReport } from './inventory-history-pallet-detail-report'
|
|
12
12
|
import { inventoryHistoryPalletStorageReport } from './inventory-history-pallet-storage-report'
|
|
13
13
|
import { inventoryHistorySummaryReport } from './inventory-history-summary-report'
|
|
14
|
-
import { onhandInventoriesResolver } from './onhand-inventories'
|
|
14
|
+
import { onhandInventoriesResolver, onhandInventories } from './onhand-inventories'
|
|
15
15
|
|
|
16
16
|
export const Query = {
|
|
17
17
|
...inventoryHistoriesResolver,
|
|
@@ -32,3 +32,6 @@ export const Mutation = {
|
|
|
32
32
|
...deleteInventoryHistory,
|
|
33
33
|
...deleteInventoryHistories
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export { onhandInventories }
|
|
@@ -6,232 +6,239 @@ import { Domain } from '@things-factory/shell'
|
|
|
6
6
|
|
|
7
7
|
export const onhandInventoriesResolver = {
|
|
8
8
|
async onhandInventories(_: any, { filters, pagination, sortings, locationSortingRules }, context: any) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
let userFilter = filters.find(data => data.name === 'user')
|
|
13
|
-
let product = filters.find(data => data.name === 'product')
|
|
14
|
-
let createdAt = filters.find(data => data.name === 'created_at')
|
|
15
|
-
let location = filters.find(data => data.name === 'location')
|
|
16
|
-
let batchId = filters.find(data => data.name === 'batchId')
|
|
17
|
-
let palletId = filters.find(data => data.name === 'palletId')
|
|
18
|
-
let cartonId = filters.find(data => data.name === 'cartonId')
|
|
19
|
-
let packingType = filters.find(data => data.name === 'packingType')
|
|
20
|
-
let timezoneOffset = filters.find(data => data.name === 'timezoneOffset').value + ' minutes'
|
|
21
|
-
|
|
22
|
-
// expiration date filter
|
|
23
|
-
let expiration = filters.find(data => data.name === 'expiration').value
|
|
24
|
-
let expFromDate = filters.find(data => data.name === 'expFromDate')
|
|
25
|
-
let expToDate = filters.find(data => data.name === 'expToDate')
|
|
26
|
-
|
|
27
|
-
let bizplaceFilter = { name: '', operator: '', value: [] }
|
|
28
|
-
|
|
29
|
-
// prepare query filters
|
|
30
|
-
if (userFilter) {
|
|
31
|
-
const user: User = await tx.getRepository(User).findOne({
|
|
32
|
-
where: { id: userFilter.value },
|
|
33
|
-
relations: ['bizplaces']
|
|
34
|
-
})
|
|
9
|
+
return await onhandInventories(filters, pagination, sortings, locationSortingRules, context)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
35
12
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
13
|
+
export async function onhandInventories(
|
|
14
|
+
filters,
|
|
15
|
+
pagination,
|
|
16
|
+
sortings,
|
|
17
|
+
locationSortingRules,
|
|
18
|
+
context,
|
|
19
|
+
setPagination = true
|
|
20
|
+
) {
|
|
21
|
+
const { domain, user, tx }: { domain: Domain; user: User; tx: EntityManager } = context.state
|
|
22
|
+
|
|
23
|
+
// define all inputs
|
|
24
|
+
let userFilter = filters.find(data => data.name === 'user')
|
|
25
|
+
let product = filters.find(data => data.name === 'product')
|
|
26
|
+
let createdAt = filters.find(data => data.name === 'created_at')
|
|
27
|
+
let location = filters.find(data => data.name === 'location')
|
|
28
|
+
let batchId = filters.find(data => data.name === 'batchId')
|
|
29
|
+
let palletId = filters.find(data => data.name === 'palletId')
|
|
30
|
+
let cartonId = filters.find(data => data.name === 'cartonId')
|
|
31
|
+
let packingType = filters.find(data => data.name === 'packingType')
|
|
32
|
+
let timezoneOffset = filters.find(data => data.name === 'timezoneOffset').value + ' minutes'
|
|
33
|
+
|
|
34
|
+
// expiration date filter
|
|
35
|
+
let expiration = filters.find(data => data.name === 'expiration').value
|
|
36
|
+
let expFromDate = filters.find(data => data.name === 'expFromDate')
|
|
37
|
+
let expToDate = filters.find(data => data.name === 'expToDate')
|
|
38
|
+
|
|
39
|
+
let bizplaceFilter = { name: '', operator: '', value: [] }
|
|
40
|
+
|
|
41
|
+
// prepare query filters
|
|
42
|
+
if (userFilter) {
|
|
43
|
+
const user: User = await tx.getRepository(User).findOne({
|
|
44
|
+
where: { id: userFilter.value },
|
|
45
|
+
relations: ['bizplaces']
|
|
46
|
+
})
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
let bizplaces = bizplaceFilter.value.map(id => `('${id}')`).join(',')
|
|
57
|
-
|
|
58
|
-
if (product) {
|
|
59
|
-
let products = product.value
|
|
60
|
-
.toLowerCase()
|
|
61
|
-
.split(',')
|
|
62
|
-
.map(prod => {
|
|
63
|
-
return "'%" + prod.trim().replace(/'/g, "''") + "%'"
|
|
64
|
-
})
|
|
65
|
-
.join(',')
|
|
66
|
-
|
|
67
|
-
queryFilter =
|
|
68
|
-
queryFilter +
|
|
69
|
-
` and exists (
|
|
70
|
-
select prd.id as product_id from products prd
|
|
71
|
-
inner join bizplaces b on b.id = prd.bizplace_id
|
|
72
|
-
inner join companies c on c.domain_id = b.domain_id
|
|
73
|
-
inner join bizplaces b2 on b2.company_id = c.id
|
|
74
|
-
where exists (
|
|
75
|
-
SELECT * FROM tmp_bizfilter bizFilter
|
|
76
|
-
WHERE bizFilter.bizplace_id = "b2"."id"
|
|
77
|
-
)
|
|
78
|
-
and (lower(prd.name) like any(array[${products}])
|
|
79
|
-
or lower(prd.description) like any(array[${products}])
|
|
80
|
-
or lower(prd.sku) like any(array[${products}]))
|
|
81
|
-
and prd.id = rih.product_id
|
|
82
|
-
group by prd.id
|
|
83
|
-
)`
|
|
84
|
-
}
|
|
48
|
+
const bizplace: Bizplace = user.bizplaces[0]
|
|
85
49
|
|
|
86
|
-
if (
|
|
87
|
-
let locations = location.value
|
|
88
|
-
.map(loc => {
|
|
89
|
-
return "'" + loc + "'"
|
|
90
|
-
})
|
|
91
|
-
.join(',')
|
|
92
|
-
|
|
93
|
-
queryFilter =
|
|
94
|
-
queryFilter +
|
|
95
|
-
`and exists (
|
|
96
|
-
select loc.id from locations loc where
|
|
97
|
-
loc.id = any(array[${locations}]::uuid[])
|
|
98
|
-
and loc.id = rih.location_id
|
|
99
|
-
)`
|
|
100
|
-
}
|
|
50
|
+
if (!bizplace) throw 'Invalid input'
|
|
101
51
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let itmIndex = arrObjectMap.findIndex(x => x.name === sorting.name)
|
|
117
|
-
|
|
118
|
-
queryOrder = `${idx === 0 ? 'order by' : queryOrder + ','} ${
|
|
119
|
-
itmIndex >= 0 ? arrObjectMap[itmIndex].value : sorting.name
|
|
120
|
-
} ${sorting.desc ? 'DESC' : 'ASC'}`
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (batchId) queryFilter = `${queryFilter} and lower(rih.batch_id) like '${batchId.value.toLowerCase()}' `
|
|
52
|
+
bizplaceFilter = { name: 'bizplace', operator: 'eq', value: [bizplace.id] }
|
|
53
|
+
} else {
|
|
54
|
+
bizplaceFilter = !filters.find((filter: any) => filter.name === 'bizplace')
|
|
55
|
+
? {
|
|
56
|
+
name: 'bizplace',
|
|
57
|
+
operator: 'in',
|
|
58
|
+
value: await getPermittedBizplaceIds(domain, user),
|
|
59
|
+
relation: true
|
|
60
|
+
}
|
|
61
|
+
: {
|
|
62
|
+
...filters.find(data => data.name === 'bizplace'),
|
|
63
|
+
value: [filters.find(data => data.name === 'bizplace').value]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
125
66
|
|
|
126
|
-
|
|
67
|
+
let queryFilter = ``
|
|
68
|
+
let bizplaces = bizplaceFilter.value.map(id => `('${id}')`).join(',')
|
|
127
69
|
|
|
128
|
-
|
|
70
|
+
if (product) {
|
|
71
|
+
let products = product.value
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.split(',')
|
|
74
|
+
.map(prod => {
|
|
75
|
+
return "'%" + prod.trim().replace(/'/g, "''") + "%'"
|
|
76
|
+
})
|
|
77
|
+
.join(',')
|
|
78
|
+
|
|
79
|
+
queryFilter =
|
|
80
|
+
queryFilter +
|
|
81
|
+
` and exists (
|
|
82
|
+
select prd.id as product_id from products prd
|
|
83
|
+
inner join bizplaces b on b.id = prd.bizplace_id
|
|
84
|
+
inner join companies c on c.domain_id = b.domain_id
|
|
85
|
+
inner join bizplaces b2 on b2.company_id = c.id
|
|
86
|
+
where exists (
|
|
87
|
+
SELECT * FROM tmp_bizfilter bizFilter
|
|
88
|
+
WHERE bizFilter.bizplace_id = "b2"."id"
|
|
89
|
+
)
|
|
90
|
+
and (lower(prd.name) like any(array[${products}])
|
|
91
|
+
or lower(prd.description) like any(array[${products}])
|
|
92
|
+
or lower(prd.sku) like any(array[${products}]))
|
|
93
|
+
and prd.id = rih.product_id
|
|
94
|
+
group by prd.id
|
|
95
|
+
)`
|
|
96
|
+
}
|
|
129
97
|
|
|
130
|
-
|
|
98
|
+
if (location) {
|
|
99
|
+
let locations = location.value
|
|
100
|
+
.map(loc => {
|
|
101
|
+
return "'" + loc + "'"
|
|
102
|
+
})
|
|
103
|
+
.join(',')
|
|
104
|
+
|
|
105
|
+
queryFilter =
|
|
106
|
+
queryFilter +
|
|
107
|
+
`and exists (
|
|
108
|
+
select loc.id from locations loc where
|
|
109
|
+
loc.id = any(array[${locations}]::uuid[])
|
|
110
|
+
and loc.id = rih.location_id
|
|
111
|
+
)`
|
|
112
|
+
}
|
|
131
113
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
114
|
+
// default sorting
|
|
115
|
+
let queryOrder = 'order by created_at desc'
|
|
116
|
+
if (sortings && sortings.length > 0) {
|
|
117
|
+
const arrObjectMap = [
|
|
118
|
+
{ name: 'palletId', value: 'rih.pallet_id' },
|
|
119
|
+
{ name: 'cartonId', value: 'rih.carton_id' },
|
|
120
|
+
{ name: 'batchId', value: 'rih.batch_id' },
|
|
121
|
+
{ name: 'initialInboundAt', value: 'rih.initial_inbound_at' },
|
|
122
|
+
{ name: 'bizplace|name', value: 'bz.name' },
|
|
123
|
+
{ name: 'product|name', value: 'prd.sku' },
|
|
124
|
+
{ name: 'remainQty', value: 'rih.qty' },
|
|
125
|
+
{ name: 'location|name', value: 'loc.name' }
|
|
126
|
+
]
|
|
127
|
+
sortings.forEach((sorting, idx) => {
|
|
128
|
+
let itmIndex = arrObjectMap.findIndex(x => x.name === sorting.name)
|
|
129
|
+
|
|
130
|
+
queryOrder = `${idx === 0 ? 'order by' : queryOrder + ','} ${
|
|
131
|
+
itmIndex >= 0 ? arrObjectMap[itmIndex].value : sorting.name
|
|
132
|
+
} ${sorting.desc ? 'DESC' : 'ASC'}`
|
|
133
|
+
})
|
|
134
|
+
}
|
|
136
135
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
136
|
+
if (batchId) queryFilter = `${queryFilter} and lower(rih.batch_id) like '${batchId.value.toLowerCase()}' `
|
|
137
|
+
|
|
138
|
+
if (palletId) queryFilter = `${queryFilter} and rih.pallet_id like '${palletId.value}' `
|
|
139
|
+
|
|
140
|
+
if (cartonId) queryFilter = `${queryFilter} and rih.carton_id like '${cartonId.value}' `
|
|
141
|
+
|
|
142
|
+
if (packingType) queryFilter = `${queryFilter} and rih.packing_type like '${packingType.value}' `
|
|
143
|
+
|
|
144
|
+
let expirationQueryFilter = ``
|
|
145
|
+
if (expiration)
|
|
146
|
+
expirationQueryFilter = ` and iv.expiration_date >= '${expFromDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL and
|
|
147
|
+
iv.expiration_date <= '${expToDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL + '1 day'::INTERVAL`
|
|
148
|
+
|
|
149
|
+
// query the results
|
|
150
|
+
await tx.query(`
|
|
151
|
+
CREATE TEMP TABLE tmp_bizfilter on commit drop AS (
|
|
152
|
+
SELECT bizplace_id::uuid FROM (VALUES ${bizplaces}) AS bizFilter(bizplace_id)
|
|
153
|
+
);
|
|
154
|
+
`)
|
|
155
|
+
|
|
156
|
+
await tx.query(
|
|
157
|
+
`
|
|
158
|
+
create temp table tmp_src on commit drop as (
|
|
159
|
+
select domain_id, pallet_id, carton_id, seq, qty, uom_value, packing_type, batch_id, batch_id_ref, created_at, status,
|
|
160
|
+
product_id::uuid as product_id, bizplace_id::uuid as bizplace_id, location_id::uuid as location_id
|
|
161
|
+
from reduced_inventory_histories rih
|
|
162
|
+
where domain_id = $1 and created_at < $2::timestamp + $3::INTERVAL + '1 day'::INTERVAL
|
|
163
|
+
);
|
|
164
|
+
`,
|
|
165
|
+
[domain.id, createdAt.value, timezoneOffset]
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
await tx.query(
|
|
169
|
+
`
|
|
170
|
+
create temp table tmp_data on commit drop as (
|
|
171
|
+
select dt.*, rih.carton_id, rih.batch_id, rih.batch_id_ref, rih.product_id, rih.packing_type, rih.bizplace_id, rih.location_id, iv.uom,
|
|
172
|
+
iv.expiration_date, iv.reusable_pallet_id, iv.remark
|
|
173
|
+
from
|
|
174
|
+
(
|
|
175
|
+
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,
|
|
176
|
+
min(ih.created_at) as initial_inbound_at
|
|
177
|
+
from tmp_src ih
|
|
178
|
+
group by ih.domain_id, ih.pallet_id
|
|
179
|
+
) dt
|
|
180
|
+
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'
|
|
181
|
+
inner join inventories iv on iv.domain_id = dt.domain_id and iv.pallet_id = dt.pallet_id
|
|
182
|
+
where exists (
|
|
183
|
+
SELECT * FROM tmp_bizfilter bizFilter
|
|
184
|
+
WHERE bizFilter.bizplace_id = "rih"."bizplace_id"
|
|
185
|
+
)
|
|
186
|
+
${queryFilter}
|
|
187
|
+
${expirationQueryFilter}
|
|
151
188
|
);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
${queryOrder}
|
|
203
|
-
OFFSET $1 LIMIT $2;
|
|
204
|
-
`,
|
|
205
|
-
[(pagination.page - 1) * pagination.limit, pagination.limit]
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
tx.query(`
|
|
209
|
-
drop table tmp_src, tmp_data, tmp_bizfilter
|
|
210
|
-
`)
|
|
211
|
-
|
|
212
|
-
// map all results
|
|
213
|
-
let items = result.map(itm => {
|
|
214
|
-
return {
|
|
215
|
-
...itm,
|
|
216
|
-
bizplace: {
|
|
217
|
-
id: itm.bizplace_id,
|
|
218
|
-
name: itm.bizplace_name
|
|
219
|
-
},
|
|
220
|
-
location: {
|
|
221
|
-
id: itm.location_id,
|
|
222
|
-
name: itm.location_name,
|
|
223
|
-
type: itm.location_type,
|
|
224
|
-
zone: itm.location_zone
|
|
225
|
-
},
|
|
226
|
-
product: {
|
|
227
|
-
id: itm.product_id,
|
|
228
|
-
name: itm.product_name,
|
|
229
|
-
description: itm.product_description,
|
|
230
|
-
sku: itm.product_sku
|
|
231
|
-
}
|
|
189
|
+
`
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
const total: any = await tx.query(`select count(*) from tmp_data`)
|
|
193
|
+
|
|
194
|
+
const result: any = await tx.query(
|
|
195
|
+
`
|
|
196
|
+
select
|
|
197
|
+
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,
|
|
198
|
+
rih.initial_inbound_at as "initialInboundAt",
|
|
199
|
+
case when rih.reusable_pallet_id is not null then concat(rih.batch_id, ' (', plt.name, ')') else rih.batch_id end as "batchId",
|
|
200
|
+
rih.batch_id_ref as "batchIdRef", rih.product_id, rih.packing_type as "packingType", rih.bizplace_id, rih.location_id,
|
|
201
|
+
prd.id as product_id, prd.name as product_name, prd.sku as product_sku, prd.description as product_description,
|
|
202
|
+
bz.id as bizplace_id, bz.name as bizplace_name,
|
|
203
|
+
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,
|
|
204
|
+
wh.name as warehouse_name, plt.name as reusable_pallet_name,
|
|
205
|
+
rih.remark,
|
|
206
|
+
rih.expiration_date as "expirationDate"
|
|
207
|
+
from tmp_data rih
|
|
208
|
+
left join pallets plt on plt.id = rih.reusable_pallet_id
|
|
209
|
+
inner join products prd on prd.id = rih.product_id
|
|
210
|
+
inner join bizplaces bz on bz.id = rih.bizplace_id
|
|
211
|
+
inner join locations loc on loc.id = rih.location_id
|
|
212
|
+
inner join warehouses wh on wh.id = loc.warehouse_id
|
|
213
|
+
WHERE 1 = 1
|
|
214
|
+
${queryOrder}
|
|
215
|
+
${setPagination ? 'OFFSET ' + (pagination.page - 1) * pagination.limit + ' LIMIT ' + pagination.limit : ''}
|
|
216
|
+
;
|
|
217
|
+
`
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
// map all results
|
|
221
|
+
let items = result.map(itm => {
|
|
222
|
+
return {
|
|
223
|
+
...itm,
|
|
224
|
+
bizplace: {
|
|
225
|
+
id: itm.bizplace_id,
|
|
226
|
+
name: itm.bizplace_name
|
|
227
|
+
},
|
|
228
|
+
location: {
|
|
229
|
+
id: itm.location_id,
|
|
230
|
+
name: itm.location_name,
|
|
231
|
+
type: itm.location_type,
|
|
232
|
+
zone: itm.location_zone
|
|
233
|
+
},
|
|
234
|
+
product: {
|
|
235
|
+
id: itm.product_id,
|
|
236
|
+
name: itm.product_name,
|
|
237
|
+
description: itm.product_description,
|
|
238
|
+
sku: itm.product_sku
|
|
232
239
|
}
|
|
233
|
-
}
|
|
240
|
+
}
|
|
241
|
+
})
|
|
234
242
|
|
|
235
|
-
|
|
236
|
-
}
|
|
243
|
+
return { items, total: total[0].count }
|
|
237
244
|
}
|
|
@@ -44,7 +44,7 @@ export const Query = /* GraphQL */ `
|
|
|
44
44
|
inventory(palletId: String!): Inventory @privilege(category: "inventory", privilege: "query")
|
|
45
45
|
inventoryByPallet(palletId: String!): Inventory @privilege(category: "inventory", privilege: "query")
|
|
46
46
|
inventoriesByProduct(filters: [Filter], pagination: Pagination, sortings: [Sorting]): InventoryList @privilege(category: "inventory", privilege: "query") @transaction
|
|
47
|
-
inventoriesByStrategy(worksheetId: String!, batchId: String!, bizplaceId: String, productName: String!, productSku: String!, packingType: String!, pickingStrategy: String! locationSortingRules: [Sorting]): InventoryList @transaction
|
|
47
|
+
inventoriesByStrategy(worksheetId: String!, batchId: String!, bizplaceId: String, productName: String!, productSku: String!, packingType: String!, packingSize: Float!, uom: String!, pickingStrategy: String! locationSortingRules: [Sorting]): InventoryList @transaction
|
|
48
48
|
checkProductIdenticality(palletA: String!, palletB: String!): Boolean @transaction
|
|
49
49
|
checkCartonIdenticality(cartonA: String!, palletA: String!, cartonB: String!): Boolean
|
|
50
50
|
checkInventoryOwner(palletId: String!, bizplaceName: String!): Boolean
|
package/server/index.ts
CHANGED
|
@@ -3,5 +3,6 @@ export * from './entities'
|
|
|
3
3
|
export * from './graphql'
|
|
4
4
|
export { createLocation, deleteLocation, deleteLocations, updateLocation } from './graphql/resolvers/location'
|
|
5
5
|
export { createWarehouse, deleteWarehouse, deleteWarehouses, updateWarehouse } from './graphql/resolvers/warehouse'
|
|
6
|
+
export { onhandInventories } from './graphql/resolvers/inventory-history/onhand-inventories'
|
|
6
7
|
export * from './migrations'
|
|
7
8
|
export * from './utils'
|