@things-factory/operato-hub 4.3.14 → 4.3.17
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/synchronization/sync-products-to-sellercraft.js +43 -38
- package/dist-server/graphql/resolvers/synchronization/sync-products-to-sellercraft.js.map +1 -1
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js +487 -447
- package/dist-server/routers/api/restful-apis/unstable/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v1/add-release-order.js +489 -452
- package/dist-server/routers/api/restful-apis/v1/add-release-order.js.map +1 -1
- package/dist-server/routers/api/restful-apis/v2/add-release-order.js +489 -455
- package/dist-server/routers/api/restful-apis/v2/add-release-order.js.map +1 -1
- package/package.json +12 -12
- package/server/graphql/resolvers/synchronization/sync-products-to-sellercraft.ts +47 -43
- package/server/routers/api/restful-apis/unstable/add-release-order.ts +613 -561
- package/server/routers/api/restful-apis/v1/add-release-order.ts +614 -566
- package/server/routers/api/restful-apis/v2/add-release-order.ts +614 -568
|
@@ -8,538 +8,575 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
|
|
|
8
8
|
const typeorm_1 = require("typeorm");
|
|
9
9
|
const api_1 = require("@things-factory/api");
|
|
10
10
|
const biz_base_1 = require("@things-factory/biz-base");
|
|
11
|
+
const integration_base_1 = require("@things-factory/integration-base");
|
|
11
12
|
const product_base_1 = require("@things-factory/product-base");
|
|
12
13
|
const sales_base_1 = require("@things-factory/sales-base");
|
|
13
14
|
const setting_base_1 = require("@things-factory/setting-base");
|
|
14
15
|
const warehouse_base_1 = require("@things-factory/warehouse-base");
|
|
15
16
|
const business_middleware_1 = require("../../../../middlewares/business-middleware");
|
|
16
17
|
const warehouse_middleware_1 = require("../../../../middlewares/warehouse-middleware");
|
|
17
|
-
const debug = require('debug')('things-factory:operato-hub:restful-api:
|
|
18
|
-
|
|
18
|
+
const debug = require('debug')('things-factory:operato-hub:restful-api:unstable:add-release-order');
|
|
19
|
+
const apiVersion = 'v1';
|
|
20
|
+
api_1.restfulApiRouter.post(`/${apiVersion}/warehouse/:warehouseId/add-release-order`, business_middleware_1.businessMiddleware, warehouse_middleware_1.warehouseMiddleware, async (context, next) => {
|
|
19
21
|
return await (0, typeorm_1.getConnection)().transaction(async (tx) => {
|
|
20
22
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
21
23
|
const { client, domain } = context.state;
|
|
22
24
|
const { warehouseId: customerBizplaceId } = context.params;
|
|
23
25
|
const { t } = context;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
debug('post:/add-release-order request.body', bodyReq);
|
|
31
|
-
await checkMandatoryKey(context, bodyReq);
|
|
32
|
-
const isAutoAssign = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true;
|
|
33
|
-
// get customer company's bizplace
|
|
34
|
-
const custCompanyBizplace = await (0, biz_base_1.getCompanyBizplace)(null, null, customerBizplaceId, tx);
|
|
35
|
-
const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
|
|
36
|
-
where: { id: customerBizplaceId }
|
|
37
|
-
});
|
|
38
|
-
let locationSortingRules = [];
|
|
39
|
-
const inventoryAssignmentSetting = await tx.getRepository(setting_base_1.Setting).findOne({
|
|
40
|
-
where: { domain, name: 'rule-for-inventory-assignment' }
|
|
41
|
-
});
|
|
42
|
-
if (inventoryAssignmentSetting) {
|
|
43
|
-
let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
|
|
44
|
-
for (const key in locationSetting) {
|
|
45
|
-
locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
|
|
26
|
+
const bodyReq = context.request.body;
|
|
27
|
+
try {
|
|
28
|
+
if (!customerBizplaceId)
|
|
29
|
+
context.throw(404, t('error.warehouse id not found'));
|
|
30
|
+
if (typeof bodyReq === undefined || !((_a = Object.keys(bodyReq)) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
31
|
+
context.throw(400, t('error.invalid body request format'));
|
|
46
32
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
33
|
+
debug('post:/add-release-order request.body', bodyReq);
|
|
34
|
+
await checkMandatoryKey(context, bodyReq);
|
|
35
|
+
const isAutoAssign = bodyReq.hasOwnProperty('isAutoAssign') ? bodyReq.isAutoAssign : true;
|
|
36
|
+
const requiredDraft = bodyReq.hasOwnProperty('requiredDraft') ? bodyReq.requiredDraft : true;
|
|
37
|
+
// get customer company's bizplace
|
|
38
|
+
const custCompanyBizplace = await (0, biz_base_1.getCompanyBizplace)(null, null, customerBizplaceId, tx);
|
|
39
|
+
const customerBizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
|
|
40
|
+
where: { id: customerBizplaceId }
|
|
41
|
+
});
|
|
42
|
+
let locationSortingRules = [];
|
|
43
|
+
const inventoryAssignmentSetting = await tx.getRepository(setting_base_1.Setting).findOne({
|
|
44
|
+
where: { domain, name: 'rule-for-inventory-assignment' }
|
|
51
45
|
});
|
|
52
|
-
if (
|
|
53
|
-
let locationSetting = JSON.parse(
|
|
46
|
+
if (inventoryAssignmentSetting) {
|
|
47
|
+
let locationSetting = JSON.parse(inventoryAssignmentSetting.value);
|
|
54
48
|
for (const key in locationSetting) {
|
|
55
49
|
locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.getRepository(product_base_1.ProductDetail)
|
|
69
|
-
.createQueryBuilder('PD')
|
|
70
|
-
.innerJoinAndSelect('PD.product', 'PROD')
|
|
71
|
-
.where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
|
|
72
|
-
if (!sku && !refCode) {
|
|
73
|
-
context.throw(404, t('error.sku or refCode not found'));
|
|
74
|
-
}
|
|
75
|
-
if (refCode) {
|
|
76
|
-
qb.andWhere('PD.ref_code = :refCode', { refCode });
|
|
77
|
-
}
|
|
78
|
-
if (sku) {
|
|
79
|
-
qb.andWhere('PROD.sku = :sku', { sku });
|
|
80
|
-
}
|
|
81
|
-
if (packingType) {
|
|
82
|
-
qb.andWhere('PD.packing_type = :packingType', { packingType });
|
|
83
|
-
}
|
|
84
|
-
if (packingSize) {
|
|
85
|
-
qb.andWhere('PD.packing_size = :packingSize', { packingSize });
|
|
86
|
-
}
|
|
87
|
-
if (!packingType && !refCode) {
|
|
88
|
-
qb.andWhere('PD.is_default = :isDefault', { isDefault: true });
|
|
89
|
-
}
|
|
90
|
-
const productDetail = await qb.getOne();
|
|
91
|
-
if (productDetail) {
|
|
92
|
-
let newOrderInventory = Object.assign({}, orderInventory);
|
|
93
|
-
newOrderInventory.product.sku = productDetail.product.sku;
|
|
94
|
-
newOrderInventory.product = productDetail.product;
|
|
95
|
-
newOrderInventory.packingType = productDetail.packingType;
|
|
96
|
-
newOrderInventory.uomValue = productDetail.uomValue;
|
|
97
|
-
newOrderInventories.push(newOrderInventory);
|
|
52
|
+
else {
|
|
53
|
+
const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
|
|
54
|
+
where: { domain, name: 'rule-for-picking-product' }
|
|
55
|
+
});
|
|
56
|
+
if (pickingProductSetting) {
|
|
57
|
+
let locationSetting = JSON.parse(pickingProductSetting.value);
|
|
58
|
+
for (const key in locationSetting) {
|
|
59
|
+
locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
98
62
|
}
|
|
99
|
-
|
|
63
|
+
const orderInventories = bodyReq.orderInventories;
|
|
64
|
+
let newOrderInventories = [];
|
|
65
|
+
let bundleInfo = [];
|
|
66
|
+
await Promise.all(orderInventories.map(async (orderInventory) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const sku = (_a = orderInventory.product) === null || _a === void 0 ? void 0 : _a.sku;
|
|
69
|
+
const refCode = (_b = orderInventory.product) === null || _b === void 0 ? void 0 : _b.refCode;
|
|
70
|
+
const packingType = orderInventory.packingType;
|
|
100
71
|
const qb = tx
|
|
101
|
-
.getRepository(product_base_1.
|
|
102
|
-
.createQueryBuilder('
|
|
103
|
-
.innerJoinAndSelect('
|
|
104
|
-
.
|
|
105
|
-
.innerJoinAndSelect('PBD.product', 'PROD')
|
|
106
|
-
.where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
|
|
72
|
+
.getRepository(product_base_1.ProductDetail)
|
|
73
|
+
.createQueryBuilder('PD')
|
|
74
|
+
.innerJoinAndSelect('PD.product', 'PROD')
|
|
75
|
+
.where('PROD.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
|
|
107
76
|
if (!sku && !refCode) {
|
|
108
77
|
context.throw(404, t('error.sku or refCode not found'));
|
|
109
78
|
}
|
|
110
79
|
if (refCode) {
|
|
111
|
-
qb.andWhere('
|
|
80
|
+
qb.andWhere('PD.ref_code = :refCode', { refCode });
|
|
112
81
|
}
|
|
113
82
|
if (sku) {
|
|
114
|
-
qb.andWhere('
|
|
83
|
+
qb.andWhere('PROD.sku = :sku', { sku });
|
|
115
84
|
}
|
|
116
85
|
if (packingType) {
|
|
117
|
-
qb.andWhere('
|
|
86
|
+
qb.andWhere('PD.packing_type = :packingType', { packingType });
|
|
118
87
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
bundleInfo.push({
|
|
122
|
-
productBundleId: foundProductBundle.id,
|
|
123
|
-
sku: foundProductBundle.sku,
|
|
124
|
-
releaseQty: orderInventory.releaseQty
|
|
125
|
-
});
|
|
126
|
-
const bundleProductSettings = foundProductBundle.productBundleSettings;
|
|
127
|
-
bundleProductSettings.map(bundleProductSetting => {
|
|
128
|
-
const productDetailBundle = bundleProductSetting.productDetail;
|
|
129
|
-
let newOrderInventory = Object.assign({}, orderInventory);
|
|
130
|
-
newOrderInventory.product.sku = productDetailBundle.product.sku;
|
|
131
|
-
newOrderInventory.packingType = productDetailBundle.packingType;
|
|
132
|
-
newOrderInventory.uomValue = productDetailBundle.uomValue;
|
|
133
|
-
newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty;
|
|
134
|
-
newOrderInventory.product = productDetailBundle.product;
|
|
135
|
-
newOrderInventories.push(newOrderInventory);
|
|
136
|
-
});
|
|
88
|
+
if (!packingType && !refCode) {
|
|
89
|
+
qb.andWhere('PD.is_default = :isDefault', { isDefault: true });
|
|
137
90
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
91
|
+
const productDetail = await qb.getOne();
|
|
92
|
+
if (productDetail) {
|
|
93
|
+
let newOrderInventory = Object.assign({}, orderInventory);
|
|
94
|
+
newOrderInventory.product.sku = productDetail.product.sku;
|
|
95
|
+
newOrderInventory.product = productDetail.product;
|
|
96
|
+
newOrderInventory.packingType = productDetail.packingType;
|
|
97
|
+
newOrderInventory.uomValue = productDetail.uomValue;
|
|
98
|
+
newOrderInventories.push(newOrderInventory);
|
|
99
|
+
}
|
|
100
|
+
if (!productDetail) {
|
|
101
|
+
const qb = tx
|
|
102
|
+
.getRepository(product_base_1.ProductBundle)
|
|
103
|
+
.createQueryBuilder('PB')
|
|
104
|
+
.innerJoinAndSelect('PB.productBundleSettings', 'PBS')
|
|
105
|
+
.innerJoinAndSelect('PBS.productDetail', 'PBD')
|
|
106
|
+
.innerJoinAndSelect('PBD.product', 'PROD')
|
|
107
|
+
.where('PB.bizplace_id = :bizplaceId', { bizplaceId: custCompanyBizplace.id });
|
|
108
|
+
if (!sku && !refCode) {
|
|
109
|
+
context.throw(404, t('error.sku or refCode not found'));
|
|
144
110
|
}
|
|
145
111
|
if (refCode) {
|
|
146
|
-
|
|
112
|
+
qb.andWhere('PB.ref_code = :refCode', { refCode });
|
|
147
113
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}));
|
|
151
|
-
let finalOrderInventories = [];
|
|
152
|
-
// Case 1. Every order inventories has specified batch id
|
|
153
|
-
if (newOrderInventories.every((orderInventory) => orderInventory.batchId)) {
|
|
154
|
-
finalOrderInventories = await Promise.all(newOrderInventories.map(async (orderInventory) => {
|
|
155
|
-
let filters = [
|
|
156
|
-
{
|
|
157
|
-
name: 'batchId',
|
|
158
|
-
operator: 'eq',
|
|
159
|
-
value: orderInventory.batchId
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
name: 'productName',
|
|
163
|
-
operator: 'eq',
|
|
164
|
-
value: orderInventory.product.sku
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
name: 'bizplace',
|
|
168
|
-
operator: 'in',
|
|
169
|
-
value: [customerBizplaceId]
|
|
114
|
+
if (sku) {
|
|
115
|
+
qb.andWhere('PB.sku = :sku', { sku });
|
|
170
116
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
switch (orderInventory.product.pickingStrategy) {
|
|
174
|
-
case 'FIFO':
|
|
175
|
-
sortings.push({ name: 'created_at', desc: false });
|
|
176
|
-
break;
|
|
177
|
-
case 'LIFO':
|
|
178
|
-
sortings.push({ name: 'created_at', desc: true });
|
|
179
|
-
break;
|
|
180
|
-
case 'FEFO':
|
|
181
|
-
sortings.push({ name: 'expiration_date', desc: false });
|
|
182
|
-
break;
|
|
183
|
-
case 'FMFO':
|
|
184
|
-
sortings.push({ name: 'manufacture_date', desc: false });
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
// 2. get all inventory data according to SKU and batchId
|
|
188
|
-
const response = await client.query({
|
|
189
|
-
query: (0, graphql_tag_1.default) `
|
|
190
|
-
query inventoriesByPallet($filters: [Filter], $sortings: [Sorting], $locationSortingRules: [Sorting]) {
|
|
191
|
-
inventoriesByPallet(
|
|
192
|
-
filters: $filters
|
|
193
|
-
sortings: $sortings
|
|
194
|
-
locationSortingRules: $locationSortingRules
|
|
195
|
-
) {
|
|
196
|
-
items {
|
|
197
|
-
product {
|
|
198
|
-
id
|
|
199
|
-
name
|
|
200
|
-
description
|
|
201
|
-
}
|
|
202
|
-
batchId
|
|
203
|
-
packingType
|
|
204
|
-
remainQty
|
|
205
|
-
remainUomValue
|
|
117
|
+
if (packingType) {
|
|
118
|
+
qb.andWhere('PB.packing_type = :packingType', { packingType });
|
|
206
119
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
120
|
+
const foundProductBundle = await qb.getOne();
|
|
121
|
+
if (foundProductBundle) {
|
|
122
|
+
bundleInfo.push({
|
|
123
|
+
productBundleId: foundProductBundle.id,
|
|
124
|
+
sku: foundProductBundle.sku,
|
|
125
|
+
releaseQty: orderInventory.releaseQty
|
|
126
|
+
});
|
|
127
|
+
const bundleProductSettings = foundProductBundle.productBundleSettings;
|
|
128
|
+
bundleProductSettings.map(bundleProductSetting => {
|
|
129
|
+
const productDetailBundle = bundleProductSetting.productDetail;
|
|
130
|
+
let newOrderInventory = Object.assign({}, orderInventory);
|
|
131
|
+
newOrderInventory.product.sku = productDetailBundle.product.sku;
|
|
132
|
+
newOrderInventory.packingType = productDetailBundle.packingType;
|
|
133
|
+
newOrderInventory.uomValue = productDetailBundle.uomValue;
|
|
134
|
+
newOrderInventory.releaseQty = orderInventory.releaseQty * bundleProductSetting.bundleQty;
|
|
135
|
+
newOrderInventory.product = productDetailBundle.product;
|
|
136
|
+
newOrderInventories.push(newOrderInventory);
|
|
137
|
+
});
|
|
221
138
|
}
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
context.
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
139
|
+
else {
|
|
140
|
+
if (sku && refCode) {
|
|
141
|
+
context.throw(404, t(`error.sku ${sku} and refCode ${refCode} not exist in product / bundle master`));
|
|
142
|
+
}
|
|
143
|
+
if (sku) {
|
|
144
|
+
context.throw(404, t(`error.sku ${sku} not exist in product / bundle master`));
|
|
145
|
+
}
|
|
146
|
+
if (refCode) {
|
|
147
|
+
context.throw(404, t(`error.refCode ${refCode} not exist in product / bundle master`));
|
|
228
148
|
}
|
|
229
|
-
// 3. add more information to orderInventory
|
|
230
|
-
orderInventory.product.id = item.product.id;
|
|
231
|
-
orderInventory.packingType = item.packingType;
|
|
232
|
-
orderInventory.batchId = item.batchId;
|
|
233
|
-
orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
|
|
234
|
-
orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
|
|
235
|
-
orderInventory.uom = item.uom;
|
|
236
|
-
});
|
|
237
|
-
return orderInventory;
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
context.body = {
|
|
241
|
-
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
242
|
-
};
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
}));
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
// Case 2. Some of order inventories doesn't have specified batch id
|
|
249
|
-
// MMS order doesn't have batch ID field.
|
|
250
|
-
// To cover this case first result of found inventory will be a target of RO
|
|
251
|
-
// To combine items from different bundles
|
|
252
|
-
newOrderInventories = combineItems(newOrderInventories);
|
|
253
|
-
for (let i = 0; i < newOrderInventories.length; i++) {
|
|
254
|
-
const orderInventory = newOrderInventories[i];
|
|
255
|
-
const { product, packingType } = orderInventory;
|
|
256
|
-
const pickingStrategy = product.pickingStrategy;
|
|
257
|
-
if (isAutoAssign) {
|
|
258
|
-
let qb = tx.getRepository(warehouse_base_1.Inventory).createQueryBuilder('iv');
|
|
259
|
-
qb.leftJoinAndSelect('iv.location', 'loc')
|
|
260
|
-
.andWhere('"iv"."domain_id" = :domainId')
|
|
261
|
-
.andWhere('"iv"."bizplace_id" = :bizplaceId')
|
|
262
|
-
.andWhere('"iv"."packing_type" = :packingType')
|
|
263
|
-
.andWhere('"iv"."product_id" = :productId')
|
|
264
|
-
.andWhere('"iv"."status" = :status')
|
|
265
|
-
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
266
|
-
.setParameters({
|
|
267
|
-
domainId: domain.id,
|
|
268
|
-
bizplaceId: customerBizplace.id,
|
|
269
|
-
packingType: packingType,
|
|
270
|
-
productId: product.id,
|
|
271
|
-
status: warehouse_base_1.INVENTORY_STATUS.STORED,
|
|
272
|
-
locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
|
|
273
|
-
});
|
|
274
|
-
switch (pickingStrategy) {
|
|
275
|
-
case 'FIFO':
|
|
276
|
-
qb.orderBy('"iv"."created_at"', 'ASC');
|
|
277
|
-
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
278
|
-
locationSortingRules.forEach((rule, idx) => {
|
|
279
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
break;
|
|
283
|
-
case 'LIFO':
|
|
284
|
-
qb.orderBy('"iv"."created_at"', 'DESC');
|
|
285
|
-
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
286
|
-
locationSortingRules.forEach((rule, idx) => {
|
|
287
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
break;
|
|
291
|
-
case 'FEFO':
|
|
292
|
-
qb.orderBy('"iv"."expiration_date"', 'ASC');
|
|
293
|
-
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
294
|
-
locationSortingRules.forEach((rule, idx) => {
|
|
295
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
break;
|
|
299
|
-
case 'FMFO':
|
|
300
|
-
qb.orderBy('"iv"."manufacture_date"', 'ASC');
|
|
301
|
-
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
302
|
-
locationSortingRules.forEach((rule, idx) => {
|
|
303
|
-
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
break;
|
|
307
|
-
case 'LOCATION':
|
|
308
|
-
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
309
|
-
locationSortingRules.forEach((rule, idx) => {
|
|
310
|
-
idx === 0
|
|
311
|
-
? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
312
|
-
: qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
qb.orderBy('"loc"."name"', 'DESC');
|
|
317
|
-
}
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
let inventories = await qb.getMany();
|
|
321
|
-
if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length)) {
|
|
322
|
-
context.body = {
|
|
323
|
-
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
324
|
-
};
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
inventories = inventories
|
|
328
|
-
.map(inventory => {
|
|
329
|
-
return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - inventory.lockedQty, remainUomValue: inventory.uomValue - inventory.lockedUomValue });
|
|
330
|
-
})
|
|
331
|
-
.filter(inventory => inventory.remainQty > 0);
|
|
332
|
-
let targetInventories;
|
|
333
|
-
try {
|
|
334
|
-
targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
|
|
335
|
-
}
|
|
336
|
-
catch (e) {
|
|
337
|
-
context.body = {
|
|
338
|
-
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
339
|
-
};
|
|
340
|
-
return;
|
|
341
149
|
}
|
|
342
|
-
targetInventories.map(item => {
|
|
343
|
-
finalOrderInventories.push(item.targetInventory);
|
|
344
|
-
});
|
|
345
150
|
}
|
|
346
|
-
|
|
151
|
+
}));
|
|
152
|
+
let finalOrderInventories = [];
|
|
153
|
+
// Case 1. Every order inventories has specified batch id
|
|
154
|
+
if (newOrderInventories.every((orderInventory) => orderInventory.batchId)) {
|
|
155
|
+
finalOrderInventories = await Promise.all(newOrderInventories.map(async (orderInventory) => {
|
|
347
156
|
let filters = [
|
|
157
|
+
{
|
|
158
|
+
name: 'batchId',
|
|
159
|
+
operator: 'eq',
|
|
160
|
+
value: orderInventory.batchId
|
|
161
|
+
},
|
|
348
162
|
{
|
|
349
163
|
name: 'productName',
|
|
350
164
|
operator: 'eq',
|
|
351
165
|
value: orderInventory.product.sku
|
|
352
166
|
},
|
|
353
167
|
{
|
|
354
|
-
name: '
|
|
355
|
-
operator: '
|
|
356
|
-
value: customerBizplaceId
|
|
168
|
+
name: 'bizplace',
|
|
169
|
+
operator: 'in',
|
|
170
|
+
value: [customerBizplaceId]
|
|
357
171
|
}
|
|
358
172
|
];
|
|
173
|
+
let sortings = [];
|
|
174
|
+
switch (orderInventory.product.pickingStrategy) {
|
|
175
|
+
case 'FIFO':
|
|
176
|
+
sortings.push({ name: 'created_at', desc: false });
|
|
177
|
+
break;
|
|
178
|
+
case 'LIFO':
|
|
179
|
+
sortings.push({ name: 'created_at', desc: true });
|
|
180
|
+
break;
|
|
181
|
+
case 'FEFO':
|
|
182
|
+
sortings.push({ name: 'expiration_date', desc: false });
|
|
183
|
+
break;
|
|
184
|
+
case 'FMFO':
|
|
185
|
+
sortings.push({ name: 'manufacture_date', desc: false });
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
359
188
|
// 2. get all inventory data according to SKU and batchId
|
|
360
189
|
const response = await client.query({
|
|
361
190
|
query: (0, graphql_tag_1.default) `
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
191
|
+
query inventoriesByPallet(
|
|
192
|
+
$filters: [Filter]
|
|
193
|
+
$sortings: [Sorting]
|
|
194
|
+
$locationSortingRules: [Sorting]
|
|
195
|
+
) {
|
|
196
|
+
inventoriesByPallet(
|
|
197
|
+
filters: $filters
|
|
198
|
+
sortings: $sortings
|
|
199
|
+
locationSortingRules: $locationSortingRules
|
|
200
|
+
) {
|
|
201
|
+
items {
|
|
202
|
+
product {
|
|
203
|
+
id
|
|
204
|
+
name
|
|
205
|
+
description
|
|
206
|
+
}
|
|
207
|
+
batchId
|
|
208
|
+
packingType
|
|
209
|
+
remainQty
|
|
210
|
+
remainUomValue
|
|
211
|
+
}
|
|
212
|
+
total
|
|
372
213
|
}
|
|
373
|
-
total
|
|
374
214
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
variables: { filters },
|
|
215
|
+
`,
|
|
216
|
+
variables: { filters, sortings, locationSortingRules },
|
|
378
217
|
context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
|
|
379
218
|
});
|
|
380
219
|
if (!response.errors) {
|
|
381
|
-
const items = response.data.
|
|
382
|
-
if (
|
|
383
|
-
|
|
384
|
-
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
385
|
-
};
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
items.forEach(async (item) => {
|
|
389
|
-
if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
|
|
220
|
+
const items = response.data.inventoriesByPallet.items || [];
|
|
221
|
+
if (requiredDraft) {
|
|
222
|
+
if (!(items === null || items === void 0 ? void 0 : items.length)) {
|
|
390
223
|
context.body = {
|
|
391
224
|
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
392
225
|
};
|
|
393
226
|
return;
|
|
394
227
|
}
|
|
228
|
+
}
|
|
229
|
+
items.forEach(async (item) => {
|
|
230
|
+
if (requiredDraft) {
|
|
231
|
+
if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
|
|
232
|
+
context.body = {
|
|
233
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
234
|
+
};
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
395
238
|
// 3. add more information to orderInventory
|
|
396
|
-
orderInventory.product =
|
|
239
|
+
orderInventory.product.id = item.product.id;
|
|
397
240
|
orderInventory.packingType = item.packingType;
|
|
398
241
|
orderInventory.batchId = item.batchId;
|
|
399
242
|
orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
|
|
400
243
|
orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
|
|
401
244
|
orderInventory.uom = item.uom;
|
|
402
245
|
});
|
|
403
|
-
|
|
404
|
-
finalOrderInventories.push(orderInventory);
|
|
246
|
+
return orderInventory;
|
|
405
247
|
}
|
|
406
248
|
else {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
249
|
+
if (requiredDraft) {
|
|
250
|
+
context.body = {
|
|
251
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
252
|
+
};
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
411
255
|
}
|
|
412
|
-
}
|
|
256
|
+
}));
|
|
413
257
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
258
|
+
else {
|
|
259
|
+
// Case 2. Some of order inventories doesn't have specified batch id
|
|
260
|
+
// MMS order doesn't have batch ID field.
|
|
261
|
+
// To cover this case first result of found inventory will be a target of RO
|
|
262
|
+
// To combine items from different bundles
|
|
263
|
+
newOrderInventories = combineItems(newOrderInventories);
|
|
264
|
+
for (let i = 0; i < newOrderInventories.length; i++) {
|
|
265
|
+
const orderInventory = newOrderInventories[i];
|
|
266
|
+
const { product, packingType } = orderInventory;
|
|
267
|
+
const pickingStrategy = product.pickingStrategy;
|
|
268
|
+
if (isAutoAssign) {
|
|
269
|
+
let qb = tx.getRepository(warehouse_base_1.Inventory).createQueryBuilder('iv');
|
|
270
|
+
qb.leftJoinAndSelect('iv.location', 'loc')
|
|
271
|
+
.andWhere('"iv"."domain_id" = :domainId')
|
|
272
|
+
.andWhere('"iv"."bizplace_id" = :bizplaceId')
|
|
273
|
+
.andWhere('"iv"."packing_type" = :packingType')
|
|
274
|
+
.andWhere('"iv"."product_id" = :productId')
|
|
275
|
+
.andWhere('"iv"."status" = :status')
|
|
276
|
+
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
277
|
+
.setParameters({
|
|
278
|
+
domainId: domain.id,
|
|
279
|
+
bizplaceId: customerBizplace.id,
|
|
280
|
+
packingType: packingType,
|
|
281
|
+
productId: product.id,
|
|
282
|
+
status: warehouse_base_1.INVENTORY_STATUS.STORED,
|
|
283
|
+
locationTypes: [warehouse_base_1.LOCATION_TYPE.QUARANTINE, warehouse_base_1.LOCATION_TYPE.RESERVE]
|
|
284
|
+
});
|
|
285
|
+
switch (pickingStrategy) {
|
|
286
|
+
case 'FIFO':
|
|
287
|
+
qb.orderBy('"iv"."created_at"', 'ASC');
|
|
288
|
+
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
289
|
+
locationSortingRules.forEach((rule, idx) => {
|
|
290
|
+
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
case 'LIFO':
|
|
295
|
+
qb.orderBy('"iv"."created_at"', 'DESC');
|
|
296
|
+
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
297
|
+
locationSortingRules.forEach((rule, idx) => {
|
|
298
|
+
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
break;
|
|
302
|
+
case 'FEFO':
|
|
303
|
+
qb.orderBy('"iv"."expiration_date"', 'ASC');
|
|
304
|
+
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
305
|
+
locationSortingRules.forEach((rule, idx) => {
|
|
306
|
+
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
case 'FMFO':
|
|
311
|
+
qb.orderBy('"iv"."manufacture_date"', 'ASC');
|
|
312
|
+
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
313
|
+
locationSortingRules.forEach((rule, idx) => {
|
|
314
|
+
qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
break;
|
|
318
|
+
case 'LOCATION':
|
|
319
|
+
if ((locationSortingRules === null || locationSortingRules === void 0 ? void 0 : locationSortingRules.length) > 0) {
|
|
320
|
+
locationSortingRules.forEach((rule, idx) => {
|
|
321
|
+
idx === 0
|
|
322
|
+
? qb.orderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
|
|
323
|
+
: qb.addOrderBy(`loc.${rule.name}`, rule.desc ? 'DESC' : 'ASC');
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
qb.orderBy('"loc"."name"', 'DESC');
|
|
328
|
+
}
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
let inventories = await qb.getMany();
|
|
332
|
+
if (requiredDraft) {
|
|
333
|
+
if (!(inventories === null || inventories === void 0 ? void 0 : inventories.length)) {
|
|
334
|
+
context.body = {
|
|
335
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
336
|
+
};
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
inventories = inventories
|
|
341
|
+
.map(inventory => {
|
|
342
|
+
return Object.assign(Object.assign({}, inventory), { remainQty: inventory.qty - inventory.lockedQty, remainUomValue: inventory.uomValue - inventory.lockedUomValue });
|
|
343
|
+
})
|
|
344
|
+
.filter(inventory => inventory.remainQty > 0);
|
|
345
|
+
let targetInventories;
|
|
346
|
+
try {
|
|
347
|
+
targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
if (requiredDraft) {
|
|
351
|
+
context.body = {
|
|
352
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
353
|
+
};
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
targetInventories = _composeTargetInventories(context, product, orderInventory, inventories);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (!(targetInventories === null || targetInventories === void 0 ? void 0 : targetInventories.length)) {
|
|
361
|
+
context.throw(404, t(`error.no inventories found`));
|
|
362
|
+
}
|
|
363
|
+
targetInventories.map(item => {
|
|
364
|
+
finalOrderInventories.push(item.targetInventory);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
let filters = [
|
|
369
|
+
{
|
|
370
|
+
name: 'productName',
|
|
371
|
+
operator: 'eq',
|
|
372
|
+
value: orderInventory.product.sku
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
name: 'bizplace_id',
|
|
376
|
+
operator: 'eq',
|
|
377
|
+
value: customerBizplaceId
|
|
378
|
+
}
|
|
379
|
+
];
|
|
380
|
+
// 2. get all inventory data according to SKU and batchId
|
|
381
|
+
const response = await client.query({
|
|
382
|
+
query: (0, graphql_tag_1.default) `
|
|
383
|
+
query inventoryProductGroup($filters: [Filter]) {
|
|
384
|
+
inventoryProductGroup(filters: $filters) {
|
|
385
|
+
items {
|
|
386
|
+
productId
|
|
387
|
+
productSKU
|
|
388
|
+
productName
|
|
389
|
+
batchId
|
|
390
|
+
packingType
|
|
391
|
+
remainQty
|
|
392
|
+
remainUomValue
|
|
393
|
+
}
|
|
394
|
+
total
|
|
395
|
+
}
|
|
454
396
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
397
|
+
`,
|
|
398
|
+
variables: { filters },
|
|
399
|
+
context: Object.assign(Object.assign({}, context), { state: Object.assign(Object.assign({}, context.state), { bizplace: customerBizplace, domain }) })
|
|
400
|
+
});
|
|
401
|
+
if (!response.errors) {
|
|
402
|
+
const items = response.data.inventoryProductGroup.items || [];
|
|
403
|
+
if (requiredDraft) {
|
|
404
|
+
if (!(items === null || items === void 0 ? void 0 : items.length)) {
|
|
405
|
+
context.body = {
|
|
406
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
407
|
+
};
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
items.forEach(async (item) => {
|
|
412
|
+
if (requiredDraft) {
|
|
413
|
+
if (orderInventory.releaseQty > item.remainQty || orderInventory.releaseQty <= 0) {
|
|
414
|
+
context.body = {
|
|
415
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
416
|
+
};
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
// 3. add more information to orderInventory
|
|
421
|
+
orderInventory.product = { id: item.productId };
|
|
422
|
+
orderInventory.packingType = item.packingType;
|
|
423
|
+
orderInventory.batchId = item.batchId;
|
|
424
|
+
orderInventory.type = sales_base_1.ORDER_TYPES.RELEASE_OF_GOODS;
|
|
425
|
+
orderInventory.releaseUomValue = orderInventory.releaseQty * orderInventory.uomValue;
|
|
426
|
+
orderInventory.uom = item.uom;
|
|
427
|
+
});
|
|
428
|
+
delete orderInventory.uomValue;
|
|
429
|
+
finalOrderInventories.push(orderInventory);
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
if (requiredDraft) {
|
|
433
|
+
context.body = {
|
|
434
|
+
result: await createDraftOrder(client, customerBizplace, bodyReq, bundleInfo, domain, context, orderInventories, tx)
|
|
435
|
+
};
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
context.body = {
|
|
443
|
+
result: (await client.mutate({
|
|
444
|
+
mutation: (0, graphql_tag_1.default) `
|
|
445
|
+
mutation addReleaseGood(
|
|
446
|
+
$releaseGood: NewReleaseGood
|
|
447
|
+
$shippingOrder: ShippingOrderPatch
|
|
448
|
+
$file: Upload
|
|
449
|
+
) {
|
|
450
|
+
addReleaseGood(releaseGood: $releaseGood, shippingOrder: $shippingOrder, file: $file) {
|
|
451
|
+
id
|
|
459
452
|
name
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
453
|
+
refNo
|
|
454
|
+
status
|
|
455
|
+
truckNo
|
|
456
|
+
ownTransport
|
|
457
|
+
crossDocking
|
|
458
|
+
marketplaceOrderStatus
|
|
459
|
+
billingAddress
|
|
460
|
+
deliveryAddress1
|
|
461
|
+
deliveryAddress2
|
|
462
|
+
deliveryAddress3
|
|
463
|
+
deliveryAddress4
|
|
464
|
+
deliveryAddress5
|
|
465
|
+
attentionTo
|
|
466
|
+
attentionCompany
|
|
467
|
+
city
|
|
468
|
+
state
|
|
469
|
+
postalCode
|
|
470
|
+
country
|
|
471
|
+
phone1
|
|
472
|
+
phone2
|
|
473
|
+
email
|
|
474
|
+
transporter
|
|
475
|
+
trackingNo
|
|
476
|
+
airwayBill
|
|
477
|
+
invoice
|
|
478
|
+
type
|
|
479
|
+
storeName
|
|
480
|
+
storeId
|
|
481
|
+
routeId
|
|
482
|
+
stopId
|
|
483
|
+
arrivalNotice {
|
|
464
484
|
name
|
|
465
|
-
description
|
|
466
485
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
releaseUomValue
|
|
472
|
-
}
|
|
473
|
-
orderVass {
|
|
474
|
-
vas {
|
|
486
|
+
exportOption
|
|
487
|
+
releaseDate
|
|
488
|
+
collectionOrderNo
|
|
489
|
+
bizplace {
|
|
475
490
|
name
|
|
476
|
-
operationGuide
|
|
477
|
-
operationGuideType
|
|
478
491
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
492
|
+
orderInventories {
|
|
493
|
+
product {
|
|
494
|
+
sku
|
|
495
|
+
name
|
|
496
|
+
description
|
|
497
|
+
}
|
|
498
|
+
batchId
|
|
499
|
+
packingType
|
|
500
|
+
packingSize
|
|
501
|
+
releaseQty
|
|
502
|
+
releaseUomValue
|
|
503
|
+
}
|
|
504
|
+
orderVass {
|
|
505
|
+
vas {
|
|
506
|
+
name
|
|
507
|
+
operationGuide
|
|
508
|
+
operationGuideType
|
|
509
|
+
}
|
|
510
|
+
set
|
|
511
|
+
targetType
|
|
512
|
+
targetBatchId
|
|
513
|
+
targetProduct {
|
|
514
|
+
name
|
|
515
|
+
description
|
|
516
|
+
}
|
|
517
|
+
packingType
|
|
518
|
+
qty
|
|
519
|
+
uomValue
|
|
520
|
+
otherTarget
|
|
484
521
|
description
|
|
522
|
+
remark
|
|
523
|
+
status
|
|
524
|
+
operationGuide
|
|
485
525
|
}
|
|
486
|
-
packingType
|
|
487
|
-
qty
|
|
488
|
-
uomValue
|
|
489
|
-
otherTarget
|
|
490
|
-
description
|
|
491
|
-
remark
|
|
492
|
-
status
|
|
493
|
-
operationGuide
|
|
494
526
|
}
|
|
495
527
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
|
|
528
|
+
`,
|
|
529
|
+
variables: {
|
|
530
|
+
releaseGood: {
|
|
531
|
+
customerBizplaceId: customerBizplace.id,
|
|
532
|
+
courierOption: bodyReq.courierOption,
|
|
533
|
+
collectionOrderNo: bodyReq.collectionOrderNo,
|
|
534
|
+
exportOption: bodyReq.exportOption,
|
|
535
|
+
orderInventories: finalOrderInventories,
|
|
536
|
+
ownTransport: bodyReq.ownTransport,
|
|
537
|
+
packingOption: bodyReq.packingOption,
|
|
538
|
+
refNo: bodyReq.refNo,
|
|
539
|
+
refNo2: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.refNo2,
|
|
540
|
+
releaseDate: bodyReq.releaseDate,
|
|
541
|
+
type: bodyReq.type,
|
|
542
|
+
marketplaceOrderStatus: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.marketplaceOrderStatus,
|
|
543
|
+
remark: (bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.remark) || null,
|
|
544
|
+
billingAddress: ((_b = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.billTo) === null || _b === void 0 ? void 0 : _b.billingAddress) || null,
|
|
545
|
+
deliveryAddress1: ((_c = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _c === void 0 ? void 0 : _c.deliveryAddress1) || null,
|
|
546
|
+
deliveryAddress2: ((_d = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _d === void 0 ? void 0 : _d.deliveryAddress2) || null,
|
|
547
|
+
deliveryAddress3: ((_e = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _e === void 0 ? void 0 : _e.deliveryAddress3) || null,
|
|
548
|
+
deliveryAddress4: ((_f = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _f === void 0 ? void 0 : _f.deliveryAddress4) || null,
|
|
549
|
+
deliveryAddress5: ((_g = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _g === void 0 ? void 0 : _g.deliveryAddress5) || null,
|
|
550
|
+
attentionTo: ((_h = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _h === void 0 ? void 0 : _h.attentionTo) || null,
|
|
551
|
+
attentionCompany: ((_j = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _j === void 0 ? void 0 : _j.attentionCompany) || null,
|
|
552
|
+
city: ((_k = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _k === void 0 ? void 0 : _k.city) || null,
|
|
553
|
+
state: ((_l = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _l === void 0 ? void 0 : _l.state) || null,
|
|
554
|
+
postalCode: ((_m = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _m === void 0 ? void 0 : _m.postalCode) || null,
|
|
555
|
+
country: ((_o = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _o === void 0 ? void 0 : _o.country) || null,
|
|
556
|
+
phone1: ((_p = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _p === void 0 ? void 0 : _p.phone1) || null,
|
|
557
|
+
phone2: ((_q = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _q === void 0 ? void 0 : _q.phone2) || null,
|
|
558
|
+
email: ((_r = bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.deliverTo) === null || _r === void 0 ? void 0 : _r.email) || null,
|
|
559
|
+
transporter: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.transporter,
|
|
560
|
+
trackingNo: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.trackingNo,
|
|
561
|
+
airwayBill: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.airwayBill,
|
|
562
|
+
invoice: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.invoice,
|
|
563
|
+
bundleInfo: JSON.stringify(bundleInfo),
|
|
564
|
+
storeName: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeName,
|
|
565
|
+
storeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.storeId,
|
|
566
|
+
routeId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.routeId,
|
|
567
|
+
stopId: bodyReq === null || bodyReq === void 0 ? void 0 : bodyReq.stopId
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
context: Object.assign(Object.assign({}, context), { hasUpload: true, state: Object.assign(Object.assign({}, context.state), { customerBizplace,
|
|
571
|
+
domain, type: 'api' }) })
|
|
572
|
+
})).data
|
|
573
|
+
};
|
|
574
|
+
(0, integration_base_1.createPayloadLog)(customerBizplaceId, `/${apiVersion}/warehouse/:warehouseId/add-release-order`, bodyReq, context.body, context, integration_base_1.PayloadType.INGESTION);
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
(0, integration_base_1.createPayloadLog)(customerBizplaceId, `/${apiVersion}/warehouse/:warehouseId/add-release-order`, bodyReq, error, context, integration_base_1.PayloadType.INGESTION);
|
|
578
|
+
throw error;
|
|
579
|
+
}
|
|
543
580
|
});
|
|
544
581
|
});
|
|
545
582
|
async function checkMandatoryKey(context, params) {
|
|
@@ -592,7 +629,7 @@ function _composeTargetInventories(context, product, record, inventories) {
|
|
|
592
629
|
totalInventoryQty += inventory.remainQty;
|
|
593
630
|
});
|
|
594
631
|
if (totalInventoryQty < record.releaseQty) {
|
|
595
|
-
context.throw(404, t(`error.invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`));
|
|
632
|
+
context.throw(404, t(`error.invalid release qty for ${product === null || product === void 0 ? void 0 : product.sku}`)); //
|
|
596
633
|
}
|
|
597
634
|
let targetInventories = [];
|
|
598
635
|
let idx = 0;
|