@things-factory/sales-base 4.3.448 → 4.3.452
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/constants/order.js +3 -1
- package/dist-server/constants/order.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-create.js +587 -0
- package/dist-server/service/draft-release-good/draft-release-good-create.js.map +1 -0
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js +3 -232
- package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-query.js +59 -28
- package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good-type.js +33 -1
- package/dist-server/service/draft-release-good/draft-release-good-type.js.map +1 -1
- package/dist-server/service/draft-release-good/draft-release-good.js +2 -7
- package/dist-server/service/draft-release-good/draft-release-good.js.map +1 -1
- package/dist-server/service/draft-release-good/index.js +4 -2
- package/dist-server/service/draft-release-good/index.js.map +1 -1
- package/dist-server/service/order-vas/order-vas-mutation.js +46 -23
- package/dist-server/service/order-vas/order-vas-mutation.js.map +1 -1
- package/dist-server/service/order-vas/order-vas-query.js +34 -0
- package/dist-server/service/order-vas/order-vas-query.js.map +1 -1
- package/dist-server/service/order-vas/order-vas-types.js +4 -0
- package/dist-server/service/order-vas/order-vas-types.js.map +1 -1
- package/dist-server/service/order-vas/order-vas.js +22 -1
- package/dist-server/service/order-vas/order-vas.js.map +1 -1
- package/dist-server/service/order-vas-item/order-vas-item-type.js +8 -0
- package/dist-server/service/order-vas-item/order-vas-item-type.js.map +1 -1
- package/dist-server/service/order-vas-item/order-vas-item.js +5 -0
- package/dist-server/service/order-vas-item/order-vas-item.js.map +1 -1
- package/dist-server/service/release-good/release-good-mutation.js +5 -3
- package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
- package/dist-server/service/release-good/release-good-query.js +4 -1
- package/dist-server/service/release-good/release-good-query.js.map +1 -1
- package/dist-server/service/release-good/release-good.js +9 -0
- package/dist-server/service/release-good/release-good.js.map +1 -1
- package/dist-server/service/vas/vas-mutation.js +5 -1
- package/dist-server/service/vas/vas-mutation.js.map +1 -1
- package/dist-server/utils/inventory-util.js +5 -3
- package/dist-server/utils/inventory-util.js.map +1 -1
- package/package.json +15 -15
- package/server/constants/order.ts +3 -1
- package/server/service/draft-release-good/draft-release-good-create.ts +715 -0
- package/server/service/draft-release-good/draft-release-good-mutation.ts +36 -288
- package/server/service/draft-release-good/draft-release-good-query.ts +109 -89
- package/server/service/draft-release-good/draft-release-good-type.ts +28 -2
- package/server/service/draft-release-good/draft-release-good.ts +2 -8
- package/server/service/draft-release-good/index.ts +4 -2
- package/server/service/order-vas/order-vas-mutation.ts +57 -29
- package/server/service/order-vas/order-vas-query.ts +43 -1
- package/server/service/order-vas/order-vas-types.ts +5 -8
- package/server/service/order-vas/order-vas.ts +19 -10
- package/server/service/order-vas-item/order-vas-item-type.ts +6 -0
- package/server/service/order-vas-item/order-vas-item.ts +4 -0
- package/server/service/release-good/release-good-mutation.ts +8 -2
- package/server/service/release-good/release-good-query.ts +7 -2
- package/server/service/release-good/release-good.ts +8 -0
- package/server/service/vas/vas-mutation.ts +4 -1
- package/server/utils/inventory-util.ts +29 -6
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
FileUpload,
|
|
3
|
+
GraphQLUpload
|
|
4
|
+
} from 'graphql-upload'
|
|
5
|
+
import {
|
|
6
|
+
Arg,
|
|
7
|
+
Ctx,
|
|
8
|
+
Directive,
|
|
9
|
+
Mutation,
|
|
10
|
+
Resolver
|
|
11
|
+
} from 'type-graphql'
|
|
3
12
|
import {
|
|
4
13
|
Brackets,
|
|
5
14
|
EntityManager,
|
|
6
|
-
getConnection,
|
|
7
15
|
getRepository,
|
|
8
16
|
ILike,
|
|
9
17
|
In,
|
|
@@ -12,19 +20,34 @@ import {
|
|
|
12
20
|
SelectQueryBuilder
|
|
13
21
|
} from 'typeorm'
|
|
14
22
|
|
|
15
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
Attachment,
|
|
25
|
+
createAttachments,
|
|
26
|
+
deleteAttachmentsByRef
|
|
27
|
+
} from '@things-factory/attachment-base'
|
|
16
28
|
import { User } from '@things-factory/auth-base'
|
|
17
|
-
import {
|
|
18
|
-
|
|
29
|
+
import {
|
|
30
|
+
Bizplace,
|
|
31
|
+
getPermittedBizplaces
|
|
32
|
+
} from '@things-factory/biz-base'
|
|
19
33
|
import { GeoCountry } from '@things-factory/geography'
|
|
20
34
|
import { generateId } from '@things-factory/id-rule-base'
|
|
21
35
|
import { LastMileDelivery } from '@things-factory/integration-lmd'
|
|
22
|
-
import {
|
|
23
|
-
|
|
36
|
+
import {
|
|
37
|
+
Product,
|
|
38
|
+
ProductBundle,
|
|
39
|
+
ProductDetail
|
|
40
|
+
} from '@things-factory/product-base'
|
|
41
|
+
import { Setting } from '@things-factory/setting-base'
|
|
24
42
|
import { Domain } from '@things-factory/shell'
|
|
25
43
|
|
|
26
44
|
// import { Location } from '@things-factory/warehouse-base'
|
|
27
|
-
import {
|
|
45
|
+
import {
|
|
46
|
+
DraftReleaseGood,
|
|
47
|
+
DraftReleaseGoodPatch,
|
|
48
|
+
NewDraftReleaseGood,
|
|
49
|
+
OrderProduct
|
|
50
|
+
} from '../'
|
|
28
51
|
import {
|
|
29
52
|
ATTACHMENT_TYPE,
|
|
30
53
|
DRAFT_RELEASE_ORDER_STATUS,
|
|
@@ -32,12 +55,8 @@ import {
|
|
|
32
55
|
ORDER_NUMBER_SETTING_KEY,
|
|
33
56
|
ORDER_STATUS
|
|
34
57
|
} from '../../constants'
|
|
35
|
-
import {
|
|
36
|
-
import { InventoryUtil, OrderNoGenerator } from '../../utils'
|
|
58
|
+
import { OrderNoGenerator } from '../../utils'
|
|
37
59
|
import { OrderProductPatch } from '../order-product/order-product-types'
|
|
38
|
-
import { ReleaseGood } from '../release-good/release-good'
|
|
39
|
-
import { bulkGenerateReleaseGood, confirmReleaseGood, receiveReleaseGood } from '../release-good/release-good-mutation'
|
|
40
|
-
import { bulkReleaseGoodsAvailableItemsFunction } from '../release-good/release-good-query'
|
|
41
60
|
import { ShippingOrder } from '../shipping-order/shipping-order'
|
|
42
61
|
import { ShippingOrderPatch } from '../shipping-order/shipping-order-types'
|
|
43
62
|
// import {
|
|
@@ -187,277 +206,6 @@ export class DraftReleaseGoodMutation {
|
|
|
187
206
|
|
|
188
207
|
return true
|
|
189
208
|
}
|
|
190
|
-
|
|
191
|
-
@Directive('@privilege(category: "order_customer", privilege: "mutation")')
|
|
192
|
-
@Directive('@transaction')
|
|
193
|
-
@Mutation(returns => Boolean, { description: 'To generate Release Goods from Draft' })
|
|
194
|
-
async generateReleaseGoodsFromDraft(
|
|
195
|
-
@Ctx() context: any,
|
|
196
|
-
@Arg('ids', type => [String]) ids: string[]
|
|
197
|
-
// @Arg('rawReleaseGoods', type => [NewReleaseGood], { nullable: true }) rawReleaseGoods: NewReleaseGood[],
|
|
198
|
-
// @Arg('bizplaceId', type => String) bizplaceId: string
|
|
199
|
-
): Promise<boolean> {
|
|
200
|
-
const { domain, user, tx } = context.state
|
|
201
|
-
try {
|
|
202
|
-
const updatableDraftOrders = await tx.getRepository(DraftReleaseGood).find({
|
|
203
|
-
where: {
|
|
204
|
-
domain,
|
|
205
|
-
id: In(ids),
|
|
206
|
-
status: DRAFT_RELEASE_ORDER_STATUS.DRAFT
|
|
207
|
-
},
|
|
208
|
-
relations: [
|
|
209
|
-
'orderProducts',
|
|
210
|
-
'orderProducts.product',
|
|
211
|
-
'orderProducts.productBundle',
|
|
212
|
-
'orderProducts.productBundle.productBundleSettings',
|
|
213
|
-
'orderProducts.productBundle.productBundleSettings.product',
|
|
214
|
-
'orderProducts.productBundle.productBundleSettings.productDetail',
|
|
215
|
-
'shippingOrder',
|
|
216
|
-
'bizplace',
|
|
217
|
-
'bizplace.domain',
|
|
218
|
-
'domain',
|
|
219
|
-
'creator',
|
|
220
|
-
'updater',
|
|
221
|
-
'lastMileDelivery'
|
|
222
|
-
]
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
if (updatableDraftOrders.length > 0) {
|
|
226
|
-
let createdReleaseGoods: ReleaseGood[] = []
|
|
227
|
-
const settingRepo: Repository<Setting> = tx?.getRepository(Setting) || getRepository(Setting)
|
|
228
|
-
|
|
229
|
-
const roNoSetting: Setting = await settingRepo.findOne({
|
|
230
|
-
where: {
|
|
231
|
-
domain,
|
|
232
|
-
name: ORDER_NUMBER_SETTING_KEY.RO_NUMBER_RULE
|
|
233
|
-
}
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
for (let index = 0; index < updatableDraftOrders.length; index++) {
|
|
237
|
-
await getConnection().transaction(async (parentTx: EntityManager) => {
|
|
238
|
-
const draftOrder = updatableDraftOrders[index]
|
|
239
|
-
|
|
240
|
-
let foundPermittedBizplace: Bizplace
|
|
241
|
-
let companyBizplace: Bizplace
|
|
242
|
-
|
|
243
|
-
if (draftOrder?.bizplace?.id) {
|
|
244
|
-
foundPermittedBizplace = await parentTx.getRepository(Bizplace).findOne(draftOrder.bizplace.id, {
|
|
245
|
-
relations: ['company', 'company.domain']
|
|
246
|
-
})
|
|
247
|
-
const companyDomain: Domain = foundPermittedBizplace.company.domain
|
|
248
|
-
companyBizplace = await parentTx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
|
|
249
|
-
} else {
|
|
250
|
-
return false
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
|
|
254
|
-
|
|
255
|
-
let loggerJson = JSON.stringify({ refNo: draftOrder.refNo, bizplaceId: draftOrder.bizplace.id, domain })
|
|
256
|
-
try {
|
|
257
|
-
console.time(`creating_order:${loggerJson}`)
|
|
258
|
-
|
|
259
|
-
let productInventory = await InventoryUtil.bizplaceProductInventory(
|
|
260
|
-
bizplaces,
|
|
261
|
-
{
|
|
262
|
-
filters: [
|
|
263
|
-
{
|
|
264
|
-
name: 'productId',
|
|
265
|
-
operator: 'in',
|
|
266
|
-
value: [
|
|
267
|
-
...draftOrder.orderProducts
|
|
268
|
-
.filter(itm => itm?.product)
|
|
269
|
-
.map(itm => {
|
|
270
|
-
return itm.product.id
|
|
271
|
-
}),
|
|
272
|
-
...draftOrder.orderProducts
|
|
273
|
-
.filter(itm => itm?.productBundle)
|
|
274
|
-
.map(itm => {
|
|
275
|
-
return itm.productBundle.productBundleSettings.map(itm => {
|
|
276
|
-
return itm.product.id
|
|
277
|
-
})
|
|
278
|
-
})
|
|
279
|
-
]
|
|
280
|
-
}
|
|
281
|
-
]
|
|
282
|
-
},
|
|
283
|
-
context,
|
|
284
|
-
parentTx
|
|
285
|
-
)
|
|
286
|
-
|
|
287
|
-
draftOrder.orderProducts = draftOrder.orderProducts.map(itm => {
|
|
288
|
-
let foundProductInv
|
|
289
|
-
if(itm.product){
|
|
290
|
-
foundProductInv = productInventory.items.find(
|
|
291
|
-
i =>
|
|
292
|
-
(i.productDetailId == itm?.productDetailId || i.productId == itm?.productBundle?.id) &&
|
|
293
|
-
itm.releaseQty <= i.remainQty
|
|
294
|
-
)
|
|
295
|
-
} else {
|
|
296
|
-
itm.productBundle.productBundleSettings.map(pbs => {
|
|
297
|
-
foundProductInv = productInventory.items.find(
|
|
298
|
-
i =>
|
|
299
|
-
(i.productDetailId == pbs?.productDetail.id || i.productId == pbs?.product?.id) &&
|
|
300
|
-
itm.releaseQty <= i.remainQty
|
|
301
|
-
)
|
|
302
|
-
})
|
|
303
|
-
}
|
|
304
|
-
return {
|
|
305
|
-
...itm,
|
|
306
|
-
releaseUomValue: (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty,
|
|
307
|
-
status: foundProductInv ? 'suffice' : 'insufficient'
|
|
308
|
-
}
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
let insufficient = draftOrder.orderProducts.find(op => op.status == 'insufficient')
|
|
312
|
-
if (!insufficient) {
|
|
313
|
-
//create RO
|
|
314
|
-
let releaseGood = { ...draftOrder }
|
|
315
|
-
delete releaseGood.id
|
|
316
|
-
delete releaseGood.name
|
|
317
|
-
delete releaseGood.createdAt
|
|
318
|
-
delete releaseGood.createdBy
|
|
319
|
-
delete releaseGood.updatedAt
|
|
320
|
-
delete releaseGood.updatedBy
|
|
321
|
-
|
|
322
|
-
let orderInventories = []
|
|
323
|
-
|
|
324
|
-
for (let index = 0; index < draftOrder.orderProducts.length; index++) {
|
|
325
|
-
const itm: Partial<OrderProduct> = draftOrder.orderProducts[index]
|
|
326
|
-
let data = []
|
|
327
|
-
if (itm.productBundle) {
|
|
328
|
-
let bundle: ProductBundle = await parentTx.getRepository(ProductBundle).findOne({
|
|
329
|
-
where: { id: itm.productBundle.id },
|
|
330
|
-
relations: [
|
|
331
|
-
'productBundleSettings',
|
|
332
|
-
'productBundleSettings.productDetail',
|
|
333
|
-
'productBundleSettings.product'
|
|
334
|
-
]
|
|
335
|
-
})
|
|
336
|
-
|
|
337
|
-
for (let index2 = 0; index2 < bundle.productBundleSettings.length; index2++) {
|
|
338
|
-
const objProductBundleSetting = bundle.productBundleSettings[index2]
|
|
339
|
-
data.push({
|
|
340
|
-
sku: objProductBundleSetting.product.sku,
|
|
341
|
-
packingType: objProductBundleSetting.productDetail.packingType,
|
|
342
|
-
packingSize: objProductBundleSetting.productDetail.packingSize,
|
|
343
|
-
uom: objProductBundleSetting.productDetail.uom,
|
|
344
|
-
releaseQty: objProductBundleSetting.bundleQty * itm.releaseQty,
|
|
345
|
-
assignedQty: undefined,
|
|
346
|
-
assignedUomValue: undefined,
|
|
347
|
-
releaseUomValue: objProductBundleSetting.bundleQty * itm.releaseQty * itm.releaseUomValue
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
} else {
|
|
351
|
-
data = [
|
|
352
|
-
{
|
|
353
|
-
sku: itm.product.sku,
|
|
354
|
-
packingType: itm.packingType,
|
|
355
|
-
packingSize: itm.packingSize,
|
|
356
|
-
uom: itm.uom,
|
|
357
|
-
releaseQty: itm.releaseQty,
|
|
358
|
-
assignedQty: undefined,
|
|
359
|
-
assignedUomValue: undefined,
|
|
360
|
-
releaseUomValue: itm.releaseUomValue
|
|
361
|
-
}
|
|
362
|
-
]
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
data.forEach(data => {
|
|
366
|
-
let existingOI = orderInventories.find(
|
|
367
|
-
itm =>
|
|
368
|
-
itm.sku == data.sku &&
|
|
369
|
-
itm.packingType == data.packingType &&
|
|
370
|
-
itm.packingSize == data.packingSize &&
|
|
371
|
-
itm.uom == data.uom
|
|
372
|
-
)
|
|
373
|
-
|
|
374
|
-
if (existingOI) {
|
|
375
|
-
existingOI.releaseQty = existingOI.releaseQty + data.releaseQty
|
|
376
|
-
existingOI.releaseUomValue = existingOI.releaseUomValue + data.uomValue
|
|
377
|
-
existingOI.uomValue = existingOI.uomValue + data.uomValue
|
|
378
|
-
} else {
|
|
379
|
-
orderInventories.push({ ...data, orderProduct: itm })
|
|
380
|
-
}
|
|
381
|
-
})
|
|
382
|
-
}
|
|
383
|
-
await getConnection().transaction(async (childTx: EntityManager) => {
|
|
384
|
-
let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
|
|
385
|
-
orderInventories,
|
|
386
|
-
draftOrder.bizplace.id,
|
|
387
|
-
context,
|
|
388
|
-
childTx
|
|
389
|
-
)
|
|
390
|
-
if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty))
|
|
391
|
-
throw new ValidationError({
|
|
392
|
-
...ValidationError.ERROR_CODES.INSUFFICIENT_STOCK,
|
|
393
|
-
detail: { data: JSON.stringify(availableItems) }
|
|
394
|
-
})
|
|
395
|
-
// update orderInventories if availableItems are valid
|
|
396
|
-
releaseGood.noOfItems = orderInventories.length
|
|
397
|
-
|
|
398
|
-
releaseGood.orderInventories = availableItems.map(itm => {
|
|
399
|
-
return {
|
|
400
|
-
...itm,
|
|
401
|
-
releaseQty: itm.releaseQty,
|
|
402
|
-
releaseUomValue: itm.releaseUomValue,
|
|
403
|
-
uomValue: itm.uomValue
|
|
404
|
-
}
|
|
405
|
-
})
|
|
406
|
-
let createdReleaseGood: ReleaseGood = await bulkGenerateReleaseGood(
|
|
407
|
-
releaseGood,
|
|
408
|
-
releaseGood.bizplace.id,
|
|
409
|
-
roNoSetting,
|
|
410
|
-
domain,
|
|
411
|
-
user,
|
|
412
|
-
childTx
|
|
413
|
-
)
|
|
414
|
-
await childTx
|
|
415
|
-
.getRepository(DraftReleaseGood)
|
|
416
|
-
.update(
|
|
417
|
-
{ id: draftOrder.id },
|
|
418
|
-
{ releaseGood: createdReleaseGood, status: DRAFT_RELEASE_ORDER_STATUS.SUBMITTED }
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
const directReceiveSetting: Setting = await tx.getRepository(Setting).findOne({
|
|
422
|
-
where: { domain, category: 'id-rule', name: 'enable-direct-receive-release-order' }
|
|
423
|
-
})
|
|
424
|
-
|
|
425
|
-
const partnerDirectReceiveSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
|
|
426
|
-
where: { setting: directReceiveSetting, domain, partnerDomain: draftOrder.bizplace?.domain }
|
|
427
|
-
})
|
|
428
|
-
|
|
429
|
-
let settingValue
|
|
430
|
-
|
|
431
|
-
if (
|
|
432
|
-
!isNaN(partnerDirectReceiveSetting?.value) &&
|
|
433
|
-
!isNaN(parseFloat(partnerDirectReceiveSetting?.value))
|
|
434
|
-
) {
|
|
435
|
-
settingValue = parseFloat(partnerDirectReceiveSetting.value)
|
|
436
|
-
} else {
|
|
437
|
-
settingValue = parseFloat(directReceiveSetting.value)
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
createdReleaseGood = await confirmReleaseGood(createdReleaseGood.name, context, childTx)
|
|
441
|
-
|
|
442
|
-
if (settingValue > 1) {
|
|
443
|
-
createdReleaseGood = await receiveReleaseGood(createdReleaseGood.name, context, childTx)
|
|
444
|
-
}
|
|
445
|
-
})
|
|
446
|
-
}
|
|
447
|
-
} catch (e) {
|
|
448
|
-
logger.error(`draft-release-good-mutation[generateReleaseGoodsFromDraft:${loggerJson}]: ${e?.message}`)
|
|
449
|
-
} finally {
|
|
450
|
-
console.timeEnd(`creating_order:${loggerJson}`)
|
|
451
|
-
}
|
|
452
|
-
})
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return true
|
|
457
|
-
} catch (e) {
|
|
458
|
-
logger.error(`draft-release-good-mutation[generateReleaseGoodsFromDraft]: ${e?.message}`)
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
209
|
}
|
|
462
210
|
|
|
463
211
|
export async function upsertDraftReleaseGoodFunction(
|
|
@@ -627,7 +375,7 @@ export async function updateDraftReleaseGoodFunction(
|
|
|
627
375
|
): Promise<DraftReleaseGood> {
|
|
628
376
|
const { domain, user }: { domain: Domain; user: User } = context.state
|
|
629
377
|
|
|
630
|
-
let existingDraftReleaseGood: any = await getDraftReleaseGoodFunction(_, draftReleaseGood.name,
|
|
378
|
+
let existingDraftReleaseGood: any = await getDraftReleaseGoodFunction(_, context, null, draftReleaseGood.name, tx)
|
|
631
379
|
|
|
632
380
|
if (draftReleaseGood?.bizplace?.id) {
|
|
633
381
|
const permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
|
|
@@ -656,7 +404,7 @@ export async function updateDraftReleaseGoodFunction(
|
|
|
656
404
|
}
|
|
657
405
|
} else {
|
|
658
406
|
// case to delete existing shippingOrder
|
|
659
|
-
if (existingDraftReleaseGood
|
|
407
|
+
if (existingDraftReleaseGood?.shippingOrder) {
|
|
660
408
|
await tx.getRepository(ShippingOrder).delete(existingDraftReleaseGood.shippingOrder)
|
|
661
409
|
}
|
|
662
410
|
}
|
|
@@ -736,7 +484,7 @@ export async function upsertDraftReleaseGoodProducts(
|
|
|
736
484
|
|
|
737
485
|
// Remove all existing order products that do not exist in current input
|
|
738
486
|
let removeOP = draftReleaseGood.orderProducts.filter(
|
|
739
|
-
existingOP => orderProductsPatch.
|
|
487
|
+
existingOP => !orderProductsPatch.some(inOP => inOP.id == existingOP.id)
|
|
740
488
|
)
|
|
741
489
|
// removeOP.forEach(async op => {
|
|
742
490
|
// await orderProductRepo.delete(op)
|
|
@@ -1,35 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Args,
|
|
4
|
-
Ctx,
|
|
5
|
-
Directive,
|
|
6
|
-
Query,
|
|
7
|
-
Resolver
|
|
8
|
-
} from 'type-graphql'
|
|
9
|
-
import {
|
|
10
|
-
EntityManager,
|
|
11
|
-
getRepository,
|
|
12
|
-
In,
|
|
13
|
-
SelectQueryBuilder
|
|
14
|
-
} from 'typeorm'
|
|
1
|
+
import { Arg, Args, Ctx, Directive, Query, Resolver } from 'type-graphql'
|
|
2
|
+
import { EntityManager, getRepository, In, SelectQueryBuilder } from 'typeorm'
|
|
15
3
|
|
|
16
4
|
import { Attachment } from '@things-factory/attachment-base'
|
|
17
5
|
import { User } from '@things-factory/auth-base'
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} from '
|
|
23
|
-
import {
|
|
24
|
-
buildQuery,
|
|
25
|
-
Domain,
|
|
26
|
-
ListParam
|
|
27
|
-
} from '@things-factory/shell'
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
ATTACHMENT_TYPE,
|
|
31
|
-
DRAFT_RELEASE_ORDER_STATUS
|
|
32
|
-
} from '../../constants'
|
|
6
|
+
import { Bizplace, getPermittedBizplaceIds, getPermittedBizplaces } from '@things-factory/biz-base'
|
|
7
|
+
import { Setting } from '@things-factory/setting-base'
|
|
8
|
+
import { buildQuery, Domain, ListParam } from '@things-factory/shell'
|
|
9
|
+
|
|
10
|
+
import { ATTACHMENT_TYPE, DRAFT_RELEASE_ORDER_STATUS } from '../../constants'
|
|
33
11
|
import { InventoryUtil } from '../../utils'
|
|
34
12
|
import { DraftReleaseGood } from './draft-release-good'
|
|
35
13
|
import { DraftReleaseGoodList } from './draft-release-good-type'
|
|
@@ -47,10 +25,14 @@ export class DraftReleaseGoodQuery {
|
|
|
47
25
|
|
|
48
26
|
@Directive('@transaction')
|
|
49
27
|
@Query(returns => DraftReleaseGood, { description: 'To fetch a DraftReleaseGood' })
|
|
50
|
-
async draftReleaseGoodByName(
|
|
28
|
+
async draftReleaseGoodByName(
|
|
29
|
+
@Ctx() context: any,
|
|
30
|
+
@Arg('name', { nullable: true }) name?: string,
|
|
31
|
+
@Arg('id', { nullable: true }) id?: string
|
|
32
|
+
): Promise<DraftReleaseGood> {
|
|
51
33
|
const { domain, tx }: { domain: Domain; tx: EntityManager } = context.state
|
|
52
34
|
|
|
53
|
-
return getDraftReleaseGoodFunction(null,
|
|
35
|
+
return getDraftReleaseGoodFunction(null, context, id, name, tx)
|
|
54
36
|
}
|
|
55
37
|
|
|
56
38
|
@Directive('@transaction')
|
|
@@ -310,24 +292,40 @@ export class DraftReleaseGoodQuery {
|
|
|
310
292
|
}
|
|
311
293
|
|
|
312
294
|
const arrChildSortData = ['bizplace', 'creator']
|
|
313
|
-
const sort =
|
|
314
|
-
(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
295
|
+
const sort =
|
|
296
|
+
(params.sortings || []).length > 0
|
|
297
|
+
? (params.sortings || []).reduce(
|
|
298
|
+
(acc, sort) => ({
|
|
299
|
+
...acc,
|
|
300
|
+
[arrChildSortData.indexOf(sort.name) >= 0 ? sort.name + '.name' : 'drg.' + sort.name]: sort.desc
|
|
301
|
+
? 'DESC'
|
|
302
|
+
: 'ASC'
|
|
303
|
+
}),
|
|
304
|
+
{}
|
|
305
|
+
)
|
|
306
|
+
: { rank: 'ASC', 'drg.createdAt': 'DESC' }
|
|
322
307
|
|
|
323
308
|
qb.orderBy(sort)
|
|
324
|
-
|
|
325
|
-
|
|
309
|
+
if (params.pagination?.page && params.pagination?.limit) {
|
|
310
|
+
qb.offset((params.pagination.page - 1) * params.pagination.limit)
|
|
311
|
+
qb.limit(params.pagination.limit)
|
|
312
|
+
}
|
|
326
313
|
|
|
327
314
|
let [items, total] = await Promise.all([qb.getRawMany(), qb.getCount()])
|
|
328
315
|
let newPlatformCode
|
|
316
|
+
let uniqueItems = await removeDuplicates(items)
|
|
317
|
+
|
|
318
|
+
const result: Setting = await tx
|
|
319
|
+
.getRepository(Setting)
|
|
320
|
+
.createQueryBuilder('st')
|
|
321
|
+
.select()
|
|
322
|
+
.where('st.domain_id = :domainId', { domainId: domain.id })
|
|
323
|
+
.andWhere('st.name = :name', { name: 'partial-release-rule' })
|
|
324
|
+
.getOne()
|
|
325
|
+
|
|
326
|
+
let settingValue = result ? result.value : null
|
|
329
327
|
|
|
330
|
-
items =
|
|
328
|
+
items = uniqueItems.map(itm => {
|
|
331
329
|
if (itm.drg_platform_code) {
|
|
332
330
|
if (itm.drg_platform_code == 'LZD') {
|
|
333
331
|
newPlatformCode = 'Lazada'
|
|
@@ -345,6 +343,7 @@ export class DraftReleaseGoodQuery {
|
|
|
345
343
|
name: itm.drg_name,
|
|
346
344
|
description: itm.drg_description,
|
|
347
345
|
type: itm.drg_type,
|
|
346
|
+
source: itm.drg_source,
|
|
348
347
|
platformCode: newPlatformCode ? newPlatformCode : itm.platformCode,
|
|
349
348
|
releaseDate: itm.drg_release_date,
|
|
350
349
|
exportOption: itm.drg_export_option,
|
|
@@ -362,20 +361,24 @@ export class DraftReleaseGoodQuery {
|
|
|
362
361
|
}
|
|
363
362
|
})
|
|
364
363
|
|
|
365
|
-
return { items, total }
|
|
364
|
+
return { items, settingValue, total }
|
|
366
365
|
} catch (error) {
|
|
367
366
|
throw error
|
|
368
367
|
}
|
|
369
368
|
}
|
|
370
369
|
}
|
|
371
370
|
|
|
372
|
-
export async function getDraftReleaseGoodFunction(_: any,
|
|
371
|
+
export async function getDraftReleaseGoodFunction(_: any, context: any, id?: any, name?: any, tx?: EntityManager) {
|
|
373
372
|
try {
|
|
374
373
|
const { domain, user, bizplace }: { domain: Domain; user: User; bizplace: Bizplace } = context.state
|
|
375
374
|
|
|
376
375
|
let permittedBizplaces = await getPermittedBizplaces(domain, user)
|
|
377
|
-
|
|
378
|
-
|
|
376
|
+
|
|
377
|
+
const whereCondition = id ? { id } : { name }
|
|
378
|
+
const where = { ...whereCondition, domain, bizplace: In(permittedBizplaces.map(biz => biz.id)) }
|
|
379
|
+
|
|
380
|
+
const result = await tx.getRepository(DraftReleaseGood).findOne({
|
|
381
|
+
where,
|
|
379
382
|
relations: [
|
|
380
383
|
'releaseGood',
|
|
381
384
|
'orderProducts',
|
|
@@ -445,63 +448,75 @@ export async function getDraftReleaseGoodFunction(_: any, name: any, context: an
|
|
|
445
448
|
tx
|
|
446
449
|
)
|
|
447
450
|
|
|
448
|
-
result.orderProducts = result.orderProducts
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
)
|
|
454
|
-
return {
|
|
455
|
-
...itm,
|
|
456
|
-
product: itm.product || {
|
|
457
|
-
id: foundProductInv.productId,
|
|
458
|
-
name: foundProductInv.productName,
|
|
459
|
-
brand: foundProductInv.productBrand,
|
|
460
|
-
sku: foundProductInv.productSKU
|
|
461
|
-
},
|
|
462
|
-
productDetail: itm.productDetail || {
|
|
463
|
-
id: foundProductInv.productDetailId
|
|
464
|
-
},
|
|
465
|
-
groupType: foundProductInv ? foundProductInv.groupType : 'SINGLE',
|
|
466
|
-
remainQty: foundProductInv ? foundProductInv.remainQty : 0,
|
|
467
|
-
remainUomValue: foundProductInv ? foundProductInv.remainUomValue : 0,
|
|
468
|
-
remainUomValueWithUom: foundProductInv ? foundProductInv.remainUomValueWithUom : 0,
|
|
469
|
-
status: foundProductInv?.transferQty
|
|
470
|
-
? DRAFT_RELEASE_ORDER_STATUS.TRANSFER
|
|
471
|
-
: (foundProductInv?.remainQty || 0) < itm.releaseQty
|
|
472
|
-
? DRAFT_RELEASE_ORDER_STATUS.INSUFFICIENT
|
|
473
|
-
: DRAFT_RELEASE_ORDER_STATUS.DRAFT
|
|
474
|
-
}
|
|
475
|
-
} else {
|
|
476
|
-
return itm.productBundle.productBundleSettings.map(pbs => {
|
|
451
|
+
result.orderProducts = result.orderProducts
|
|
452
|
+
.map(itm => {
|
|
453
|
+
let foundProductInv
|
|
454
|
+
let orgReleaseQty = itm.releaseQty // to get the original release qty based of that bundle to be used when calculating the components release qty in the bundle
|
|
455
|
+
|
|
456
|
+
if (itm.product) {
|
|
477
457
|
foundProductInv = productInventory?.items.find(
|
|
478
|
-
i => i.productDetailId ==
|
|
458
|
+
i => i.productDetailId == itm?.productDetail?.id || i.productId == itm?.productBundle?.id
|
|
479
459
|
)
|
|
480
|
-
return
|
|
460
|
+
return {
|
|
481
461
|
...itm,
|
|
482
|
-
product:
|
|
462
|
+
product: itm.product || {
|
|
483
463
|
id: foundProductInv.productId,
|
|
484
464
|
name: foundProductInv.productName,
|
|
485
465
|
brand: foundProductInv.productBrand,
|
|
486
466
|
sku: foundProductInv.productSKU
|
|
487
467
|
},
|
|
488
|
-
productDetail:
|
|
468
|
+
productDetail: itm.productDetail || {
|
|
489
469
|
id: foundProductInv.productDetailId
|
|
490
470
|
},
|
|
491
471
|
groupType: foundProductInv ? foundProductInv.groupType : 'SINGLE',
|
|
492
472
|
remainQty: foundProductInv ? foundProductInv.remainQty : 0,
|
|
493
473
|
remainUomValue: foundProductInv ? foundProductInv.remainUomValue : 0,
|
|
494
474
|
remainUomValueWithUom: foundProductInv ? foundProductInv.remainUomValueWithUom : 0,
|
|
495
|
-
status:
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
475
|
+
status:
|
|
476
|
+
itm.status === DRAFT_RELEASE_ORDER_STATUS.PARTIAL_RELEASED
|
|
477
|
+
? DRAFT_RELEASE_ORDER_STATUS.PARTIAL_RELEASED
|
|
478
|
+
: foundProductInv?.transferQty
|
|
479
|
+
? DRAFT_RELEASE_ORDER_STATUS.TRANSFER
|
|
480
|
+
: (foundProductInv?.remainQty || 0) < itm.releaseQty
|
|
481
|
+
? DRAFT_RELEASE_ORDER_STATUS.INSUFFICIENT
|
|
482
|
+
: DRAFT_RELEASE_ORDER_STATUS.DRAFT
|
|
500
483
|
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
484
|
+
} else {
|
|
485
|
+
return itm.productBundle.productBundleSettings.map(pbs => {
|
|
486
|
+
foundProductInv = productInventory?.items.find(
|
|
487
|
+
i => i.productDetailId == pbs?.productDetail?.id || i.productId == pbs?.product.id
|
|
488
|
+
)
|
|
489
|
+
let itmBundleReleaseQty = orgReleaseQty * pbs.bundleQty // to calculate for each component release qty based on releaseQty set for tht bundle
|
|
490
|
+
return (itm = {
|
|
491
|
+
...itm,
|
|
492
|
+
product: pbs.product || {
|
|
493
|
+
id: foundProductInv.productId,
|
|
494
|
+
name: foundProductInv.productName,
|
|
495
|
+
brand: foundProductInv.productBrand,
|
|
496
|
+
sku: foundProductInv.productSKU
|
|
497
|
+
},
|
|
498
|
+
productDetail: pbs.productDetail || {
|
|
499
|
+
id: foundProductInv.productDetailId
|
|
500
|
+
},
|
|
501
|
+
groupType: 'BUNDLE',
|
|
502
|
+
releaseQty: itmBundleReleaseQty,
|
|
503
|
+
remainQty: foundProductInv ? foundProductInv.remainQty : 0,
|
|
504
|
+
remainUomValue: foundProductInv ? foundProductInv.remainUomValue : 0,
|
|
505
|
+
remainUomValueWithUom: foundProductInv ? foundProductInv.remainUomValueWithUom : 0,
|
|
506
|
+
status:
|
|
507
|
+
itm.status === DRAFT_RELEASE_ORDER_STATUS.PARTIAL_RELEASED
|
|
508
|
+
? DRAFT_RELEASE_ORDER_STATUS.PARTIAL_RELEASED
|
|
509
|
+
: foundProductInv?.transferQty
|
|
510
|
+
? DRAFT_RELEASE_ORDER_STATUS.TRANSFER
|
|
511
|
+
: (foundProductInv?.remainQty || 0) < itmBundleReleaseQty
|
|
512
|
+
? DRAFT_RELEASE_ORDER_STATUS.INSUFFICIENT
|
|
513
|
+
: DRAFT_RELEASE_ORDER_STATUS.DRAFT
|
|
514
|
+
})
|
|
515
|
+
})
|
|
516
|
+
}
|
|
517
|
+
})
|
|
518
|
+
.flat()
|
|
519
|
+
|
|
505
520
|
const foundAttachments: Attachment[] = await tx.getRepository(Attachment).find({
|
|
506
521
|
where: {
|
|
507
522
|
domain,
|
|
@@ -518,3 +533,8 @@ export async function getDraftReleaseGoodFunction(_: any, name: any, context: an
|
|
|
518
533
|
console.error(error)
|
|
519
534
|
}
|
|
520
535
|
}
|
|
536
|
+
|
|
537
|
+
function removeDuplicates(items) {
|
|
538
|
+
const uniqueItems = [...new Set(items.map(item => item.drg_id))];
|
|
539
|
+
return items.filter(item => uniqueItems.includes(item.drg_id));
|
|
540
|
+
}
|