@things-factory/worksheet-base 4.3.367 → 4.3.369

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 (25) hide show
  1. package/dist-server/controllers/outbound/picking-worksheet-controller.js +111 -140
  2. package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
  3. package/dist-server/entities/active-worksheet-picking-view.js +141 -0
  4. package/dist-server/entities/active-worksheet-picking-view.js.map +1 -0
  5. package/dist-server/entities/index.js +4 -1
  6. package/dist-server/entities/index.js.map +1 -1
  7. package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js +64 -55
  8. package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js.map +1 -1
  9. package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +3 -0
  10. package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
  11. package/dist-server/graphql/resolvers/worksheet/picking/fetch-and-assign-picking-task.js +2 -1
  12. package/dist-server/graphql/resolvers/worksheet/picking/fetch-and-assign-picking-task.js.map +1 -1
  13. package/dist-server/graphql/resolvers/worksheet/picking-worksheet.js +73 -71
  14. package/dist-server/graphql/resolvers/worksheet/picking-worksheet.js.map +1 -1
  15. package/dist-server/graphql/resolvers/worksheet/worksheet.js +0 -3
  16. package/dist-server/graphql/resolvers/worksheet/worksheet.js.map +1 -1
  17. package/package.json +4 -4
  18. package/server/controllers/outbound/picking-worksheet-controller.ts +134 -167
  19. package/server/entities/active-worksheet-picking-view.ts +118 -0
  20. package/server/entities/index.ts +4 -0
  21. package/server/graphql/resolvers/worksheet/picking/activate-picking.ts +73 -67
  22. package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +4 -1
  23. package/server/graphql/resolvers/worksheet/picking/fetch-and-assign-picking-task.ts +3 -2
  24. package/server/graphql/resolvers/worksheet/picking-worksheet.ts +82 -80
  25. package/server/graphql/resolvers/worksheet/worksheet.ts +0 -3
@@ -7,7 +7,7 @@ import { ORDER_STATUS, ReleaseGood } from '@things-factory/sales-base'
7
7
  import { Domain } from '@things-factory/shell'
8
8
 
9
9
  import { EcommerceController, PickingWorksheetController } from '../../../../controllers'
10
- import { Worksheet } from '../../../../entities'
10
+ import { ActiveWorksheetPickingView, Worksheet } from '../../../../entities'
11
11
 
