@things-factory/sales-base 4.0.24 → 4.0.28

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.
Files changed (59) hide show
  1. package/dist-server/controllers/ecommerce/ecommerce-controller.js +7 -4
  2. package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/sellercraft-controller.js +59 -0
  4. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  5. package/dist-server/controllers/order-controller.js +40 -1
  6. package/dist-server/controllers/order-controller.js.map +1 -1
  7. package/dist-server/service/arrival-notice/arrival-notice-mutation.js +180 -0
  8. package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
  9. package/dist-server/service/arrival-notice/arrival-notice-query.js +193 -1
  10. package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
  11. package/dist-server/service/arrival-notice/arrival-notice-types.js +160 -2
  12. package/dist-server/service/arrival-notice/arrival-notice-types.js.map +1 -1
  13. package/dist-server/service/delivery-order/delivery-order-types.js +1 -1
  14. package/dist-server/service/delivery-order/delivery-order-types.js.map +1 -1
  15. package/dist-server/service/delivery-order/delivery-order.js +1 -1
  16. package/dist-server/service/delivery-order/delivery-order.js.map +1 -1
  17. package/dist-server/service/goods-receival-note/goods-receival-note.js +5 -0
  18. package/dist-server/service/goods-receival-note/goods-receival-note.js.map +1 -1
  19. package/dist-server/service/job-sheet/job-sheet-mutation.js +1 -0
  20. package/dist-server/service/job-sheet/job-sheet-mutation.js.map +1 -1
  21. package/dist-server/service/job-sheet/job-sheet-query.js +2 -0
  22. package/dist-server/service/job-sheet/job-sheet-query.js.map +1 -1
  23. package/dist-server/service/order-inventory/order-inventory.js +22 -1
  24. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  25. package/dist-server/service/purchase-order/purchase-order.js +10 -1
  26. package/dist-server/service/purchase-order/purchase-order.js.map +1 -1
  27. package/dist-server/service/release-good/release-good-mutation.js +219 -212
  28. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  29. package/dist-server/service/release-good/release-good-query.js +135 -99
  30. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  31. package/dist-server/service/release-good/release-good-types.js +38 -2
  32. package/dist-server/service/release-good/release-good-types.js.map +1 -1
  33. package/dist-server/service/release-good/release-good.js +63 -1
  34. package/dist-server/service/release-good/release-good.js.map +1 -1
  35. package/dist-server/service/return-order/return-order-mutation.js +1 -1
  36. package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
  37. package/dist-server/utils/inventory-util.js +89 -1
  38. package/dist-server/utils/inventory-util.js.map +1 -1
  39. package/package.json +12 -12
  40. package/server/controllers/ecommerce/ecommerce-controller.ts +15 -6
  41. package/server/controllers/ecommerce/sellercraft-controller.ts +77 -1
  42. package/server/controllers/order-controller.ts +55 -2
  43. package/server/service/arrival-notice/arrival-notice-mutation.ts +237 -1
  44. package/server/service/arrival-notice/arrival-notice-query.ts +214 -4
  45. package/server/service/arrival-notice/arrival-notice-types.ts +120 -1
  46. package/server/service/delivery-order/delivery-order-types.ts +1 -1
  47. package/server/service/delivery-order/delivery-order.ts +1 -1
  48. package/server/service/goods-receival-note/goods-receival-note.ts +4 -0
  49. package/server/service/job-sheet/job-sheet-mutation.ts +1 -0
  50. package/server/service/job-sheet/job-sheet-query.ts +3 -1
  51. package/server/service/order-inventory/order-inventory.ts +17 -1
  52. package/server/service/purchase-order/purchase-order.ts +8 -1
  53. package/server/service/release-good/release-good-mutation.ts +280 -283
  54. package/server/service/release-good/release-good-query.ts +158 -115
  55. package/server/service/release-good/release-good-types.ts +30 -2
  56. package/server/service/release-good/release-good.ts +46 -0
  57. package/server/service/return-order/return-order-mutation.ts +1 -1
  58. package/server/utils/index.ts +1 -1
  59. package/server/utils/inventory-util.ts +129 -1
@@ -13,7 +13,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
13
13
  };
14
14
  var _a;
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.extractRawReleaseGoods = exports.bulkConfirmReleaseGoods = exports.bulkGenerateReleaseGoods = exports.rejectReleaseGood = exports.receiveReleaseGood = exports.confirmReleaseGood = exports.bulkReleaseGoodsAvailableItemsFunction = exports.generateReleaseGoodFunction = exports.deleteReleaseGood = exports.ReleaseGoodMutation = void 0;
16
+ exports.bulkConfirmReleaseGoods = exports.bulkGenerateReleaseGood = exports.rejectReleaseGood = exports.receiveReleaseGood = exports.confirmReleaseGood = exports.generateReleaseGoodFunction = exports.deleteReleaseGood = exports.ReleaseGoodMutation = void 0;
17
17
  const graphql_upload_1 = require("graphql-upload");
18
18
  const type_graphql_1 = require("type-graphql");
19
19
  const typeorm_1 = require("typeorm");
@@ -23,6 +23,7 @@ const biz_base_1 = require("@things-factory/biz-base");
23
23
  const id_rule_base_1 = require("@things-factory/id-rule-base");
24
24
  const integration_marketplace_1 = require("@things-factory/integration-marketplace");
25
25
  const integration_sellercraft_1 = require("@things-factory/integration-sellercraft");
26
+ const marketplace_base_1 = require("@things-factory/marketplace-base");
26
27
  const notification_1 = require("@things-factory/notification");
27
28
  const product_base_1 = require("@things-factory/product-base");
28
29
  const setting_base_1 = require("@things-factory/setting-base");
@@ -34,7 +35,55 @@ const errors_1 = require("../../errors");
34
35
  const utils_1 = require("../../utils");
