@things-factory/worksheet-base 4.3.184 → 4.3.186

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 (37) hide show
  1. package/dist-server/controllers/ecommerce/ecommerce-controller.js +4 -1
  2. package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
  3. package/dist-server/controllers/ecommerce/sellercraft-controller.js +10 -1
  4. package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
  5. package/dist-server/controllers/outbound/picking-worksheet-controller.js +13 -2
  6. package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
  7. package/dist-server/controllers/pos/xilnex-controller.js +5 -1
  8. package/dist-server/controllers/pos/xilnex-controller.js.map +1 -1
  9. package/dist-server/controllers/render-ro-do.js +7 -3
  10. package/dist-server/controllers/render-ro-do.js.map +1 -1
  11. package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js +23 -1
  12. package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js.map +1 -1
  13. package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js +36 -27
  14. package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js.map +1 -1
  15. package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +16 -2
  16. package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
  17. package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +15 -3
  18. package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
  19. package/dist-server/index.js +1 -0
  20. package/dist-server/index.js.map +1 -1
  21. package/dist-server/utils/index.js +1 -0
  22. package/dist-server/utils/index.js.map +1 -1
  23. package/dist-server/utils/lmd-util.js +76 -0
  24. package/dist-server/utils/lmd-util.js.map +1 -0
  25. package/package.json +13 -13
  26. package/server/controllers/ecommerce/ecommerce-controller.ts +4 -1
  27. package/server/controllers/ecommerce/sellercraft-controller.ts +15 -1
  28. package/server/controllers/outbound/picking-worksheet-controller.ts +18 -7
  29. package/server/controllers/pos/xilnex-controller.ts +6 -1
  30. package/server/controllers/render-ro-do.ts +4 -0
  31. package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +22 -1
  32. package/server/graphql/resolvers/worksheet/inventories-by-pallet.ts +80 -42
  33. package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +16 -2
  34. package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +16 -2
  35. package/server/index.ts +1 -0
  36. package/server/utils/index.ts +1 -0
  37. package/server/utils/lmd-util.ts +86 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLmdParcel = void 0;