12
12
  export const activatePickingResolver = {
13
13
  async activatePicking(_: any, { worksheetNo }, context: any) {
@@ -22,77 +22,83 @@ export async function activatePicking(
22
22
  user: User,
23
23
  worksheetNo: string
24
24
  ): Promise<Worksheet> {
25
- const worksheetController: PickingWorksheetController = new PickingWorksheetController(tx, domain, user)
26
- const worksheet = await worksheetController.activatePicking(worksheetNo)
27
- const companyDomain: Domain = worksheet?.bizplace.company.domain
28
-
29
- let releaseGood: ReleaseGood = worksheet.releaseGood
30
-
31
- const orderSource: string = releaseGood.source
32
- switch (orderSource) {
33
- case ApplicationType.MMS:
34
- // find for any existing marketplace store connections
35
- const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
36
- where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
37
- relations: ['marketplaceDistributors']
38
- })
39
-
40
- if (marketplaceStores?.length) {
41
- if (marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
42
- const worksheetDetails = worksheet.worksheetDetails
43
- let orderInventories: any[] = worksheetDetails.map(wsd => wsd.targetInventory)
44
- const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
45
- await ecommerceCtrl.updateProductVariationStock(marketplaceStores, orderInventories, companyDomain)
46
- }
47
-
48
- const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
49
- where: { orderNo: releaseGood.refNo, domain: companyDomain },
50
- relations: ['marketplaceStore']
25
+ try {
26
+ const worksheetController: PickingWorksheetController = new PickingWorksheetController(tx, domain, user)
27
+ const worksheet = await worksheetController.activatePicking(worksheetNo)
28
+ const companyDomain: Domain = worksheet?.bizplace.company.domain
29
+
30
+ let releaseGood: ReleaseGood = worksheet.releaseGood
31
+
32
+ const orderSource: string = releaseGood.source
33
+ switch (orderSource) {
34
+ case ApplicationType.MMS:
35
+ // find for any existing marketplace store connections
36
+ const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
37
+ where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
38
+ relations: ['marketplaceDistributors']
51
39
  })
52
40
 
53
- if (marketplaceOrder) {
54
- const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
55
-
56
- if (marketplaceStore.isAutoUpdateShipment) {
41
+ if (marketplaceStores?.length) {
42
+ if (marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
43
+ const worksheetDetails = worksheet.worksheetDetails
44
+ let orderInventories: any[] = worksheetDetails.map(wsd => wsd.targetInventory)
57
45
  const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
58
- await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PICKING)
46
+ await ecommerceCtrl.updateProductVariationStock(marketplaceStores, orderInventories, companyDomain)
59
47
  }
60
- }
61
- }
62
- break
63
48
 
64
- default:
65
- break
49
+ const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
50
+ where: { orderNo: releaseGood.refNo, domain: companyDomain },
51
+ relations: ['marketplaceStore']
52
+ })
53
+
54
+ if (marketplaceOrder) {
55
+ const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
56
+
57
+ if (marketplaceStore.isAutoUpdateShipment) {
58
+ const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
59
+ await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PICKING)
60
+ }
61
+ }
62
+ }
63
+ break
64
+
65
+ default:
66
+ break
67
+ }
68
+
69
+ // if (releaseGood.type === 'b2c') {
70
+ // const sellercraft: Sellercraft = await tx
71
+ // .getRepository(Sellercraft)
72
+ // .findOne({ domain: worksheet.bizplace.domain, status: SellercraftStatus.ACTIVE })
73
+
74
+ // if (marketplaceStores?.length && !sellercraft) {
75
+ // if (marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
76
+ // const worksheetDetails = worksheet.worksheetDetails
77
+ // let orderInventories: any[] = worksheetDetails.map(wsd => wsd.targetInventory)
78
+ // const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
79
+ // await ecommerceCtrl.updateProductVariationStock(marketplaceStores, orderInventories, companyDomain)
80
+ // }
81
+
82
+ // const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
83
+ // where: { orderNo: releaseGood.refNo, domain: companyDomain },
84
+ // relations: ['marketplaceStore']
85
+ // })
86
+
87
+ // if (marketplaceOrder) {
88
+ // const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
89
+
90
+ // if (marketplaceStore.isAutoUpdateShipment) {
91
+ // const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
92
+ // await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PICKING)
93
+ // }
94
+ // }
95
+ // }
96
+ // }
97
+ return worksheet
98
+ } catch (error) {
99
+ throw error
100
+ } finally {
101
+ ActiveWorksheetPickingView.refreshView()
66
102
  }
67
103
 
68
- // if (releaseGood.type === 'b2c') {
69
- // const sellercraft: Sellercraft = await tx
70
- // .getRepository(Sellercraft)
71
- // .findOne({ domain: worksheet.bizplace.domain, status: SellercraftStatus.ACTIVE })
72
-
73
- // if (marketplaceStores?.length && !sellercraft) {
74
- // if (marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
75
- // const worksheetDetails = worksheet.worksheetDetails
76
- // let orderInventories: any[] = worksheetDetails.map(wsd => wsd.targetInventory)
77
- // const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
78
- // await ecommerceCtrl.updateProductVariationStock(marketplaceStores, orderInventories, companyDomain)
79
- // }
80
-
81
- // const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
82
- // where: { orderNo: releaseGood.refNo, domain: companyDomain },
83
- // relations: ['marketplaceStore']
84
- // })
85
-
86
- // if (marketplaceOrder) {
87
- // const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
88
-
89
- // if (marketplaceStore.isAutoUpdateShipment) {
90
- // const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
91
- // await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PICKING)
92
- // }
93
- // }
94
- // }
95
- // }
96
-
97
- return worksheet
98
104
  }