35
36
  const arrival_notice_mutation_1 = require("../arrival-notice/arrival-notice-mutation");
36
37
  const release_good_1 = require("./release-good");
38
+ const release_good_query_1 = require("./release-good-query");
37
39
  let ReleaseGoodMutation = class ReleaseGoodMutation {
40
+ async bulkAddReleaseGoods(context, rawReleaseGoods, bizplaceId) {
41
+ const { domain, user, tx } = context.state;
42
+ if (!bizplaceId)
43
+ throw new Error('company ID is not provided');
44
+ let createdReleaseGoods = [];
45
+ const settingRepo = (tx === null || tx === void 0 ? void 0 : tx.getRepository(setting_base_1.Setting)) || (0, typeorm_1.getRepository)(setting_base_1.Setting);
46
+ const roNoSetting = await settingRepo.findOne({
47
+ where: {
48
+ domain,
49
+ name: constants_1.ORDER_NUMBER_SETTING_KEY.RO_NUMBER_RULE
50
+ }
51
+ });
52
+ let releaseGoods = extractRawReleaseGoods(rawReleaseGoods);
53
+ let errorsFound = [];
54
+ for (let i = 0, l = releaseGoods.length; i < l; i++) {
55
+ // generate release good by group to avoid duplication
56
+ // if this function is called simultaneously by different users
57
+ try {
58
+ await (0, typeorm_1.getConnection)().transaction(async (childTx) => {
59
+ const existingReleaseGood = await childTx.getRepository(release_good_1.ReleaseGood).findOne({
60
+ where: Object.assign(Object.assign({}, Object.fromEntries(Object.entries(releaseGoods[i]).filter(([_, val]) => !/^\s*$/.test(val) && _ != 'orderInventories'))), { domain })
61
+ });
62
+ if (existingReleaseGood)
63
+ throw new Error('release good order is already exist in the system');
64
+ let availableItems = await (0, release_good_query_1.bulkReleaseGoodsAvailableItemsFunction)([...releaseGoods[i].orderInventories], bizplaceId, context, childTx);
65
+ if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty))
66
+ throw new errors_1.ValidationError(Object.assign(Object.assign({}, errors_1.ValidationError.ERROR_CODES.INSUFFICIENT_STOCK), { detail: { data: JSON.stringify(availableItems) } }));
67
+ // update orderInventories if availableItems are valid
68
+ releaseGoods[i].orderInventories = availableItems;
69
+ const createdReleaseGood = await bulkGenerateReleaseGood(releaseGoods[i], bizplaceId, roNoSetting, domain, user, childTx);
70
+ createdReleaseGoods.push(createdReleaseGood);
71
+ });
72
+ }
73
+ catch (e) {
74
+ errorsFound.push(e);
75
+ }
76
+ }
77
+ let confirmedReleaseGoods = [];
78
+ try {
79
+ confirmedReleaseGoods = await bulkConfirmReleaseGoods(createdReleaseGoods.map(rg => rg.name), domain, user, context, tx);
80
+ }
81
+ catch (e) {
82
+ errorsFound.push(e);
83
+ }
84
+ // if (errorsFound.length) { then ?? }
85
+ return confirmedReleaseGoods;
86
+ }
38
87
  async deleteReleaseGood(name, context) {
39
88
  const { tx, user, domain } = context.state;
40
89
  return await deleteReleaseGood(tx, name, user, domain);
@@ -104,34 +153,18 @@ let ReleaseGoodMutation = class ReleaseGoodMutation {
104
153
  const receivedRO = await receiveReleaseGood(confirmedRO.name, context, tx);
105
154
  return receivedRO;
106
155
  }
107
- async bulkAddReleaseGoods(context, rawReleaseGoods, bizplaceId) {
108
- const { domain, user, tx } = context.state;
109
- if (!bizplaceId)
110
- throw new Error('company ID is not provided');
111
- let createdReleaseGoods = [];
112
- const settingRepo = (tx === null || tx === void 0 ? void 0 : tx.getRepository(setting_base_1.Setting)) || (0, typeorm_1.getRepository)(setting_base_1.Setting);
113
- const roNoSetting = await settingRepo.findOne({
114
- where: {
115
- domain,
116
- name: constants_1.ORDER_NUMBER_SETTING_KEY.RO_NUMBER_RULE
117
- }
118
- });
119
- let releaseGoods = extractRawReleaseGoods(rawReleaseGoods);
120
- for (let i = 0, l = releaseGoods.length; i < l; i++) {
121
- // generate release good by group to avoid duplication
122
- // if this function is called simultaneously by different users
123
- let availableItems = await bulkReleaseGoodsAvailableItemsFunction([...releaseGoods[i].orderInventories], bizplaceId, context, tx);
124
- if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty))
125
- throw new errors_1.ValidationError(Object.assign(Object.assign({}, errors_1.ValidationError.ERROR_CODES.INSUFFICIENT_STOCK), { detail: { data: JSON.stringify(availableItems) } }));
126
- // update orderInventories if availableItems are valid
127
- releaseGoods[i].orderInventories = availableItems;
128
- const createdReleaseGood = await bulkGenerateReleaseGoods(releaseGoods[i], bizplaceId, roNoSetting, domain, user, tx);
129
- createdReleaseGoods.push(createdReleaseGood);
130
- }
131
- let confirmedReleaseGoods = await bulkConfirmReleaseGoods(createdReleaseGoods.map(rg => rg.name), domain, user, context, tx);
132
- return confirmedReleaseGoods;
133
- }
134
156
  };
