@things-factory/worksheet-base 4.3.156 → 4.3.159
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/inbound/putaway-returning-worksheet-controller.js +1 -3
- package/dist-server/controllers/inbound/putaway-returning-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/inbound/putaway-worksheet-controller.js +1 -3
- package/dist-server/controllers/inbound/putaway-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/picking-worksheet-controller.js +13 -16
- package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/worksheet-controller.js +17 -9
- package/dist-server/controllers/worksheet-controller.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js +0 -4
- package/dist-server/graphql/resolvers/worksheet/inventories-by-pallet.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js +118 -146
- package/dist-server/graphql/resolvers/worksheet/picking/complete-batch-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js +216 -245
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.js +4 -12
- package/dist-server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.js.map +1 -1
- package/dist-server/utils/inventory-util.js +1 -29
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +18 -18
- package/server/controllers/inbound/putaway-returning-worksheet-controller.ts +1 -3
- package/server/controllers/inbound/putaway-worksheet-controller.ts +1 -3
- package/server/controllers/outbound/picking-worksheet-controller.ts +15 -23
- package/server/controllers/worksheet-controller.ts +17 -13
- package/server/graphql/resolvers/worksheet/inventories-by-pallet.ts +0 -7
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +131 -168
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +237 -272
- package/server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.ts +7 -17
- package/server/utils/inventory-util.ts +0 -36
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManager, getManager
|
|
1
|
+
import { EntityManager, getManager } from 'typeorm'
|
|
2
2
|
|
|
3
3
|
import { ApplicationType, User } from '@things-factory/auth-base'
|
|
4
4
|
import { Bizplace, ContactPoint, getMyBizplace } from '@things-factory/biz-base'
|
|
@@ -33,7 +33,6 @@ import {
|
|
|
33
33
|
PickingWorksheetController,
|
|
34
34
|
SellercraftController
|
|
35
35
|
} from '../../../../controllers/'
|
|
36
|
-
import { Inventory } from '@things-factory/warehouse-base'
|
|
37
36
|
import { EcommerceController } from '../../../../controllers/ecommerce'
|
|
38
37
|
import { WorksheetController } from '../../../../controllers/worksheet-controller'
|
|
39
38
|
import { Worksheet, WorksheetDetail } from '../../../../entities'
|
|
@@ -60,7 +59,7 @@ export async function completePicking(
|
|
|
60
59
|
domain: Domain,
|
|
61
60
|
user: User,
|
|
62
61
|
releaseGoodNo: string
|
|
63
|
-
): Promise<
|
|
62
|
+
): Promise<void> {
|
|
64
63
|
const pickingWSCtrl: PickingWorksheetController = new PickingWorksheetController(tx, domain, user)
|
|
65
64
|
let releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
|
|
66
65
|
where: { domain, name: releaseGoodNo },
|
|
@@ -81,8 +80,7 @@ export async function completePicking(
|
|
|
81
80
|
|
|
82
81
|
const worksheet: Worksheet = await pickingWSCtrl.findWorksheetByRefOrder(releaseGood, WORKSHEET_TYPE.PICKING, [
|
|
83
82
|
'worksheetDetails',
|
|
84
|
-
'worksheetDetails.targetInventory'
|
|
85
|
-
'worksheetDetails.targetInventory.inventory'
|
|
83
|
+
'worksheetDetails.targetInventory'
|
|
86
84
|
])
|
|
87
85
|
|
|
88
86
|
const warehouseContactPoint: ContactPoint = await tx.getRepository(ContactPoint).findOne({
|
|
@@ -94,287 +92,267 @@ export async function completePicking(
|
|
|
94
92
|
|
|
95
93
|
const worksheetDetails: WorksheetDetail[] = worksheet.worksheetDetails
|
|
96
94
|
const targetInventories: OrderInventory[] = worksheetDetails.map((wsd: WorksheetDetail) => wsd.targetInventory)
|
|
97
|
-
const inventories: Inventory[] = targetInventories.map((ti: OrderInventory) => ti.inventory)
|
|
98
95
|
const pickedTargetInventories: OrderInventory[] = targetInventories.filter(
|
|
99
96
|
targetInventory => targetInventory.status === ORDER_INVENTORY_STATUS.PICKED
|
|
100
97
|
)
|
|
101
98
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
111
|
-
|
|
112
|
-
if (sellercraft) {
|
|
113
|
-
const initSCOrderShipment = async sellercraft => {
|
|
114
|
-
await getManager().transaction(async txMgr => {
|
|
115
|
-
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
116
|
-
|
|
117
|
-
if (!releaseGood?.orderPackages?.length && !releaseGood?.marketPackCallSuccess) {
|
|
118
|
-
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
119
|
-
where: { releaseGood },
|
|
120
|
-
relations: ['product', 'product.productDetails']
|
|
121
|
-
})
|
|
122
|
-
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
123
|
-
}
|
|
99
|
+
await pickingWSCtrl.completePicking(releaseGoodNo)
|
|
100
|
+
|
|
101
|
+
const orderSource: string = releaseGood.source
|
|
102
|
+
switch (orderSource) {
|
|
103
|
+
case ApplicationType.SELLERCRAFT:
|
|
104
|
+
const sellercraft: Sellercraft = await tx
|
|
105
|
+
.getRepository(Sellercraft)
|
|
106
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
|
|
124
107
|
|
|
125
|
-
|
|
126
|
-
|
|
108
|
+
if (sellercraft) {
|
|
109
|
+
const initSCOrderShipment = async sellercraft => {
|
|
110
|
+
await getManager().transaction(async txMgr => {
|
|
111
|
+
const sellercraftCtrl: SellercraftController = new SellercraftController(txMgr, domain, user)
|
|
112
|
+
|
|
113
|
+
if (!releaseGood?.orderPackages?.length && !releaseGood?.marketPackCallSuccess) {
|
|
114
|
+
const orderProducts: OrderProduct[] = await txMgr.getRepository(OrderProduct).find({
|
|
115
|
+
where: { releaseGood },
|
|
116
|
+
relations: ['product', 'product.productDetails']
|
|
127
117
|
})
|
|
118
|
+
await sellercraftCtrl.packOrder(sellercraft, { ...releaseGood, orderProducts })
|
|
119
|
+
}
|
|
128
120
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
121
|
+
const rtsTriggerLevel: Setting = await txMgr.getRepository(Setting).findOne({
|
|
122
|
+
where: { domain, category: 'id-rule', name: 'rts-trigger-level' }
|
|
132
123
|
})
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
|
|
125
|
+
if (rtsTriggerLevel && parseInt(rtsTriggerLevel?.value || 0) == 1) {
|
|
126
|
+
await sellercraftCtrl.initiateOrderShipment(sellercraft, releaseGood)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
136
129
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
155
|
-
let eTraxOption: boolean
|
|
156
|
-
|
|
157
|
-
if (marketplaceStore?.isAutoUpdateShipment) {
|
|
158
|
-
await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
|
|
159
|
-
|
|
160
|
-
await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
|
|
161
|
-
}
|
|
130
|
+
// asynchronouly call to initiate sellercraft order shipment/ RTS
|
|
131
|
+
initSCOrderShipment(sellercraft)
|
|
132
|
+
}
|
|
133
|
+
break
|
|
134
|
+
|
|
135
|
+
case ApplicationType.MMS:
|
|
136
|
+
const companyDomain: Domain = releaseGood.bizplace.company.domain
|
|
137
|
+
let marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
138
|
+
where: { orderNo: releaseGood.refNo, domain: companyDomain },
|
|
139
|
+
relations: [
|
|
140
|
+
'marketplaceStore',
|
|
141
|
+
'marketplaceStore.marketplaceDistributors',
|
|
142
|
+
'marketplaceOrderItems',
|
|
143
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
144
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
145
|
+
]
|
|
146
|
+
})
|
|
162
147
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
if (marketplaceOrder) {
|
|
149
|
+
const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
|
|
150
|
+
const marketplaceStore: MarketplaceStore = marketplaceOrder.marketplaceStore
|
|
151
|
+
let eTraxOption: boolean
|
|
166
152
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// if eTrax option is true
|
|
170
|
-
if (eTraxOption) {
|
|
171
|
-
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
172
|
-
|
|
173
|
-
// access every marketplaceOrderItems for shipping information you need
|
|
174
|
-
// trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
175
|
-
// for etrax didn't support multi awb per order
|
|
176
|
-
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
177
|
-
marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
178
|
-
const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
179
|
-
marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
180
|
-
const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
181
|
-
where: {
|
|
182
|
-
domain,
|
|
183
|
-
platform: 'eTrax'
|
|
184
|
-
}
|
|
185
|
-
})
|
|
153
|
+
if (marketplaceStore?.isAutoUpdateShipment) {
|
|
154
|
+
await ecommerceCtrl.createOrderComment(marketplaceStore, marketplaceOrder, ORDER_STATUS.PACKING)
|
|
186
155
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
.getRepository(MarketplaceTransporter)
|
|
190
|
-
.findOne({
|
|
191
|
-
where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
192
|
-
relations: ['pickupTransporter', 'deliveryTransporter']
|
|
193
|
-
})
|
|
156
|
+
await ecommerceCtrl.createOrderShip(releaseGood, marketplaceStore, marketplaceOrder, companyDomain)
|
|
157
|
+
}
|
|
194
158
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
clientType: lmd.clientType,
|
|
199
|
-
clientName: lmd.clientName,
|
|
200
|
-
transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
201
|
-
pickupName: warehouseContactPoint.name,
|
|
202
|
-
pickupAddress1: warehouseContactPoint.address,
|
|
203
|
-
pickupAddress2: warehouseContactPoint.address2,
|
|
204
|
-
pickupPostcode: warehouseContactPoint.postCode,
|
|
205
|
-
pickupState: warehouseContactPoint.state,
|
|
206
|
-
pickupCity: warehouseContactPoint.city,
|
|
207
|
-
pickupPhone: warehouseContactPoint.phone,
|
|
208
|
-
pickupEmail: warehouseContactPoint.email,
|
|
209
|
-
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
210
|
-
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
211
|
-
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
212
|
-
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
213
|
-
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
214
|
-
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
215
|
-
phone: marketplaceOrderShipping.phone1 || '',
|
|
216
|
-
email: marketplaceOrderShipping.email || '',
|
|
217
|
-
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
218
|
-
quantity: marketplaceOrderItems.length
|
|
219
|
-
})
|
|
159
|
+
if (!marketplaceOrder) {
|
|
160
|
+
throw new Error('Failed to find ecommerce order, kindly contact our support team regarding this issue')
|
|
161
|
+
}
|
|
220
162
|
|
|
221
|
-
|
|
222
|
-
|
|
163
|
+
eTraxOption = marketplaceOrder?.marketplaceStore.eTrax
|
|
164
|
+
|
|
165
|
+
// if eTrax option is true
|
|
166
|
+
if (eTraxOption) {
|
|
167
|
+
const marketplaceOrderItems: MarketplaceOrderItem[] = marketplaceOrder.marketplaceOrderItems
|
|
168
|
+
|
|
169
|
+
// access every marketplaceOrderItems for shipping information you need
|
|
170
|
+
// trigger the controller from integration-lmd that trigger the API, build the parameters needed
|
|
171
|
+
// for etrax didn't support multi awb per order
|
|
172
|
+
const marketplaceOrderShippingItems: MarketplaceOrderShippingItem[] =
|
|
173
|
+
marketplaceOrderItems[0].marketplaceOrderShippingItems
|
|
174
|
+
const marketplaceOrderShipping: MarketplaceOrderShipping =
|
|
175
|
+
marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
176
|
+
const lmd: LastMileDelivery = await tx.getRepository(LastMileDelivery).findOne({
|
|
177
|
+
where: {
|
|
178
|
+
domain,
|
|
179
|
+
platform: 'eTrax'
|
|
223
180
|
}
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
//Get which transporter to use
|
|
184
|
+
const marketplaceTransporter: MarketplaceTransporter = await tx
|
|
185
|
+
.getRepository(MarketplaceTransporter)
|
|
186
|
+
.findOne({
|
|
187
|
+
where: { marketplaceStore: marketplaceOrder.marketplaceStore },
|
|
188
|
+
relations: ['pickupTransporter', 'deliveryTransporter']
|
|
189
|
+
})
|
|
224
190
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
191
|
+
const resp = await LastMileAPI.createShipmentRequest(lmd, {
|
|
192
|
+
orderNo: marketplaceOrder.orderNo,
|
|
193
|
+
clientId: lmd.clientId,
|
|
194
|
+
clientType: lmd.clientType,
|
|
195
|
+
clientName: lmd.clientName,
|
|
196
|
+
transporterId: marketplaceTransporter.pickupTransporter.transporterId,
|
|
197
|
+
pickupName: warehouseContactPoint.name,
|
|
198
|
+
pickupAddress1: warehouseContactPoint.address,
|
|
199
|
+
pickupAddress2: warehouseContactPoint.address2,
|
|
200
|
+
pickupPostcode: warehouseContactPoint.postCode,
|
|
201
|
+
pickupState: warehouseContactPoint.state,
|
|
202
|
+
pickupCity: warehouseContactPoint.city,
|
|
203
|
+
pickupPhone: warehouseContactPoint.phone,
|
|
204
|
+
pickupEmail: warehouseContactPoint.email,
|
|
205
|
+
name: marketplaceOrderShipping?.attentionTo ? marketplaceOrderShipping.attentionTo.trim() : '',
|
|
206
|
+
address1: marketplaceOrderShipping?.address1 ? marketplaceOrderShipping?.address1.trim() : '-',
|
|
207
|
+
address2: marketplaceOrderShipping?.address2 ? marketplaceOrderShipping?.address2.trim() : '-',
|
|
208
|
+
postCode: marketplaceOrderShipping?.postCode ? marketplaceOrderShipping?.postCode.trim() : '',
|
|
209
|
+
city: marketplaceOrderShipping?.city ? marketplaceOrderShipping?.city.trim() : '',
|
|
210
|
+
state: marketplaceOrderShipping?.state ? marketplaceOrderShipping?.state.trim() : '',
|
|
211
|
+
phone: marketplaceOrderShipping.phone1 || '',
|
|
212
|
+
email: marketplaceOrderShipping.email || '',
|
|
213
|
+
attentionTo: marketplaceOrderShipping.attentionTo,
|
|
214
|
+
quantity: marketplaceOrderItems.length
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const delay = (ms: number) => {
|
|
218
|
+
return new Promise(resolve => setTimeout(resolve, ms))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (resp.Status === 'SUCCESS') {
|
|
222
|
+
//Success
|
|
223
|
+
let awbObtained = false
|
|
224
|
+
let retry = 0
|
|
225
|
+
while (!awbObtained) {
|
|
226
|
+
const marketplaceOrder2: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
|
|
227
|
+
where: { releaseOrderId: releaseGood.id },
|
|
228
|
+
relations: [
|
|
229
|
+
'marketplaceStore',
|
|
230
|
+
'marketplaceOrderItems',
|
|
231
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems',
|
|
232
|
+
'marketplaceOrderItems.marketplaceOrderShippingItems.marketplaceOrderShipping'
|
|
233
|
+
]
|
|
234
|
+
})
|
|
235
|
+
const orderShipping =
|
|
236
|
+
marketplaceOrder2.marketplaceOrderItems[0].marketplaceOrderShippingItems[0].marketplaceOrderShipping
|
|
237
|
+
if (orderShipping?.airwayBill) {
|
|
238
|
+
awbObtained = true
|
|
239
|
+
}
|
|
240
|
+
await delay(5000)
|
|
241
|
+
//Timeout after 15sec
|
|
242
|
+
if (++retry > 3) {
|
|
243
|
+
break
|
|
249
244
|
}
|
|
250
|
-
} else {
|
|
251
|
-
if (resp?.AWBurl && resp?.TrackingNo)
|
|
252
|
-
await tx
|
|
253
|
-
.getRepository(MarketplaceOrderShipping)
|
|
254
|
-
.update({ id: marketplaceOrderShipping.id }, { airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo })
|
|
255
|
-
else throw resp
|
|
256
245
|
}
|
|
246
|
+
} else {
|
|
247
|
+
if (resp?.AWBurl && resp?.TrackingNo)
|
|
248
|
+
await tx
|
|
249
|
+
.getRepository(MarketplaceOrderShipping)
|
|
250
|
+
.update({ id: marketplaceOrderShipping.id }, { airwayBill: resp.AWBurl, trackingNo: resp.TrackingNo })
|
|
251
|
+
else throw resp
|
|
257
252
|
}
|
|
258
|
-
|
|
259
|
-
await ecommerceCtrl.createOrderPackage(tx, marketplaceOrder, companyDomain, marketplaceStore, releaseGood)
|
|
260
253
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
254
|
+
|
|
255
|
+
await ecommerceCtrl.createOrderPackage(tx, marketplaceOrder, companyDomain, marketplaceStore, releaseGood)
|
|
256
|
+
}
|
|
257
|
+
break
|
|
258
|
+
|
|
259
|
+
default:
|
|
260
|
+
const orderPackage: OrderPackage = {
|
|
261
|
+
name: OrderNoGenerator.orderPackage(),
|
|
262
|
+
packageId: null,
|
|
263
|
+
trackingNo: null,
|
|
264
|
+
transporter: null,
|
|
265
|
+
airwayBill: null,
|
|
266
|
+
status: ORDER_STATUS.PROCESSING,
|
|
267
|
+
releaseGood,
|
|
268
|
+
domain: releaseGood.domain,
|
|
269
|
+
bizplace: releaseGood.bizplace,
|
|
270
|
+
creator: releaseGood.creator,
|
|
271
|
+
updater: releaseGood.updater
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let savedOrderPackage: OrderPackage = await tx.getRepository(OrderPackage).save(orderPackage)
|
|
275
|
+
const orderPackageItems: OrderPackageItem[] = releaseGood.orderProducts.map(op => {
|
|
276
|
+
return {
|
|
277
|
+
name: OrderNoGenerator.orderPackageItem(),
|
|
278
|
+
orderProduct: op,
|
|
270
279
|
status: ORDER_STATUS.PROCESSING,
|
|
271
|
-
|
|
280
|
+
releaseQty: op.releaseQty,
|
|
281
|
+
orderPackage: savedOrderPackage,
|
|
272
282
|
domain: releaseGood.domain,
|
|
273
283
|
bizplace: releaseGood.bizplace,
|
|
274
284
|
creator: releaseGood.creator,
|
|
275
285
|
updater: releaseGood.updater
|
|
276
286
|
}
|
|
287
|
+
})
|
|
277
288
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
name: OrderNoGenerator.orderPackageItem(),
|
|
282
|
-
orderProduct: op,
|
|
283
|
-
status: ORDER_STATUS.PROCESSING,
|
|
284
|
-
releaseQty: op.releaseQty,
|
|
285
|
-
orderPackage: savedOrderPackage,
|
|
286
|
-
domain: releaseGood.domain,
|
|
287
|
-
bizplace: releaseGood.bizplace,
|
|
288
|
-
creator: releaseGood.creator,
|
|
289
|
-
updater: releaseGood.updater
|
|
290
|
-
}
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
await tx.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
294
|
-
break
|
|
295
|
-
}
|
|
289
|
+
await tx.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
290
|
+
break
|
|
291
|
+
}
|
|
296
292
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
293
|
+
const account: Account = await tx
|
|
294
|
+
.getRepository(Account)
|
|
295
|
+
.findOne({ domain: releaseGood.bizplace.domain, status: 'active' })
|
|
296
|
+
|
|
297
|
+
// Xilnex Create Sales Order and Post Sales Order to Sales Invoice
|
|
298
|
+
const createSalesOrder = async (account, tx) => {
|
|
299
|
+
if (account) {
|
|
300
|
+
try {
|
|
301
|
+
if (account.platform == 'xilnex') {
|
|
302
|
+
const salesOrder: any = await AccountingAPI.createSalesOrder(account, {
|
|
303
|
+
releaseGood,
|
|
304
|
+
orderProducts: releaseGood.orderProducts
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
if (salesOrder) {
|
|
308
|
+
const salesInvoice: any = await AccountingAPI.postSalesOrderToSalesInvoice(account, {
|
|
309
|
+
orderId: salesOrder?.id || null
|
|
309
310
|
})
|
|
310
311
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
312
|
+
const salesOrderItems: any = salesInvoice.sale.items
|
|
313
|
+
await Promise.all(
|
|
314
|
+
releaseGood.orderProducts.map(async op => {
|
|
315
|
+
const matchedProduct: any = salesOrderItems.find(soi => soi.itemId == op.productDetail.refCode)
|
|
316
|
+
if (matchedProduct) {
|
|
317
|
+
await tx.getRepository(OrderProduct).update({ id: op.id }, { refItemId: matchedProduct.id })
|
|
318
|
+
}
|
|
314
319
|
})
|
|
320
|
+
)
|
|
315
321
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const matchedProduct: any = salesOrderItems.find(soi => soi.itemId == op.productDetail.refCode)
|
|
320
|
-
if (matchedProduct) {
|
|
321
|
-
await tx.getRepository(OrderProduct).update({ id: op.id }, { refItemId: matchedProduct.id })
|
|
322
|
-
}
|
|
323
|
-
})
|
|
324
|
-
)
|
|
325
|
-
|
|
326
|
-
await tx
|
|
327
|
-
.getRepository(ReleaseGood)
|
|
328
|
-
.update(
|
|
329
|
-
{ id: releaseGood.id },
|
|
330
|
-
{ collectionOrderNo: salesInvoice.salesId, updater: releaseGood.updater }
|
|
331
|
-
)
|
|
332
|
-
}
|
|
322
|
+
await tx
|
|
323
|
+
.getRepository(ReleaseGood)
|
|
324
|
+
.update({ id: releaseGood.id }, { collectionOrderNo: salesInvoice.salesId, updater: releaseGood.updater })
|
|
333
325
|
}
|
|
334
|
-
} catch (error) {
|
|
335
|
-
logger.error(`complete-picking[createSalesOrder]: ${error}`)
|
|
336
326
|
}
|
|
327
|
+
} catch (error) {
|
|
328
|
+
logger.error(`complete-picking[createSalesOrder]: ${error}`)
|
|
337
329
|
}
|
|
338
330
|
}
|
|
331
|
+
}
|
|
339
332
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (releaseGood.packingOption) {
|
|
345
|
-
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
346
|
-
await packingWSCtrl.generatePackingWorksheet(releaseGoodNo)
|
|
347
|
-
} else {
|
|
348
|
-
// Find Existing Loading Worksheet if any
|
|
349
|
-
let existLoadingWorksheet: Worksheet = await tx.getRepository(Worksheet).findOne({
|
|
350
|
-
where: {
|
|
351
|
-
releaseGood,
|
|
352
|
-
type: WORKSHEET_TYPE.LOADING,
|
|
353
|
-
status: WORKSHEET_STATUS.DEACTIVATED
|
|
354
|
-
}
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
if (!existLoadingWorksheet && !releaseGood.courierOption && !releaseGood.packingOption) {
|
|
358
|
-
if (pickedTargetInventories.length > 0) {
|
|
359
|
-
const loadingWSCtrl: LoadingWorksheetController = new LoadingWorksheetController(tx, domain, user)
|
|
360
|
-
let loadingWorksheet: Worksheet = await loadingWSCtrl.generateLoadingWorksheet(
|
|
361
|
-
releaseGoodNo,
|
|
362
|
-
pickedTargetInventories
|
|
363
|
-
)
|
|
333
|
+
if (releaseGood.type == 'b2c') {
|
|
334
|
+
await createSalesOrder(account, tx)
|
|
335
|
+
}
|
|
364
336
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
337
|
+
if (releaseGood.packingOption) {
|
|
338
|
+
const packingWSCtrl: PackingWorksheetController = new PackingWorksheetController(tx, domain, user)
|
|
339
|
+
await packingWSCtrl.generatePackingWorksheet(releaseGoodNo)
|
|
340
|
+
} else {
|
|
341
|
+
// Find Existing Loading Worksheet if any
|
|
342
|
+
let existLoadingWorksheet: Worksheet = await tx.getRepository(Worksheet).findOne({
|
|
343
|
+
where: {
|
|
344
|
+
releaseGood,
|
|
345
|
+
type: WORKSHEET_TYPE.LOADING,
|
|
346
|
+
status: WORKSHEET_STATUS.DEACTIVATED
|
|
347
|
+
}
|
|
348
|
+
})
|
|
368
349
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
} else {
|
|
350
|
+
if (!existLoadingWorksheet && !releaseGood.courierOption && !releaseGood.packingOption) {
|
|
351
|
+
if (pickedTargetInventories.length > 0) {
|
|
373
352
|
const loadingWSCtrl: LoadingWorksheetController = new LoadingWorksheetController(tx, domain, user)
|
|
374
|
-
let loadingWorksheet: Worksheet = await loadingWSCtrl.
|
|
353
|
+
let loadingWorksheet: Worksheet = await loadingWSCtrl.generateLoadingWorksheet(
|
|
375
354
|
releaseGoodNo,
|
|
376
|
-
pickedTargetInventories
|
|
377
|
-
existLoadingWorksheet
|
|
355
|
+
pickedTargetInventories
|
|
378
356
|
)
|
|
379
357
|
|
|
380
358
|
if (!loadingWorksheet.worksheetDetails?.length) {
|
|
@@ -384,33 +362,20 @@ export async function completePicking(
|
|
|
384
362
|
const loadingWorksheetDetails: WorksheetDetail[] = loadingWorksheet.worksheetDetails
|
|
385
363
|
await loadingWSCtrl.activateLoading(loadingWorksheet.name, loadingWorksheetDetails)
|
|
386
364
|
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
365
|
+
} else {
|
|
366
|
+
const loadingWSCtrl: LoadingWorksheetController = new LoadingWorksheetController(tx, domain, user)
|
|
367
|
+
let loadingWorksheet: Worksheet = await loadingWSCtrl.updateLoadingWorksheet(
|
|
368
|
+
releaseGoodNo,
|
|
369
|
+
pickedTargetInventories,
|
|
370
|
+
existLoadingWorksheet
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
if (!loadingWorksheet.worksheetDetails?.length) {
|
|
374
|
+
loadingWorksheet = await pickingWSCtrl.findWorksheetById(loadingWorksheet.id)
|
|
375
|
+
}
|
|
391
376
|
|
|
392
|
-
|
|
393
|
-
.
|
|
394
|
-
|
|
395
|
-
})
|
|
396
|
-
.join(',')
|
|
397
|
-
|
|
398
|
-
//update any orders that is assigned with obsolete inventories
|
|
399
|
-
await tx.getRepository(ReleaseGood).query(`
|
|
400
|
-
update release_goods rg set status = 'OBSOLETE'
|
|
401
|
-
from order_inventories oi
|
|
402
|
-
where oi.release_good_id = rg.id
|
|
403
|
-
and oi.inventory_id in (${foundObsoleteInventories})
|
|
404
|
-
and rg.status in ('PICKING', 'PENDING_WORKSHEET', 'READY_TO_PICK')`)
|
|
405
|
-
|
|
406
|
-
await tx.getRepository(Worksheet).query(`
|
|
407
|
-
update worksheets w set status = 'DEACTIVATED', updater_id = '${user.id}', assignee_id = null
|
|
408
|
-
from worksheet_details wd
|
|
409
|
-
inner join order_inventories oi on oi.id = wd.target_inventory_id
|
|
410
|
-
where wd.worksheet_id = w.id
|
|
411
|
-
and oi.inventory_id in (${foundObsoleteInventories})
|
|
412
|
-
`)
|
|
413
|
-
|
|
414
|
-
return false
|
|
377
|
+
const loadingWorksheetDetails: WorksheetDetail[] = loadingWorksheet.worksheetDetails
|
|
378
|
+
await loadingWSCtrl.activateLoading(loadingWorksheet.name, loadingWorksheetDetails)
|
|
379
|
+
}
|
|
415
380
|
}
|
|
416
381
|
}
|
package/server/graphql/resolvers/worksheet-detail/regenerate-release-good-worksheet-details.ts
CHANGED
|
@@ -81,23 +81,13 @@ export async function regenerateReleaseGoodWorksheetDetails(
|
|
|
81
81
|
await Promise.all(
|
|
82
82
|
prevOrderInventories.map(async prevOI => {
|
|
83
83
|
if (prevOI?.inventory) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
)
|
|
92
|
-
} else {
|
|
93
|
-
await tx.getRepository(Inventory).update(
|
|
94
|
-
{ id: prevOI.inventory.id },
|
|
95
|
-
{
|
|
96
|
-
lockedQty: prevOI.inventory.lockedQty - prevOI.releaseQty,
|
|
97
|
-
lockedUomValue: prevOI.inventory.lockedUomValue - prevOI.releaseUomValue
|
|
98
|
-
}
|
|
99
|
-
)
|
|
100
|
-
}
|
|
84
|
+
await tx.getRepository(Inventory).update(
|
|
85
|
+
{ id: prevOI.inventory.id },
|
|
86
|
+
{
|
|
87
|
+
lockedQty: prevOI.inventory.lockedQty - prevOI.releaseQty,
|
|
88
|
+
lockedUomValue: prevOI.inventory.lockedUomValue - prevOI.releaseUomValue
|
|
89
|
+
}
|
|
90
|
+
)
|
|
101
91
|
}
|
|
102
92
|
})
|
|
103
93
|
)
|