@things-factory/warehouse-base 3.7.5 → 3.7.9
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.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/inventory-bundle-group.js +1 -1
- package/dist-server/index.js +3 -1
- package/dist-server/index.js.map +1 -1
- package/package.json +6 -6
- 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/inventory-bundle-group.ts +1 -1
- package/server/index.ts +1 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inventoriesResolver = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
4
5
|
const biz_base_1 = require("@things-factory/biz-base");
|
|
5
6
|
const product_base_1 = require("@things-factory/product-base");
|
|
6
7
|
const shell_1 = require("@things-factory/shell");
|
|
7
|
-
const typeorm_1 = require("typeorm");
|
|
8
8
|
const entities_1 = require("../../../entities");
|
|
9
9
|
exports.inventoriesResolver = {
|
|
10
10
|
async inventories(_, { filters, pagination, sortings, locationSortingRules }, context) {
|
|
@@ -52,15 +52,16 @@ exports.inventoriesResolver = {
|
|
|
52
52
|
}
|
|
53
53
|
if (productFilters) {
|
|
54
54
|
let productFilterValue = `%${productFilters.value.toLowerCase()}%`;
|
|
55
|
-
qb.andWhere(
|
|
56
|
-
const subQuery = qb
|
|
55
|
+
qb.andWhere(qb => {
|
|
56
|
+
const subQuery = qb
|
|
57
|
+
.subQuery()
|
|
57
58
|
.select()
|
|
58
59
|
.from(product_base_1.Product, `products`)
|
|
59
60
|
.where(`products.id = iv.product_id`)
|
|
60
61
|
.andWhere(new typeorm_1.Brackets(qb => {
|
|
61
|
-
qb.where(
|
|
62
|
-
.orWhere(
|
|
63
|
-
.orWhere(
|
|
62
|
+
qb.where('Lower(products.sku) LIKE :productInfo', { productInfo: productFilterValue })
|
|
63
|
+
.orWhere('Lower(products.name) LIKE :productInfo', { productInfo: productFilterValue })
|
|
64
|
+
.orWhere('Lower(products.description) LIKE :productInfo', { productInfo: productFilterValue });
|
|
64
65
|
}))
|
|
65
66
|
.getQuery();
|
|
66
67
|
return `EXISTS ${subQuery}`;
|
|
@@ -85,6 +86,13 @@ exports.inventoriesResolver = {
|
|
|
85
86
|
});
|
|
86
87
|
const selectedQty = item.lockedQty ? item.lockedQty : 0;
|
|
87
88
|
const selectedUomValue = item.lockedUomValue ? item.lockedUomValue : 0;
|
|
89
|
+
item.product['productDetails'] = await (0, typeorm_1.getRepository)(product_base_1.ProductDetail).find({
|
|
90
|
+
where: {
|
|
91
|
+
product: item.product.id,
|
|
92
|
+
packingType: item.packingType,
|
|
93
|
+
packingSize: item.packingSize
|
|
94
|
+
}
|
|
95
|
+
});
|
|
88
96
|
return Object.assign(Object.assign({}, item), { changeCount: inventoryChangeCount, remainQty: item.qty - selectedQty, remainUomValue: item.uomValue - selectedUomValue });
|
|
89
97
|
}));
|
|
90
98
|
return { items, total };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inventories.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/inventory/inventories.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"inventories.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/inventory/inventories.ts"],"names":[],"mappings":";;;AAAA,qCAAqE;AAGrE,uDAAkE;AAClE,+DAAqE;AACrE,iDAA0D;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AAE,IAAI,CAAC,OAAO,CAAC,EAAE;oBACxB,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;iBAC9B;aACF,CAAC,CAAA;YAEF,uCACK,IAAI,KACP,WAAW,EAAE,oBAAoB,EACjC,SAAS,EAAE,IAAI,CAAC,GAAG,GAAG,WAAW,EACjC,cAAc,EAAE,IAAI,CAAC,QAAQ,GAAG,gBAAgB,IACjD;QACH,CAAC,CAAC,CACH,CAAA;QAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;CACF,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Mutation = exports.Query = void 0;
|
|
3
|
+
exports.onhandInventories = exports.Mutation = exports.Query = void 0;
|
|
4
4
|
const create_inventory_history_1 = require("./create-inventory-history");
|
|
5
5
|
const delete_inventory_histories_1 = require("./delete-inventory-histories");
|
|
6
6
|
const delete_inventory_history_1 = require("./delete-inventory-history");
|
|
@@ -15,6 +15,7 @@ const inventory_history_pallet_detail_report_1 = require("./inventory-history-pa
|
|
|
15
15
|
const inventory_history_pallet_storage_report_1 = require("./inventory-history-pallet-storage-report");
|
|
16
16
|
const inventory_history_summary_report_1 = require("./inventory-history-summary-report");
|
|
17
17
|
const onhand_inventories_1 = require("./onhand-inventories");
|
|
18
|
+
Object.defineProperty(exports, "onhandInventories", { enumerable: true, get: function () { return onhand_inventories_1.onhandInventories; } });
|
|
18
19
|
exports.Query = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, inventory_histories_1.inventoryHistoriesResolver), inventory_history_1.inventoryHistoryResolver), bizplace_inventory_histories_1.bizplaceInventoryHistories), inventory_history_report_1.inventoryHistoryReport), inventory_history_pallet_report_1.inventoryHistoryPalletReport), inventory_history_pallet_detail_report_1.inventoryHistoryPalletDetailReport), inventory_history_pallet_storage_report_1.inventoryHistoryPalletStorageReport), inventory_history_summary_report_1.inventoryHistorySummaryReport), onhand_inventories_1.onhandInventoriesResolver);
|
|
19
20
|
exports.Mutation = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, update_inventory_history_1.updateInventoryHistory), update_multiple_inventory_history_1.updateMultipleInventoryHistory), create_inventory_history_1.createInventoryHistory), delete_inventory_history_1.deleteInventoryHistory), delete_inventory_histories_1.deleteInventoryHistories);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/inventory-history/index.ts"],"names":[],"mappings":";;;AAAA,yEAAmE;AACnE,6EAAuE;AACvE,yEAAmE;AACnE,+DAAkE;AAClE,2DAA8D;AAC9D,yEAAmE;AACnE,2FAAoF;AACpF,iFAA2E;AAC3E,yEAAmE;AACnE,uFAAgF;AAChF,qGAA6F;AAC7F,uGAA+F;AAC/F,yFAAkF;AAClF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/inventory-history/index.ts"],"names":[],"mappings":";;;AAAA,yEAAmE;AACnE,6EAAuE;AACvE,yEAAmE;AACnE,+DAAkE;AAClE,2DAA8D;AAC9D,yEAAmE;AACnE,2FAAoF;AACpF,iFAA2E;AAC3E,yEAAmE;AACnE,uFAAgF;AAChF,qGAA6F;AAC7F,uGAA+F;AAC/F,yFAAkF;AAClF,6DAAmF;AAuB1E,kGAvB2B,sCAAiB,OAuB3B;AArBb,QAAA,KAAK,qIACb,gDAA0B,GAC1B,4CAAwB,GACxB,yDAA0B,GAC1B,iDAAsB,GACtB,8DAA4B,GAC5B,2EAAkC,GAClC,6EAAmC,GACnC,gEAA6B,GAC7B,8CAAyB,EAC7B;AAEY,QAAA,QAAQ,6EAChB,iDAAsB,GACtB,kEAA8B,GAC9B,iDAAsB,GACtB,iDAAsB,GACtB,qDAAwB,EAC5B"}
|
|
@@ -1,198 +1,200 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onhandInventoriesResolver = void 0;
|
|
3
|
+
exports.onhandInventories = exports.onhandInventoriesResolver = void 0;
|
|
4
4
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
5
5
|
const biz_base_1 = require("@things-factory/biz-base");
|
|
6
6
|
exports.onhandInventoriesResolver = {
|
|
7
7
|
async onhandInventories(_, { filters, pagination, sortings, locationSortingRules }, context) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
and (lower(prd.name) like any(array[${products}])
|
|
67
|
-
or lower(prd.description) like any(array[${products}])
|
|
68
|
-
or lower(prd.sku) like any(array[${products}]))
|
|
69
|
-
and prd.id = rih.product_id
|
|
70
|
-
group by prd.id
|
|
71
|
-
)`;
|
|
72
|
-
}
|
|
73
|
-
if (location) {
|
|
74
|
-
let locations = location.value
|
|
75
|
-
.map(loc => {
|
|
76
|
-
return "'" + loc + "'";
|
|
77
|
-
})
|
|
78
|
-
.join(',');
|
|
79
|
-
queryFilter =
|
|
80
|
-
queryFilter +
|
|
81
|
-
`and exists (
|
|
82
|
-
select loc.id from locations loc where
|
|
83
|
-
loc.id = any(array[${locations}]::uuid[])
|
|
84
|
-
and loc.id = rih.location_id
|
|
85
|
-
)`;
|
|
86
|
-
}
|
|
87
|
-
// default sorting
|
|
88
|
-
let queryOrder = 'order by created_at desc';
|
|
89
|
-
if (sortings && sortings.length > 0) {
|
|
90
|
-
const arrObjectMap = [
|
|
91
|
-
{ name: 'palletId', value: 'rih.pallet_id' },
|
|
92
|
-
{ name: 'cartonId', value: 'rih.carton_id' },
|
|
93
|
-
{ name: 'batchId', value: 'rih.batch_id' },
|
|
94
|
-
{ name: 'initialInboundAt', value: 'rih.initial_inbound_at' },
|
|
95
|
-
{ name: 'bizplace|name', value: 'bz.name' },
|
|
96
|
-
{ name: 'product|name', value: 'prd.sku' },
|
|
97
|
-
{ name: 'remainQty', value: 'rih.qty' },
|
|
98
|
-
{ name: 'location|name', value: 'loc.name' }
|
|
99
|
-
];
|
|
100
|
-
sortings.forEach((sorting, idx) => {
|
|
101
|
-
let itmIndex = arrObjectMap.findIndex(x => x.name === sorting.name);
|
|
102
|
-
queryOrder = `${idx === 0 ? 'order by' : queryOrder + ','} ${itmIndex >= 0 ? arrObjectMap[itmIndex].value : sorting.name} ${sorting.desc ? 'DESC' : 'ASC'}`;
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (batchId)
|
|
106
|
-
queryFilter = `${queryFilter} and lower(rih.batch_id) like '${batchId.value.toLowerCase()}' `;
|
|
107
|
-
if (palletId)
|
|
108
|
-
queryFilter = `${queryFilter} and rih.pallet_id like '${palletId.value}' `;
|
|
109
|
-
if (cartonId)
|
|
110
|
-
queryFilter = `${queryFilter} and rih.carton_id like '${cartonId.value}' `;
|
|
111
|
-
if (packingType)
|
|
112
|
-
queryFilter = `${queryFilter} and rih.packing_type like '${packingType.value}' `;
|
|
113
|
-
let expirationQueryFilter = ``;
|
|
114
|
-
if (expiration)
|
|
115
|
-
expirationQueryFilter = ` and iv.expiration_date >= '${expFromDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL and
|
|
116
|
-
iv.expiration_date <= '${expToDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL + '1 day'::INTERVAL`;
|
|
117
|
-
// query the results
|
|
118
|
-
await tx.query(`
|
|
119
|
-
CREATE TEMP TABLE tmp_bizfilter AS (
|
|
120
|
-
SELECT bizplace_id::uuid FROM (VALUES ${bizplaces}) AS bizFilter(bizplace_id)
|
|
121
|
-
);
|
|
122
|
-
`);
|
|
123
|
-
await tx.query(`
|
|
124
|
-
create temp table tmp_src as (
|
|
125
|
-
select domain_id, pallet_id, carton_id, seq, qty, uom_value, packing_type, batch_id, batch_id_ref, created_at, status,
|
|
126
|
-
product_id::uuid as product_id, bizplace_id::uuid as bizplace_id, location_id::uuid as location_id
|
|
127
|
-
from reduced_inventory_histories rih
|
|
128
|
-
where domain_id = $1 and created_at < $2::timestamp + $3::INTERVAL + '1 day'::INTERVAL
|
|
129
|
-
);
|
|
130
|
-
`, [domain.id, createdAt.value, timezoneOffset]);
|
|
131
|
-
await tx.query(`
|
|
132
|
-
create temp table tmp_data as (
|
|
133
|
-
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,
|
|
134
|
-
iv.expiration_date, iv.reusable_pallet_id, iv.remark
|
|
135
|
-
from
|
|
136
|
-
(
|
|
137
|
-
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,
|
|
138
|
-
min(ih.created_at) as initial_inbound_at
|
|
139
|
-
from tmp_src ih
|
|
140
|
-
group by ih.domain_id, ih.pallet_id
|
|
141
|
-
) dt
|
|
142
|
-
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'
|
|
143
|
-
inner join inventories iv on iv.domain_id = dt.domain_id and iv.pallet_id = dt.pallet_id
|
|
8
|
+
return await onhandInventories(filters, pagination, sortings, locationSortingRules, context);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
async function onhandInventories(filters, pagination, sortings, locationSortingRules, context, setPagination = true) {
|
|
12
|
+
const { domain, user, tx } = context.state;
|
|
13
|
+
// define all inputs
|
|
14
|
+
let userFilter = filters.find(data => data.name === 'user');
|
|
15
|
+
let product = filters.find(data => data.name === 'product');
|
|
16
|
+
let createdAt = filters.find(data => data.name === 'created_at');
|
|
17
|
+
let location = filters.find(data => data.name === 'location');
|
|
18
|
+
let batchId = filters.find(data => data.name === 'batchId');
|
|
19
|
+
let palletId = filters.find(data => data.name === 'palletId');
|
|
20
|
+
let cartonId = filters.find(data => data.name === 'cartonId');
|
|
21
|
+
let packingType = filters.find(data => data.name === 'packingType');
|
|
22
|
+
let timezoneOffset = filters.find(data => data.name === 'timezoneOffset').value + ' minutes';
|
|
23
|
+
// expiration date filter
|
|
24
|
+
let expiration = filters.find(data => data.name === 'expiration').value;
|
|
25
|
+
let expFromDate = filters.find(data => data.name === 'expFromDate');
|
|
26
|
+
let expToDate = filters.find(data => data.name === 'expToDate');
|
|
27
|
+
let bizplaceFilter = { name: '', operator: '', value: [] };
|
|
28
|
+
// prepare query filters
|
|
29
|
+
if (userFilter) {
|
|
30
|
+
const user = await tx.getRepository(auth_base_1.User).findOne({
|
|
31
|
+
where: { id: userFilter.value },
|
|
32
|
+
relations: ['bizplaces']
|
|
33
|
+
});
|
|
34
|
+
const bizplace = user.bizplaces[0];
|
|
35
|
+
if (!bizplace)
|
|
36
|
+
throw 'Invalid input';
|
|
37
|
+
bizplaceFilter = { name: 'bizplace', operator: 'eq', value: [bizplace.id] };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
bizplaceFilter = !filters.find((filter) => filter.name === 'bizplace')
|
|
41
|
+
? {
|
|
42
|
+
name: 'bizplace',
|
|
43
|
+
operator: 'in',
|
|
44
|
+
value: await (0, biz_base_1.getPermittedBizplaceIds)(domain, user),
|
|
45
|
+
relation: true
|
|
46
|
+
}
|
|
47
|
+
: Object.assign(Object.assign({}, filters.find(data => data.name === 'bizplace')), { value: [filters.find(data => data.name === 'bizplace').value] });
|
|
48
|
+
}
|
|
49
|
+
let queryFilter = ``;
|
|
50
|
+
let bizplaces = bizplaceFilter.value.map(id => `('${id}')`).join(',');
|
|
51
|
+
if (product) {
|
|
52
|
+
let products = product.value
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.split(',')
|
|
55
|
+
.map(prod => {
|
|
56
|
+
return "'%" + prod.trim().replace(/'/g, "''") + "%'";
|
|
57
|
+
})
|
|
58
|
+
.join(',');
|
|
59
|
+
queryFilter =
|
|
60
|
+
queryFilter +
|
|
61
|
+
` and exists (
|
|
62
|
+
select prd.id as product_id from products prd
|
|
63
|
+
inner join bizplaces b on b.id = prd.bizplace_id
|
|
64
|
+
inner join companies c on c.domain_id = b.domain_id
|
|
65
|
+
inner join bizplaces b2 on b2.company_id = c.id
|
|
144
66
|
where exists (
|
|
145
67
|
SELECT * FROM tmp_bizfilter bizFilter
|
|
146
|
-
WHERE bizFilter.bizplace_id = "
|
|
68
|
+
WHERE bizFilter.bizplace_id = "b2"."id"
|
|
147
69
|
)
|
|
148
|
-
${
|
|
149
|
-
${
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
name: itm.location_name,
|
|
186
|
-
type: itm.location_type,
|
|
187
|
-
zone: itm.location_zone
|
|
188
|
-
}, product: {
|
|
189
|
-
id: itm.product_id,
|
|
190
|
-
name: itm.product_name,
|
|
191
|
-
description: itm.product_description,
|
|
192
|
-
sku: itm.product_sku
|
|
193
|
-
} });
|
|
70
|
+
and (lower(prd.name) like any(array[${products}])
|
|
71
|
+
or lower(prd.description) like any(array[${products}])
|
|
72
|
+
or lower(prd.sku) like any(array[${products}]))
|
|
73
|
+
and prd.id = rih.product_id
|
|
74
|
+
group by prd.id
|
|
75
|
+
)`;
|
|
76
|
+
}
|
|
77
|
+
if (location) {
|
|
78
|
+
let locations = location.value
|
|
79
|
+
.map(loc => {
|
|
80
|
+
return "'" + loc + "'";
|
|
81
|
+
})
|
|
82
|
+
.join(',');
|
|
83
|
+
queryFilter =
|
|
84
|
+
queryFilter +
|
|
85
|
+
`and exists (
|
|
86
|
+
select loc.id from locations loc where
|
|
87
|
+
loc.id = any(array[${locations}]::uuid[])
|
|
88
|
+
and loc.id = rih.location_id
|
|
89
|
+
)`;
|
|
90
|
+
}
|
|
91
|
+
// default sorting
|
|
92
|
+
let queryOrder = 'order by created_at desc';
|
|
93
|
+
if (sortings && sortings.length > 0) {
|
|
94
|
+
const arrObjectMap = [
|
|
95
|
+
{ name: 'palletId', value: 'rih.pallet_id' },
|
|
96
|
+
{ name: 'cartonId', value: 'rih.carton_id' },
|
|
97
|
+
{ name: 'batchId', value: 'rih.batch_id' },
|
|
98
|
+
{ name: 'initialInboundAt', value: 'rih.initial_inbound_at' },
|
|
99
|
+
{ name: 'bizplace|name', value: 'bz.name' },
|
|
100
|
+
{ name: 'product|name', value: 'prd.sku' },
|
|
101
|
+
{ name: 'remainQty', value: 'rih.qty' },
|
|
102
|
+
{ name: 'location|name', value: 'loc.name' }
|
|
103
|
+
];
|
|
104
|
+
sortings.forEach((sorting, idx) => {
|
|
105
|
+
let itmIndex = arrObjectMap.findIndex(x => x.name === sorting.name);
|
|
106
|
+
queryOrder = `${idx === 0 ? 'order by' : queryOrder + ','} ${itmIndex >= 0 ? arrObjectMap[itmIndex].value : sorting.name} ${sorting.desc ? 'DESC' : 'ASC'}`;
|
|
194
107
|
});
|
|
195
|
-
return { items, total: total[0].count };
|
|
196
108
|
}
|
|
197
|
-
|
|
109
|
+
if (batchId)
|
|
110
|
+
queryFilter = `${queryFilter} and lower(rih.batch_id) like '${batchId.value.toLowerCase()}' `;
|
|
111
|
+
if (palletId)
|
|
112
|
+
queryFilter = `${queryFilter} and rih.pallet_id like '${palletId.value}' `;
|
|
113
|
+
if (cartonId)
|
|
114
|
+
queryFilter = `${queryFilter} and rih.carton_id like '${cartonId.value}' `;
|
|
115
|
+
if (packingType)
|
|
116
|
+
queryFilter = `${queryFilter} and rih.packing_type like '${packingType.value}' `;
|
|
117
|
+
let expirationQueryFilter = ``;
|
|
118
|
+
if (expiration)
|
|
119
|
+
expirationQueryFilter = ` and iv.expiration_date >= '${expFromDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL and
|
|
120
|
+
iv.expiration_date <= '${expToDate.value}'::timestamp + '${timezoneOffset}'::INTERVAL + '1 day'::INTERVAL`;
|
|
121
|
+
// query the results
|
|
122
|
+
await tx.query(`
|
|
123
|
+
CREATE TEMP TABLE tmp_bizfilter on commit drop AS (
|
|
124
|
+
SELECT bizplace_id::uuid FROM (VALUES ${bizplaces}) AS bizFilter(bizplace_id)
|
|
125
|
+
);
|
|
126
|
+
`);
|
|
127
|
+
await tx.query(`
|
|
128
|
+
create temp table tmp_src on commit drop as (
|
|
129
|
+
select domain_id, pallet_id, carton_id, seq, qty, uom_value, packing_type, batch_id, batch_id_ref, created_at, status,
|
|
130
|
+
product_id::uuid as product_id, bizplace_id::uuid as bizplace_id, location_id::uuid as location_id
|
|
131
|
+
from reduced_inventory_histories rih
|
|
132
|
+
where domain_id = $1 and created_at < $2::timestamp + $3::INTERVAL + '1 day'::INTERVAL
|
|
133
|
+
);
|
|
134
|
+
`, [domain.id, createdAt.value, timezoneOffset]);
|
|
135
|
+
await tx.query(`
|
|
136
|
+
create temp table tmp_data on commit drop as (
|
|
137
|
+
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,
|
|
138
|
+
iv.expiration_date, iv.reusable_pallet_id, iv.remark
|
|
139
|
+
from
|
|
140
|
+
(
|
|
141
|
+
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,
|
|
142
|
+
min(ih.created_at) as initial_inbound_at
|
|
143
|
+
from tmp_src ih
|
|
144
|
+
group by ih.domain_id, ih.pallet_id
|
|
145
|
+
) dt
|
|
146
|
+
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'
|
|
147
|
+
inner join inventories iv on iv.domain_id = dt.domain_id and iv.pallet_id = dt.pallet_id
|
|
148
|
+
where exists (
|
|
149
|
+
SELECT * FROM tmp_bizfilter bizFilter
|
|
150
|
+
WHERE bizFilter.bizplace_id = "rih"."bizplace_id"
|
|
151
|
+
)
|
|
152
|
+
${queryFilter}
|
|
153
|
+
${expirationQueryFilter}
|
|
154
|
+
);
|
|
155
|
+
`);
|
|
156
|
+
const total = await tx.query(`select count(*) from tmp_data`);
|
|
157
|
+
const result = await tx.query(`
|
|
158
|
+
select
|
|
159
|
+
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,
|
|
160
|
+
rih.initial_inbound_at as "initialInboundAt",
|
|
161
|
+
case when rih.reusable_pallet_id is not null then concat(rih.batch_id, ' (', plt.name, ')') else rih.batch_id end as "batchId",
|
|
162
|
+
rih.batch_id_ref as "batchIdRef", rih.product_id, rih.packing_type as "packingType", rih.bizplace_id, rih.location_id,
|
|
163
|
+
prd.id as product_id, prd.name as product_name, prd.sku as product_sku, prd.description as product_description,
|
|
164
|
+
bz.id as bizplace_id, bz.name as bizplace_name,
|
|
165
|
+
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,
|
|
166
|
+
wh.name as warehouse_name, plt.name as reusable_pallet_name,
|
|
167
|
+
rih.remark,
|
|
168
|
+
rih.expiration_date as "expirationDate"
|
|
169
|
+
from tmp_data rih
|
|
170
|
+
left join pallets plt on plt.id = rih.reusable_pallet_id
|
|
171
|
+
inner join products prd on prd.id = rih.product_id
|
|
172
|
+
inner join bizplaces bz on bz.id = rih.bizplace_id
|
|
173
|
+
inner join locations loc on loc.id = rih.location_id
|
|
174
|
+
inner join warehouses wh on wh.id = loc.warehouse_id
|
|
175
|
+
WHERE 1 = 1
|
|
176
|
+
${queryOrder}
|
|
177
|
+
${setPagination ? 'OFFSET ' + (pagination.page - 1) * pagination.limit + ' LIMIT ' + pagination.limit : ''}
|
|
178
|
+
;
|
|
179
|
+
`);
|
|
180
|
+
// map all results
|
|
181
|
+
let items = result.map(itm => {
|
|
182
|
+
return Object.assign(Object.assign({}, itm), { bizplace: {
|
|
183
|
+
id: itm.bizplace_id,
|
|
184
|
+
name: itm.bizplace_name
|
|
185
|
+
}, location: {
|
|
186
|
+
id: itm.location_id,
|
|
187
|
+
name: itm.location_name,
|
|
188
|
+
type: itm.location_type,
|
|
189
|
+
zone: itm.location_zone
|
|
190
|
+
}, product: {
|
|
191
|
+
id: itm.product_id,
|
|
192
|
+
name: itm.product_name,
|
|
193
|
+
description: itm.product_description,
|
|
194
|
+
sku: itm.product_sku
|
|
195
|
+
} });
|
|
196
|
+
});
|
|
197
|
+
return { items, total: total[0].count };
|
|
198
|
+
}
|
|
199
|
+
exports.onhandInventories = onhandInventories;
|
|
198
200
|
//# sourceMappingURL=onhand-inventories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onhand-inventories.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/inventory-history/onhand-inventories.ts"],"names":[],"mappings":";;;AAEA,yDAAgD;AAChD,uDAA4E;AAG/D,QAAA,yBAAyB,GAAG;IACvC,KAAK,CAAC,iBAAiB,CAAC,CAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,OAAY;QACnG,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"onhand-inventories.js","sourceRoot":"","sources":["../../../../server/graphql/resolvers/inventory-history/onhand-inventories.ts"],"names":[],"mappings":";;;AAEA,yDAAgD;AAChD,uDAA4E;AAG/D,QAAA,yBAAyB,GAAG;IACvC,KAAK,CAAC,iBAAiB,CAAC,CAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAAE,OAAY;QACnG,OAAO,MAAM,iBAAiB,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IAC9F,CAAC;CACF,CAAA;AAEM,KAAK,UAAU,iBAAiB,CACrC,OAAO,EACP,UAAU,EACV,QAAQ,EACR,oBAAoB,EACpB,OAAO,EACP,aAAa,GAAG,IAAI;IAEpB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAsD,OAAO,CAAC,KAAK,CAAA;IAE7F,oBAAoB;IACpB,IAAI,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,I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gBAClB,IAAI,EAAE,GAAG,CAAC,YAAY;gBACtB,WAAW,EAAE,GAAG,CAAC,mBAAmB;gBACpC,GAAG,EAAE,GAAG,CAAC,WAAW;aACrB,IACF;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;AACzC,CAAC;AAvOD,8CAuOC"}
|
|
@@ -25,10 +25,10 @@ exports.InventoryBundleGroup = (0, graphql_tag_1.default) `
|
|
|
25
25
|
releaseQty: Int
|
|
26
26
|
remainUomValue: Float
|
|
27
27
|
lockedUomValue: Float
|
|
28
|
+
uom: String
|
|
28
29
|
releaseUomValue: Float
|
|
29
30
|
releaseUomValueWithUom: String
|
|
30
31
|
packingType: String
|
|
31
|
-
uom: String
|
|
32
32
|
domain: Domain
|
|
33
33
|
description: String
|
|
34
34
|
updater: User
|
package/dist-server/index.js
CHANGED
|
@@ -10,7 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.updateWarehouse = exports.deleteWarehouses = exports.deleteWarehouse = exports.createWarehouse = exports.updateLocation = exports.deleteLocations = exports.deleteLocation = exports.createLocation = void 0;
|
|
13
|
+
exports.onhandInventories = exports.updateWarehouse = exports.deleteWarehouses = exports.deleteWarehouse = exports.createWarehouse = exports.updateLocation = exports.deleteLocations = exports.deleteLocation = exports.createLocation = void 0;
|
|
14
14
|
__exportStar(require("./constants"), exports);
|
|
15
15
|
__exportStar(require("./entities"), exports);
|
|
16
16
|
__exportStar(require("./graphql"), exports);
|
|
@@ -24,6 +24,8 @@ Object.defineProperty(exports, "createWarehouse", { enumerable: true, get: funct
|
|
|
24
24
|
Object.defineProperty(exports, "deleteWarehouse", { enumerable: true, get: function () { return warehouse_1.deleteWarehouse; } });
|
|
25
25
|
Object.defineProperty(exports, "deleteWarehouses", { enumerable: true, get: function () { return warehouse_1.deleteWarehouses; } });
|
|
26
26
|
Object.defineProperty(exports, "updateWarehouse", { enumerable: true, get: function () { return warehouse_1.updateWarehouse; } });
|
|
27
|
+
var onhand_inventories_1 = require("./graphql/resolvers/inventory-history/onhand-inventories");
|
|
28
|
+
Object.defineProperty(exports, "onhandInventories", { enumerable: true, get: function () { return onhand_inventories_1.onhandInventories; } });
|
|
27
29
|
__exportStar(require("./migrations"), exports);
|
|
28
30
|
__exportStar(require("./utils"), exports);
|
|
29
31
|
//# sourceMappingURL=index.js.map
|
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,6CAA0B;AAC1B,4CAAyB;AACzB,yDAA8G;AAArG,0GAAA,cAAc,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxE,2DAAmH;AAA1G,4GAAA,eAAe,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,4GAAA,eAAe,OAAA;AAC5E,+CAA4B;AAC5B,0CAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,6CAA0B;AAC1B,4CAAyB;AACzB,yDAA8G;AAArG,0GAAA,cAAc,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,0GAAA,cAAc,OAAA;AACxE,2DAAmH;AAA1G,4GAAA,eAAe,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,4GAAA,eAAe,OAAA;AAC5E,+FAA4F;AAAnF,uHAAA,iBAAiB,OAAA;AAC1B,+CAA4B;AAC5B,0CAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/warehouse-base",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.9",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@things-factory/biz-base": "^3.7.5",
|
|
28
|
-
"@things-factory/id-rule-base": "^3.7.
|
|
29
|
-
"@things-factory/integration-sellercraft": "^3.7.
|
|
30
|
-
"@things-factory/marketplace-base": "^3.7.
|
|
31
|
-
"@things-factory/product-base": "^3.7.
|
|
28
|
+
"@things-factory/id-rule-base": "^3.7.6",
|
|
29
|
+
"@things-factory/integration-sellercraft": "^3.7.7",
|
|
30
|
+
"@things-factory/marketplace-base": "^3.7.9",
|
|
31
|
+
"@things-factory/product-base": "^3.7.8",
|
|
32
32
|
"@things-factory/setting-base": "^3.7.5"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "4d4b67315ce5f7a8a3e2cbc3206ff23b0f1d5f9d"
|
|
35
35
|
}
|
|
@@ -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
|
}
|
|
@@ -20,10 +20,10 @@ export const InventoryBundleGroup = gql`
|
|
|
20
20
|
releaseQty: Int
|
|
21
21
|
remainUomValue: Float
|
|
22
22
|
lockedUomValue: Float
|
|
23
|
+
uom: String
|
|
23
24
|
releaseUomValue: Float
|
|
24
25
|
releaseUomValueWithUom: String
|
|
25
26
|
packingType: String
|
|
26
|
-
uom: String
|
|
27
27
|
domain: Domain
|
|
28
28
|
description: String
|
|
29
29
|
updater: User
|
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'
|