157
+ __decorate([
158
+ (0, type_graphql_1.Directive)('@privilege(category: "order_customer", privilege: "mutation")'),
159
+ (0, type_graphql_1.Directive)('@transaction'),
160
+ (0, type_graphql_1.Mutation)(returns => [release_good_1.ReleaseGood]),
161
+ __param(0, (0, type_graphql_1.Ctx)()),
162
+ __param(1, (0, type_graphql_1.Arg)('rawReleaseGoods', type => [__1.NewReleaseGood], { nullable: true })),
163
+ __param(2, (0, type_graphql_1.Arg)('bizplaceId', type => String)),
164
+ __metadata("design:type", Function),
165
+ __metadata("design:paramtypes", [Object, Array, String]),
166
+ __metadata("design:returntype", Promise)
167
+ ], ReleaseGoodMutation.prototype, "bulkAddReleaseGoods", null);
135
168
  __decorate([
136
169
  (0, type_graphql_1.Directive)('@privilege(category: "order_customer", privilege: "mutation")'),
137
170
  (0, type_graphql_1.Directive)('@transaction'),
@@ -220,16 +253,6 @@ __decorate([
220
253
  __1.ShippingOrderPatch, typeof (_a = typeof graphql_upload_1.FileUpload !== "undefined" && graphql_upload_1.FileUpload) === "function" ? _a : Object]),
221
254
  __metadata("design:returntype", Promise)
222
255
  ], ReleaseGoodMutation.prototype, "addReleaseGood", null);
223
- __decorate([
224
- (0, type_graphql_1.Directive)('@transaction'),
225
- (0, type_graphql_1.Mutation)(returns => [release_good_1.ReleaseGood]),
226
- __param(0, (0, type_graphql_1.Ctx)()),
227
- __param(1, (0, type_graphql_1.Arg)('rawReleaseGoods', type => [__1.NewReleaseGood], { nullable: true })),
228
- __param(2, (0, type_graphql_1.Arg)('bizplaceId', type => String)),
229
- __metadata("design:type", Function),
230
- __metadata("design:paramtypes", [Object, Array, String]),
231
- __metadata("design:returntype", Promise)
232
- ], ReleaseGoodMutation.prototype, "bulkAddReleaseGoods", null);
233
256
  ReleaseGoodMutation = __decorate([
234
257
  (0, type_graphql_1.Resolver)(release_good_1.ReleaseGood)
235
258
  ], ReleaseGoodMutation);
@@ -368,10 +391,32 @@ async function generateReleaseGoodFunction(_, releaseGood, shippingOrder, attach
368
391
  domain: warehouseDomain,
369
392
  refNo,
370
393
  status: (0, typeorm_1.Not)((0, typeorm_1.In)([constants_1.ORDER_STATUS.CANCELLED, constants_1.ORDER_STATUS.PENDING_CANCEL]))
371
- }
394
+ },
395
+ relations: ['bizplace', 'bizplace.domain', 'bizplace.company', 'bizplace.company.domain']
372
396
  });
373
- if (foundReleaseGood)
374
- throw new Error('Existing release order found');
397
+ if (foundReleaseGood) {
398
+ const customerCompanyDomain = foundReleaseGood.bizplace.company.domain;
399
+ const marketplaceOrder = await tx.getRepository(marketplace_base_1.MarketplaceOrder).findOne({
400
+ where: { orderNo: refNo, domain: customerCompanyDomain }
401
+ });
402
+ // Need to restructure the validation
403
+ if (marketplaceOrder.isSplitted) {
404
+ const refNo2 = releaseGood.refNo2;
405
+ const foundSplittedReleaseGood = await tx.getRepository(release_good_1.ReleaseGood).findOne({
406
+ where: {
407
+ domain: warehouseDomain,
408
+ refNo2,
409
+ status: (0, typeorm_1.Not)((0, typeorm_1.In)([constants_1.ORDER_STATUS.CANCELLED, constants_1.ORDER_STATUS.PENDING_CANCEL]))
410
+ },
411
+ relations: ['bizplace', 'bizplace.domain', 'bizplace.company', 'bizplace.company.domain']
412
+ });
413
+ if (foundSplittedReleaseGood)
414
+ throw new Error('Existing release order found');
415
+ }
416
+ else {
417
+ throw new Error('Existing release order found');
418
+ }
419
+ }
375
420
  }
376
421
  }
377
422
  let newReleaseGood = new release_good_1.ReleaseGood();
@@ -391,7 +436,7 @@ async function generateReleaseGoodFunction(_, releaseGood, shippingOrder, attach
391
436
  });
