@things-factory/worksheet-base 4.3.324 → 4.3.326
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/outbound/picking-worksheet-controller.js +4 -4
- package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/vas/vas-worksheet-controller.js +2 -128
- package/dist-server/controllers/vas/vas-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/worksheet-controller.js +4 -2
- package/dist-server/controllers/worksheet-controller.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +356 -353
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/vas/index.js +1 -2
- package/dist-server/graphql/resolvers/worksheet/vas/index.js.map +1 -1
- package/dist-server/graphql/types/worksheet/index.js +0 -6
- package/dist-server/graphql/types/worksheet/index.js.map +1 -1
- package/package.json +3 -3
- package/server/controllers/outbound/picking-worksheet-controller.ts +4 -4
- package/server/controllers/vas/vas-worksheet-controller.ts +2 -177
- package/server/controllers/worksheet-controller.ts +5 -3
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +395 -391
- package/server/graphql/resolvers/worksheet/vas/index.ts +0 -2
- package/server/graphql/types/worksheet/index.ts +0 -6
- package/dist-server/graphql/resolvers/worksheet/vas/edit-vas.js +0 -16
- package/dist-server/graphql/resolvers/worksheet/vas/edit-vas.js.map +0 -1
- package/server/graphql/resolvers/worksheet/vas/edit-vas.ts +0 -25
|
@@ -71,458 +71,459 @@ export async function completePicking(
|
|
|
71
71
|
user: User,
|
|
72
72
|
releaseGoodNo: string
|
|
73
73
|
): Promise<any> {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
'domain',
|
|
84
|
-
'bizplace',
|
|
85
|
-
'bizplace.domain',
|
|
86
|
-
'bizplace.company',
|
|
87
|
-
'bizplace.company.domain',
|
|
88
|
-
'lastMileDelivery',
|
|
89
|
-
'orderPackages',
|
|
90
|
-
'orderPackages.orderPackageItems',
|
|
91
|
-
'orderPackages.orderPackageItems.orderProduct',
|
|
92
|
-
'orderPackages.orderPackageItems.orderProduct.product',
|
|
93
|
-
'orderPackages.orderPackageItems.orderProduct.productDetail',
|
|
94
|
-
'orderProducts',
|
|
95
|
-
'orderProducts.product',
|
|
96
|
-
'orderProducts.productDetail',
|
|
97
|
-
'creator',
|
|
98
|
-
'updater'
|
|
99
|
-
]
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
103
|
-
|
|
104
|
-
let marketplaceOrder: MarketplaceOrder
|
|
105
|
-
if (releaseGood.source == ApplicationType.MMS || releaseGood.lmdOption) {
|
|
106
|
-
marketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
107
|
-
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
74
|
+
try {
|
|
75
|
+
const pickingWSCtrl: PickingWorksheetController = new PickingWorksheetController(tx, domain, user)
|
|
76
|
+
const replenishmentPickingWSCtrl: ReplenishmentWorksheetController = new ReplenishmentWorksheetController(
|
|
77
|
+
tx,
|
|
78
|
+
domain,
|
|
79
|
+
user
|
|
80
|
+
)
|
|
81
|
+
let releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
82
|
+
where: { domain, name: releaseGoodNo },
|
|
108
83
|
relations: [
|
|
109
|
-
'
|
|
110
|
-
'
|
|
111
|
-
'
|
|
112
|
-
'
|
|
113
|
-
'
|
|
84
|
+
'domain',
|
|
85
|
+
'bizplace',
|
|
86
|
+
'bizplace.domain',
|
|
87
|
+
'bizplace.company',
|
|
88
|
+
'bizplace.company.domain',
|
|
89
|
+
'lastMileDelivery',
|
|
90
|
+
'orderPackages',
|
|
91
|
+
'orderPackages.orderPackageItems',
|
|
92
|
+
'orderPackages.orderPackageItems.orderProduct',
|
|
93
|
+
'orderPackages.orderPackageItems.orderProduct.product',
|
|
94
|
+
'orderPackages.orderPackageItems.orderProduct.productDetail',
|
|
95
|
+
'orderProducts',
|
|
96
|
+
'orderProducts.product',
|
|
97
|
+
'orderProducts.productDetail',
|
|
98
|
+
'creator',
|
|
99
|
+
'updater'
|
|
114
100
|
]
|
|
115
101
|
})
|
|
116
|
-
}
|
|
117
102
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
103
|
+
const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
104
|
+
|
|
105
|
+
let marketplaceOrder: MarketplaceOrder
|
|
106
|
+
if (releaseGood.source == ApplicationType.MMS || releaseGood.lmdOption) {
|
|
107
|
+
marketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
108
|
+
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
109
|
+
relations: [
|
|
110
|
+
'marketplaceStore',
|
|
111
|
+
'marketplaceStore.marketplaceDistributors',
|
|
112
|
+
'marketplaceOrderItems',
|
|
113
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
114
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (releaseGood) {
|
|
120
|
+
const worksheet: Worksheet = await pickingWSCtrl.findWorksheetByRefOrder(releaseGood, WORKSHEET_TYPE.PICKING, [
|
|
121
|
+
'worksheetDetails',
|
|
122
|
+
'worksheetDetails.targetInventory',
|
|
123
|
+
'worksheetDetails.targetInventory.inventory'
|
|
124
|
+
])
|
|
125
|
+
const worksheetDetails: WorksheetDetail[] = worksheet.worksheetDetails
|
|
126
|
+
const targetInventories: OrderInventory[] = worksheetDetails.map((wsd: WorksheetDetail) => wsd.targetInventory)
|
|
127
|
+
const pickedTargetInventories: OrderInventory[] = targetInventories.filter(
|
|
128
|
+
targetInventory => targetInventory.status === ORDER_INVENTORY_STATUS.PICKED
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
if (pickedTargetInventories.length == 0) {
|
|
132
|
+
throw new Error('Something went wrong. Please contact support.')
|
|
129
133
|
}
|
|
130
|
-
})
|
|
131
134
|
|
|
132
|
-
|
|
133
|
-
const targetInventories: OrderInventory[] = worksheetDetails.map((wsd: WorksheetDetail) => wsd.targetInventory)
|
|
134
|
-
const inventories: Inventory[] = targetInventories.map((ti: OrderInventory) => ti.inventory)
|
|
135
|
-
const pickedTargetInventories: OrderInventory[] = targetInventories.filter(
|
|
136
|
-
targetInventory => targetInventory.status === ORDER_INVENTORY_STATUS.PICKED
|
|
137
|
-
)
|
|
135
|
+
const inventories: Inventory[] = targetInventories.map((ti: OrderInventory) => ti.inventory)
|
|
138
136
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const sellercraft: Sellercraft = await tx
|
|
146
|
-
.getRepository(Sellercraft)
|
|
147
|
-
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
148
|
-
|
|
149
|
-
if (sellercraft) {
|
|
150
|
-
const initSCOrderShipment = async sellercraft => {
|
|
151
|
-
await getManager().transaction(async txMgr => {
|
|
152
|
-
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
153
|
-
|
|
154
|
-
if (!releaseGood?.orderPackages?.length && !releaseGood?.marketPackCallSuccess) {
|
|
155
|
-
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
156
|
-
where: { releaseGood },
|
|
157
|
-
relations: ['product', 'product.productDetails']
|
|
158
|
-
})
|
|
159
|
-
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
160
|
-
}
|
|
137
|
+
const warehouseContactPoint: ContactPoint = await tx.getRepository(ContactPoint).findOne({
|
|
138
|
+
where: {
|
|
139
|
+
domain,
|
|
140
|
+
type: 'WAREHOUSE'
|
|
141
|
+
}
|
|
142
|
+
})
|
|
161
143
|
|
|
162
|
-
|
|
163
|
-
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
164
|
-
})
|
|
144
|
+
let foundObsoleteInventories = await pickingWSCtrl.completePicking(releaseGood, worksheet, inventories)
|
|
165
145
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
break
|
|
175
|
-
|
|
176
|
-
case ApplicationType.POWRUP:
|
|
177
|
-
const powrup: Powrup = await tx.getRepository(Powrup).findOne({ active: true, platform: 'POWRUP' })
|
|
146
|
+
if (foundObsoleteInventories?.type) {
|
|
147
|
+
const orderSource: string = releaseGood.source
|
|
148
|
+
switch (orderSource) {
|
|
149
|
+
case ApplicationType.SELLERCRAFT:
|
|
150
|
+
const sellercraft: Sellercraft = await tx
|
|
151
|
+
.getRepository(Sellercraft)
|
|
152
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
178
153
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
154
|
+
if (sellercraft) {
|
|
155
|
+
const initSCOrderShipment = async sellercraft => {
|
|
156
|
+
await getManager().transaction(async txMgr => {
|
|
157
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
158
|
+
|
|
159
|
+
if (!releaseGood?.orderPackages?.length && !releaseGood?.marketPackCallSuccess) {
|
|
160
|
+
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
161
|
+
where: { releaseGood },
|
|
162
|
+
relations: ['product', 'product.productDetails']
|
|
163
|
+
})
|
|
164
|
+
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
165
|
+
}
|
|
183
166
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
where: { releaseGood },
|
|
187
|
-
relations: ['product', 'productDetail']
|
|
167
|
+
const rtsTriggerLevel: Setting = await txMgr.getRepository(Setting).findOne({
|
|
168
|
+
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
188
169
|
})
|
|
189
|
-
await powrupController.packOrder(powrup, { ...releaseGood, orderProducts }, domain, user, txMgr)
|
|
190
|
-
}
|
|
191
170
|
|
|
192
|
-
|
|
193
|
-
|
|
171
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
172
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
173
|
+
}
|
|
194
174
|
})
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
})
|
|
175
|
+
}
|
|
176
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
177
|
+
initSCOrderShipment(sellercraft)
|
|
200
178
|
}
|
|
201
|
-
|
|
202
|
-
initPowrupShipment(powrup)
|
|
203
|
-
}
|
|
204
|
-
break
|
|
179
|
+
break
|
|
205
180
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
209
|
-
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
210
|
-
let eTraxOption: boolean
|
|
181
|
+
case ApplicationType.POWRUP:
|
|
182
|
+
const powrup: Powrup = await tx.getRepository(Powrup).findOne({ active: true, platform: 'POWRUP' })
|
|
211
183
|
|
|
212
|
-
if (
|
|
213
|
-
|
|
184
|
+
if (powrup) {
|
|
185
|
+
const initPowrupShipment = async powrup => {
|
|
186
|
+
await getManager().transaction(async txMgr => {
|
|
187
|
+
const powrupController: PowrupController = new PowrupController()
|
|
188
|
+
|
|
189
|
+
if (!releaseGood?.orderPackages?.length && !releaseGood?.marketPackCallSuccess) {
|
|
190
|
+
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
191
|
+
where: { releaseGood },
|
|
192
|
+
relations: ['product', 'productDetail']
|
|
193
|
+
})
|
|
194
|
+
await powrupController.packOrder(powrup, { ...releaseGood, orderProducts }, domain, user, txMgr)
|
|
195
|
+
}
|
|
214
196
|
|
|
215
|
-
|
|
216
|
-
|
|
197
|
+
const rtsTriggerLevel: Setting = await txMgr.getRepository(Setting).findOne({
|
|
198
|
+
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
202
|
+
await powrupController.initiateShipment(powrup, releaseGood, domain, user, txMgr)
|
|
203
|
+
}
|
|
204
|
+
})
|
|
217
205
|
}
|
|
206
|
+
// asynchronouly call to initiate powrup order shipment/ RTS
|
|
207
|
+
initPowrupShipment(powrup)
|
|
218
208
|
}
|
|
209
|
+
break
|
|
219
210
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
211
|
+
case ApplicationType.MMS:
|
|
212
|
+
if (marketplaceOrder) {
|
|
213
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
214
|
+
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
215
|
+
let eTraxOption: boolean
|
|
216
|
+
|
|
217
|
+
if (marketplaceStore?.isAutoUpdateShipment) {
|
|
218
|
+
await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
|
|
223
219
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
// if eTrax option is true
|
|
227
|
-
if (eTraxOption) {
|
|
228
|
-
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
229
|
-
|
|
230
|
-
// access every marketplaceOrderItems for shipping information you need
|
|
231
|
-
// trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
232
|
-
// for etrax didn't support multi awb per order
|
|
233
|
-
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
234
|
-
marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
235
|
-
const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
236
|
-
marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
237
|
-
const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
238
|
-
where: {
|
|
239
|
-
domain,
|
|
240
|
-
platform: 'eTrax'
|
|
220
|
+
if (!releaseGood.lmdOption) {
|
|
221
|
+
await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
|
|
241
222
|
}
|
|
242
|
-
}
|
|
223
|
+
}
|
|
243
224
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
225
|
+
if (!marketplaceOrder) {
|
|
226
|
+
throw new Error('Failed to find ecommerce order, kindly contact our support team regarding this issue')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
eTraxOption = marketplaceOrder?.marketplaceStore.eTrax
|
|
230
|
+
|
|
231
|
+
// if eTrax option is true
|
|
232
|
+
if (eTraxOption) {
|
|
233
|
+
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
234
|
+
|
|
235
|
+
// access every marketplaceOrderItems for shipping information you need
|
|
236
|
+
// trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
237
|
+
// for etrax didn't support multi awb per order
|
|
238
|
+
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
239
|
+
marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
240
|
+
const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
241
|
+
marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
242
|
+
const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
243
|
+
where: {
|
|
244
|
+
domain,
|
|
245
|
+
platform: 'eTrax'
|
|
246
|
+
}
|
|
250
247
|
})
|
|
251
248
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
pickupAddress1: warehouseContactPoint.address,
|
|
260
|
-
pickupAddress2: warehouseContactPoint.address2,
|
|
261
|
-
pickupPostcode: warehouseContactPoint.postCode,
|
|
262
|
-
pickupState: warehouseContactPoint.state,
|
|
263
|
-
pickupCity: warehouseContactPoint.city,
|
|
264
|
-
pickupPhone: warehouseContactPoint.phone,
|
|
265
|
-
pickupEmail: warehouseContactPoint.email,
|
|
266
|
-
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
267
|
-
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
268
|
-
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
269
|
-
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
270
|
-
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
271
|
-
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
272
|
-
phone: marketplaceOrderShipping.phone1 || '',
|
|
273
|
-
email: marketplaceOrderShipping.email || '',
|
|
274
|
-
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
275
|
-
quantity: marketplaceOrderItems.length
|
|
276
|
-
})
|
|
249
|
+
//Get which transporter to use
|
|
250
|
+
const marketplaceTransporter: MarketplaceTransporter = await tx
|
|
251
|
+
.getRepository(MarketplaceTransporter)
|
|
252
|
+
.findOne({
|
|
253
|
+
where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
254
|
+
relations: ['pickupTransporter', 'deliveryTransporter']
|
|
255
|
+
})
|
|
277
256
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
257
|
+
const resp = await LastMileAPI.createShipmentRequest(lmd, {
|
|
258
|
+
orderNo: marketplaceOrder.orderNo,
|
|
259
|
+
clientId: lmd.clientId,
|
|
260
|
+
clientType: lmd.clientType,
|
|
261
|
+
clientName: lmd.clientName,
|
|
262
|
+
transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
263
|
+
pickupName: warehouseContactPoint.name,
|
|
264
|
+
pickupAddress1: warehouseContactPoint.address,
|
|
265
|
+
pickupAddress2: warehouseContactPoint.address2,
|
|
266
|
+
pickupPostcode: warehouseContactPoint.postCode,
|
|
267
|
+
pickupState: warehouseContactPoint.state,
|
|
268
|
+
pickupCity: warehouseContactPoint.city,
|
|
269
|
+
pickupPhone: warehouseContactPoint.phone,
|
|
270
|
+
pickupEmail: warehouseContactPoint.email,
|
|
271
|
+
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
272
|
+
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
273
|
+
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
274
|
+
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
275
|
+
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
276
|
+
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
277
|
+
phone: marketplaceOrderShipping.phone1 || '',
|
|
278
|
+
email: marketplaceOrderShipping.email || '',
|
|
279
|
+
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
280
|
+
quantity: marketplaceOrderItems.length
|
|
281
|
+
})
|
|
281
282
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
283
|
+
const delay = (ms: number) => {
|
|
284
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (resp.Status === 'SUCCESS') {
|
|
288
|
+
//Success
|
|
289
|
+
let awbObtained = false
|
|
290
|
+
let retry = 0
|
|
291
|
+
while (!awbObtained) {
|
|
292
|
+
const marketplaceOrder2: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
293
|
+
where: { releaseOrderId: releaseGood.id },
|
|
294
|
+
relations: [
|
|
295
|
+
'marketplaceStore',
|
|
296
|
+
'marketplaceOrderItems',
|
|
297
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
298
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
299
|
+
]
|
|
300
|
+
})
|
|
301
|
+
const orderShipping =
|
|
302
|
+
marketplaceOrder2.marketplaceOrderItems[0].marketplaceOrderShippingItems[0]
|
|
303
|
+
.marketplaceOrderShipping
|
|
304
|
+
if (orderShipping?.airwayBill) {
|
|
305
|
+
awbObtained = true
|
|
306
|
+
}
|
|
307
|
+
await delay(5000)
|
|
308
|
+
//Timeout after 15sec
|
|
309
|
+
if (++retry > 3) {
|
|
310
|
+
break
|
|
311
|
+
}
|
|
305
312
|
}
|
|
313
|
+
} else {
|
|
314
|
+
if (resp?.AWBurl && resp?.TrackingNo)
|
|
315
|
+
await tx
|
|
316
|
+
.getRepository(MarketplaceOrderShipping)
|
|
317
|
+
.update(
|
|
318
|
+
{ id: marketplaceOrderShipping.id },
|
|
319
|
+
{ airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo }
|
|
320
|
+
)
|
|
321
|
+
else throw resp
|
|
306
322
|
}
|
|
307
|
-
} else {
|
|
308
|
-
if (resp?.AWBurl && resp?.TrackingNo)
|
|
309
|
-
await tx
|
|
310
|
-
.getRepository(MarketplaceOrderShipping)
|
|
311
|
-
.update(
|
|
312
|
-
{ id: marketplaceOrderShipping.id },
|
|
313
|
-
{ airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo }
|
|
314
|
-
)
|
|
315
|
-
else throw resp
|
|
316
323
|
}
|
|
317
|
-
}
|
|
318
324
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
status: ORDER_STATUS.PROCESSING,
|
|
331
|
-
releaseGood,
|
|
332
|
-
domain: releaseGood.domain,
|
|
333
|
-
bizplace: releaseGood.bizplace,
|
|
334
|
-
creator: releaseGood.creator,
|
|
335
|
-
updater: releaseGood.updater
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
let savedOrderPackage: OrderPackage = await tx.getRepository(OrderPackage).save(orderPackage)
|
|
339
|
-
const orderPackageItems: OrderPackageItem[] = releaseGood.orderProducts.map(op => {
|
|
340
|
-
return {
|
|
341
|
-
name: OrderNoGenerator.orderPackageItem(),
|
|
342
|
-
orderProduct: op,
|
|
325
|
+
await ecommerceCtrl.createOrderPackage(tx, marketplaceOrder, companyDomain, marketplaceStore, releaseGood)
|
|
326
|
+
}
|
|
327
|
+
break
|
|
328
|
+
|
|
329
|
+
default:
|
|
330
|
+
let orderPackage: OrderPackage = {
|
|
331
|
+
name: OrderNoGenerator.orderPackage(),
|
|
332
|
+
packageId: null,
|
|
333
|
+
trackingNo: null,
|
|
334
|
+
transporter: null,
|
|
335
|
+
airwayBill: null,
|
|
343
336
|
status: ORDER_STATUS.PROCESSING,
|
|
344
|
-
|
|
345
|
-
orderPackage: savedOrderPackage,
|
|
337
|
+
releaseGood,
|
|
346
338
|
domain: releaseGood.domain,
|
|
347
339
|
bizplace: releaseGood.bizplace,
|
|
348
340
|
creator: releaseGood.creator,
|
|
349
341
|
updater: releaseGood.updater
|
|
350
342
|
}
|
|
351
|
-
})
|
|
352
|
-
await tx.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
353
|
-
orderPackage.orderPackageItems = orderPackageItems
|
|
354
|
-
releaseGood.orderPackages = [orderPackage]
|
|
355
|
-
break
|
|
356
|
-
}
|
|
357
343
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
const body = {
|
|
372
|
-
accessToken: account.accessToken,
|
|
373
|
-
appId: account.accountId,
|
|
374
|
-
accountInfo: account.accountInfo,
|
|
375
|
-
req: JSON.stringify({
|
|
376
|
-
releaseGood,
|
|
377
|
-
orderProducts: releaseGood.orderProducts
|
|
378
|
-
})
|
|
344
|
+
let savedOrderPackage: OrderPackage = await tx.getRepository(OrderPackage).save(orderPackage)
|
|
345
|
+
const orderPackageItems: OrderPackageItem[] = releaseGood.orderProducts.map(op => {
|
|
346
|
+
return {
|
|
347
|
+
name: OrderNoGenerator.orderPackageItem(),
|
|
348
|
+
orderProduct: op,
|
|
349
|
+
status: ORDER_STATUS.PROCESSING,
|
|
350
|
+
releaseQty: op.releaseQty,
|
|
351
|
+
orderPackage: savedOrderPackage,
|
|
352
|
+
domain: releaseGood.domain,
|
|
353
|
+
bizplace: releaseGood.bizplace,
|
|
354
|
+
creator: releaseGood.creator,
|
|
355
|
+
updater: releaseGood.updater
|
|
379
356
|
}
|
|
357
|
+
})
|
|
358
|
+
await tx.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
359
|
+
orderPackage.orderPackageItems = orderPackageItems
|
|
360
|
+
releaseGood.orderPackages = [orderPackage]
|
|
361
|
+
break
|
|
362
|
+
}
|
|
380
363
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
364
|
+
const account: Account = await tx
|
|
365
|
+
.getRepository(Account)
|
|
366
|
+
.findOne({ where: { domain: releaseGood.bizplace.domain, status: 'active' }, relations: ['domain'] })
|
|
367
|
+
|
|
368
|
+
// Xilnex Create Sales Order and Post Sales Order to Sales Invoice
|
|
369
|
+
const createSalesOrder = async (account, releaseGood, tx) => {
|
|
370
|
+
if (account) {
|
|
371
|
+
if (account.platform == 'xilnex') {
|
|
372
|
+
try {
|
|
373
|
+
delete releaseGood.orderPackages
|
|
374
|
+
delete releaseGood.creator
|
|
375
|
+
delete releaseGood.updater
|
|
376
|
+
|
|
377
|
+
const body = {
|
|
378
|
+
accessToken: account.accessToken,
|
|
379
|
+
appId: account.accountId,
|
|
380
|
+
accountInfo: account.accountInfo,
|
|
381
|
+
req: JSON.stringify({
|
|
382
|
+
releaseGood,
|
|
383
|
+
orderProducts: releaseGood.orderProducts
|
|
384
|
+
})
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
await sqsSendMessage({
|
|
388
|
+
body,
|
|
389
|
+
deduplicationId: releaseGood.refNo,
|
|
390
|
+
groupId: releaseGood.refNo,
|
|
391
|
+
queueName: 'prototypeQueue.fifo'
|
|
392
|
+
})
|
|
393
|
+
} catch (e) {
|
|
394
|
+
console.log(`[Create Sales Order] SQS Send Message: ${e}`)
|
|
395
|
+
}
|
|
389
396
|
}
|
|
390
397
|
}
|
|
391
398
|
}
|
|
392
|
-
}
|
|
393
399
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
400
|
+
if (releaseGood.type == 'b2c') {
|
|
401
|
+
createSalesOrder(account, releaseGood, tx)
|
|
402
|
+
}
|
|
397
403
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
where: {
|
|
405
|
-
releaseGood,
|
|
406
|
-
type: WORKSHEET_TYPE.LOADING,
|
|
407
|
-
status: WORKSHEET_STATUS.DEACTIVATED
|
|
408
|
-
}
|
|
409
|
-
})
|
|
404
|
+
if (releaseGood.packingOption) {
|
|
405
|
+
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
406
|
+
await packingWSCtrl.generatePackingWorksheet(releaseGoodNo)
|
|
407
|
+
} else {
|
|
408
|
+
// Find Existing Loading Worksheet if any
|
|
409
|
+
let existLoadingWorksheet: Worksheet
|
|
410
410
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const vasWorksheet: Worksheet = await tx
|
|
415
|
-
.getRepository(Worksheet)
|
|
416
|
-
.findOne({ where: { releaseGood, type: WORKSHEET_TYPE.VAS } })
|
|
411
|
+
let orderVas: OrderVas[] = await tx.getRepository(OrderVas).find({ where: { domain: domain, releaseGood } })
|
|
412
|
+
if (orderVas?.length > 0) {
|
|
413
|
+
const wSCtrl: WorksheetController = new WorksheetController(tx, domain, user)
|
|
417
414
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
.find({ where: { domain: domain, worksheet: vasWorksheet.id } })
|
|
415
|
+
let vasWorksheet = await wSCtrl.createWorksheet(releaseGood, WORKSHEET_TYPE.VAS)
|
|
416
|
+
let vasWorksheetDetails = await wSCtrl.createWorksheetDetails(vasWorksheet, WORKSHEET_TYPE.VAS, orderVas)
|
|
421
417
|
|
|
422
418
|
if (vasWorksheet) {
|
|
423
419
|
await activateVas(tx, domain, user, vasWorksheet.name, vasWorksheetDetails)
|
|
424
420
|
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
pickedTargetInventories
|
|
434
|
-
)
|
|
435
|
-
|
|
436
|
-
if (!loadingWorksheet.worksheetDetails?.length) {
|
|
437
|
-
loadingWorksheet = await pickingWSCtrl.findWorksheetById(loadingWorksheet.id)
|
|
438
|
-
}
|
|
421
|
+
} else {
|
|
422
|
+
existLoadingWorksheet = await tx.getRepository(Worksheet).findOne({
|
|
423
|
+
where: {
|
|
424
|
+
releaseGood,
|
|
425
|
+
type: WORKSHEET_TYPE.LOADING,
|
|
426
|
+
status: WORKSHEET_STATUS.DEACTIVATED
|
|
427
|
+
}
|
|
428
|
+
})
|
|
439
429
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (!loadingWorksheet.worksheetDetails?.length) {
|
|
452
|
-
loadingWorksheet = await pickingWSCtrl.findWorksheetById(loadingWorksheet.id)
|
|
453
|
-
}
|
|
430
|
+
if (!existLoadingWorksheet && !releaseGood.courierOption && !releaseGood.packingOption) {
|
|
431
|
+
const loadingWSCtrl: LoadingWorksheetController = new LoadingWorksheetController(tx, domain, user)
|
|
432
|
+
let loadingWorksheet: Worksheet = await loadingWSCtrl.generateLoadingWorksheet(
|
|
433
|
+
releaseGoodNo,
|
|
434
|
+
pickedTargetInventories
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
if (!loadingWorksheet.worksheetDetails?.length) {
|
|
438
|
+
loadingWorksheet = await pickingWSCtrl.findWorksheetById(loadingWorksheet.id)
|
|
439
|
+
}
|
|
454
440
|
|
|
455
|
-
|
|
456
|
-
|
|
441
|
+
const loadingWorksheetDetails: WorksheetDetail[] = loadingWorksheet.worksheetDetails
|
|
442
|
+
await loadingWSCtrl.activateLoading(loadingWorksheet.name, loadingWorksheetDetails)
|
|
443
|
+
} else {
|
|
444
|
+
const loadingWSCtrl: LoadingWorksheetController = new LoadingWorksheetController(tx, domain, user)
|
|
445
|
+
let loadingWorksheet: Worksheet = await loadingWSCtrl.updateLoadingWorksheet(
|
|
446
|
+
releaseGoodNo,
|
|
447
|
+
pickedTargetInventories,
|
|
448
|
+
existLoadingWorksheet
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
if (!loadingWorksheet.worksheetDetails?.length) {
|
|
452
|
+
loadingWorksheet = await pickingWSCtrl.findWorksheetById(loadingWorksheet.id)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const loadingWorksheetDetails: WorksheetDetail[] = loadingWorksheet.worksheetDetails
|
|
456
|
+
await loadingWSCtrl.activateLoading(loadingWorksheet.name, loadingWorksheetDetails)
|
|
457
|
+
}
|
|
458
|
+
}
|
|
457
459
|
}
|
|
458
|
-
}
|
|
459
460
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
})
|
|
477
|
-
if (sellercraft) {
|
|
478
|
-
const sellercraftCtrl: SellercraftController = new SellercraftController(tx, null, null)
|
|
479
|
-
const rtsTriggerLevel: Setting = await tx.getRepository(Setting).findOne({
|
|
480
|
-
where: { domain: releaseGood.domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
461
|
+
// trigger LMD API to create parcel
|
|
462
|
+
if (
|
|
463
|
+
releaseGood?.orderPackages?.length &&
|
|
464
|
+
releaseGood.lmdOption &&
|
|
465
|
+
releaseGood.lastMileDelivery &&
|
|
466
|
+
releaseGood?.orderPackages?.some(op => op.parcelId == null)
|
|
467
|
+
) {
|
|
468
|
+
await createLmdParcel([releaseGood], tx, domain, user, marketplaceOrder)
|
|
469
|
+
// trigger RTS
|
|
470
|
+
try {
|
|
471
|
+
const orderSource: string = releaseGood.source
|
|
472
|
+
|
|
473
|
+
if (orderSource == ApplicationType.SELLERCRAFT) {
|
|
474
|
+
const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({
|
|
475
|
+
domain: releaseGood.bizplace.domain,
|
|
476
|
+
status: SellercraftStatus.ACTIVE
|
|
481
477
|
})
|
|
478
|
+
if (sellercraft) {
|
|
479
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(tx, null, null)
|
|
480
|
+
const rtsTriggerLevel: Setting = await tx.getRepository(Setting).findOne({
|
|
481
|
+
where: { domain: releaseGood.domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
482
|
+
})
|
|
482
483
|
|
|
483
|
-
|
|
484
|
-
|
|
484
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
485
|
+
sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
486
|
+
}
|
|
485
487
|
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
const powrup: Powrup = await tx.getRepository(Powrup).findOne({ active: true, platform: 'POWRUP' })
|
|
488
|
+
} else if (orderSource == ApplicationType.POWRUP) {
|
|
489
|
+
const powrup: Powrup = await tx.getRepository(Powrup).findOne({ active: true, platform: 'POWRUP' })
|
|
489
490
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
491
|
+
if (powrup) {
|
|
492
|
+
const powrupController: PowrupController = new PowrupController()
|
|
493
|
+
const rtsTriggerLevel: Setting = await tx.getRepository(Setting).findOne({
|
|
494
|
+
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
495
|
+
})
|
|
495
496
|
|
|
496
|
-
|
|
497
|
-
|
|
497
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
498
|
+
powrupController.initiateShipment(powrup, releaseGood, domain, user, tx)
|
|
499
|
+
}
|
|
498
500
|
}
|
|
499
501
|
}
|
|
502
|
+
} catch (e) {
|
|
503
|
+
logger.error(`[get-lmd-awb-sof-trigger]: ${e}`)
|
|
500
504
|
}
|
|
501
|
-
|
|
502
|
-
logger.error(`[get-lmd-awb-sof-trigger]: ${e}`)
|
|
505
|
+
//
|
|
503
506
|
}
|
|
504
507
|
//
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
//update inventories obsolete to true
|
|
509
|
-
await tx.getRepository(Inventory).update({ id: In(foundObsoleteInventories) }, { obsolete: true })
|
|
508
|
+
} else {
|
|
509
|
+
//update inventories obsolete to true
|
|
510
|
+
await tx.getRepository(Inventory).update({ id: In(foundObsoleteInventories) }, { obsolete: true })
|
|
510
511
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
512
|
+
foundObsoleteInventories = foundObsoleteInventories
|
|
513
|
+
.map(inv => {
|
|
514
|
+
return "'" + inv.trim() + "'"
|
|
515
|
+
})
|
|
516
|
+
.join(',')
|
|
516
517
|
|
|
517
|
-
|
|
518
|
-
|
|
518
|
+
//update any orders that is assigned with obsolete inventories
|
|
519
|
+
await tx.getRepository(ReleaseGood).query(`
|
|
519
520
|
update release_goods rg set status = 'OBSOLETE'
|
|
520
521
|
from order_inventories oi
|
|
521
522
|
where oi.release_good_id = rg.id
|
|
522
523
|
and oi.inventory_id in (${foundObsoleteInventories})
|
|
523
524
|
and rg.status in ('PICKING', 'PENDING_WORKSHEET', 'READY_TO_PICK')`)
|
|
524
525
|
|
|
525
|
-
|
|
526
|
+
await tx.getRepository(Worksheet).query(`
|
|
526
527
|
update worksheets w set status = 'DEACTIVATED', updater_id = '${user.id}', assignee_id = null
|
|
527
528
|
from worksheet_details wd
|
|
528
529
|
inner join order_inventories oi on oi.id = wd.target_inventory_id
|
|
@@ -530,21 +531,24 @@ export async function completePicking(
|
|
|
530
531
|
and oi.inventory_id in (${foundObsoleteInventories})
|
|
531
532
|
`)
|
|
532
533
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
534
|
+
return true
|
|
535
|
+
}
|
|
536
|
+
} else {
|
|
537
|
+
let replenishment: Replenishment = await tx.getRepository(Replenishment).findOne({
|
|
538
|
+
where: { domain, name: releaseGoodNo }
|
|
539
|
+
})
|
|
539
540
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
541
|
+
const worksheet: Worksheet = await pickingWSCtrl.findWorksheetByRefOrder(
|
|
542
|
+
replenishment,
|
|
543
|
+
WORKSHEET_TYPE.PICKING_REPLENISHMENT,
|
|
544
|
+
['worksheetDetails', 'worksheetDetails.targetInventory', 'worksheetDetails.targetInventory.inventory']
|
|
545
|
+
)
|
|
545
546
|
|
|
546
|
-
|
|
547
|
+
await replenishmentPickingWSCtrl.completeReplenishmentPicking(replenishment, worksheet)
|
|
547
548
|
|
|
548
|
-
|
|
549
|
+
await replenishmentPickingWSCtrl.generatePutawayReplenishmentWorksheet(releaseGoodNo)
|
|
550
|
+
}
|
|
551
|
+
} catch (error) {
|
|
552
|
+
throw error
|
|
549
553
|
}
|
|
550
554
|
}
|