@things-factory/worksheet-base 4.3.150 → 4.3.152
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/controllers/ecommerce/sellercraft-controller.js +74 -55
- package/dist-server/controllers/ecommerce/sellercraft-controller.js.map +1 -1
- package/dist-server/controllers/outbound/packing-worksheet-controller.js +8 -7
- package/dist-server/controllers/outbound/packing-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/picking-worksheet-controller.js +79 -5
- package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +6 -6
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +3 -3
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/package.json +18 -18
- package/server/controllers/ecommerce/sellercraft-controller.ts +90 -68
- package/server/controllers/outbound/packing-worksheet-controller.ts +6 -8
- package/server/controllers/outbound/picking-worksheet-controller.ts +93 -11
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +93 -100
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bizplace } from '@things-factory/biz-base'
|
|
2
2
|
import { Sellercraft, SellercraftAPI } from '@things-factory/integration-sellercraft'
|
|
3
|
+
import { logger } from '@things-factory/env'
|
|
3
4
|
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
4
5
|
import {
|
|
5
6
|
ArrivalNotice,
|
|
@@ -17,6 +18,8 @@ import { Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/ware
|
|
|
17
18
|
|
|
18
19
|
import { WorksheetController } from '../worksheet-controller'
|
|
19
20
|
|
|
21
|
+
import { getRepository } from 'typeorm'
|
|
22
|
+
|
|
20
23
|
export class SellercraftController extends WorksheetController {
|
|
21
24
|
async packOrder(sellercraft: Sellercraft, releaseGood: ReleaseGood): Promise<ReleaseGood> {
|
|
22
25
|
let sellercraftSetting: any = sellercraft.sellercraftSetting
|
|
@@ -37,63 +40,68 @@ export class SellercraftController extends WorksheetController {
|
|
|
37
40
|
}
|
|
38
41
|
})
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (orderPack?.packages) {
|
|
51
|
-
const packages: any[] = orderPack.packages
|
|
52
|
-
|
|
53
|
-
await this.trxMgr
|
|
54
|
-
.getRepository(ReleaseGood)
|
|
55
|
-
.update({ id: releaseGood.id }, { packageId: packages[0].packageId, updatedAt: new Date() })
|
|
56
|
-
|
|
57
|
-
await Promise.all(
|
|
58
|
-
packages.map(async pkg => {
|
|
59
|
-
const items = pkg.items
|
|
60
|
-
const orderPackage: OrderPackage = {
|
|
61
|
-
name: OrderNoGenerator.orderPackage(),
|
|
62
|
-
packageId: pkg.packageId,
|
|
63
|
-
status: ORDER_STATUS.PROCESSING,
|
|
64
|
-
releaseGood,
|
|
65
|
-
domain: releaseGood.domain,
|
|
66
|
-
bizplace: releaseGood.bizplace,
|
|
67
|
-
creator: releaseGood.creator,
|
|
68
|
-
updater: releaseGood.updater
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
let savedOrderPackage: OrderPackage = await this.trxMgr.getRepository(OrderPackage).save(orderPackage)
|
|
43
|
+
try {
|
|
44
|
+
const orderInformation: any = {
|
|
45
|
+
accountId: sellercraft.accountId,
|
|
46
|
+
orderId: releaseGood.refNo2,
|
|
47
|
+
sellercraftOPs
|
|
48
|
+
}
|
|
49
|
+
const orderPack: any = await SellercraftAPI.packMarketplaceOrder(sellercraft, {
|
|
50
|
+
...orderInformation,
|
|
51
|
+
context: { state: { domain: this?.domain, user: this?.user } }
|
|
52
|
+
})
|
|
72
53
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const matchedOrderProduct: OrderProduct = orderProducts.find(op => op.product.sku == sku)
|
|
54
|
+
if (orderPack?.packages) {
|
|
55
|
+
const packages: any[] = orderPack.packages
|
|
76
56
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
57
|
+
await Promise.all(
|
|
58
|
+
packages.map(async pkg => {
|
|
59
|
+
const items = pkg.items
|
|
60
|
+
const orderPackage: OrderPackage = {
|
|
61
|
+
name: OrderNoGenerator.orderPackage(),
|
|
62
|
+
packageId: pkg.packageId,
|
|
80
63
|
status: ORDER_STATUS.PROCESSING,
|
|
81
|
-
|
|
82
|
-
orderPackage: savedOrderPackage,
|
|
64
|
+
releaseGood,
|
|
83
65
|
domain: releaseGood.domain,
|
|
84
66
|
bizplace: releaseGood.bizplace,
|
|
85
67
|
creator: releaseGood.creator,
|
|
86
68
|
updater: releaseGood.updater
|
|
87
69
|
}
|
|
70
|
+
|
|
71
|
+
let savedOrderPackage: OrderPackage = await this.trxMgr.getRepository(OrderPackage).save(orderPackage)
|
|
72
|
+
|
|
73
|
+
const orderPackageItems: OrderPackageItem[] = items.map(itm => {
|
|
74
|
+
const { sku, qty } = itm
|
|
75
|
+
const matchedOrderProduct: OrderProduct = orderProducts.find(op => op.product.sku == sku)
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
name: OrderNoGenerator.orderPackageItem(),
|
|
79
|
+
orderProduct: matchedOrderProduct,
|
|
80
|
+
status: ORDER_STATUS.PROCESSING,
|
|
81
|
+
releaseQty: qty,
|
|
82
|
+
orderPackage: savedOrderPackage,
|
|
83
|
+
domain: releaseGood.domain,
|
|
84
|
+
bizplace: releaseGood.bizplace,
|
|
85
|
+
creator: releaseGood.creator,
|
|
86
|
+
updater: releaseGood.updater
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
await this.trxMgr.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
88
91
|
})
|
|
92
|
+
)
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
await this.trxMgr
|
|
95
|
+
.getRepository(ReleaseGood)
|
|
96
|
+
.update({ id: releaseGood.id }, { packageId: packages[0].packageId, marketPackCallSuccess: new Date(), updatedAt: new Date() })
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
logger.error(`sellercraft-controller[packOrder]: ${error}`)
|
|
100
|
+
throw error
|
|
93
101
|
}
|
|
94
|
-
}
|
|
95
102
|
|
|
96
|
-
|
|
103
|
+
return releaseGood
|
|
104
|
+
}
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
async registerProductInbound(sellercraft: Sellercraft, arrivalNotice: ArrivalNotice): Promise<void> {
|
|
@@ -307,36 +315,50 @@ export class SellercraftController extends WorksheetController {
|
|
|
307
315
|
}
|
|
308
316
|
|
|
309
317
|
async initiateOrderShipment(sellercraft: Sellercraft, releaseGood: ReleaseGood): Promise<void> {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
318
|
+
try {
|
|
319
|
+
let sellercraftSetting: any = sellercraft.sellercraftSetting
|
|
320
|
+
let disableInitiateOrderShipment: boolean =
|
|
321
|
+
sellercraftSetting?.disableInitiateOrderShipment && sellercraftSetting?.disableInitiateOrderShipment == 1
|
|
322
|
+
? true
|
|
323
|
+
: false
|
|
315
324
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
325
|
+
if (!disableInitiateOrderShipment) {
|
|
326
|
+
let orderPackages: OrderPackage[] = await this.trxMgr
|
|
327
|
+
.getRepository(OrderPackage)
|
|
328
|
+
.find({ where: { releaseGood, bizplace: releaseGood.bizplace } })
|
|
320
329
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
330
|
+
if (orderPackages?.length) {
|
|
331
|
+
await Promise.all(
|
|
332
|
+
orderPackages.filter(op => op?.marketRtsCallSuccess == undefined).map(async op => {
|
|
333
|
+
if (!op?.packageId) throw new Error('Order package id is not found')
|
|
325
334
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
335
|
+
const orderInformation: any = {
|
|
336
|
+
accountId: sellercraft.accountId,
|
|
337
|
+
orderId: releaseGood.refNo2,
|
|
338
|
+
packageId: op.packageId
|
|
339
|
+
}
|
|
331
340
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
341
|
+
try {
|
|
342
|
+
await SellercraftAPI.initiateOrderShipment(sellercraft, {
|
|
343
|
+
...orderInformation,
|
|
344
|
+
context: { state: { domain: this?.domain, user: this?.user } }
|
|
345
|
+
})
|
|
346
|
+
await getRepository(OrderPackage).update({ id: op.id }, { marketRtsCallSuccess: new Date() })
|
|
347
|
+
} catch (error) {
|
|
348
|
+
logger.error(`sellercraft-controller[initiateOrderShipment]: ${JSON.stringify({
|
|
349
|
+
...orderInformation,
|
|
350
|
+
context: { state: { domain: this?.domain, user: this?.user } },
|
|
351
|
+
error: error
|
|
352
|
+
})}`)
|
|
353
|
+
}
|
|
335
354
|
})
|
|
336
|
-
|
|
337
|
-
|
|
355
|
+
)
|
|
356
|
+
}
|
|
338
357
|
}
|
|
358
|
+
} catch (error) {
|
|
359
|
+
throw error
|
|
339
360
|
}
|
|
361
|
+
|
|
340
362
|
}
|
|
341
363
|
|
|
342
364
|
async initiateOrderDocument(sellercraft: Sellercraft, releaseGood: ReleaseGood): Promise<void> {
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
OrderProduct,
|
|
14
14
|
ReleaseGood
|
|
15
15
|
} from '@things-factory/sales-base'
|
|
16
|
-
import { Setting } from '@things-factory/setting-base'
|
|
17
16
|
import {
|
|
18
17
|
Inventory,
|
|
19
18
|
INVENTORY_ITEM_SOURCE,
|
|
@@ -102,15 +101,10 @@ export class PackingWorksheetController extends VasWorksheetController {
|
|
|
102
101
|
if (sellercraft) {
|
|
103
102
|
const sellercraftCtrl: SellercraftController = new SellercraftController(this.trxMgr, this.domain, this.user)
|
|
104
103
|
|
|
105
|
-
const rtsTriggerLevel: Setting = await this.trxMgr.getRepository(Setting).findOne({
|
|
106
|
-
where: { domain: this.domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
107
|
-
})
|
|
108
|
-
|
|
109
104
|
let rtsOrderDoc = async (sellercraft: any, releaseGood: any, domain: any, user: any) => {
|
|
110
105
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
106
|
+
// trigger RTS
|
|
107
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
114
108
|
|
|
115
109
|
await sellercraftCtrl.initiateOrderDocument(sellercraft, releaseGood)
|
|
116
110
|
} catch (error) {
|
|
@@ -269,6 +263,8 @@ export class PackingWorksheetController extends VasWorksheetController {
|
|
|
269
263
|
|
|
270
264
|
if (orderPackageItem.packedQty == orderPackageItem.releaseQty) {
|
|
271
265
|
orderPackageItem.status = ORDER_STATUS.DONE
|
|
266
|
+
} else if (orderPackageItem.packedQty > orderPackageItem.releaseQty) {
|
|
267
|
+
throw new Error(this.ERROR_MSG.VALIDITY.CANT_PROCEED_STEP_BY('pack', `packed quantity can't exceed release qty`))
|
|
272
268
|
}
|
|
273
269
|
|
|
274
270
|
await this.trxMgr.getRepository(OrderPackageItem).save(orderPackageItem)
|
|
@@ -433,6 +429,8 @@ export class PackingWorksheetController extends VasWorksheetController {
|
|
|
433
429
|
|
|
434
430
|
if (orderPackageItem.packedQty == orderPackageItem.releaseQty) {
|
|
435
431
|
orderPackageItem.status = ORDER_STATUS.DONE
|
|
432
|
+
} else if (orderPackageItem.packedQty > orderPackageItem.releaseQty) {
|
|
433
|
+
throw new Error(this.ERROR_MSG.VALIDITY.CANT_PROCEED_STEP_BY('pack', `packed quantity can't exceed release qty`))
|
|
436
434
|
}
|
|
437
435
|
|
|
438
436
|
await this.trxMgr.getRepository(OrderPackageItem).save(orderPackageItem)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { EntityManager, Equal, getConnection, In, IsNull, Not } from 'typeorm'
|
|
1
|
+
import { EntityManager, Equal, getConnection, In, IsNull, Not, getManager } from 'typeorm'
|
|
2
2
|
|
|
3
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
3
4
|
import { Bizplace } from '@things-factory/biz-base'
|
|
4
5
|
import { generateId } from '@things-factory/id-rule-base'
|
|
5
6
|
import { Product, ProductDetail, ProductBarcode } from '@things-factory/product-base'
|
|
@@ -38,6 +39,9 @@ import { Worksheet, WorksheetDetail } from '../../entities'
|
|
|
38
39
|
import { WorksheetNoGenerator } from '../../utils'
|
|
39
40
|
import { VasWorksheetController } from '../vas/vas-worksheet-controller'
|
|
40
41
|
|
|
42
|
+
import { SellercraftController } from '../../controllers'
|
|
43
|
+
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
44
|
+
|
|
41
45
|
export class PickingWorksheetController extends VasWorksheetController {
|
|
42
46
|
async generatePickingWorksheet(releaseGoodNo: string, currentStatus: string = null): Promise<Worksheet> {
|
|
43
47
|
let releaseGood: ReleaseGood = await this.findRefOrder(
|
|
@@ -184,6 +188,7 @@ export class PickingWorksheetController extends VasWorksheetController {
|
|
|
184
188
|
let worksheet: Worksheet = await this.findActivatableWorksheet(worksheetNo, WORKSHEET_TYPE.PICKING, [
|
|
185
189
|
'releaseGood',
|
|
186
190
|
'releaseGood.bizplace',
|
|
191
|
+
'releaseGood.bizplace.domain',
|
|
187
192
|
'domain',
|
|
188
193
|
'bizplace',
|
|
189
194
|
'bizplace.domain',
|
|
@@ -215,7 +220,7 @@ export class PickingWorksheetController extends VasWorksheetController {
|
|
|
215
220
|
if (vasWorksheet) {
|
|
216
221
|
await this.activateVAS(vasWorksheet.name, vasWorksheet.worksheetDetails)
|
|
217
222
|
}
|
|
218
|
-
} catch (e) {}
|
|
223
|
+
} catch (e) { }
|
|
219
224
|
|
|
220
225
|
const pendingSplitOIs: OrderInventory[] = await this.trxMgr.getRepository(OrderInventory).find({
|
|
221
226
|
where: { domain: this.domain, releaseGood, status: ORDER_INVENTORY_STATUS.PENDING_SPLIT }
|
|
@@ -225,6 +230,39 @@ export class PickingWorksheetController extends VasWorksheetController {
|
|
|
225
230
|
await this.trxMgr.getRepository(OrderInventory).delete(ids)
|
|
226
231
|
}
|
|
227
232
|
|
|
233
|
+
try {
|
|
234
|
+
// trigger SC pack order asynchronously
|
|
235
|
+
const orderSource: string = releaseGood?.source
|
|
236
|
+
switch (orderSource) {
|
|
237
|
+
case ApplicationType.SELLERCRAFT:
|
|
238
|
+
getManager().transaction(async txMgr => {
|
|
239
|
+
const sellercraft: Sellercraft = await txMgr
|
|
240
|
+
.getRepository(Sellercraft)
|
|
241
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
242
|
+
|
|
243
|
+
if (sellercraft) {
|
|
244
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, this.domain, this.user)
|
|
245
|
+
|
|
246
|
+
if (!releaseGood?.orderPackages?.length) {
|
|
247
|
+
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
248
|
+
where: { releaseGood },
|
|
249
|
+
relations: ['product', 'product.productDetails']
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
// asynchronously pack order
|
|
253
|
+
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
break
|
|
258
|
+
|
|
259
|
+
default:
|
|
260
|
+
break
|
|
261
|
+
}
|
|
262
|
+
} catch (error) {
|
|
263
|
+
logger.error(`picking-worksheet-controller[activatePicking]: ${error}`)
|
|
264
|
+
}
|
|
265
|
+
|
|
228
266
|
return worksheet
|
|
229
267
|
}
|
|
230
268
|
|
|
@@ -254,19 +292,63 @@ export class PickingWorksheetController extends VasWorksheetController {
|
|
|
254
292
|
// retrieve order inventory
|
|
255
293
|
const pickingOrderInventory: OrderInventory[] = await this.trxMgr.getRepository(OrderInventory).find({
|
|
256
294
|
where: { domain: this.domain, refWorksheetId: worksheet.id, status: ORDER_STATUS.PICKING },
|
|
257
|
-
relations: [
|
|
295
|
+
relations: [
|
|
296
|
+
'releaseGood',
|
|
297
|
+
'releaseGood.bizplace',
|
|
298
|
+
'releaseGood.bizplace.domain',
|
|
299
|
+
'releaseGood.orderPackages'
|
|
300
|
+
]
|
|
258
301
|
})
|
|
259
302
|
|
|
260
|
-
let releaseGoods: ReleaseGood[] = pickingOrderInventory.
|
|
303
|
+
let releaseGoods: ReleaseGood[] = pickingOrderInventory.reduce((data, oi: OrderInventory) => {
|
|
304
|
+
if (!data.find(x => x.id == oi.releaseGood.id)) {
|
|
305
|
+
data.push(oi.releaseGood)
|
|
306
|
+
}
|
|
307
|
+
return data
|
|
308
|
+
}, [])
|
|
261
309
|
|
|
310
|
+
// massage data and trigger SC pack order asynchronously
|
|
262
311
|
if (releaseGoods?.length) {
|
|
263
|
-
releaseGoods =
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
312
|
+
releaseGoods = await Promise.all(
|
|
313
|
+
releaseGoods.map(async (releaseGood: ReleaseGood) => {
|
|
314
|
+
try {
|
|
315
|
+
const orderSource: string = releaseGood?.source
|
|
316
|
+
switch (orderSource) {
|
|
317
|
+
case ApplicationType.SELLERCRAFT:
|
|
318
|
+
getManager().transaction(async txMgr => {
|
|
319
|
+
const sellercraft: Sellercraft = await txMgr
|
|
320
|
+
.getRepository(Sellercraft)
|
|
321
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
322
|
+
|
|
323
|
+
if (sellercraft) {
|
|
324
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, this.domain, this.user)
|
|
325
|
+
|
|
326
|
+
if (!releaseGood?.orderPackages?.length) {
|
|
327
|
+
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
328
|
+
where: { releaseGood },
|
|
329
|
+
relations: ['product', 'product.productDetails']
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
// asynchronously pack order
|
|
333
|
+
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
break
|
|
338
|
+
|
|
339
|
+
default:
|
|
340
|
+
break
|
|
341
|
+
}
|
|
342
|
+
} catch (error) {
|
|
343
|
+
logger.error(`picking-worksheet-controller[activateBatchPicking]: ${error}`)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return {
|
|
347
|
+
...releaseGood,
|
|
348
|
+
status: ORDER_STATUS.PICKING,
|
|
349
|
+
updater: this.user
|
|
350
|
+
}
|
|
351
|
+
}))
|
|
270
352
|
await this.trxMgr.getRepository(ReleaseGood).save(releaseGoods)
|
|
271
353
|
}
|
|
272
354
|
|
|
@@ -11,7 +11,8 @@ import {
|
|
|
11
11
|
OrderNoGenerator,
|
|
12
12
|
OrderPackage,
|
|
13
13
|
OrderPackageItem,
|
|
14
|
-
ReleaseGood
|
|
14
|
+
ReleaseGood,
|
|
15
|
+
OrderProduct
|
|
15
16
|
} from '@things-factory/sales-base'
|
|
16
17
|
import { Setting } from '@things-factory/setting-base'
|
|
17
18
|
import { Domain } from '@things-factory/shell'
|
|
@@ -69,115 +70,107 @@ export async function completeBatchPicking(
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
109
|
-
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
110
|
-
}
|
|
73
|
+
for (let i = 0; i < uniqueReleaseGoods.length; i++) {
|
|
74
|
+
let foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
75
|
+
where: { id: uniqueReleaseGoods[i].id },
|
|
76
|
+
relations: [
|
|
77
|
+
'domain',
|
|
78
|
+
'creator',
|
|
79
|
+
'updater',
|
|
80
|
+
'orderPackages',
|
|
81
|
+
'orderProducts',
|
|
82
|
+
'orderProducts.product',
|
|
83
|
+
'bizplace',
|
|
84
|
+
'bizplace.company',
|
|
85
|
+
'bizplace.company.domain'
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
const orderSource: string = foundReleaseGood.source
|
|
89
|
+
switch (orderSource) {
|
|
90
|
+
case ApplicationType.SELLERCRAFT:
|
|
91
|
+
const sellercraft: Sellercraft = await tx
|
|
92
|
+
.getRepository(Sellercraft)
|
|
93
|
+
.findOne({ domain: worksheet.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
94
|
+
|
|
95
|
+
if (sellercraft) {
|
|
96
|
+
const initSCOrderShipment = async (sellercraft: Sellercraft, foundReleaseGood: ReleaseGood) => {
|
|
97
|
+
await getManager().transaction(async txMgr => {
|
|
98
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
99
|
+
|
|
100
|
+
if (!foundReleaseGood?.orderPackages?.length && !foundReleaseGood?.marketPackCallSuccess) {
|
|
101
|
+
await sellercraftCtrl.packOrder(sellercraft, foundReleaseGood)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const rtsTriggerLevel: Setting = await tx.getRepository(Setting).findOne({
|
|
105
|
+
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
111
106
|
})
|
|
112
|
-
}
|
|
113
107
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
case ApplicationType.MMS:
|
|
120
|
-
const companyDomain: Domain = foundReleaseGood.bizplace.company.domain
|
|
121
|
-
const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
122
|
-
where: { orderNo: foundReleaseGood.refNo, domain: companyDomain },
|
|
123
|
-
relations: [
|
|
124
|
-
'marketplaceOrderItems',
|
|
125
|
-
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
126
|
-
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
|
|
127
|
-
'marketplaceStore',
|
|
128
|
-
'marketplaceStore.marketplaceDistributors'
|
|
129
|
-
]
|
|
130
|
-
})
|
|
131
|
-
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
132
|
-
|
|
133
|
-
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
134
|
-
if (marketplaceStore?.isAutoUpdateShipment) {
|
|
135
|
-
await ecommerceCtrl.createOrderShip(foundReleaseGood, marketplaceStore, marketplaceOrder, companyDomain)
|
|
108
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
109
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, foundReleaseGood)
|
|
110
|
+
}
|
|
111
|
+
})
|
|
136
112
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
113
|
+
|
|
114
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
115
|
+
initSCOrderShipment(sellercraft, foundReleaseGood)
|
|
116
|
+
}
|
|
117
|
+
break
|
|
118
|
+
|
|
119
|
+
case ApplicationType.MMS:
|
|
120
|
+
const companyDomain: Domain = foundReleaseGood.bizplace.company.domain
|
|
121
|
+
const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
122
|
+
where: { orderNo: foundReleaseGood.refNo, domain: companyDomain },
|
|
123
|
+
relations: [
|
|
124
|
+
'marketplaceOrderItems',
|
|
125
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
126
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping',
|
|
127
|
+
'marketplaceStore',
|
|
128
|
+
'marketplaceStore.marketplaceDistributors'
|
|
129
|
+
]
|
|
130
|
+
})
|
|
131
|
+
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
132
|
+
|
|
133
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
134
|
+
if (marketplaceStore?.isAutoUpdateShipment) {
|
|
135
|
+
await ecommerceCtrl.createOrderShip(foundReleaseGood, marketplaceStore, marketplaceOrder, companyDomain)
|
|
136
|
+
}
|
|
137
|
+
await ecommerceCtrl.createOrderPackage(tx, marketplaceOrder, companyDomain, marketplaceStore, foundReleaseGood)
|
|
138
|
+
break
|
|
139
|
+
|
|
140
|
+
default:
|
|
141
|
+
const orderPackage: OrderPackage = {
|
|
142
|
+
name: OrderNoGenerator.orderPackage(),
|
|
143
|
+
packageId: null,
|
|
144
|
+
trackingNo: null,
|
|
145
|
+
transporter: null,
|
|
146
|
+
airwayBill: null,
|
|
147
|
+
status: ORDER_STATUS.PROCESSING,
|
|
148
|
+
releaseGood: foundReleaseGood,
|
|
149
|
+
domain: foundReleaseGood.domain,
|
|
150
|
+
bizplace: foundReleaseGood.bizplace,
|
|
151
|
+
creator: foundReleaseGood.creator,
|
|
152
|
+
updater: foundReleaseGood.updater
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let savedOrderPackage: OrderPackage = await tx.getRepository(OrderPackage).save(orderPackage)
|
|
156
|
+
const orderPackageItems: OrderPackageItem[] = foundReleaseGood.orderProducts.map(op => {
|
|
157
|
+
return {
|
|
158
|
+
name: OrderNoGenerator.orderPackageItem(),
|
|
159
|
+
orderProduct: op,
|
|
153
160
|
status: ORDER_STATUS.PROCESSING,
|
|
154
|
-
|
|
161
|
+
releaseQty: op.releaseQty,
|
|
162
|
+
orderPackage: savedOrderPackage,
|
|
155
163
|
domain: foundReleaseGood.domain,
|
|
156
164
|
bizplace: foundReleaseGood.bizplace,
|
|
157
165
|
creator: foundReleaseGood.creator,
|
|
158
166
|
updater: foundReleaseGood.updater
|
|
159
167
|
}
|
|
168
|
+
})
|
|
160
169
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
orderProduct: op,
|
|
166
|
-
status: ORDER_STATUS.PROCESSING,
|
|
167
|
-
releaseQty: op.releaseQty,
|
|
168
|
-
orderPackage: savedOrderPackage,
|
|
169
|
-
domain: foundReleaseGood.domain,
|
|
170
|
-
bizplace: foundReleaseGood.bizplace,
|
|
171
|
-
creator: foundReleaseGood.creator,
|
|
172
|
-
updater: foundReleaseGood.updater
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
await tx.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
177
|
-
break
|
|
178
|
-
}
|
|
179
|
-
})
|
|
180
|
-
)
|
|
170
|
+
await tx.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
}
|
|
181
174
|
|
|
182
175
|
const pickPackTargetInventories: OrderInventory[] = targetInventories
|
|
183
176
|
.filter(targetInventory => targetInventory.releaseGood.packingOption)
|
|
@@ -110,15 +110,15 @@ export async function completePicking(
|
|
|
110
110
|
await getManager().transaction(async txMgr => {
|
|
111
111
|
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
112
112
|
|
|
113
|
-
if (!releaseGood?.orderPackages?.length) {
|
|
114
|
-
const orderProducts: OrderProduct[] = await
|
|
113
|
+
if (!releaseGood?.orderPackages?.length && !releaseGood?.marketPackCallSuccess) {
|
|
114
|
+
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
115
115
|
where: { releaseGood },
|
|
116
116
|
relations: ['product', 'product.productDetails']
|
|
117
117
|
})
|
|
118
118
|
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const rtsTriggerLevel: Setting = await
|
|
121
|
+
const rtsTriggerLevel: Setting = await txMgr.getRepository(Setting).findOne({
|
|
122
122
|
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
123
123
|
})
|
|
124
124
|
|