392
437
  newReleaseGood = Object.assign(Object.assign({}, newReleaseGood), { name: roNoSetting
393
438
  ? await (0, id_rule_base_1.generateId)({ domain, type: constants_1.ORDER_NUMBER_RULE_TYPE.RO_NUMBER, seed: {} })
394
- : utils_1.OrderNoGenerator.releaseGood(), domain: warehouseDomain, bizplace: bizplace, collectionOrderNo: releaseGood.collectionOrderNo, courierOption: releaseGood.courierOption, exportOption: releaseGood.exportOption, ownTransport: releaseGood.ownTransport, packingOption: releaseGood.packingOption, marketplaceOrderStatus: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.marketplaceOrderStatus) || null, billingAddress: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.billingAddress) || null, deliveryAddress1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress1) || null, deliveryAddress2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress2) || null, deliveryAddress3: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress3) || null, deliveryAddress4: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress4) || null, deliveryAddress5: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress5) || null, attentionTo: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionTo) || null, attentionCompany: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionCompany) || null, city: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.city) || null, state: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.state) || null, postalCode: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.postalCode) || null, country: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.country) || null, phone1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone1) || null, phone2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone2) || null, email: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.email) || null, transporter: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.transporter, trackingNo: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.trackingNo, airwayBill: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.airwayBill, invoice: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.invoice, refNo: releaseGood.refNo, refNo2: releaseGood.refNo2, refNo3: releaseGood.refNo3, releaseDate: releaseGood.releaseDate, truckNo: releaseGood.truckNo, orderInventories: releaseGood.orderInventories, type: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.type) ? releaseGood.type : 'b2b', status: constants_1.ORDER_STATUS.PENDING, creator: user, updater: user });
439
+ : utils_1.OrderNoGenerator.releaseGood(), domain: warehouseDomain, bizplace: bizplace, collectionOrderNo: releaseGood.collectionOrderNo, courierOption: releaseGood.courierOption, exportOption: releaseGood.exportOption, ownTransport: releaseGood.ownTransport, packingOption: releaseGood.packingOption, marketplaceOrderStatus: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.marketplaceOrderStatus) || null, billingAddress: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.billingAddress) || null, deliveryAddress1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress1) || null, deliveryAddress2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress2) || null, deliveryAddress3: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress3) || null, deliveryAddress4: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress4) || null, deliveryAddress5: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress5) || null, attentionTo: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionTo) || null, attentionCompany: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionCompany) || null, city: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.city) || null, state: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.state) || null, postalCode: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.postalCode) || null, country: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.country) || null, phone1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone1) || null, phone2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone2) || null, email: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.email) || null, transporter: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.transporter, trackingNo: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.trackingNo, airwayBill: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.airwayBill, invoice: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.invoice, refNo: releaseGood.refNo, refNo2: releaseGood.refNo2, refNo3: releaseGood.refNo3, releaseDate: releaseGood.releaseDate, truckNo: releaseGood.truckNo, bundleInfo: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.bundleInfo) || [], orderInventories: releaseGood.orderInventories, type: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.type) ? releaseGood.type : 'b2b', status: constants_1.ORDER_STATUS.PENDING, creator: user, updater: user });
395
440
  // Make relation with GAN for cross docking
396
441
  let crossDockingGAN = undefined;
397
442
  if (releaseGood.crossDocking && releaseGood.ganNo) {
@@ -402,7 +447,6 @@ async function generateReleaseGoodFunction(_, releaseGood, shippingOrder, attach
402
447
  throw new Error(`Failed to find GAN (${releaseGood.ganNo}) for cross docking`);
403
448
  newReleaseGood.arrivalNotice = crossDockingGAN;
404
449
  }
405
- newReleaseGood = await tx.getRepository(release_good_1.ReleaseGood).save(newReleaseGood);
406
450
  // Make relation with RO for cross docking
407
451
  if (newReleaseGood.crossDocking) {
408
452
  crossDockingGAN.releaseGood = newReleaseGood;
@@ -431,6 +475,8 @@ async function generateReleaseGoodFunction(_, releaseGood, shippingOrder, attach
431
475
  }));
432
476
  }
433
477
  orderInventories = [...singleProductOIs, ...splitBundleOIs];
478
+ newReleaseGood.noOfItems = orderInventories.length;
479
+ newReleaseGood = await tx.getRepository(release_good_1.ReleaseGood).save(newReleaseGood);
434
480
  for (let oi of orderInventories) {
435
481
  let newOrderInv = Object.assign({}, oi);
436
482
  newOrderInv = Object.assign(Object.assign({}, newOrderInv), { domain: warehouseDomain, bizplace: bizplace, status: constants_1.ORDER_INVENTORY_STATUS.PENDING, name: utils_1.OrderNoGenerator.orderInventory(), releaseGood: newReleaseGood, product: await tx.getRepository(product_base_1.Product).findOne(oi.product.id), creator: user, updater: user });
@@ -496,157 +542,6 @@ async function generateReleaseGoodFunction(_, releaseGood, shippingOrder, attach
496
542
  }
497
543
  }
498
544
  exports.generateReleaseGoodFunction = generateReleaseGoodFunction;