4
+ const integration_lmd_1 = require("@things-factory/integration-lmd");
5
+ const env_1 = require("@things-factory/env");
6
+ const geography_1 = require("@things-factory/geography");
7
+ const biz_base_1 = require("@things-factory/biz-base");
8
+ const sales_base_1 = require("@things-factory/sales-base");
9
+ async function createLmdParcel(releaseGoods, tx) {
10
+ try {
11
+ let parcelsRequest = [];
12
+ for (let releaseGood of releaseGoods) {
13
+ const lmd = releaseGood.lastMileDelivery;
14
+ const bizplace = await tx.getRepository(biz_base_1.Bizplace).findOne({
15
+ where: { domain: releaseGood.domain },
16
+ relations: ['domain']
17
+ });
18
+ const senderGeoArea = await tx
19
+ .getRepository(geography_1.GeoArea)
20
+ .findOne({ where: { postalCode: bizplace.postalCode } });
21
+ let data = {
22
+ courier: lmd.platform,
23
+ clientId: lmd === null || lmd === void 0 ? void 0 : lmd.clientId,
24
+ clientPass: lmd === null || lmd === void 0 ? void 0 : lmd.secretKey,
25
+ pickupAccountId: lmd === null || lmd === void 0 ? void 0 : lmd.pickupAccountId,
26
+ soldToAccountId: lmd === null || lmd === void 0 ? void 0 : lmd.soldToAccountId,
27
+ token: lmd === null || lmd === void 0 ? void 0 : lmd.accessToken,
28
+ recipient: releaseGood.attentionTo,
29
+ phone: releaseGood.phone1,
30
+ email: releaseGood.email,
31
+ address: releaseGood.deliveryAddress1,
32
+ address2: releaseGood.deliveryAddress2,
33
+ city: releaseGood.city,
34
+ postcode: releaseGood.postalCode,
35
+ district: releaseGood.city,
36
+ state: releaseGood.state,
37
+ country: releaseGood.country,
38
+ pAddress: bizplace.address,
39
+ pAddress2: bizplace.address2,
40
+ pCity: senderGeoArea.cityName,
41
+ pPostcode: senderGeoArea.postalCode,
42
+ pDistrict: senderGeoArea.cityName,
43
+ pState: senderGeoArea.stateName,
44
+ pCountry: senderGeoArea.countryCode,
45
+ };
46
+ let unprocessedOrderPackages = releaseGood.orderPackages.filter(op => !op.parcelId);
47
+ let packagesData = unprocessedOrderPackages.map(op => {
48
+ return Object.assign(Object.assign({}, data), { refNo: op.id, items: op.orderPackageItems.map(opi => {
49
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
50
+ return {
51
+ quantity: ((_a = opi === null || opi === void 0 ? void 0 : opi.releaseQty) === null || _a === void 0 ? void 0 : _a.toString()) || ' ',
52
+ item: opi.orderProduct.product.name.slice(0, 49).trim() || ' ',
53
+ sku: opi.orderProduct.product.sku || ' ',
54
+ price: ((_c = (_b = opi === null || opi === void 0 ? void 0 : opi.orderProduct.productDetail) === null || _b === void 0 ? void 0 : _b.costPrice) === null || _c === void 0 ? void 0 : _c.toString()) || ' ',
55
+ weight: ((_e = (_d = opi === null || opi === void 0 ? void 0 : opi.orderProduct.productDetail) === null || _d === void 0 ? void 0 : _d.grossWeight) === null || _e === void 0 ? void 0 : _e.toString()) || ' ',
56
+ width: ((_g = (_f = opi === null || opi === void 0 ? void 0 : opi.orderProduct.productDetail) === null || _f === void 0 ? void 0 : _f.width) === null || _g === void 0 ? void 0 : _g.toString()) || ' ',
57
+ length: ((_j = (_h = opi === null || opi === void 0 ? void 0 : opi.orderProduct.productDetail) === null || _h === void 0 ? void 0 : _h.depth) === null || _j === void 0 ? void 0 : _j.toString()) || ' ',
58
+ height: ((_l = (_k = opi === null || opi === void 0 ? void 0 : opi.orderProduct.productDetail) === null || _k === void 0 ? void 0 : _k.height) === null || _l === void 0 ? void 0 : _l.toString()) || ' '
59
+ };
60
+ }) });
61
+ });
62
+ parcelsRequest.push(...packagesData);
63
+ }
64
+ if (parcelsRequest && parcelsRequest.length > 0) {
65
+ let res = await integration_lmd_1.LastMileAPI.createParcel(Object.assign(Object.assign({}, releaseGoods[0].lastMileDelivery), { platform: 'lmdMiddleware' }), parcelsRequest);
66
+ for (let parcel of res) {
67
+ await tx.getRepository(sales_base_1.OrderPackage).update({ id: parcel.refNo }, { parcelId: parcel.parcelId });
68
+ }
69
+ }
70
+ }
71
+ catch (e) {
72
+ env_1.logger.error(`[lmd-create-parcel]: ${e}`);
73
+ }
74
+ }
75
+ exports.createLmdParcel = createLmdParcel;
76
+ //# sourceMappingURL=lmd-util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lmd-util.js","sourceRoot":"","sources":["../../server/utils/lmd-util.ts"],"names":[],"mappings":";;;AAAA,qEAA+E;AAC/E,6CAA4C;AAC5C,yDAAmD;AACnD,uDAAmD;AACnD,2DAAsE;AAE/D,KAAK,UAAU,eAAe,CAAC,YAAY,EAAE,EAAE;IACpD,IAAI;QACF,IAAI,cAAc,GAAG,EAAE,CAAA;QACvB,KAAK,IAAI,WAAW,IAAI,YAAY,EAAE;YAEpC,MAAM,GAAG,GAAqB,WAAW,CAAC,gBAAgB,CAAA;YAE1D,MAAM,QAAQ,GAAa,MAAM,EAAE,CAAC,aAAa,CAAC,mBAAQ,CAAC,CAAC,OAAO,CAAC;gBAClE,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE;gBACrC,SAAS,EAAE,CAAC,QAAQ,CAAC;aACtB,CAAC,CAAA;YAEF,MAAM,aAAa,GAAY,MAAM,EAAE;iBACpC,aAAa,CAAC,mBAAO,CAAC;iBACtB,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EA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CAAC,CAAA;YACF,cAAc,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAA;SACrC;QAED,IAAI,cAAc,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/C,IAAI,GAAG,GAAG,MAAM,6BAAW,CAAC,YAAY,iCACjC,YAAY,CAAC,CAAC,CAAC,CAAC,gBAAgB,KAAE,QAAQ,EAAE,eAAe,KAChE,cAAc,CACf,CAAA;YACD,KAAK,IAAI,MAAM,IAAI,GAAG,EAAE;gBACtB,MAAM,EAAE,CAAC,aAAa,CAAC,yBAAY,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;aACjG;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,YAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,EAAE,CAAC,CAAA;KAC1C;AACH,CAAC;AA/ED,0CA+EC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/worksheet-base",
3
- "version": "4.3.184",
3
+ "version": "4.3.186",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -26,19 +26,19 @@
26
26
  "@things-factory/auth-base": "^4.3.179",
