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