499
- async function bulkReleaseGoodsAvailableItemsFunction(rawReleaseGoods, bizplaceId, context, tx) {
500
- const { domain } = context.state;
501
- const companyBizplaceId = await (0, biz_base_1.getCompanyBizplace)(null, null, bizplaceId);
502
- if (!rawReleaseGoods)
503
- return;
504
- const json_oi = JSON.stringify(rawReleaseGoods.map(raw => {
505
- return {
506
- sku: raw.sku,
507
- packing_type: raw.packingType,
508
- packing_size: raw.packingSize,
509
- uom: raw.uom,
510
- release_qty: raw.releaseQty
511
- };
512
- }));
513
- await tx.query(`
514
- CREATE TEMP TABLE temp_order_products(
515
- product_id VARCHAR(50),
516
- sku VARCHAR(150),
517
- packing_type VARCHAR(50),
518
- packing_size INT,
519
- uom VARCHAR(10),
520
- release_qty INT
521
- );
522
- `);
523
- await tx.query(`
524
- INSERT INTO temp_order_products
525
- SELECT p.id AS product_id, js.sku,
526
- CASE WHEN js.packing_type NOTNULL AND js.packing_size NOTNULL THEN js.packing_type ELSE pd.packing_type END,
527
- CASE WHEN js.packing_type NOTNULL AND js.packing_size NOTNULL THEN js.packing_size ELSE pd.packing_size END,
528
- CASE WHEN js.uom NOTNULL THEN js.uom ELSE pd.uom END,
529
- js.release_qty
530
- FROM JSON_POPULATE_RECORDSET(NULL::temp_order_products,'${json_oi}') js
531
- LEFT JOIN products p ON js.sku = p.sku AND p.bizplace_id = $1
532
- LEFT JOIN product_details pd ON p.id = pd.product_id AND pd.is_default = TRUE;
533
- `, [companyBizplaceId.id]);
534
- let availableItems = await tx.query(`
535
- SELECT i.product_id, foo.sku, i.batch_id, i.packing_type, i.packing_size, i.uom,
536
- SUM(i.qty - COALESCE(i.locked_qty, 0)) - COALESCE(
537
- (
538
- SELECT SUM(oi.release_qty) FROM order_inventories oi
539
- WHERE (
540
- oi.status = 'PENDING'
541
- OR oi.status = 'PENDING_RECEIVE'
542
- OR oi.status = 'PENDING_WORKSHEET'
543
- OR oi.status = 'PENDING_SPLIT'
544
- )
545
- AND oi.inventory_id IS null
546
- AND oi.product_id = i.product_id::uuid
547
- AND oi.packing_type = i.packing_type
548
- AND oi.uom = i.uom
549
- AND oi.domain_id = $1
550
- AND oi.bizplace_id = $2
551
- ), 0) as "remain_qty",
552
- SUM(i.uom_value - COALESCE(i.locked_uom_value, 0)) - COALESCE(
553
- (
554
- SELECT SUM(oi.release_uom_value) FROM order_inventories oi
555
- WHERE (
556
- oi.status = 'PENDING'
557
- OR oi.status = 'PENDING_RECEIVE'
558
- OR oi.status = 'PENDING_WORKSHEET'
559
- OR oi.status = 'PENDING_SPLIT'
560
- )
561
- AND oi.inventory_id IS null
562
- AND oi.product_id = i.product_id::uuid
563
- AND oi.packing_type = i.packing_type
564
- AND oi.uom = i.uom
565
- AND oi.domain_id = $1
566
- AND oi.bizplace_id = $2
567
- ), 0) as "remain_uom_value"
568
- FROM inventories i
569
- INNER JOIN (
570
- SELECT top.product_id, top.sku, top.packing_type, top.packing_size, top.uom
571
- FROM temp_order_products top
572
- GROUP BY top.product_id, top.sku, top.packing_type, top.packing_size, top.uom
573
- ) AS foo
574
- ON i.product_id = foo.product_id::uuid
575
- AND i.packing_type = foo.packing_type
576
- AND i.packing_size = foo.packing_size
577
- AND i.uom = foo.uom
578
- AND i.domain_id = $1
579
- AND i.bizplace_id = $2
580
- GROUP BY i.product_id, foo.sku, i.batch_id, i.packing_type, i.packing_size, i.uom
581
- ORDER BY foo.sku, remain_qty
582
- `, [domain.id, bizplaceId]);
583
- await tx.query('DROP TABLE temp_order_products');
584
- availableItems = availableItems.map(item => {
585
- return {
586
- productId: item.product_id,
587
- sku: item.sku,
588
- batchId: item.batch_id,
589
- packingType: item.packing_type,
590
- packingSize: item.packing_size,
591
- uom: item.uom,
592
- remainQty: item.remain_qty,
593
- remainUomValue: item.remain_uom_value
594
- };
595
- });
596
- return _extractData(rawReleaseGoods, availableItems);
597
- }
598
- exports.bulkReleaseGoodsAvailableItemsFunction = bulkReleaseGoodsAvailableItemsFunction;
599
- function _extractData(rawData, validatedData) {
600
- return rawData.map(raw => {
601
- var _a, _b;
602
- const idx = validatedData.findIndex(val => {
603
- const comparison = ['packingType', 'packingSize', 'uom'];
604
- let a = {}, b = {};
605
- comparison.forEach(cc => {
606
- if (raw[cc]) {
607
- a[cc] = raw[cc];
608
- b[cc] = val[cc];
609
- }
610
- });
611
- a = JSON.stringify(Object.fromEntries(Object.entries(a).sort()));
612
- b = JSON.stringify(Object.fromEntries(Object.entries(b).sort()));
613
- return val.sku == raw.sku && a === b;
614
- });
615
- let releaseUomValue = 0;
616
- // if sku is matched, assign qty and product id
617
- if (idx >= 0) {
618
- // assign qty to rawData as much as possible
619
- releaseUomValue =
620
- (Math.round((((_a = validatedData[idx]) === null || _a === void 0 ? void 0 : _a.remainUomValue) / ((_b = validatedData[idx]) === null || _b === void 0 ? void 0 : _b.remainQty)) * 100) / 100) * raw.releaseQty;
621
- raw.assignedQty =
622
- validatedData[idx].remainQty >= raw.releaseQty
623
- ? raw.releaseQty > 0
624
- ? raw.releaseQty
625
- : 0
626
- : validatedData[idx].remainQty;
627
- raw.assignedUomValue =
628
- validatedData[idx].remainUomValue >= releaseUomValue
629
- ? releaseUomValue > 0
630
- ? releaseUomValue
631
- : 0
632
- : validatedData[idx].remainUomValue;
633
- // deduct qty & uomValue from validateData
634
- validatedData[idx].remainQty -= raw.assignedQty;
635
- validatedData[idx].remainUomValue -= raw.assignedUomValue;
636
- raw.productId = validatedData[idx].productId;
637
- raw.packingType = validatedData[idx].packingType;
638
- raw.packingSize = validatedData[idx].packingSize;
639
- raw.uom = validatedData[idx].uom;
640
- raw.batchId = validatedData[idx].batchId;
641
- }
642
- else {
643
- raw.assignedQty = 0;
644
- raw.assignedUomValue = 0;
645
- raw.productId = null;
646
- }
647
- return Object.assign(Object.assign({}, raw), { releaseUomValue });
648
- });
649
- }
650
545
  async function confirmReleaseGood(name, context, tx) {
651
546
  var _a;
652
547
  const { user, domain } = context.state;
@@ -660,6 +555,7 @@ async function confirmReleaseGood(name, context, tx) {
660
555
  'bizplace.company.domain',
661
556
  'orderProducts',
662
557
  'orderProducts.product',
558
+ 'orderProducts.product.productDetails',
663
559
  'orderInventories',
664
560
  'orderInventories.product',
665
561
  'orderVass'
@@ -668,24 +564,65 @@ async function confirmReleaseGood(name, context, tx) {
668
564
  if (!foundReleaseGood)
669
565
  throw new Error(`Release good order doesn't exists.`);
670
566
  let foundOIs = foundReleaseGood.orderInventories;
567
+ let foundBundleInfo = JSON.parse(foundReleaseGood.bundleInfo);
671
568
  let foundOVs = foundReleaseGood.orderVass;
569
+ let foundOPs = foundReleaseGood.orderProducts;
672
570
  let customerBizplace = foundReleaseGood.bizplace;
673
571
  const companyDomain = customerBizplace === null || customerBizplace === void 0 ? void 0 : customerBizplace.company.domain;
572
+ const sellercraft = await tx
573
+ .getRepository(integration_sellercraft_1.Sellercraft)
574
+ .findOne({ domain: foundReleaseGood.bizplace.domain, status: integration_sellercraft_1.SellercraftStatus.ACTIVE });
674
575
  if (foundReleaseGood.type == 'b2c') {
675
- const sellercraft = await tx
676
- .getRepository(integration_sellercraft_1.Sellercraft)
677
- .findOne({ domain: foundReleaseGood.bizplace.domain, status: integration_sellercraft_1.SellercraftStatus.ACTIVE });
678
576
  if (sellercraft) {
679
577
  const sellercraftCtrl = new controllers_1.SellercraftController(tx, domain, user);
680
578
  foundReleaseGood = await sellercraftCtrl.packOrder(sellercraft, foundReleaseGood);
681
579
  }
682
580
  else {
683
581
  // find for any existing marketplace store connections
684
- const marketplaceStores = await tx.getRepository(integration_marketplace_1.MarketplaceStore).find({
685
- where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
582
+ let marketplaceStores = await tx.getRepository(integration_marketplace_1.MarketplaceStore).find({
583
+ where: { domain: companyDomain, status: 'ACTIVE' },
686
584
  relations: ['marketplaceDistributors']
687
585
  });
586
+ const foundMarketplaceOrder = await tx.getRepository(marketplace_base_1.MarketplaceOrder).findOne({
587
+ where: { domain: companyDomain, orderNo: foundReleaseGood.refNo },
588
+ relations: ['marketplaceStore']
589
+ });
590
+ let matchedMarketplaceStore;
591
+ if (foundMarketplaceOrder) {
592
+ matchedMarketplaceStore = marketplaceStores.filter(marketplaceStore => marketplaceStore.id == foundMarketplaceOrder.marketplaceStore.id)[0];
593
+ }
594
+ let combinedOrderInventories = foundOIs.map(oi => {
595
+ return {
596
+ sku: oi.product.sku,
597
+ releaseQty: oi.releaseQty
598
+ };
599
+ });
600
+ if (foundBundleInfo === null || foundBundleInfo === void 0 ? void 0 : foundBundleInfo.length) {
601
+ foundBundleInfo.map(bundle => {
602
+ combinedOrderInventories.push({
603
+ sku: bundle.sku,
604
+ releaseQty: bundle.releaseQty
605
+ });
606
+ });
607
+ }
608
+ for (let oi of combinedOrderInventories) {
609
+ let foundMarketplaceProductVariations = await tx
610
+ .getRepository(marketplace_base_1.MarketplaceProductVariation)
611
+ .find({
612
+ where: { domain: companyDomain, sku: oi.sku },
613
+ relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
614
+ });
615
+ if (foundMarketplaceProductVariations) {
616
+ await Promise.all(foundMarketplaceProductVariations.map(async (variation) => {
617
+ if (variation.marketplaceProduct.marketplaceStore.id != matchedMarketplaceStore.id) {
618
+ variation.reserveQty -= oi.releaseQty;
619
+ await tx.getRepository(marketplace_base_1.MarketplaceProductVariation).save(variation);
620
+ }
621
+ }));
622
+ }
623
+ }
688
624
  if ((marketplaceStores === null || marketplaceStores === void 0 ? void 0 : marketplaceStores.length) && marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
625
+ marketplaceStores = marketplaceStores.filter(marketplaceStore => marketplaceStore.isAutoUpdateStockQty);
689
626
  let productIds = foundOIs.map(oi => oi.product.id);
690
627
  productIds = Array.from(new Set([...productIds]));
691
628
  const ecommerceCtrl = new controllers_1.EcommerceController(tx, domain, user);
@@ -693,6 +630,12 @@ async function confirmReleaseGood(name, context, tx) {
693
630
  }
694
631
  }
695
632
  }
633
+ if (foundReleaseGood.type == 'b2b') {
634
+ if (sellercraft) {
635
+ const sellercraftCtrl = new controllers_1.SellercraftController(tx, domain, user);
636
+ await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'CONFIRM_ORDER');
637
+ }
638
+ }
696
639
  // 1. RO Status change (PENDING => PENDING_RECEIVE)
697
640
  const releaseGood = await tx.getRepository(release_good_1.ReleaseGood).save(Object.assign(Object.assign({}, foundReleaseGood), { status: constants_1.ORDER_STATUS.PENDING_RECEIVE, updater: user }));
698
641
  // 1. Update status of order inventories
@@ -809,7 +752,17 @@ async function rejectReleaseGood(tx, context, name, remark) {
809
752
  const { domain, user } = context.state;
810
753
  const releaseGood = await tx.getRepository(release_good_1.ReleaseGood).findOne({
811
754
  where: { domain, name, status: constants_1.ORDER_STATUS.PENDING_RECEIVE },
812
- relations: ['bizplace', 'orderInventories', 'orderInventories.inventory', 'orderVass', 'shippingOrder']
755
+ relations: [
756
+ 'bizplace',
757
+ 'bizplace.domain',
758
+ 'orderProducts',
759
+ 'orderProducts.product',
760
+ 'orderProducts.product.productDetails',
761
+ 'orderInventories',
762
+ 'orderInventories.inventory',
763
+ 'orderVass',
764
+ 'shippingOrder'
765
+ ]
813
766
  });
814
767
  if (!releaseGood)
815
768
  throw new Error(`Release good doesn't exists.`);
@@ -817,6 +770,7 @@ async function rejectReleaseGood(tx, context, name, remark) {
817
770
  throw new Error('Remark is not exist.');
818
771
  let foundOIs = releaseGood.orderInventories;
819
772
  let foundOVs = releaseGood.orderVass;
773
+ let foundOPs = releaseGood.orderProducts;
820
774
  // 1. Update status of order products (PENDING_RECEIVE => REJECTED)
821
775
  if (foundOIs && foundOIs.length) {
822
776
  await tx.getRepository(__1.OrderInventory).save(await Promise.all(foundOIs.map(async (oi) => {
@@ -830,6 +784,20 @@ async function rejectReleaseGood(tx, context, name, remark) {
830
784
  return oi;
831
785
  })));
832
786
  }
787
+ if (foundOPs && foundOPs.length) {
788
+ const sellercraft = await tx
789
+ .getRepository(integration_sellercraft_1.Sellercraft)
790
+ .findOne({ domain: releaseGood.bizplace.domain, status: integration_sellercraft_1.SellercraftStatus.ACTIVE });
791
+ if (sellercraft) {
792
+ const sellercraftCtrl = new controllers_1.SellercraftController(tx, domain, user);
793
+ await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'REJECT_ORDER');
794
+ }
795
+ await tx.getRepository(__1.OrderProduct).save(await Promise.all(foundOPs.map(async (op) => {
796
+ op.status = constants_1.ORDER_PRODUCT_STATUS.REJECTED;
797
+ op.updater = user;
798
+ return op;
799
+ })));
800
+ }
833
801
  // 2. Update status of order vass if it exists (PENDING_RECEIVE => REJECTED)
834
802
  if (foundOVs && foundOVs.length) {
835
803
  foundOVs = foundOVs.map((ov) => {
@@ -870,32 +838,71 @@ async function rejectReleaseGood(tx, context, name, remark) {
870
838
  return releaseGood;
871
839
  }
872
840
  exports.rejectReleaseGood = rejectReleaseGood;
873
- async function bulkGenerateReleaseGoods(releaseGood, bizplaceId, roNoSetting, domain, user, tx) {
841
+ async function bulkGenerateReleaseGood(releaseGood, bizplaceId, roNoSetting, domain, user, tx) {
842
+ var _a, _b;
874
843
  try {
875
844
  let warehouseDomain = domain;
876
845
  let { orderInventories } = releaseGood;
877
846
  let bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne(bizplaceId);
878
847
  let newReleaseGood = Object.assign(Object.assign({}, releaseGood), { name: roNoSetting
879
848
  ? await (0, id_rule_base_1.generateId)({ domain, type: constants_1.ORDER_NUMBER_RULE_TYPE.RO_NUMBER, seed: {} })
880
- : utils_1.OrderNoGenerator.releaseGood(), domain: warehouseDomain, bizplace: bizplace, deliveryAddress1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress1) || null, deliveryAddress2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress2) || null, deliveryAddress3: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress3) || null, deliveryAddress4: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress4) || null, deliveryAddress5: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress5) || null, attentionTo: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionTo) || null, attentionCompany: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionCompany) || null, city: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.city) || null, state: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.state) || null, postalCode: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.postalCode) || null, country: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.country) || null, phone1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone1) || null, phone2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone2) || null, email: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.email) || null, airwayBill: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.airwayBill, refNo: releaseGood.refNo, refNo2: releaseGood.refNo2, refNo3: releaseGood.refNo3, releaseDate: releaseGood.releaseDate, ownTransport: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.ownTransport) || false, status: constants_1.ORDER_STATUS.PENDING, creator: user, updater: user });
849
+ : utils_1.OrderNoGenerator.releaseGood(), domain: warehouseDomain, bizplace: bizplace, deliveryAddress1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress1) || null, deliveryAddress2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress2) || null, deliveryAddress3: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress3) || null, deliveryAddress4: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.deliveryAddress4) || null, attentionTo: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionTo) || null, attentionCompany: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.attentionCompany) || null, city: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.city) || null, state: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.state) || null, postalCode: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.postalCode) || null, country: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.country) || null, phone1: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone1) || null, phone2: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.phone2) || null, email: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.email) || null, airwayBill: releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.airwayBill, refNo: releaseGood.refNo, refNo2: releaseGood.refNo2, refNo3: releaseGood.refNo3, releaseDate: releaseGood.releaseDate, ownTransport: (releaseGood === null || releaseGood === void 0 ? void 0 : releaseGood.ownTransport) || false, status: constants_1.ORDER_STATUS.PENDING, creator: user, updater: user });
881
850
  newReleaseGood = await tx.getRepository(release_good_1.ReleaseGood).save(newReleaseGood);