27
27
  "@things-factory/biz-base": "^4.3.179",
28
28
  "@things-factory/document-template-base": "^4.3.179",
29
- "@things-factory/id-rule-base": "^4.3.179",
30
- "@things-factory/integration-accounting": "^4.3.179",
31
- "@things-factory/integration-lmd": "^4.3.179",
32
- "@things-factory/integration-marketplace": "^4.3.179",
33
- "@things-factory/integration-sellercraft": "^4.3.179",
34
- "@things-factory/integration-sftp": "^4.3.179",
35
- "@things-factory/marketplace-base": "^4.3.180",
36
- "@things-factory/notification": "^4.3.179",
37
- "@things-factory/sales-base": "^4.3.184",
38
- "@things-factory/setting-base": "^4.3.179",
29
+ "@things-factory/id-rule-base": "^4.3.186",
30
+ "@things-factory/integration-accounting": "^4.3.186",
31
+ "@things-factory/integration-lmd": "^4.3.186",
32
+ "@things-factory/integration-marketplace": "^4.3.186",
33
+ "@things-factory/integration-sellercraft": "^4.3.186",
34
+ "@things-factory/integration-sftp": "^4.3.186",
35
+ "@things-factory/marketplace-base": "^4.3.186",
36
+ "@things-factory/notification": "^4.3.186",
37
+ "@things-factory/sales-base": "^4.3.186",
38
+ "@things-factory/setting-base": "^4.3.186",
39
39
  "@things-factory/shell": "^4.3.179",
40
40
  "@things-factory/transport-base": "^4.3.179",
41
- "@things-factory/warehouse-base": "^4.3.183"
41
+ "@things-factory/warehouse-base": "^4.3.186"
42
42
  },
43
- "gitHead": "e4ece27cb59de6b0b49ab8638f7f192eceb1b98c"
43
+ "gitHead": "854c79b134b5d94c5635c75c467eca229430183b"
44
44
  }
@@ -232,7 +232,7 @@ export class EcommerceController extends WorksheetController {
232
232
  ? marketplaceOrderShipping.ownTransporter
233
233
  : marketplaceOrderShipping.transporter
234
234
 
235
- const orderPackage: OrderPackage = {
235
+ let orderPackage: OrderPackage = {
236
236
  name: OrderNoGenerator.orderPackage(),
237
237
  packageId: null,
238
238
  trackingNo,
@@ -262,5 +262,8 @@ export class EcommerceController extends WorksheetController {
262
262
  })
263
263
 
264
264
  await tx.getRepository(OrderPackageItem).save(orderPackageItems)
265
+ orderPackage.orderPackageItems = orderPackageItems
266
+ releaseGood.orderPackages = [orderPackage]
267
+ return releaseGood
265
268
  }
266
269
  }