@@ -67,7 +67,8 @@ import { EcommerceController } from '../../../../controllers/ecommerce'
67
67
  import { WorksheetController } from '../../../../controllers/worksheet-controller'
68
68
  import {
69
69
  Worksheet,
70
- WorksheetDetail
70
+ WorksheetDetail,
71
+ ActiveWorksheetPickingView
71
72
  } from '../../../../entities'
72
73
  import { createLmdParcel } from '../../../../utils'
73
74
  import { activateVas } from '../vas/activate-vas'
@@ -577,5 +578,7 @@ export async function completePicking(
577
578
  }
578
579
  } catch (error) {
579
580
  throw error
581
+ } finally {
582
+ ActiveWorksheetPickingView.refreshView()
580
583
  }
581
584
  }
@@ -11,7 +11,7 @@ import { pickingWorksheet } from '../picking-worksheet'
11
11
  import { activatePicking } from './activate-picking'
12
12
 
13
13
  export const fetchAndAssignPickingTaskResolver = {
14
- async fetchAndAssignPickingTask(_: any, {}, context: any) {
14
+ async fetchAndAssignPickingTask(_: any, { }, context: any) {
15
15
  try {
16
16
  const { tx, domain, user }: { tx: EntityManager; domain: Domain; user: User } = context.state
17
17
  const assignee: User = await tx.getRepository(User).findOne(user.id, { relations: ['domains'] })
@@ -108,7 +108,8 @@ export const fetchAndAssignPickingTaskResolver = {
108
108
 
109
109
  const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne(worksheet.releaseGood.id)
110
110
 
111
- return await pickingWorksheet(domain, releaseGood.name, locationSortingRule, tx)
111
+ let data = await pickingWorksheet(domain, releaseGood.name, locationSortingRule, tx)
112
+ return data
112
113
  } catch (error) {
113
114
  throw error
114
115
  }
@@ -36,26 +36,28 @@ export async function pickingWorksheet(domain: Domain, orderNo: String, location
36
36
  where: { domain, name: orderNo }
37
37
  })
38
38
 
39
- const orderInventoryByBin: OrderInventory = await tx.getRepository(OrderInventory).findOne({
40
- where: {
41
- domain,
42
- binLocation,
43
- status: In([ORDER_INVENTORY_STATUS.PICKING, ORDER_INVENTORY_STATUS.PICKED])
44
- },
45
- order: {
46
- createdAt: 'ASC'
47
- },
48
- relations: ['releaseGood', 'releaseGood.bizplace', 'releaseGood.bizplace.domain']
49
- })
39
+ if (binLocation) {
40
+ const orderInventoryByBin: OrderInventory = await tx.getRepository(OrderInventory).findOne({
41
+ where: {
42
+ domain,
43
+ binLocation,
44
+ status: In([ORDER_INVENTORY_STATUS.PICKING, ORDER_INVENTORY_STATUS.PICKED])
45
+ },
46
+ order: {
47
+ createdAt: 'ASC'
48
+ },
49
+ relations: ['releaseGood', 'releaseGood.bizplace', 'releaseGood.bizplace.domain']
50
+ })
50
51
 
51
- if (orderInventoryByBin?.releaseGood) {
52
- orderNo = orderInventoryByBin.releaseGood.name
53
- releaseGood = orderInventoryByBin.releaseGood
52
+ if (orderInventoryByBin?.releaseGood) {
53
+ orderNo = orderInventoryByBin.releaseGood.name
54
+ releaseGood = orderInventoryByBin.releaseGood
55
+ }
54
56
  }
55
57
  }
56
58
 
57
59
  if (!releaseGood) {
58
- const replenishment = await replenishmentWorksheet(orderNo)
60
+ const replenishment = await replenishmentWorksheet(orderNo, tx, domain, locationSortingRules)
59
61
 
60
62
  if (!replenishment) {
61
63
  throw new Error(`Couldn't find picking worksheet by order no (${orderNo})`)
@@ -157,76 +159,76 @@ export async function pickingWorksheet(domain: Domain, orderNo: String, location
157
159
  })
158
160
  }
159
161
  }
162
+ }
160
163
 
161
- async function replenishmentWorksheet(orderNo: String) {
162
- let replenishment: Replenishment = await tx.getRepository(Replenishment).findOne({
163
- where: { domain, name: orderNo }
164
- })
164
+ async function replenishmentWorksheet(orderNo: String, tx, domain, locationSortingRules) {
165
+ let replenishment: Replenishment = await tx.getRepository(Replenishment).findOne({
166
+ where: { domain, name: orderNo }
167
+ })
165
168
 
166
- if (replenishment) {
167
- const worksheet = await fetchExecutingWorksheet(
168
- domain,
169
- null,
170
- [],
171
- WORKSHEET_TYPE.PICKING_REPLENISHMENT,
172
- replenishment,
173
- tx
174
- )
175
-
176
- const qb: SelectQueryBuilder<WorksheetDetail> = tx.createQueryBuilder(WorksheetDetail, 'WSD')
177
- qb.leftJoinAndSelect('WSD.targetInventory', 'T_INV')
178
- .leftJoinAndSelect('T_INV.binLocation', 'BIN_LOC')
179
- .leftJoinAndSelect('T_INV.inventory', 'INV')
180
- .leftJoinAndSelect('T_INV.product', 'PROD')
181
- .leftJoinAndSelect('T_INV.productDetail', 'PROD_DET')
182
- .leftJoinAndSelect('INV.location', 'LOC')
183
-
184
- if (locationSortingRules?.length > 0) {
185
- locationSortingRules.forEach((rule: { name: string; desc: boolean }) => {
186
- qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
187
- })
188
- }
169
+ if (replenishment) {
170
+ const worksheet = await fetchExecutingWorksheet(
171
+ domain,
172
+ null,
173
+ [],
174
+ WORKSHEET_TYPE.PICKING_REPLENISHMENT,
175
+ replenishment,
176
+ tx
177
+ )
178
+
179
+ const qb: SelectQueryBuilder<WorksheetDetail> = tx.createQueryBuilder(WorksheetDetail, 'WSD')
180
+ qb.leftJoinAndSelect('WSD.targetInventory', 'T_INV')
181
+ .leftJoinAndSelect('T_INV.binLocation', 'BIN_LOC')
182
+ .leftJoinAndSelect('T_INV.inventory', 'INV')
183
+ .leftJoinAndSelect('T_INV.product', 'PROD')
184
+ .leftJoinAndSelect('T_INV.productDetail', 'PROD_DET')
185
+ .leftJoinAndSelect('INV.location', 'LOC')
189
186
 
190
- qb.addOrderBy(`PROD.name`, 'ASC')
187
+ if (locationSortingRules?.length > 0) {
188
+ locationSortingRules.forEach((rule: { name: string; desc: boolean }) => {
189
+ qb.addOrderBy(`LOC.${rule.name}`, rule.desc ? 'DESC' : 'ASC')
190
+ })
191
+ }
191
192
 
192
- const worksheetDetails: WorksheetDetail[] = await qb
193
- .where('"WSD"."worksheet_id" = :worksheetId', { worksheetId: worksheet.id })
194
- .andWhere('"WSD"."status" != :status', { status: WORKSHEET_STATUS.REPLACED })
195
- .andWhere('"T_INV"."status" != :t_invstatus', { t_invstatus: ORDER_INVENTORY_STATUS.CANCELLED })
196
- .getMany()
193
+ qb.addOrderBy(`PROD.name`, 'ASC')
197
194
 
198
- return {
199
- worksheetInfo: {
200
- startedAt: worksheet.startedAt,
201
- replenishment
202
- },
203
- worksheetDetailInfos: worksheetDetails.map(async (pickingWSD: WorksheetDetail) => {
204
- const targetInventory: OrderInventory = pickingWSD.targetInventory
205
- const inventory: Inventory = targetInventory.inventory
206
-
207
- return {
208
- name: pickingWSD.name,
209
- palletId: inventory?.palletId,
210
- cartonId: inventory?.cartonId,
211
- batchId: inventory?.batchId,
212
- batchIdRef: inventory?.batchIdRef,
213
- product: inventory?.product,
214
- qty: inventory?.qty,
215
- binLocation: targetInventory?.binLocation || '',
216
- releaseQty: targetInventory.releaseQty,
217
- pickedQty: targetInventory.pickedQty,
218
- status: pickingWSD.status,
219
- description: pickingWSD.description,
220
- targetName: targetInventory.name,
221
- packingType: inventory?.packingType,
222
- packingSize: inventory?.packingSize,
223
- expirationDate: inventory?.expirationDate,
224
- location: inventory?.location,
225
- relatedOrderInv: targetInventory
226
- }
227
- })
228
- }
195
+ const worksheetDetails: WorksheetDetail[] = await qb
196
+ .where('"WSD"."worksheet_id" = :worksheetId', { worksheetId: worksheet.id })
197
+ .andWhere('"WSD"."status" != :status', { status: WORKSHEET_STATUS.REPLACED })
198
+ .andWhere('"T_INV"."status" != :t_invstatus', { t_invstatus: ORDER_INVENTORY_STATUS.CANCELLED })
199
+ .getMany()
200
+
201
+ return {
202
+ worksheetInfo: {
203
+ startedAt: worksheet.startedAt,
204
+ replenishment
205
+ },
206
+ worksheetDetailInfos: worksheetDetails.map(async (pickingWSD: WorksheetDetail) => {
207
+ const targetInventory: OrderInventory = pickingWSD.targetInventory
208
+ const inventory: Inventory = targetInventory.inventory
209
+
210
+ return {
211
+ name: pickingWSD.name,
212
+ palletId: inventory?.palletId,
213
+ cartonId: inventory?.cartonId,
214
+ batchId: inventory?.batchId,
215
+ batchIdRef: inventory?.batchIdRef,
216
+ product: inventory?.product,
217
+ qty: inventory?.qty,
218
+ binLocation: targetInventory?.binLocation || '',
219
+ releaseQty: targetInventory.releaseQty,
220
+ pickedQty: targetInventory.pickedQty,
221
+ status: pickingWSD.status,
222
+ description: pickingWSD.description,
223
+ targetName: targetInventory.name,
224
+ packingType: inventory?.packingType,
225
+ packingSize: inventory?.packingSize,
226
+ expirationDate: inventory?.expirationDate,
227
+ location: inventory?.location,
228
+ relatedOrderInv: targetInventory
229
+ }
230
+ })
229
231
  }
230
- return replenishment
231
232
  }
233
+ return replenishment
232
234
  }
@@ -18,7 +18,6 @@ interface WorksheetInterface extends Worksheet {
18
18
 
19
19
  export const worksheetResolver = {
20
20
  async worksheet(_: any, { name }, context: any) {
21
- console.time('query for worksheet')
22
21
  const { domain }: { domain: Domain } = context.state
23
22
 
24
23
  let worksheet: WorksheetInterface
@@ -377,7 +376,6 @@ export const worksheetResolver = {
377
376
  relations: ['targetProduct']
378
377
  })
379
378
  }
380
- console.timeEnd('query for worksheet')
381
379
  return worksheet
382
380
  },
383
381
 
@@ -449,7 +447,6 @@ export const worksheetResolver = {
449
447
  }
450
448
  })
451
449
 
452
- // console.time('map')
453
450
  let worksheet: WorksheetInterface = {
454
451
  ...foundWorksheet,
455
452
  worksheetDetails: worksheetDetails,