851
+ let finalOrderInventories = [];
852
+ // pre assign inventory to orderInventories
882
853
  for (let oi of orderInventories) {
883
- delete oi.sku;
884
- let newOrderInv = Object.assign(new __1.OrderInventory(), oi);
885
- newOrderInv = Object.assign(Object.assign({}, newOrderInv), { domain: warehouseDomain, bizplace: bizplace, status: constants_1.ORDER_INVENTORY_STATUS.PENDING, name: utils_1.OrderNoGenerator.orderInventory(), batchId: (oi === null || oi === void 0 ? void 0 : oi.batchId) || '', releaseGood: newReleaseGood, product: await tx.getRepository(product_base_1.Product).findOne(oi.productId), creator: user, updater: user });
886
- let newOrderProduct = Object.assign(new __1.OrderProduct(), newOrderInv);
887
- newOrderProduct = Object.assign(Object.assign({}, newOrderProduct), { packQty: 0, actualPackQty: 0, palletQty: 0, actualPalletQty: 0, status: constants_1.ORDER_PRODUCT_STATUS.PENDING_ASSIGN });
854
+ const pickingProductSetting = await tx.getRepository(setting_base_1.Setting).findOne({
855
+ where: { domain, name: 'rule-for-picking-product' }
856
+ });
857
+ let locationSortingRules = [];
858
+ if (pickingProductSetting) {
859
+ let locationSetting = JSON.parse(pickingProductSetting.value);
860
+ for (const key in locationSetting) {
861
+ locationSortingRules.push({ name: key, desc: locationSetting[key] == 'ASC' ? false : true });
862
+ }
863
+ }
864
+ const product = await tx.getRepository(product_base_1.Product).findOne(oi.productId);
865
+ finalOrderInventories.push(...(await utils_1.InventoryUtil.autoAssignInventoryForRelease(product, oi, oi.packingType, locationSortingRules, bizplace, warehouseDomain, tx)));
866
+ }
867
+ for (let oi of finalOrderInventories) {
868
+ let generatedOI = Object.assign(new __1.OrderInventory(), oi);
869
+ generatedOI = Object.assign(Object.assign({}, generatedOI), { domain: warehouseDomain, bizplace, status: constants_1.ORDER_INVENTORY_STATUS.PENDING, name: utils_1.OrderNoGenerator.orderInventory(), releaseGood: newReleaseGood, creator: user, updater: user });
870
+ let newOrderProduct = {
871
+ name: generatedOI.name,
872
+ product: generatedOI.product,
873
+ batchId: generatedOI.batchId,
874
+ packingType: generatedOI.packingType,
875
+ packingSize: generatedOI.packingSize,
876
+ uom: generatedOI.uom,
877
+ domain: warehouseDomain,
878
+ bizplace,
879
+ releaseQty: generatedOI.releaseQty,
880
+ releaseUomValue: generatedOI.releaseUomValue,
881
+ packQty: 0,
882
+ actualPackQty: 0,
883
+ palletQty: 0,
884
+ actualPalletQty: 0,
885
+ status: constants_1.ORDER_PRODUCT_STATUS.PENDING_ASSIGN,
886
+ releaseGood: newReleaseGood,
887
+ creator: user,
888
+ updater: user
889
+ };
888
890
  newOrderProduct = await tx.getRepository(__1.OrderProduct).save(newOrderProduct);
889
- await tx.getRepository(__1.OrderInventory).save(Object.assign(Object.assign({}, newOrderInv), { orderProduct: newOrderProduct }));
891
+ await tx.getRepository(__1.OrderInventory).save(Object.assign(Object.assign({}, generatedOI), { orderProduct: newOrderProduct }));
892
+ // update inventory locked qty and uom value
893
+ await tx.getRepository(warehouse_base_1.Inventory).update(oi.inventory.id, {
894
+ lockedQty: (((_a = oi.inventory) === null || _a === void 0 ? void 0 : _a.lockedQty) || 0) + generatedOI.releaseQty,
895
+ lockedUomValue: (((_b = oi.inventory) === null || _b === void 0 ? void 0 : _b.lockedUomValue) || 0) + generatedOI.releaseUomValue,
896
+ updater: user
897
+ });
890
898
  }
