@things-factory/worksheet-base 4.3.87 → 4.3.94
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/ecommerce-controller.js +1 -1
- package/dist-server/controllers/ecommerce/ecommerce-controller.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/delivery-order-by-worksheet.js +7 -4
- package/dist-server/graphql/resolvers/worksheet/delivery-order-by-worksheet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/loading/complete-loading.js +67 -28
- package/dist-server/graphql/resolvers/worksheet/loading/complete-loading.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/activate-packing.js +23 -8
- package/dist-server/graphql/resolvers/worksheet/packing/activate-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js +30 -7
- package/dist-server/graphql/resolvers/worksheet/packing/complete-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/packing.js +23 -8
- package/dist-server/graphql/resolvers/worksheet/packing/packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/scan-product-packing.js +25 -8
- package/dist-server/graphql/resolvers/worksheet/packing/scan-product-packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js +61 -13
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js +51 -25
- package/dist-server/graphql/resolvers/worksheet/picking/activate-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +37 -29
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +132 -118
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/putaway/complete-putaway.js +39 -14
- package/dist-server/graphql/resolvers/worksheet/putaway/complete-putaway.js.map +1 -1
- package/dist-server/graphql/types/worksheet/delivery-order-info.js +1 -0
- package/dist-server/graphql/types/worksheet/delivery-order-info.js.map +1 -1
- package/package.json +17 -17
- package/server/controllers/ecommerce/ecommerce-controller.ts +1 -1
- package/server/graphql/resolvers/worksheet/delivery-order-by-worksheet.ts +7 -6
- package/server/graphql/resolvers/worksheet/loading/complete-loading.ts +77 -33
- package/server/graphql/resolvers/worksheet/packing/activate-packing.ts +26 -9
- package/server/graphql/resolvers/worksheet/packing/complete-packing.ts +34 -9
- package/server/graphql/resolvers/worksheet/packing/packing.ts +26 -9
- package/server/graphql/resolvers/worksheet/packing/scan-product-packing.ts +28 -9
- package/server/graphql/resolvers/worksheet/packing-worksheet.ts +70 -14
- package/server/graphql/resolvers/worksheet/picking/activate-picking.ts +60 -30
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +46 -40
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +142 -131
- package/server/graphql/resolvers/worksheet/putaway/complete-putaway.ts +45 -15
- package/server/graphql/types/worksheet/delivery-order-info.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EntityManager,
|
|
1
|
+
import { EntityManager, getManager, SelectQueryBuilder } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
3
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { logger } from '@things-factory/env'
|
|
5
5
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
6
6
|
import {
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
MarketplaceOrderShippingItem
|
|
11
11
|
} from '@things-factory/marketplace-base'
|
|
12
12
|
import { ORDER_INVENTORY_STATUS, ORDER_STATUS, OrderInventory, ReleaseGood } from '@things-factory/sales-base'
|
|
13
|
+
import { PartnerSetting, Setting } from '@things-factory/setting-base'
|
|
13
14
|
import { Domain } from '@things-factory/shell'
|
|
14
15
|
import { Inventory, Location } from '@things-factory/warehouse-base'
|
|
15
16
|
|
|
@@ -17,7 +18,6 @@ import { WORKSHEET_TYPE } from '../../../constants'
|
|
|
17
18
|
import { PackingWorksheetController, SellercraftController } from '../../../controllers'
|
|
18
19
|
import { Worksheet, WorksheetDetail } from '../../../entities'
|
|
19
20
|
import { fetchExecutingWorksheet } from '../../../utils'
|
|
20
|
-
import { PartnerSetting, Setting } from '@things-factory/setting-base'
|
|
21
21
|
|
|
22
22
|
export const packingWorksheetResolver = {
|
|
23
23
|
async packingWorksheet(_: any, { releaseGoodNo }, context: any) {
|
|
@@ -146,16 +146,21 @@ export const packingWorksheetResolver = {
|
|
|
146
146
|
let shippingProvider: string
|
|
147
147
|
let marketplaceStatus: string
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
149
|
+
const orderSource: string = releaseGood.source
|
|
150
|
+
switch (orderSource) {
|
|
151
|
+
case ApplicationType.SELLERCRAFT:
|
|
152
|
+
const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({
|
|
153
|
+
domain: worksheet.bizplace.domain,
|
|
154
|
+
status: SellercraftStatus.ACTIVE
|
|
155
|
+
})
|
|
154
156
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
if (sellercraft) {
|
|
158
|
+
// asynchronously get document from sellercraft
|
|
159
|
+
getSellercraftDocument(sellercraft, releaseGood, domain, user)
|
|
160
|
+
}
|
|
161
|
+
break
|
|
162
|
+
|
|
163
|
+
case ApplicationType.MMS:
|
|
159
164
|
marketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
160
165
|
where: { orderNo: releaseGood.refNo },
|
|
161
166
|
relations: [
|
|
@@ -191,9 +196,60 @@ export const packingWorksheetResolver = {
|
|
|
191
196
|
|
|
192
197
|
marketplaceStore = marketplaceOrder?.marketplaceStore
|
|
193
198
|
marketplaceStatus = marketplaceOrder?.status
|
|
194
|
-
|
|
199
|
+
break
|
|
200
|
+
|
|
201
|
+
default:
|
|
202
|
+
break
|
|
195
203
|
}
|
|
196
204
|
|
|
205
|
+
// if (releaseGood.type === 'b2c') {
|
|
206
|
+
// const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({
|
|
207
|
+
// domain: worksheet.bizplace.domain,
|
|
208
|
+
// status: SellercraftStatus.ACTIVE
|
|
209
|
+
// })
|
|
210
|
+
|
|
211
|
+
// if (sellercraft) {
|
|
212
|
+
// // asynchronously get document from sellercraft
|
|
213
|
+
// getSellercraftDocument(sellercraft, releaseGood, domain, user)
|
|
214
|
+
// } else {
|
|
215
|
+
// marketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
216
|
+
// where: { orderNo: releaseGood.refNo },
|
|
217
|
+
// relations: [
|
|
218
|
+
// 'domain',
|
|
219
|
+
// 'marketplaceStore',
|
|
220
|
+
// 'marketplaceOrderItems',
|
|
221
|
+
// 'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
222
|
+
// 'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
223
|
+
// ]
|
|
224
|
+
// })
|
|
225
|
+
|
|
226
|
+
// if (!marketplaceOrder) {
|
|
227
|
+
// throw new Error('Failed to retrieve ecommerce information, kindly contact our support team for this issue.')
|
|
228
|
+
// }
|
|
229
|
+
|
|
230
|
+
// let marketplaceOrderShipping: MarketplaceOrderShipping
|
|
231
|
+
// if (marketplaceOrder.isSplitted) {
|
|
232
|
+
// marketplaceOrderShipping = await tx.getRepository(MarketplaceOrderShipping).findOne({
|
|
233
|
+
// where: { subOrderNoRef: worksheet.releaseGood.refNo2 }
|
|
234
|
+
// })
|
|
235
|
+
// } else {
|
|
236
|
+
// marketplaceOrderShipping = await tx.getRepository(MarketplaceOrderShipping).findOne({
|
|
237
|
+
// where: { orderNoRef: worksheet.releaseGood.refNo }
|
|
238
|
+
// })
|
|
239
|
+
// }
|
|
240
|
+
|
|
241
|
+
// trackingNo = marketplaceOrderShipping.ownTrackingNo
|
|
242
|
+
// ? marketplaceOrderShipping.ownTrackingNo
|
|
243
|
+
// : marketplaceOrderShipping.trackingNo
|
|
244
|
+
// shippingProvider = marketplaceOrderShipping.ownTransporter
|
|
245
|
+
// ? marketplaceOrderShipping.ownTransporter
|
|
246
|
+
// : marketplaceOrderShipping.transporter
|
|
247
|
+
|
|
248
|
+
// marketplaceStore = marketplaceOrder?.marketplaceStore
|
|
249
|
+
// marketplaceStatus = marketplaceOrder?.status
|
|
250
|
+
// }
|
|
251
|
+
// }
|
|
252
|
+
|
|
197
253
|
return {
|
|
198
254
|
worksheetInfo: {
|
|
199
255
|
releaseGood,
|
|
@@ -213,7 +269,7 @@ export const packingWorksheetResolver = {
|
|
|
213
269
|
marketplaceStatus: marketplaceStatus ? marketplaceStatus : '',
|
|
214
270
|
marketplaceOrder: marketplaceOrder ? marketplaceOrder : ''
|
|
215
271
|
},
|
|
216
|
-
worksheetDetailInfos: worksheet.worksheetDetails.map(
|
|
272
|
+
worksheetDetailInfos: worksheet.worksheetDetails.map((packingWSD: WorksheetDetail) => {
|
|
217
273
|
const targetInventory: OrderInventory = packingWSD.targetInventory
|
|
218
274
|
const inventory: Inventory = targetInventory.inventory
|
|
219
275
|
return {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { EntityManager } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
3
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
5
|
-
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
6
5
|
import { MarketplaceOrder } from '@things-factory/marketplace-base'
|
|
7
6
|
import { ORDER_STATUS, ReleaseGood } from '@things-factory/sales-base'
|
|
8
7
|
import { Domain } from '@things-factory/shell'
|
|
@@ -27,42 +26,73 @@ export async function activatePicking(
|
|
|
27
26
|
const worksheet = await worksheetController.activatePicking(worksheetNo)
|
|
28
27
|
const companyDomain: Domain = worksheet?.bizplace.company.domain
|
|
29
28
|
|
|
30
|
-
// find for any existing marketplace store connections
|
|
31
|
-
const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
32
|
-
where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
33
|
-
relations: ['marketplaceDistributors']
|
|
34
|
-
})
|
|
35
|
-
|
|
36
29
|
let releaseGood: ReleaseGood = worksheet.releaseGood
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const worksheetDetails = worksheet.worksheetDetails
|
|
46
|
-
let orderInventories: any[] = worksheetDetails.map(wsd => wsd.targetInventory)
|
|
47
|
-
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
48
|
-
await ecommerceCtrl.updateProductVariationStock(marketplaceStores, orderInventories, companyDomain)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
52
|
-
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
53
|
-
relations: ['marketplaceStore']
|
|
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']
|
|
54
38
|
})
|
|
55
39
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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)
|
|
60
44
|
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
61
|
-
await ecommerceCtrl.
|
|
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']
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
if (marketplaceOrder) {
|
|
54
|
+
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
55
|
+
|
|
56
|
+
if (marketplaceStore.isAutoUpdateShipment) {
|
|
57
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
58
|
+
await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PICKING)
|
|
59
|
+
}
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
|
-
|
|
62
|
+
break
|
|
63
|
+
|
|
64
|
+
default:
|
|
65
|
+
break
|
|
65
66
|
}
|
|
66
67
|
|
|
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
|
+
|
|
67
97
|
return worksheet
|
|
68
98
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityManager } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
3
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, getMyBizplace } from '@things-factory/biz-base'
|
|
5
5
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
6
6
|
import { OrderInventory, ReleaseGood } from '@things-factory/sales-base'
|
|
@@ -46,48 +46,54 @@ export async function completeBatchPicking(
|
|
|
46
46
|
.filter(wsd => wsd.status != 'MISSING')
|
|
47
47
|
.map((wsd: WorksheetDetail) => wsd.targetInventory)
|
|
48
48
|
|
|
49
|
-
const
|
|
50
|
-
.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const map = new Map()
|
|
59
|
-
for (const releaseGood of releaseGoods) {
|
|
60
|
-
if (!map.has(releaseGood.id)) {
|
|
61
|
-
map.set(releaseGood.id, true)
|
|
62
|
-
uniqueReleaseGoods.push({ ...releaseGood })
|
|
63
|
-
}
|
|
49
|
+
const releaseGoods: ReleaseGood[] = worksheetDetails.map(
|
|
50
|
+
worksheetDetail => worksheetDetail.targetInventory && worksheetDetail.targetInventory.releaseGood
|
|
51
|
+
)
|
|
52
|
+
const uniqueReleaseGoods: ReleaseGood[] = []
|
|
53
|
+
const map = new Map()
|
|
54
|
+
for (const releaseGood of releaseGoods) {
|
|
55
|
+
if (!map.has(releaseGood.id)) {
|
|
56
|
+
map.set(releaseGood.id, true)
|
|
57
|
+
uniqueReleaseGoods.push({ ...releaseGood })
|
|
64
58
|
}
|
|
59
|
+
}
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
61
|
+
await Promise.all(
|
|
62
|
+
uniqueReleaseGoods.map(async releaseGood => {
|
|
63
|
+
let foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
64
|
+
where: { id: releaseGood.id },
|
|
65
|
+
relations: ['orderProducts', 'orderProducts.product']
|
|
66
|
+
})
|
|
67
|
+
const orderSource: string = foundReleaseGood.source
|
|
68
|
+
switch (orderSource) {
|
|
69
|
+
case ApplicationType.SELLERCRAFT:
|
|
70
|
+
const sellercraft: Sellercraft = await tx
|
|
71
|
+
.getRepository(Sellercraft)
|
|
72
|
+
.findOne({ domain: worksheet.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
73
|
+
|
|
74
|
+
if (sellercraft) {
|
|
75
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
|
|
76
|
+
if (!foundReleaseGood?.packageId) {
|
|
77
|
+
foundReleaseGood = await sellercraftCtrl.packOrder(sellercraft, foundReleaseGood)
|
|
78
|
+
if (foundReleaseGood?.packageId) {
|
|
79
|
+
await tx
|
|
80
|
+
.getRepository(ReleaseGood)
|
|
81
|
+
.update(
|
|
82
|
+
{ id: foundReleaseGood.id },
|
|
83
|
+
{ packageId: foundReleaseGood.packageId, updater: foundReleaseGood.updater }
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
sellercraftCtrl.initiateOrderShipment(sellercraft, foundReleaseGood)
|
|
84
89
|
}
|
|
85
|
-
|
|
90
|
+
break
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
default:
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
)
|
|
91
97
|
|
|
92
98
|
const pickPackTargetInventories: OrderInventory[] = targetInventories
|
|
93
99
|
.filter(targetInventory => targetInventory.releaseGood.packingOption)
|
|
@@ -112,7 +118,7 @@ export async function completeBatchPicking(
|
|
|
112
118
|
})
|
|
113
119
|
|
|
114
120
|
// loop to generate packing worksheet
|
|
115
|
-
for (
|
|
121
|
+
for (let i: number = 0; i < uniqueRoNo.length; i++) {
|
|
116
122
|
const releaseGoodNo: string = uniqueRoNo[i]
|
|
117
123
|
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
118
124
|
await packingWSCtrl.generatePackingWorksheet(releaseGoodNo)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EntityManager, getManager } from 'typeorm'
|
|
2
2
|
|
|
3
|
-
import { User } from '@things-factory/auth-base'
|
|
3
|
+
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, ContactPoint, getMyBizplace } from '@things-factory/biz-base'
|
|
5
5
|
import { LastMileAPI, LastMileDelivery } from '@things-factory/integration-lmd'
|
|
6
6
|
import { MarketplaceStore, MarketplaceTransporter } from '@things-factory/integration-marketplace'
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
OrderProduct,
|
|
19
19
|
ReleaseGood
|
|
20
20
|
} from '@things-factory/sales-base'
|
|
21
|
-
import { PartnerSetting, Setting } from '@things-factory/setting-base'
|
|
22
21
|
import { Domain } from '@things-factory/shell'
|
|
23
22
|
|
|
24
23
|
import { WORKSHEET_STATUS, WORKSHEET_TYPE } from '../../../../constants'
|
|
@@ -81,147 +80,159 @@ export async function completePicking(
|
|
|
81
80
|
|
|
82
81
|
await pickingWSCtrl.completePicking(releaseGoodNo)
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
83
|
+
const orderSource: string = releaseGood.source
|
|
84
|
+
switch (orderSource) {
|
|
85
|
+
case ApplicationType.SELLERCRAFT:
|
|
86
|
+
const sellercraft: Sellercraft = await tx
|
|
87
|
+
.getRepository(Sellercraft)
|
|
88
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
89
|
+
const initSCOrderShipment = async sellercraft => {
|
|
90
|
+
if (sellercraft) {
|
|
91
|
+
await getManager().transaction(async txMgr => {
|
|
92
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
93
|
+
|
|
94
|
+
if (!releaseGood?.packageId) {
|
|
95
|
+
const orderProducts: OrderProduct[] = await tx.getRepository(OrderProduct).find({
|
|
96
|
+
where: { releaseGood },
|
|
97
|
+
relations: ['product', 'product.productDetails']
|
|
98
|
+
})
|
|
99
|
+
releaseGood = await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
100
|
+
|
|
101
|
+
if (releaseGood?.packageId) {
|
|
102
|
+
await txMgr
|
|
103
|
+
.getRepository(ReleaseGood)
|
|
104
|
+
.update({ id: releaseGood.id }, { packageId: releaseGood.packageId, updater: releaseGood.updater })
|
|
105
|
+
}
|
|
102
106
|
}
|
|
103
|
-
}
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
107
111
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
111
|
-
initSCOrderShipment(sellercraft)
|
|
112
|
-
|
|
113
|
-
const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
114
|
-
let marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
115
|
-
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
116
|
-
relations: [
|
|
117
|
-
'marketplaceStore',
|
|
118
|
-
'marketplaceOrderItems',
|
|
119
|
-
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
120
|
-
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
121
|
-
]
|
|
122
|
-
})
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
113
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
114
|
+
initSCOrderShipment(sellercraft)
|
|
115
|
+
break
|
|
116
|
+
|
|
117
|
+
case ApplicationType.MMS:
|
|
118
|
+
const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
119
|
+
let marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
120
|
+
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
121
|
+
relations: [
|
|
122
|
+
'marketplaceStore',
|
|
123
|
+
'marketplaceOrderItems',
|
|
124
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
125
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
if (marketplaceOrder) {
|
|
130
|
+
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
131
|
+
let eTraxOption: boolean
|
|
132
|
+
|
|
133
|
+
if (marketplaceStore.isAutoUpdateShipment) {
|
|
134
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
135
|
+
await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
|
|
136
|
+
}
|
|
127
137
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
138
|
+
if (!marketplaceOrder)
|
|
139
|
+
throw new Error('Failed to find ecommerce order, kindly contact our support team regarding this issue')
|
|
140
|
+
eTraxOption = marketplaceOrder?.marketplaceStore.eTrax
|
|
141
|
+
|
|
142
|
+
// if eTrax option is true
|
|
143
|
+
if (eTraxOption) {
|
|
144
|
+
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
145
|
+
|
|
146
|
+
// access every marketplaceOrderItems for shipping information you need
|
|
147
|
+
// trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
148
|
+
// for etrax didn't support multi awb per order
|
|
149
|
+
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
150
|
+
marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
151
|
+
const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
152
|
+
marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
153
|
+
const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
154
|
+
where: {
|
|
155
|
+
domain,
|
|
156
|
+
platform: 'eTrax'
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
//Get which transporter to use
|
|
161
|
+
const marketplaceTransporter: MarketplaceTransporter = await tx
|
|
162
|
+
.getRepository(MarketplaceTransporter)
|
|
163
|
+
.findOne({
|
|
164
|
+
where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
165
|
+
relations: ['pickupTransporter', 'deliveryTransporter']
|
|
166
|
+
})
|
|
132
167
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
168
|
+
const resp = await LastMileAPI.createShipmentRequest(lmd, {
|
|
169
|
+
orderNo: marketplaceOrder.orderNo,
|
|
170
|
+
clientId: lmd.clientId,
|
|
171
|
+
clientType: lmd.clientType,
|
|
172
|
+
clientName: lmd.clientName,
|
|
173
|
+
transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
174
|
+
pickupName: warehouseContactPoint.name,
|
|
175
|
+
pickupAddress1: warehouseContactPoint.address,
|
|
176
|
+
pickupAddress2: warehouseContactPoint.address2,
|
|
177
|
+
pickupPostcode: warehouseContactPoint.postCode,
|
|
178
|
+
pickupState: warehouseContactPoint.state,
|
|
179
|
+
pickupCity: warehouseContactPoint.city,
|
|
180
|
+
pickupPhone: warehouseContactPoint.phone,
|
|
181
|
+
pickupEmail: warehouseContactPoint.email,
|
|
182
|
+
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
183
|
+
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
184
|
+
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
185
|
+
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
186
|
+
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
187
|
+
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
188
|
+
phone: marketplaceOrderShipping.phone1 || '',
|
|
189
|
+
email: marketplaceOrderShipping.email || '',
|
|
190
|
+
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
191
|
+
quantity: marketplaceOrderItems.length
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
const delay = (ms: number) => {
|
|
195
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
152
196
|
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
//Get which transporter to use
|
|
156
|
-
const marketplaceTransporter: MarketplaceTransporter = await tx.getRepository(MarketplaceTransporter).findOne({
|
|
157
|
-
where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
158
|
-
relations: ['pickupTransporter', 'deliveryTransporter']
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
const resp = await LastMileAPI.createShipmentRequest(lmd, {
|
|
162
|
-
orderNo: marketplaceOrder.orderNo,
|
|
163
|
-
clientId: lmd.clientId,
|
|
164
|
-
clientType: lmd.clientType,
|
|
165
|
-
clientName: lmd.clientName,
|
|
166
|
-
transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
167
|
-
pickupName: warehouseContactPoint.name,
|
|
168
|
-
pickupAddress1: warehouseContactPoint.address,
|
|
169
|
-
pickupAddress2: warehouseContactPoint.address2,
|
|
170
|
-
pickupPostcode: warehouseContactPoint.postCode,
|
|
171
|
-
pickupState: warehouseContactPoint.state,
|
|
172
|
-
pickupCity: warehouseContactPoint.city,
|
|
173
|
-
pickupPhone: warehouseContactPoint.phone,
|
|
174
|
-
pickupEmail: warehouseContactPoint.email,
|
|
175
|
-
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
176
|
-
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
177
|
-
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
178
|
-
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
179
|
-
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
180
|
-
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
181
|
-
phone: marketplaceOrderShipping.phone1 || '',
|
|
182
|
-
email: marketplaceOrderShipping.email || '',
|
|
183
|
-
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
184
|
-
quantity: marketplaceOrderItems.length
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
const delay = (ms: number) => {
|
|
188
|
-
return new Promise(resolve => setTimeout(resolve, ms))
|
|
189
|
-
}
|
|
190
197
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
198
|
+
if (resp.Status === 'SUCCESS') {
|
|
199
|
+
//Success
|
|
200
|
+
let awbObtained = false
|
|
201
|
+
let retry = 0
|
|
202
|
+
while (!awbObtained) {
|
|
203
|
+
const marketplaceOrder2: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
204
|
+
where: { releaseOrderId: releaseGood.id },
|
|
205
|
+
relations: [
|
|
206
|
+
'marketplaceStore',
|
|
207
|
+
'marketplaceOrderItems',
|
|
208
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
209
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
210
|
+
]
|
|
211
|
+
})
|
|
212
|
+
const orderShipping =
|
|
213
|
+
marketplaceOrder2.marketplaceOrderItems[0].marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
214
|
+
if (orderShipping?.airwayBill) {
|
|
215
|
+
awbObtained = true
|
|
216
|
+
}
|
|
217
|
+
await delay(5000)
|
|
218
|
+
//Timeout after 15sec
|
|
219
|
+
if (++retry > 3) {
|
|
220
|
+
break
|
|
221
|
+
}
|
|
214
222
|
}
|
|
223
|
+
} else {
|
|
224
|
+
if (resp?.AWBurl && resp?.TrackingNo)
|
|
225
|
+
await tx
|
|
226
|
+
.getRepository(MarketplaceOrderShipping)
|
|
227
|
+
.update({ id: marketplaceOrderShipping.id }, { airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo })
|
|
228
|
+
else throw resp
|
|
215
229
|
}
|
|
216
|
-
} else {
|
|
217
|
-
if (resp?.AWBurl && resp?.TrackingNo)
|
|
218
|
-
await tx
|
|
219
|
-
.getRepository(MarketplaceOrderShipping)
|
|
220
|
-
.update({ id: marketplaceOrderShipping.id }, { airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo })
|
|
221
|
-
else throw resp
|
|
222
230
|
}
|
|
223
231
|
}
|
|
224
|
-
|
|
232
|
+
break
|
|
233
|
+
|
|
234
|
+
default:
|
|
235
|
+
break
|
|
225
236
|
}
|
|
226
237
|
|
|
227
238
|
if (releaseGood.packingOption) {
|