@things-factory/worksheet-base 4.3.243 → 4.3.246
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/controllers/ecommerce/index.js +0 -1
- package/dist-server/controllers/ecommerce/index.js.map +1 -1
- package/dist-server/controllers/outbound/packing-worksheet-controller.js +2 -2
- package/dist-server/controllers/outbound/packing-worksheet-controller.js.map +1 -1
- package/dist-server/controllers/outbound/picking-worksheet-controller.js +3 -3
- package/dist-server/controllers/outbound/picking-worksheet-controller.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js +21 -0
- package/dist-server/graphql/resolvers/worksheet/confirm-cancellation-release-order.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing/packing.js +3 -3
- package/dist-server/graphql/resolvers/worksheet/packing/packing.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.js +2 -2
- package/dist-server/graphql/resolvers/worksheet/packing-worksheet.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 +2 -2
- package/dist-server/graphql/resolvers/worksheet/picking/complete-picking.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/putaway/complete-putaway.js +10 -8
- package/dist-server/graphql/resolvers/worksheet/putaway/complete-putaway.js.map +1 -1
- package/dist-server/graphql/resolvers/worksheet/putaway-return/complete-putaway-return.js +12 -9
- package/dist-server/graphql/resolvers/worksheet/putaway-return/complete-putaway-return.js.map +1 -1
- package/package.json +5 -5
- package/server/controllers/ecommerce/index.ts +0 -1
- package/server/controllers/outbound/packing-worksheet-controller.ts +5 -4
- package/server/controllers/outbound/picking-worksheet-controller.ts +14 -8
- package/server/graphql/resolvers/worksheet/confirm-cancellation-release-order.ts +46 -13
- package/server/graphql/resolvers/worksheet/packing/packing.ts +4 -5
- package/server/graphql/resolvers/worksheet/packing-worksheet.ts +5 -4
- package/server/graphql/resolvers/worksheet/picking/complete-batch-picking.ts +5 -5
- package/server/graphql/resolvers/worksheet/picking/complete-picking.ts +5 -5
- package/server/graphql/resolvers/worksheet/putaway/complete-putaway.ts +10 -10
- package/server/graphql/resolvers/worksheet/putaway-return/complete-putaway-return.ts +11 -11
- package/dist-server/controllers/ecommerce/powrup-controller.js +0 -201
- package/dist-server/controllers/ecommerce/powrup-controller.js.map +0 -1
- package/server/controllers/ecommerce/powrup-controller.ts +0 -272
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { getRepository } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { Bizplace } from '@things-factory/biz-base'
|
|
4
|
-
import { logger } from '@things-factory/env'
|
|
5
|
-
import { Powrup, PowrupAPI } from '@things-factory/integration-powrup'
|
|
6
|
-
import { Product, ProductDetail } from '@things-factory/product-base'
|
|
7
|
-
import {
|
|
8
|
-
ORDER_STATUS,
|
|
9
|
-
OrderNoGenerator,
|
|
10
|
-
OrderPackage,
|
|
11
|
-
OrderPackageItem,
|
|
12
|
-
OrderProduct,
|
|
13
|
-
ReleaseGood
|
|
14
|
-
} from '@things-factory/sales-base'
|
|
15
|
-
import { Inventory, INVENTORY_STATUS, LOCATION_TYPE } from '@things-factory/warehouse-base'
|
|
16
|
-
|
|
17
|
-
import { DateTimeDifference } from '../../utils/datetime-util'
|
|
18
|
-
import { WorksheetController } from '../worksheet-controller'
|
|
19
|
-
|
|
20
|
-
export class PowrupController extends WorksheetController {
|
|
21
|
-
async packOrder(powrup: Powrup, releaseGood: ReleaseGood): Promise<ReleaseGood> {
|
|
22
|
-
try {
|
|
23
|
-
const orderProducts: OrderProduct[] = releaseGood.orderProducts
|
|
24
|
-
const orderInformation: any = {
|
|
25
|
-
refOrderId: releaseGood.refOrderId
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
releaseGood?.lastMarketPackCall &&
|
|
30
|
-
DateTimeDifference.timeDifferenceInSeconds(releaseGood.lastMarketPackCall, new Date()) <= 5
|
|
31
|
-
) {
|
|
32
|
-
return false
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await getRepository(ReleaseGood).update(
|
|
36
|
-
{ id: releaseGood.id },
|
|
37
|
-
{
|
|
38
|
-
lastMarketPackCall: new Date()
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
const orderPack: any = await PowrupAPI.packOrder(powrup, {
|
|
43
|
-
...orderInformation,
|
|
44
|
-
context: { state: { domain: this?.domain, user: this?.user } }
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
if (orderPack?.packages) {
|
|
48
|
-
const packages: any[] = orderPack.packages
|
|
49
|
-
|
|
50
|
-
await Promise.all(
|
|
51
|
-
packages.map(async pkg => {
|
|
52
|
-
const items = pkg.items
|
|
53
|
-
const orderPackage: OrderPackage = {
|
|
54
|
-
name: OrderNoGenerator.orderPackage(),
|
|
55
|
-
packageId: pkg.packageId,
|
|
56
|
-
status: ORDER_STATUS.PROCESSING,
|
|
57
|
-
releaseGood,
|
|
58
|
-
domain: releaseGood.domain,
|
|
59
|
-
bizplace: releaseGood.bizplace,
|
|
60
|
-
creator: releaseGood.creator,
|
|
61
|
-
updater: releaseGood.updater
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let savedOrderPackage: OrderPackage = await this.trxMgr.getRepository(OrderPackage).save(orderPackage)
|
|
65
|
-
|
|
66
|
-
const orderPackageItems: OrderPackageItem[] = items.map(itm => {
|
|
67
|
-
const { refCode, qty } = itm
|
|
68
|
-
const matchedOrderProduct: OrderProduct = orderProducts.find(op => op.productDetail.refCode == refCode)
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
name: OrderNoGenerator.orderPackageItem(),
|
|
72
|
-
orderProduct: matchedOrderProduct,
|
|
73
|
-
status: ORDER_STATUS.PROCESSING,
|
|
74
|
-
releaseQty: qty,
|
|
75
|
-
orderPackage: savedOrderPackage,
|
|
76
|
-
domain: releaseGood.domain,
|
|
77
|
-
bizplace: releaseGood.bizplace,
|
|
78
|
-
creator: releaseGood.creator,
|
|
79
|
-
updater: releaseGood.updater
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
await this.trxMgr.getRepository(OrderPackageItem).save(orderPackageItems)
|
|
84
|
-
})
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
await this.trxMgr.getRepository(ReleaseGood).update(
|
|
88
|
-
{ id: releaseGood.id },
|
|
89
|
-
{
|
|
90
|
-
packageId: packages[0].packageId,
|
|
91
|
-
marketPackCallSuccess: new Date(),
|
|
92
|
-
lastMarketPackCall: new Date(),
|
|
93
|
-
updatedAt: new Date()
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
} catch (error) {
|
|
98
|
-
logger.error(`powrup-controller[packOrder]: ${error}`)
|
|
99
|
-
throw error
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return releaseGood
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async updateStock(powrup: Powrup, inventory: Inventory): Promise<void> {
|
|
106
|
-
const bizplace: Bizplace = await this.trxMgr.getRepository(Bizplace).findOne({ domain: powrup.domain })
|
|
107
|
-
let product: Product = inventory.product
|
|
108
|
-
const productDetail: ProductDetail = inventory.productDetail
|
|
109
|
-
let qb = await this.trxMgr.getRepository(Inventory).createQueryBuilder('inv')
|
|
110
|
-
qb.leftJoinAndSelect('inv.location', 'loc')
|
|
111
|
-
.andWhere('"inv"."domain_id" = :domainId')
|
|
112
|
-
.andWhere('"inv"."bizplace_id" = :bizplaceId')
|
|
113
|
-
.andWhere('"inv"."product_id" = :productId')
|
|
114
|
-
.andWhere('"inv"."product_detail_id" = :productDetailId')
|
|
115
|
-
.andWhere('"inv"."status" = :status')
|
|
116
|
-
.andWhere('"loc"."type" NOT IN (:...locationTypes)')
|
|
117
|
-
.setParameters({
|
|
118
|
-
domainId: this.domain.id,
|
|
119
|
-
bizplaceId: bizplace.id,
|
|
120
|
-
productId: product.id,
|
|
121
|
-
productDetailId: productDetail.id,
|
|
122
|
-
status: INVENTORY_STATUS.STORED,
|
|
123
|
-
locationTypes: [LOCATION_TYPE.QUARANTINE]
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const warehouseDomainId = this.domain.id
|
|
127
|
-
let inventories: Inventory[] = await qb.getMany()
|
|
128
|
-
let inventoryTotalQty: number = 0
|
|
129
|
-
let inventoryTotalLockedQty: number = 0
|
|
130
|
-
let inventoryBufferQty: number = 0
|
|
131
|
-
|
|
132
|
-
inventories.forEach((inventory: Inventory) => {
|
|
133
|
-
const { qty, lockedQty } = inventory
|
|
134
|
-
inventoryTotalQty += qty
|
|
135
|
-
inventoryTotalLockedQty += lockedQty
|
|
136
|
-
if (inventory.location.type === LOCATION_TYPE.RESERVE) {
|
|
137
|
-
inventoryBufferQty += qty
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const powrupInvs: any[] = [
|
|
142
|
-
{
|
|
143
|
-
refCode: productDetail.refCode,
|
|
144
|
-
stock: {
|
|
145
|
-
quantityTotal: inventoryTotalQty - inventoryTotalLockedQty - inventoryBufferQty,
|
|
146
|
-
quantityReserved: inventoryTotalLockedQty - inventoryBufferQty,
|
|
147
|
-
quantityBuffer: inventoryBufferQty
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
|
|
152
|
-
await PowrupAPI.updateStock(powrup, {
|
|
153
|
-
context: { state: { domain: this?.domain, user: this?.user } },
|
|
154
|
-
warehouseDomainId,
|
|
155
|
-
powrupInvs
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async initiateShipment(powrup: Powrup, releaseGood: ReleaseGood): Promise<void> {
|
|
160
|
-
try {
|
|
161
|
-
let orderPackages: OrderPackage[] = await this.trxMgr
|
|
162
|
-
.getRepository(OrderPackage)
|
|
163
|
-
.find({ where: { releaseGood, bizplace: releaseGood.bizplace } })
|
|
164
|
-
|
|
165
|
-
if (orderPackages?.length) {
|
|
166
|
-
await Promise.all(
|
|
167
|
-
orderPackages
|
|
168
|
-
.filter(op => op?.marketRtsCallSuccess == undefined)
|
|
169
|
-
.map(async op => {
|
|
170
|
-
if (!op?.packageId) throw new Error('Order package id is not found')
|
|
171
|
-
if (releaseGood.lmdOption && !op?.parcelId) return
|
|
172
|
-
|
|
173
|
-
let orderInformation: any = {
|
|
174
|
-
refOrderId: releaseGood.refOrderId,
|
|
175
|
-
packageId: op.packageId
|
|
176
|
-
}
|
|
177
|
-
if (releaseGood.lmdOption) {
|
|
178
|
-
let releaseGoodQuery: ReleaseGood = await getRepository(ReleaseGood).findOne({
|
|
179
|
-
where: { id: releaseGood.id },
|
|
180
|
-
relations: ['lastMileDelivery']
|
|
181
|
-
})
|
|
182
|
-
orderInformation = {
|
|
183
|
-
...orderInformation,
|
|
184
|
-
awb: op.airwayBill,
|
|
185
|
-
trackingNo: op.trackingNo,
|
|
186
|
-
lmdOption: releaseGood.lmdOption,
|
|
187
|
-
shipperName: releaseGoodQuery.lastMileDelivery.platform
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
await PowrupAPI.initiateShipment(powrup, {
|
|
193
|
-
...orderInformation,
|
|
194
|
-
context: { state: { domain: this?.domain, user: this?.user } }
|
|
195
|
-
})
|
|
196
|
-
await getRepository(OrderPackage).update({ id: op.id }, { marketRtsCallSuccess: new Date() })
|
|
197
|
-
} catch (error) {
|
|
198
|
-
logger.error(
|
|
199
|
-
`powrup-controller[initiateShipment]: ${JSON.stringify({
|
|
200
|
-
...orderInformation,
|
|
201
|
-
context: { state: { domain: this?.domain, user: this?.user } },
|
|
202
|
-
error: error
|
|
203
|
-
})}`
|
|
204
|
-
)
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
} catch (error) {
|
|
210
|
-
throw error
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async fetchDocument(powrup: Powrup, releaseGood: ReleaseGood): Promise<ReleaseGood> {
|
|
215
|
-
if (releaseGood?.ownTransport && releaseGood?.lmdOption) {
|
|
216
|
-
return
|
|
217
|
-
}
|
|
218
|
-
try {
|
|
219
|
-
let orderPackages: OrderPackage[] = await this.trxMgr
|
|
220
|
-
.getRepository(OrderPackage)
|
|
221
|
-
.find({ where: { releaseGood, bizplace: releaseGood.bizplace } })
|
|
222
|
-
|
|
223
|
-
if (orderPackages?.length) {
|
|
224
|
-
await Promise.all(
|
|
225
|
-
orderPackages.map(async op => {
|
|
226
|
-
if (!op?.packageId) throw new Error('Order package id is not found')
|
|
227
|
-
|
|
228
|
-
const orderInformation: any = {
|
|
229
|
-
refOrderId: releaseGood.refOrderId,
|
|
230
|
-
packageId: op.packageId
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const {
|
|
234
|
-
documents,
|
|
235
|
-
trackingNo,
|
|
236
|
-
transporter
|
|
237
|
-
}: { documents: any[]; trackingNo: string; transporter: string } = await PowrupAPI.fetchDocument(powrup, {
|
|
238
|
-
...orderInformation,
|
|
239
|
-
context: { state: { domain: this?.domain, user: this?.user } }
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
let updateInfo: any
|
|
243
|
-
if (documents?.length) {
|
|
244
|
-
documents.map(document => {
|
|
245
|
-
if (document.type === 'invoice') {
|
|
246
|
-
updateInfo = { ...updateInfo, invoice: document.download_url }
|
|
247
|
-
} else if (document.type === 'airway_bill') {
|
|
248
|
-
updateInfo = { ...updateInfo, airwayBill: document.download_url }
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
|
|
252
|
-
updateInfo = {
|
|
253
|
-
...updateInfo,
|
|
254
|
-
trackingNo: trackingNo,
|
|
255
|
-
transporter: transporter,
|
|
256
|
-
updater: this.user
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
await this.trxMgr.getRepository(OrderPackage).update({ id: op.id }, { ...updateInfo })
|
|
260
|
-
}
|
|
261
|
-
})
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
releaseGood = await this.trxMgr.getRepository(ReleaseGood).findOne({ id: releaseGood.id })
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return releaseGood
|
|
268
|
-
} catch (error) {
|
|
269
|
-
throw error
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|