891
- // Change the status to PENDING_RECEIVE
892
899
  return newReleaseGood;
893
900
  }
894
901
  catch (error) {
895
902
  throw error;
896
903
  }
897
904
  }
898
- exports.bulkGenerateReleaseGoods = bulkGenerateReleaseGoods;
905
+ exports.bulkGenerateReleaseGood = bulkGenerateReleaseGood;
899
906
  async function bulkConfirmReleaseGoods(releaseGoodsNo, domain, user, context, tx) {
900
907
  var _a;
901
908
  let foundReleaseGoods = await tx.getRepository(release_good_1.ReleaseGood).find({
@@ -914,7 +921,7 @@ async function bulkConfirmReleaseGoods(releaseGoodsNo, domain, user, context, tx
914
921
  ]
915
922
  });
916
923
  if (!foundReleaseGoods.length)
917
- throw new Error(`Release good order doesn't exists.`);
924
+ throw new Error(`release good order doesn't exists.`);
918
925
  let customerBizplace = foundReleaseGoods[0].bizplace;
919
926
  let foundOrderInventories = foundReleaseGoods
920
927
  .map((releaseGood) => releaseGood.orderInventories)
@@ -992,6 +999,7 @@ function extractRawReleaseGoods(rawReleaseGoods) {
992
999
  });
993
1000
  if (idx >= 0) {
994
1001
  const duplicateSkuIdx = releaseGoods[idx].orderInventories.findIndex(oi => oi.sku === item.sku && oi.packingType === item.packingType && oi.packingSize === item.packingSize);
1002
+ // if there is duplicated SKU, merge them and sum up the releaseQty
995
1003
  if (duplicateSkuIdx >= 0) {
996
1004
  releaseGoods[idx].orderInventories[duplicateSkuIdx].releaseQty += item.releaseQty;
997
1005
  }
@@ -1039,5 +1047,4 @@ function extractRawReleaseGoods(rawReleaseGoods) {
1039
1047
  return releaseGoods;
1040
1048
  }, []);
1041
1049
  }
1042
- exports.extractRawReleaseGoods = extractRawReleaseGoods;
1043
1050
  //# sourceMappingURL=release-good-mutation.js.map