@things-factory/worksheet-base 4.3.78 → 4.3.79-alpha.0
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/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 +59 -12
- 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 +2 -2
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +262 -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/package.json +17 -17
- 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 +68 -13
- package/server/graphql/resolvers/worksheet/picking/activate-picking.ts +60 -30
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +2 -2
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +288 -130
- package/server/graphql/resolvers/worksheet/putaway/complete-putaway.ts +45 -15
|
@@ -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
|
}
|
|
@@ -69,7 +69,7 @@ export async function completeBatchPicking(
|
|
|
69
69
|
|
|
70
70
|
let foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
71
71
|
where: { id: releaseGood.id },
|
|
72
|
-
relations: ['orderProducts', 'orderProducts.product'
|
|
72
|
+
relations: ['orderProducts', 'orderProducts.product']
|
|
73
73
|
})
|
|
74
74
|
|
|
75
75
|
if (!foundReleaseGood?.packageId) {
|
|
@@ -112,7 +112,7 @@ export async function completeBatchPicking(
|
|
|
112
112
|
})
|
|
113
113
|
|
|
114
114
|
// loop to generate packing worksheet
|
|
115
|
-
for (
|
|
115
|
+
for (let i: number = 0; i < uniqueRoNo.length; i++) {
|
|
116
116
|
const releaseGoodNo: string = uniqueRoNo[i]
|
|
117
117
|
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
118
118
|
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'
|
|
@@ -81,149 +81,307 @@ export async function completePicking(
|
|
|
81
81
|
|
|
82
82
|
await pickingWSCtrl.completePicking(releaseGoodNo)
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
84
|
+
const orderSource: string = releaseGood.source
|
|
85
|
+
switch (orderSource) {
|
|
86
|
+
case ApplicationType.SELLERCRAFT:
|
|
87
|
+
const sellercraft: Sellercraft = await tx
|
|
88
|
+
.getRepository(Sellercraft)
|
|
89
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
90
|
+
const initSCOrderShipment = async sellercraft => {
|
|
91
|
+
if (sellercraft) {
|
|
92
|
+
await getManager().transaction(async txMgr => {
|
|
93
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
94
|
+
|
|
95
|
+
if (!releaseGood?.packageId) {
|
|
96
|
+
const orderProducts: OrderProduct[] = await tx.getRepository(OrderProduct).find({
|
|
97
|
+
where: { releaseGood },
|
|
98
|
+
relations: ['product', 'product.productDetails']
|
|
99
|
+
})
|
|
100
|
+
releaseGood = await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
101
|
+
|
|
102
|
+
if (releaseGood?.packageId) {
|
|
103
|
+
await txMgr
|
|
104
|
+
.getRepository(ReleaseGood)
|
|
105
|
+
.update({ id: releaseGood.id }, { packageId: releaseGood.packageId, updater: releaseGood.updater })
|
|
106
|
+
}
|
|
102
107
|
}
|
|
103
|
-
}
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
109
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
110
|
+
})
|
|
111
|
+
}
|
|
107
112
|
}
|
|
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
113
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
115
|
+
initSCOrderShipment(sellercraft)
|
|
116
|
+
break
|
|
117
|
+
|
|
118
|
+
case ApplicationType.MMS:
|
|
119
|
+
const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
120
|
+
let marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
121
|
+
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
122
|
+
relations: [
|
|
123
|
+
'marketplaceStore',
|
|
124
|
+
'marketplaceOrderItems',
|
|
125
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
126
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
127
|
+
]
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
if (marketplaceOrder) {
|
|
131
|
+
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
132
|
+
let eTraxOption: boolean
|
|
133
|
+
|
|
134
|
+
if (marketplaceStore.isAutoUpdateShipment) {
|
|
135
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
136
|
+
await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
|
|
137
|
+
}
|
|
127
138
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
if (!marketplaceOrder)
|
|
140
|
+
throw new Error('Failed to find ecommerce order, kindly contact our support team regarding this issue')
|
|
141
|
+
eTraxOption = marketplaceOrder?.marketplaceStore.eTrax
|
|
142
|
+
|
|
143
|
+
// if eTrax option is true
|
|
144
|
+
if (eTraxOption) {
|
|
145
|
+
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
146
|
+
|
|
147
|
+
// access every marketplaceOrderItems for shipping information you need
|
|
148
|
+
// trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
149
|
+
// for etrax didn't support multi awb per order
|
|
150
|
+
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
151
|
+
marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
152
|
+
const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
153
|
+
marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
154
|
+
const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
155
|
+
where: {
|
|
156
|
+
domain,
|
|
157
|
+
platform: 'eTrax'
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
//Get which transporter to use
|
|
162
|
+
const marketplaceTransporter: MarketplaceTransporter = await tx
|
|
163
|
+
.getRepository(MarketplaceTransporter)
|
|
164
|
+
.findOne({
|
|
165
|
+
where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
166
|
+
relations: ['pickupTransporter', 'deliveryTransporter']
|
|
167
|
+
})
|
|
132
168
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
169
|
+
const resp = await LastMileAPI.createShipmentRequest(lmd, {
|
|
170
|
+
orderNo: marketplaceOrder.orderNo,
|
|
171
|
+
clientId: lmd.clientId,
|
|
172
|
+
clientType: lmd.clientType,
|
|
173
|
+
clientName: lmd.clientName,
|
|
174
|
+
transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
175
|
+
pickupName: warehouseContactPoint.name,
|
|
176
|
+
pickupAddress1: warehouseContactPoint.address,
|
|
177
|
+
pickupAddress2: warehouseContactPoint.address2,
|
|
178
|
+
pickupPostcode: warehouseContactPoint.postCode,
|
|
179
|
+
pickupState: warehouseContactPoint.state,
|
|
180
|
+
pickupCity: warehouseContactPoint.city,
|
|
181
|
+
pickupPhone: warehouseContactPoint.phone,
|
|
182
|
+
pickupEmail: warehouseContactPoint.email,
|
|
183
|
+
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
184
|
+
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
185
|
+
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
186
|
+
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
187
|
+
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
188
|
+
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
189
|
+
phone: marketplaceOrderShipping.phone1 || '',
|
|
190
|
+
email: marketplaceOrderShipping.email || '',
|
|
191
|
+
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
192
|
+
quantity: marketplaceOrderItems.length
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const delay = (ms: number) => {
|
|
196
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
152
197
|
}
|
|
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
198
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
199
|
+
if (resp.Status === 'SUCCESS') {
|
|
200
|
+
//Success
|
|
201
|
+
let awbObtained = false
|
|
202
|
+
let retry = 0
|
|
203
|
+
while (!awbObtained) {
|
|
204
|
+
const marketplaceOrder2: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
205
|
+
where: { releaseOrderId: releaseGood.id },
|
|
206
|
+
relations: [
|
|
207
|
+
'marketplaceStore',
|
|
208
|
+
'marketplaceOrderItems',
|
|
209
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
210
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
211
|
+
]
|
|
212
|
+
})
|
|
213
|
+
const orderShipping =
|
|
214
|
+
marketplaceOrder2.marketplaceOrderItems[0].marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
215
|
+
if (orderShipping?.airwayBill) {
|
|
216
|
+
awbObtained = true
|
|
217
|
+
}
|
|
218
|
+
await delay(5000)
|
|
219
|
+
//Timeout after 15sec
|
|
220
|
+
if (++retry > 3) {
|
|
221
|
+
break
|
|
222
|
+
}
|
|
214
223
|
}
|
|
224
|
+
} else {
|
|
225
|
+
if (resp?.AWBurl && resp?.TrackingNo)
|
|
226
|
+
await tx
|
|
227
|
+
.getRepository(MarketplaceOrderShipping)
|
|
228
|
+
.update({ id: marketplaceOrderShipping.id }, { airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo })
|
|
229
|
+
else throw resp
|
|
215
230
|
}
|
|
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
231
|
}
|
|
223
232
|
}
|
|
224
|
-
|
|
233
|
+
break
|
|
234
|
+
|
|
235
|
+
default:
|
|
236
|
+
break
|
|
225
237
|
}
|
|
226
238
|
|
|
239
|
+
// if (releaseGood.type == 'b2c') {
|
|
240
|
+
// const sellercraft: Sellercraft = await tx
|
|
241
|
+
// .getRepository(Sellercraft)
|
|
242
|
+
// .findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
243
|
+
|
|
244
|
+
// const initSCOrderShipment = async sellercraft => {
|
|
245
|
+
// if (sellercraft) {
|
|
246
|
+
// await getManager().transaction(async txMgr => {
|
|
247
|
+
// const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
248
|
+
|
|
249
|
+
// if (!releaseGood?.packageId) {
|
|
250
|
+
// const orderProducts: OrderProduct[] = await tx.getRepository(OrderProduct).find({
|
|
251
|
+
// where: { releaseGood },
|
|
252
|
+
// relations: ['product', 'product.productDetails']
|
|
253
|
+
// })
|
|
254
|
+
// releaseGood = await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
255
|
+
|
|
256
|
+
// if (releaseGood?.packageId) {
|
|
257
|
+
// await txMgr
|
|
258
|
+
// .getRepository(ReleaseGood)
|
|
259
|
+
// .update({ id: releaseGood.id }, { packageId: releaseGood.packageId, updater: releaseGood.updater })
|
|
260
|
+
// }
|
|
261
|
+
// }
|
|
262
|
+
|
|
263
|
+
// await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
264
|
+
// })
|
|
265
|
+
// }
|
|
266
|
+
// }
|
|
267
|
+
|
|
268
|
+
// // asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
269
|
+
// initSCOrderShipment(sellercraft)
|
|
270
|
+
|
|
271
|
+
// const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
272
|
+
// let marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
273
|
+
// where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
274
|
+
// relations: [
|
|
275
|
+
// 'marketplaceStore',
|
|
276
|
+
// 'marketplaceOrderItems',
|
|
277
|
+
// 'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
278
|
+
// 'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
279
|
+
// ]
|
|
280
|
+
// })
|
|
281
|
+
|
|
282
|
+
// if (!sellercraft && marketplaceOrder) {
|
|
283
|
+
// const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
284
|
+
// let eTraxOption: boolean
|
|
285
|
+
|
|
286
|
+
// if (marketplaceStore.isAutoUpdateShipment) {
|
|
287
|
+
// const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
288
|
+
// await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
|
|
289
|
+
// }
|
|
290
|
+
|
|
291
|
+
// if (!marketplaceOrder)
|
|
292
|
+
// throw new Error('Failed to find ecommerce order, kindly contact our support team regarding this issue')
|
|
293
|
+
// eTraxOption = marketplaceOrder?.marketplaceStore.eTrax
|
|
294
|
+
|
|
295
|
+
// // if eTrax option is true
|
|
296
|
+
// if (eTraxOption) {
|
|
297
|
+
// const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
298
|
+
|
|
299
|
+
// // access every marketplaceOrderItems for shipping information you need
|
|
300
|
+
// // trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
301
|
+
// // for etrax didn't support multi awb per order
|
|
302
|
+
// const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
303
|
+
// marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
304
|
+
// const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
305
|
+
// marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
306
|
+
// const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
307
|
+
// where: {
|
|
308
|
+
// domain,
|
|
309
|
+
// platform: 'eTrax'
|
|
310
|
+
// }
|
|
311
|
+
// })
|
|
312
|
+
|
|
313
|
+
// //Get which transporter to use
|
|
314
|
+
// const marketplaceTransporter: MarketplaceTransporter = await tx.getRepository(MarketplaceTransporter).findOne({
|
|
315
|
+
// where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
316
|
+
// relations: ['pickupTransporter', 'deliveryTransporter']
|
|
317
|
+
// })
|
|
318
|
+
|
|
319
|
+
// const resp = await LastMileAPI.createShipmentRequest(lmd, {
|
|
320
|
+
// orderNo: marketplaceOrder.orderNo,
|
|
321
|
+
// clientId: lmd.clientId,
|
|
322
|
+
// clientType: lmd.clientType,
|
|
323
|
+
// clientName: lmd.clientName,
|
|
324
|
+
// transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
325
|
+
// pickupName: warehouseContactPoint.name,
|
|
326
|
+
// pickupAddress1: warehouseContactPoint.address,
|
|
327
|
+
// pickupAddress2: warehouseContactPoint.address2,
|
|
328
|
+
// pickupPostcode: warehouseContactPoint.postCode,
|
|
329
|
+
// pickupState: warehouseContactPoint.state,
|
|
330
|
+
// pickupCity: warehouseContactPoint.city,
|
|
331
|
+
// pickupPhone: warehouseContactPoint.phone,
|
|
332
|
+
// pickupEmail: warehouseContactPoint.email,
|
|
333
|
+
// name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
334
|
+
// address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
335
|
+
// address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
336
|
+
// postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
337
|
+
// city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
338
|
+
// state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
339
|
+
// phone: marketplaceOrderShipping.phone1 || '',
|
|
340
|
+
// email: marketplaceOrderShipping.email || '',
|
|
341
|
+
// attentionTo: marketplaceOrderShipping.attentionTo,
|
|
342
|
+
// quantity: marketplaceOrderItems.length
|
|
343
|
+
// })
|
|
344
|
+
|
|
345
|
+
// const delay = (ms: number) => {
|
|
346
|
+
// return new Promise(resolve => setTimeout(resolve, ms))
|
|
347
|
+
// }
|
|
348
|
+
|
|
349
|
+
// if (resp.Status === 'SUCCESS') {
|
|
350
|
+
// //Success
|
|
351
|
+
// let awbObtained = false
|
|
352
|
+
// let retry = 0
|
|
353
|
+
// while (!awbObtained) {
|
|
354
|
+
// const marketplaceOrder2: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
355
|
+
// where: { releaseOrderId: releaseGood.id },
|
|
356
|
+
// relations: [
|
|
357
|
+
// 'marketplaceStore',
|
|
358
|
+
// 'marketplaceOrderItems',
|
|
359
|
+
// 'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
360
|
+
// 'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
361
|
+
// ]
|
|
362
|
+
// })
|
|
363
|
+
// const orderShipping =
|
|
364
|
+
// marketplaceOrder2.marketplaceOrderItems[0].marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
365
|
+
// if (orderShipping?.airwayBill) {
|
|
366
|
+
// awbObtained = true
|
|
367
|
+
// }
|
|
368
|
+
// await delay(5000)
|
|
369
|
+
// //Timeout after 15sec
|
|
370
|
+
// if (++retry > 3) {
|
|
371
|
+
// break
|
|
372
|
+
// }
|
|
373
|
+
// }
|
|
374
|
+
// } else {
|
|
375
|
+
// if (resp?.AWBurl && resp?.TrackingNo)
|
|
376
|
+
// await tx
|
|
377
|
+
// .getRepository(MarketplaceOrderShipping)
|
|
378
|
+
// .update({ id: marketplaceOrderShipping.id }, { airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo })
|
|
379
|
+
// else throw resp
|
|
380
|
+
// }
|
|
381
|
+
// }
|
|
382
|
+
// }
|
|
383
|
+
// }
|
|
384
|
+
|
|
227
385
|
if (releaseGood.packingOption) {
|
|
228
386
|
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
229
387
|
await packingWSCtrl.generatePackingWorksheet(releaseGoodNo)
|
|
@@ -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 { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
5
5
|
import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
|
|
6
6
|
import { ArrivalNotice } from '@things-factory/sales-base'
|
|
@@ -33,24 +33,54 @@ export const completePutawayResolver = {
|
|
|
33
33
|
// search for any active marketplace connection
|
|
34
34
|
const companyDomain: Domain = arrivalNotice.bizplace.company.domain
|
|
35
35
|
const customerDomain: Domain = arrivalNotice.bizplace.domain
|
|
36
|
-
const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
37
|
-
where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
38
|
-
relations: ['marketplaceDistributors']
|
|
39
|
-
})
|
|
40
36
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
.
|
|
37
|
+
const orderSource: string = arrivalNotice.source
|
|
38
|
+
switch (orderSource) {
|
|
39
|
+
case ApplicationType.SELLERCRAFT:
|
|
40
|
+
const sellercraft: Sellercraft = await tx
|
|
41
|
+
.getRepository(Sellercraft)
|
|
42
|
+
.findOne({ domain: customerDomain, status: SellercraftStatus.ACTIVE })
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
if (sellercraft) {
|
|
45
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
|
|
46
|
+
await sellercraftCtrl.registerProductInbound(sellercraft, arrivalNotice)
|
|
47
|
+
}
|
|
48
|
+
break
|
|
49
|
+
|
|
50
|
+
case ApplicationType.MMS:
|
|
51
|
+
const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
52
|
+
where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
53
|
+
relations: ['marketplaceDistributors']
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
if (marketplaceStores?.length && marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
|
|
57
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
58
|
+
await ecommerceCtrl.updateProductVariationStock(marketplaceStores, arrivalNotice.orderProducts, companyDomain)
|
|
59
|
+
}
|
|
60
|
+
break
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await ecommerceCtrl.updateProductVariationStock(marketplaceStores, arrivalNotice.orderProducts, companyDomain)
|
|
62
|
+
default:
|
|
63
|
+
break
|
|
53
64
|
}
|
|
65
|
+
|
|
66
|
+
// const marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
|
|
67
|
+
// where: { domain: companyDomain, status: 'ACTIVE', isAutoUpdateStockQty: true },
|
|
68
|
+
// relations: ['marketplaceDistributors']
|
|
69
|
+
// })
|
|
70
|
+
|
|
71
|
+
// const sellercraft: Sellercraft = await tx
|
|
72
|
+
// .getRepository(Sellercraft)
|
|
73
|
+
// .findOne({ domain: customerDomain, status: SellercraftStatus.ACTIVE })
|
|
74
|
+
|
|
75
|
+
// if (sellercraft) {
|
|
76
|
+
// const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
|
|
77
|
+
// await sellercraftCtrl.registerProductInbound(sellercraft, arrivalNotice)
|
|
78
|
+
// }
|
|
79
|
+
|
|
80
|
+
// if (marketplaceStores?.length && marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
|
|
81
|
+
// const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
82
|
+
// await ecommerceCtrl.updateProductVariationStock(marketplaceStores, arrivalNotice.orderProducts, companyDomain)
|
|
83
|
+
// }
|
|
54
84
|
}
|
|
55
85
|
}
|
|
56
86
|
|