@@ -336,12 +336,26 @@ export class SellercraftController extends WorksheetController {
336
336
  .filter(op => op?.marketRtsCallSuccess == undefined)
337
337
  .map(async op => {
338
338
  if (!op?.packageId) throw new Error('Order package id is not found')
339
+ if (releaseGood.lmdOption && !op?.parcelId) return
339
340
 
340
- const orderInformation: any = {
341
+ let orderInformation: any = {
341
342
  accountId: sellercraft.accountId,
342
343
  orderId: releaseGood.refNo2,
343
344
  packageId: op.packageId
344
345
  }
346
+ if (releaseGood.lmdOption) {
347
+ let releaseGoodQuery: ReleaseGood = await getRepository(ReleaseGood).findOne({
348
+ where: { id: releaseGood.id },
349
+ relations: ['lastMileDelivery']
350
+ })
351
+ orderInformation = {
352
+ ...orderInformation,
353
+ awb: op.airwayBill,
354
+ trackingNo: op.trackingNo,
355
+ lmdOption: releaseGood.lmdOption,
356
+ shipperName: releaseGoodQuery.lastMileDelivery.platform
357
+ }
358
+ }
345
359
 
346
360
  try {
347
361
  await SellercraftAPI.initiateOrderShipment(sellercraft, {
@@ -2,7 +2,6 @@ import { EntityManager, Equal, getConnection, getManager, In, IsNull, Not } from
2
2
 
3
3
  import { ApplicationType } from '@things-factory/auth-base'
4
4
  import { Bizplace } from '@things-factory/biz-base'
5
- import { logger } from '@things-factory/env'
6
5
  import { generateId } from '@things-factory/id-rule-base'
7
6
  import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
8
7
  import { Product, ProductBarcode, ProductDetail } from '@things-factory/product-base'
@@ -40,6 +39,7 @@ import { SellercraftController } from '../../controllers'
40
39
  import { Worksheet, WorksheetDetail } from '../../entities'
41
40
  import { isInventoryObsolete, WorksheetNoGenerator } from '../../utils'
42
41
  import { VasWorksheetController } from '../vas/vas-worksheet-controller'
42
+ import { logger } from '@things-factory/env'
43
43
 
44
44
  export class PickingWorksheetController extends VasWorksheetController {
45
45
  async generatePickingWorksheet(releaseGoodNo: string, currentStatus: string = null): Promise<Worksheet> {
@@ -187,7 +187,13 @@ export class PickingWorksheetController extends VasWorksheetController {
187
187
  let worksheet: Worksheet = await this.findActivatableWorksheet(worksheetNo, WORKSHEET_TYPE.PICKING, [
188
188
  'releaseGood',
189
189
  'releaseGood.bizplace',
190
+ 'releaseGood.domain',
191
+ 'releaseGood.lastMileDelivery',
190
192
  'releaseGood.bizplace.domain',
193
+ 'releaseGood.orderPackages',
194
+ 'releaseGood.orderPackages.orderPackageItems',
195
+ 'releaseGood.orderPackages.orderPackageItems.orderProduct',
196
+ 'releaseGood.orderPackages.orderPackageItems.orderProduct.product',
191
197
  'domain',
192
198
  'bizplace',
193
199
  'bizplace.domain',
@@ -274,6 +280,7 @@ export class PickingWorksheetController extends VasWorksheetController {
274
280
  'worksheetDetails',
275
281
  'worksheetDetails.targetInventory',
276
282
  'worksheetDetails.targetInventory.releaseGood',
283
+ 'worksheetDetails.targetInventory.releaseGood.domain',
277
284
  'worksheetDetails.targetInventory.product',
278
285
  'bizplace',
279
286
  'bizplace.domain',
@@ -296,12 +303,16 @@ export class PickingWorksheetController extends VasWorksheetController {
296
303
  const pickingOrderInventory: OrderInventory[] = await this.trxMgr.getRepository(OrderInventory).find({
297
304
  where: { domain: this.domain, refWorksheetId: worksheet.id, status: ORDER_STATUS.PICKING },
298
305
  relations: [
299
- 'releaseGood',
300
- 'releaseGood.domain',
301
- 'releaseGood.bizplace',
302
- 'releaseGood.bizplace.domain',
303
- 'releaseGood.orderPackages'
304
- ]
306
+ 'releaseGood',
307
+ 'releaseGood.domain',
308
+ 'releaseGood.lastMileDelivery',
309
+ 'releaseGood.bizplace',
310
+ 'releaseGood.bizplace.domain',
311
+ 'releaseGood.orderPackages',
312
+ 'releaseGood.orderPackages.orderPackageItems',
313
+ 'releaseGood.orderPackages.orderPackageItems.orderProduct',
314
+ 'releaseGood.orderPackages.orderPackageItems.orderProduct.product'
315
+ ]
305
316
  })
306
317
 
307
318
  let releaseGoods: ReleaseGood[] = pickingOrderInventory.reduce((data, oi: OrderInventory) => {
@@ -7,6 +7,7 @@ import {
7
7
  DeliveryOrder,
8
8
  ORDER_SOURCE_TYPE,
9
9
  OrderInventory,
10
+ OrderProduct,
10
11
  ReleaseGood
11
12
  } from '@things-factory/sales-base'
12
13
  import { Inventory } from '@things-factory/warehouse-base'
@@ -31,14 +32,17 @@ export class XilnexController extends WorksheetController {
31
32
  .getRepository(Inventory)
32
33
  .createQueryBuilder('iv')
33
34
  .select('p.sku', 'productSku')
35
+ .addSelect('op.ref_item_id', 'refItemId')
34
36
  .addSelect('SUM(COALESCE(iv.qty,0))', 'totalQty')
35
37
  .addSelect('SUM(COALESCE(iv.unit_cost,0))', 'unitCost')
36
38
  .innerJoin('iv.location', 'loc')
37
39
  .innerJoin('iv.product', 'p')
40
+ .leftJoin(OrderProduct, 'op', 'iv.order_product_id::uuid = op.id::uuid')
38
41
  .where('"iv"."id" IN (:...inventoryIds)')
39
42
  .groupBy('iv.product_id')
40
43
  .addGroupBy('p.sku')
41
44
  .addGroupBy('iv.batch_id')
45
+ .addGroupBy('op.ref_item_id')
42
46
  .setParameters({
43
47
  inventoryIds: inventoryIds
44
48
  })
@@ -50,7 +54,8 @@ export class XilnexController extends WorksheetController {
50
54
  sku: item.productSku
51
55
  },
52
56
  actualPackQty: item.totalQty,
53
- unitPrice: item.unitCost
57
+ unitPrice: item.unitCost,
58
+ refItemId: item.refItemId
54
59
  }
55
60
  })
56
61
 
@@ -187,6 +187,7 @@ export async function renderRODO({ doNo }, context: any) {
187
187
  product_gross_weight: inventory.product.grossWeight,
188
188
  product_uom_value: targetInventory.releaseUomValue,
189
189
  product_uom: inventory.uom,
190
+ product_brand_sku: `${inventory.product?.brandSku || ''}`,
190
191
  remark: targetInventory.remark,
191
192
  inventory_remark: inventory.remark,
192
193
  cross_docking: targetInventory.crossDocking,
@@ -196,7 +197,9 @@ export async function renderRODO({ doNo }, context: any) {
196
197
  .reduce((newItem, item) => {
197
198
  var foundItem = newItem.find(
198
199
  newItem =>
200
+ newItem.product_sku === item.product_sku &&
199
201
  newItem.product_name === item.product_name &&
202
+ newItem.product_type === item.product_type &&
200
203
  newItem.product_batch === item.product_batch &&
201
204
  newItem.product_batch_ref === item.product_batch_ref &&
202
205
  newItem.cross_docking === item.cross_docking &&
@@ -217,6 +220,7 @@ export async function renderRODO({ doNo }, context: any) {
217
220
  product_uom: item.product_uom,
218
221
  product_desc: item.product_desc,
219
222
  product_nameOnly: item.product_nameOnly,
223
+ product_brand_sku: item.product_brand_sku,
220
224
  remark: item.remark,
221
225
  inventory_remark: item.inventory_remark,
222
226
  palletQty: 1,
@@ -22,6 +22,7 @@ import {
22
22
  } from '@things-factory/warehouse-base'
23
23
 
24
24
  import { Worksheet, WorksheetDetail } from '../../../entities'
25
+ import { LastMileAPI } from '@things-factory/integration-lmd'
25
26
 
26
27
  export const confirmCancellationReleaseOrder = {
27
28
  async confirmCancellationReleaseOrder(_: any, { name }, context: any) {
@@ -35,7 +36,9 @@ export const confirmCancellationReleaseOrder = {
35
36
  'orderInventories',
36
37
  'orderInventories.inventory',
37
38
  'orderInventories.inventory.location',
38
- 'orderVass'
39
+ 'orderVass',
40
+ 'lastMileDelivery',
41
+ 'orderPackages'
39
42
  ]
40
43
  })
41
44
 
@@ -232,6 +235,24 @@ export const confirmCancellationReleaseOrder = {
232
235
  createSalesReturn(account)
233
236
  }
234
237
 
238
+ // cancel consignment for lmd orders
239
+ if (releaseGood?.lmdOption && releaseGood?.lastMileDelivery && releaseGood?.orderPackages) {
240
+ for (let op of releaseGood.orderPackages) {
241
+ if (op?.parcelId) {
242
+ let res = await LastMileAPI.deleteParcel({...releaseGood.lastMileDelivery, platform: 'lmdMiddleware'}, {
243
+ clientId: releaseGood.lastMileDelivery?.clientId,
244
+ clientPass: releaseGood.lastMileDelivery?.secretKey,
245
+ soldToAccountId: releaseGood.lastMileDelivery?.soldToAccountId,
246
+ pickupAccountId: releaseGood.lastMileDelivery?.pickupAccountId,
247
+ token: releaseGood.lastMileDelivery?.accessToken,
248
+ parcelId: op.parcelId,
249
+ warehouse: domain?.name
250
+ })
251
+ if (!res?.status) throw new Error('cannot cancel consignment note')
252
+ }
253
+ }
254
+ }
255
+
235
256
  return
236
257
  }
237
258
  }
@@ -1,16 +1,28 @@
1
- import { Brackets, getRepository, SelectQueryBuilder } from 'typeorm'
1
+ import {
2
+ Brackets,
3
+ getRepository,
4
+ SelectQueryBuilder
5
+ } from 'typeorm'
2
6
 
3
7
  import { User } from '@things-factory/auth-base'
4
8
  import { getPermittedBizplaceIds } from '@things-factory/biz-base'
5
9
  import { ORDER_INVENTORY_STATUS } from '@things-factory/sales-base'
6
- import { buildCondition, buildQuery, Domain } from '@things-factory/shell'
7
- import { Inventory, LOCATION_TYPE } from '@things-factory/warehouse-base'
10
+ import {
11
+ buildCondition,
12
+ buildQuery,
13
+ Domain
14
+ } from '@things-factory/shell'
15
+ import {
16
+ Inventory,
17
+ LOCATION_TYPE
18
+ } from '@things-factory/warehouse-base'
8
19
 
9
20
  export const inventoriesByPalletResolver = {
10
21
  async inventoriesByPallet(_: any, { filters, pagination, sortings, locationSortingRules }, context: any) {
11
22
  const { domain, user }: { domain: Domain; user: User } = context.state
12
23
  const params = { filters, pagination }
13
24
  let permittedBizplaceIds: string[] = await getPermittedBizplaceIds(domain, user)
25
+ const bizplaceId = params.filters.find(x => x.name == 'bizplace_id')
14
26
  const productFilters = params.filters.filter(x => x.name == 'productName')
15
27
  const recallFilters = params.filters.find(x => x.name === 'recall')
16
28
  const skipLockCheckFilters = params.filters.find(x => x.name === 'skipLockCheck')
@@ -18,17 +30,10 @@ export const inventoriesByPalletResolver = {
18
30
  skipLockCheckFilters && skipLockCheckFilters?.value ? skipLockCheckFilters?.value : false
19
31
  const productFilterColumns = ['sku', 'brandSku', 'name', 'description', 'brand', 'subBrand']
20
32
  params.filters = params.filters.filter(x => x.name != 'productName')
33
+ const batchIdFilters = params.filters.find(x => x.name == 'batchId')
21
34
 
22
- if (!params.filters.find((filter: any) => filter.name === 'bizplace')) {
23
- params.filters.push({
24
- name: 'bizplace',
25
- operator: 'in',
26
- value: permittedBizplaceIds,
27
- relation: true
28
- })
29
- } else {
30
- permittedBizplaceIds = params.filters.find(filter => filter.name === 'bizplace').value
31
- params.filters.find(filter => filter.name === 'bizplace').relation = true
35
+ if (!params.filters.find((filter: any) => filter.name === 'bizplace_id')) {
36
+ throw new Error('No Bizplace found')
32
37
  }
33
38
 
34
39
  const locationFilters = params.filters.find(x => x.name == 'locationName')
@@ -63,12 +68,37 @@ export const inventoriesByPalletResolver = {
63
68
  oi.product_id = p2.id
64
69
  WHERE
65
70
  oi.status = '${ORDER_INVENTORY_STATUS.PENDING_SPLIT}'
66
- AND oi.bizplace_id IN (:...permittedBizplaceIds)
67
71
  AND oi.domain_id = (:domainId)
72
+ AND oi.bizplace_id = (:bizplaceId)
68
73
  )`,
69
- { permittedBizplaceIds, domainId: domain.id }
74
+ { bizplaceId: bizplaceId.value , domainId: domain.id }
70
75
  )
71
76
 
77
+ if (locationFilters) {
78
+ qb.andWhere
79
+ (`location.name ilike '${locationFilters.value}'`)
80
+ }
81
+
82
+ if (productFilters && productFilters.length > 0) {
83
+ let productInfo = productFilters[0]
84
+ qb.andWhere(
85
+ new Brackets(qb2 => {
86
+ productFilterColumns.forEach(filter => {
87
+ const condition = buildCondition(
88
+ 'product',
89
+ filter,
90
+ 'i_like',
91
+ productInfo.value,
92
+ false,
93
+ Object.keys(qb.getParameters()).length
94
+ )
95
+
96
+ qb2.orWhere(condition.clause, condition.parameters)
97
+ })
98
+ })
99
+ )
100
+ }
101
+
72
102
  if (!skipLockCheck) {
73
103
  qb.andWhere('CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END >= 0')
74
104
  qb.andWhere('iv.qty - CASE WHEN iv.lockedQty IS NULL THEN 0 ELSE iv.lockedQty END > 0')
@@ -76,8 +106,39 @@ export const inventoriesByPalletResolver = {
76
106
 
77
107
  if (recallFilters?.value === true) {
78
108
  qb.orWhere(
79
- '(iv.obsolete = true or case when iv.expiration_date is not null and product.shelf_life is not null then CURRENT_DATE > iv.expiration_date - product.shelf_life else true end)'
80
- )
109
+ '(iv.domain_id = (:domainId) and iv.bizplace_id = (:bizplaceId)'
110
+ )
111
+ if (locationFilters){
112
+ qb.andWhere
113
+ (`location.name ilike '${locationFilters.value}'`)
114
+ }
115
+ if (productFilters && productFilters.length > 0) {
116
+ let productInfo = productFilters[0]
117
+ qb.andWhere(
118
+ new Brackets(qb2 => {
119
+ productFilterColumns.forEach(filter => {
120
+ const condition = buildCondition(
121
+ 'product',
122
+ filter,
123
+ 'i_like',
124
+ productInfo.value,
125
+ false,
126
+ Object.keys(qb.getParameters()).length
127
+ )
128
+
129
+ qb2.orWhere(condition.clause, condition.parameters)
130
+ })
131
+ })
132
+ )
133
+ }
134
+ if (batchIdFilters) {
135
+ qb.andWhere(
136
+ `iv.batch_id ilike '${batchIdFilters.value}'`
137
+ )
138
+ }
139
+ qb.andWhere(
140
+ 'iv.obsolete = true and case when iv.expiration_date is not null and product.shelf_life is not null then CURRENT_DATE > iv.expiration_date - product.shelf_life else true end)'
141
+ )
81
142
  } else {
82
143
  qb.andWhere('iv.obsolete = false')
83
144
  qb.andWhere(
@@ -85,9 +146,7 @@ export const inventoriesByPalletResolver = {
85
146
  )
86
147
  }
87
148
 
88
- if (locationFilters) {
89
- qb.andWhere(`location.name ilike '${locationFilters.value}'`)
90
- }
149
+ let [items, total] = await qb.getManyAndCount()
91
150
 
92
151
  if (sortings?.length !== 0) {
93
152
  const arrChildSortData = ['productName', 'productSKU']
@@ -112,27 +171,6 @@ export const inventoriesByPalletResolver = {
112
171
  qb.addOrderBy('location.name', 'DESC')
113
172
  }
114
173
 
115
- if (productFilters && productFilters.length > 0) {
116
- let productInfo = productFilters[0]
117
- qb.andWhere(
118
- new Brackets(qb2 => {
119
- productFilterColumns.forEach(filter => {
120
- const condition = buildCondition(
121
- 'product',
122
- filter,
123
- 'i_like',
124
- productInfo.value,
125
- false,
126
- Object.keys(qb.getParameters()).length
127
- )
128
-
129
- qb2.orWhere(condition.clause, condition.parameters)
130
- })
131
- })
132
- )
133
- }
134
- let [items, total] = await qb.getManyAndCount()
135
-
136
174
  items = await Promise.all(
137
175
  items.map(async (item: Inventory) => {
138
176
  const { remainQty, remainUomValue } = await getRemainAmount(item)
@@ -161,4 +199,4 @@ async function getRemainAmount(inventory: Inventory): Promise<{ remainQty: numbe
161
199
  remainQty: inventory.qty - (inventory.lockedQty || 0),
162
200
  remainUomValue: inventory.uomValue - (inventory.lockedUomValue || 0)
163
201
  }
164
- }
202
+ }
@@ -26,6 +26,7 @@ import {
26
26
  import { EcommerceController } from '../../../../controllers/ecommerce'
27
27
  import { WorksheetController } from '../../../../controllers/worksheet-controller'
28
28
  import { Worksheet, WorksheetDetail } from '../../../../entities'
29
+ import { createLmdParcel } from '../../../../utils'
29
30
 
30
31
  export const completeBatchPickingResolver = {
31
32
  async completeBatchPicking(_: any, { taskNo }, context: any) {
@@ -81,9 +82,14 @@ export async function completeBatchPicking(
81
82
  'domain',
82
83
  'creator',
83
84
  'updater',
85
+ 'lastMileDelivery',
84
86
  'orderPackages',
87
+ 'orderPackages.orderPackageItems',
88
+ 'orderPackages.orderPackageItems.orderProduct',
89
+ 'orderPackages.orderPackageItems.orderProduct.product',
85
90
  'orderProducts',
86
91
  'orderProducts.product',
92
+ 'orderProducts.productDetail',
87
93
  'bizplace',
88
94
  'bizplace.company',
89
95
  'bizplace.company.domain'
@@ -138,7 +144,7 @@ export async function completeBatchPicking(
138
144
  if (marketplaceStore?.isAutoUpdateShipment) {
139
145
  await ecommerceCtrl.createOrderShip(foundReleaseGood, marketplaceStore, marketplaceOrder, companyDomain)
140
146
  }
141
- await ecommerceCtrl.createOrderPackage(
147
+ foundReleaseGood = await ecommerceCtrl.createOrderPackage(
142
148
  tx,
143
149
  marketplaceOrder,
144
150
  companyDomain,
@@ -148,7 +154,7 @@ export async function completeBatchPicking(
148
154
  break
149
155
 
150
156
  default:
151
- const orderPackage: OrderPackage = {
157
+ let orderPackage: OrderPackage = {
152
158
  name: OrderNoGenerator.orderPackage(),
153
159
  packageId: null,
154
160
  trackingNo: null,
@@ -178,8 +184,16 @@ export async function completeBatchPicking(
178
184
  })
179
185
 
180
186
  await tx.getRepository(OrderPackageItem).save(orderPackageItems)
187
+ orderPackage.orderPackageItems = orderPackageItems
188
+ foundReleaseGood.orderPackages = [orderPackage]
181
189
  break
182
190
  }
191
+
192
+ // trigger LMD API to create parcel
193
+ if (foundReleaseGood?.orderPackages?.length && foundReleaseGood.lmdOption && foundReleaseGood.lastMileDelivery && foundReleaseGood?.orderPackages?.some(op => op.parcelId == null)){
194
+ await createLmdParcel([foundReleaseGood], tx)
195
+ }
196
+ //
183
197
  }
184
198
 
185
199
  const pickPackTargetInventories: OrderInventory[] = targetInventories
@@ -37,6 +37,7 @@ import {
37
37
  import { EcommerceController } from '../../../../controllers/ecommerce'
38
38
  import { WorksheetController } from '../../../../controllers/worksheet-controller'
39
39
  import { Worksheet, WorksheetDetail } from '../../../../entities'
40
+ import { createLmdParcel } from '../../../../utils'
40
41
 
41
42
  export const completePickingResolver = {
42
43
  async completePicking(_: any, { releaseGoodNo }, context: any) {
@@ -72,7 +73,11 @@ export async function completePicking(
72
73
  'bizplace.domain',
73
74
  'bizplace.company',
74
75
  'bizplace.company.domain',
76
+ 'lastMileDelivery',
75
77
  'orderPackages',
78
+ 'orderPackages.orderPackageItems',
79
+ 'orderPackages.orderPackageItems.orderProduct',
80
+ 'orderPackages.orderPackageItems.orderProduct.product',
76
81
  'orderProducts',
77
82
  'orderProducts.product',
78
83
  'orderProducts.productDetail',
@@ -258,12 +263,12 @@ export async function completePicking(
258
263
  }
259
264
  }
260
265
 
261
- await ecommerceCtrl.createOrderPackage(tx, marketplaceOrder, companyDomain, marketplaceStore, releaseGood)
266
+ releaseGood = await ecommerceCtrl.createOrderPackage(tx, marketplaceOrder, companyDomain, marketplaceStore, releaseGood)
262
267
  }
263
268
  break
264
269
 
265
270
  default:
266
- const orderPackage: OrderPackage = {
271
+ let orderPackage: OrderPackage = {
267
272
  name: OrderNoGenerator.orderPackage(),
268
273
  packageId: null,
269
274
  trackingNo: null,
@@ -293,6 +298,8 @@ export async function completePicking(
293
298
  })
294
299
 
295
300
  await tx.getRepository(OrderPackageItem).save(orderPackageItems)
301
+ orderPackage.orderPackageItems = orderPackageItems
302
+ releaseGood.orderPackages = [orderPackage]
296
303
  break
297
304
  }
298
305
 
@@ -431,6 +438,13 @@ export async function completePicking(
431
438
  await loadingWSCtrl.activateLoading(loadingWorksheet.name, loadingWorksheetDetails)
432
439
  }
433
440
  }
441
+
442
+ // trigger LMD API to create parcel
443
+ if (releaseGood?.orderPackages?.length && releaseGood.lmdOption && releaseGood.lastMileDelivery && releaseGood?.orderPackages?.some(op => op.parcelId == null)){
444
+ await createLmdParcel([releaseGood], tx)
445
+ }
446
+ //
447
+
434
448
  } else {
435
449
  //update inventories obsolete to true
436
450
  await tx.getRepository(Inventory).update({ id: In(foundObsoleteInventories) }, { obsolete: true })
package/server/index.ts CHANGED
@@ -6,3 +6,4 @@ export * from './graphql'
6
6
  export * from './graphql/resolvers/worksheet/generate-worksheet/generate-release-good-worksheet'
7
7
  export * from './graphql/resolvers/worksheet-detail/generate-release-good-worksheet-details'
8
8
  export * from './migrations'
9
+ export * from './utils'
@@ -2,3 +2,4 @@ export * from './inventory-util'
2
2
  export * from './worksheet-no-generator'
3
3
  export * from './datetime-util'
4
4
  export * from './worksheet-util'
5
+ export * from './lmd-util'