@things-factory/sales-base 4.3.113-alpha.0 → 4.3.114

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.
Files changed (82) hide show
  1. package/dist-server/service/arrival-notice/arrival-notice-mutation.js +5 -6
  2. package/dist-server/service/arrival-notice/arrival-notice-mutation.js.map +1 -1
  3. package/dist-server/service/arrival-notice/arrival-notice-query.js +0 -1
  4. package/dist-server/service/arrival-notice/arrival-notice-query.js.map +1 -1
  5. package/dist-server/service/delivery-order/delivery-order-mutation.js +30 -3
  6. package/dist-server/service/delivery-order/delivery-order-mutation.js.map +1 -1
  7. package/dist-server/service/draft-release-good/draft-release-good-mutation.js +4 -3
  8. package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
  9. package/dist-server/service/draft-release-good/draft-release-good-query.js +15 -11
  10. package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
  11. package/dist-server/service/goods-receival-note/goods-receival-note-mutation.js +32 -4
  12. package/dist-server/service/goods-receival-note/goods-receival-note-mutation.js.map +1 -1
  13. package/dist-server/service/invoice-product/invoice-product.js +3 -8
  14. package/dist-server/service/invoice-product/invoice-product.js.map +1 -1
  15. package/dist-server/service/order-inventory/order-inventory-query.js +1 -2
  16. package/dist-server/service/order-inventory/order-inventory-query.js.map +1 -1
  17. package/dist-server/service/order-inventory/order-inventory-types.js +10 -18
  18. package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
  19. package/dist-server/service/order-inventory/order-inventory.js +3 -12
  20. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  21. package/dist-server/service/order-product/order-product-query.js +0 -1
  22. package/dist-server/service/order-product/order-product-query.js.map +1 -1
  23. package/dist-server/service/order-product/order-product-types.js +10 -18
  24. package/dist-server/service/order-product/order-product-types.js.map +1 -1
  25. package/dist-server/service/order-product/order-product.js +5 -0
  26. package/dist-server/service/order-product/order-product.js.map +1 -1
  27. package/dist-server/service/order-vas/order-vas.js +3 -8
  28. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  29. package/dist-server/service/others/other-query.js +177 -196
  30. package/dist-server/service/others/other-query.js.map +1 -1
  31. package/dist-server/service/others/other-types.js +1 -9
  32. package/dist-server/service/others/other-types.js.map +1 -1
  33. package/dist-server/service/purchase-order/purchase-order-mutation.js +2 -10
  34. package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
  35. package/dist-server/service/purchase-order/purchase-order-query.js +0 -1
  36. package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -1
  37. package/dist-server/service/release-good/release-good-mutation.js +39 -29
  38. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  39. package/dist-server/service/release-good/release-good-query.js +11 -10
  40. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  41. package/dist-server/service/release-good/release-good-types.js +4 -8
  42. package/dist-server/service/release-good/release-good-types.js.map +1 -1
  43. package/dist-server/service/release-good/release-good.js +14 -1
  44. package/dist-server/service/release-good/release-good.js.map +1 -1
  45. package/dist-server/service/return-order/return-order-mutation.js +0 -3
  46. package/dist-server/service/return-order/return-order-mutation.js.map +1 -1
  47. package/dist-server/service/return-order/return-order-types.js.map +1 -1
  48. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +3 -8
  49. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
  50. package/dist-server/utils/inventory-util.js +104 -39
  51. package/dist-server/utils/inventory-util.js.map +1 -1
  52. package/package.json +14 -13
  53. package/server/service/arrival-notice/arrival-notice-mutation.ts +3 -6
  54. package/server/service/arrival-notice/arrival-notice-query.ts +0 -1
  55. package/server/service/delivery-order/delivery-order-mutation.ts +49 -19
  56. package/server/service/draft-release-good/draft-release-good-mutation.ts +4 -3
  57. package/server/service/draft-release-good/draft-release-good-query.ts +21 -17
  58. package/server/service/goods-receival-note/goods-receival-note-mutation.ts +38 -4
  59. package/server/service/invoice-product/invoice-product.ts +1 -5
  60. package/server/service/order-inventory/order-inventory-query.ts +0 -2
  61. package/server/service/order-inventory/order-inventory-types.ts +0 -6
  62. package/server/service/order-inventory/order-inventory.ts +1 -8
  63. package/server/service/order-product/order-product-query.ts +0 -1
  64. package/server/service/order-product/order-product-types.ts +0 -6
  65. package/server/service/order-product/order-product.ts +4 -0
  66. package/server/service/order-vas/order-vas.ts +1 -6
  67. package/server/service/others/other-query.ts +219 -231
  68. package/server/service/others/other-types.ts +1 -7
  69. package/server/service/purchase-order/purchase-order-mutation.ts +1 -10
  70. package/server/service/purchase-order/purchase-order-query.ts +0 -1
  71. package/server/service/release-good/release-good-mutation.ts +54 -37
  72. package/server/service/release-good/release-good-query.ts +10 -9
  73. package/server/service/release-good/release-good-types.ts +3 -4
  74. package/server/service/release-good/release-good.ts +10 -0
  75. package/server/service/return-order/return-order-mutation.ts +1 -4
  76. package/server/service/return-order/return-order-types.ts +0 -1
  77. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +1 -5
  78. package/server/utils/inventory-util.ts +149 -75
  79. package/translations/en.json +0 -1
  80. package/translations/ko.json +1 -2
  81. package/translations/ms.json +1 -2
  82. package/translations/zh.json +0 -25
@@ -7,7 +7,6 @@ import { Bizplace, getPermittedBizplaces } from '@things-factory/biz-base'
7
7
  import { Product, ProductDetail } from '@things-factory/product-base'
8
8
  import { PartnerSetting, Setting } from '@things-factory/setting-base'
9
9
  import { Domain, ListParam } from '@things-factory/shell'
10
- import i18next from 'i18next'
11
10
 
12
11
  import {
13
12
  InventoryProductGroup,
@@ -188,12 +187,6 @@ export class OtherQuery {
188
187
  operator: 'eq',
189
188
  value: orderInventory.packingType
190
189
  })
191
- } else {
192
- filters.push({
193
- name: 'packingType',
194
- operator: 'eq',
195
- value: ''
196
- })
197
190
  }
198
191
 
199
192
  const params: any = {
@@ -212,30 +205,32 @@ export class OtherQuery {
212
205
 
213
206
  let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
214
207
  const newOrderInventory: any = {
215
- product:
216
- total > 0 ? { id: items[0].productId, sku: items[0].productSKU, name: items[0].productName } : { id: null },
217
- productDetail: total > 0 ? { id: items[0].productDetailId } : null,
218
- inventory:
219
- total > 0
220
- ? {
221
- ...items[0],
222
- remainQty: total > 0 ? items[0].remainQty : null,
223
- remainUomValue: total > 0 ? items[0].remainUomValue : null,
224
- remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : ''
225
- }
226
- : null,
227
- productId: total > 0 ? items[0].productId : null,
228
- productDetailID: total > 0 ? items[0].productDetailId : null,
229
- productSKU: total > 0 ? items[0].productSKU : orderInventory.productSKU,
230
- productName: total > 0 ? items[0].productName : null,
231
- uom: total > 0 ? items[0].uom : null,
232
- remainQty: total > 0 ? items[0].remainQty : null,
233
- remainUomValue: total > 0 ? items[0].remainUomValue : null,
234
- remainUomValueWithUom: total > 0 ? items[0].remainUomValueWithUom : '',
235
- batchId: total > 0 ? items[0].batchId : null,
236
- batchIdRef: total > 0 ? items[0].batchIdRef : null,
237
- packingType: total > 0 ? items[0].packingType : orderInventory.packingType,
238
- packingSize: total > 0 ? items[0].packingSize : 1,
208
+ product: availableItem
209
+ ? {
210
+ id: availableItem.productId,
211
+ sku: availableItem.productSKU,
212
+ name: availableItem.productName
213
+ }
214
+ : { id: null },
215
+ inventory: availableItem
216
+ ? {
217
+ ...availableItem,
218
+ remainQty: availableItem ? availableItem.remainQty : null,
219
+ remainUomValue: availableItem ? availableItem.remainUomValue : null,
220
+ remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : ''
221
+ }
222
+ : null,
223
+ productId: availableItem ? availableItem.productId : null,
224
+ productSKU: availableItem ? availableItem.productSKU : orderInventory.productSKU,
225
+ productName: availableItem ? availableItem.productName : null,
226
+ uom: availableItem ? availableItem.uom : null,
227
+ remainQty: availableItem ? availableItem.remainQty : null,
228
+ remainUomValue: availableItem ? availableItem.remainUomValue : null,
229
+ remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : '',
230
+ batchId: availableItem ? availableItem.batchId : null,
231
+ batchIdRef: availableItem ? availableItem.batchIdRef : null,
232
+ packingType: availableItem ? availableItem.packingType : orderInventory.packingType,
233
+ packingSize: availableItem ? availableItem.packingSize : 1,
239
234
  releaseQty: orderInventory.releaseQty
240
235
  ? Number.isInteger(orderInventory.releaseQty)
241
236
  ? orderInventory.releaseQty
@@ -247,7 +242,7 @@ export class OtherQuery {
247
242
  : null
248
243
  : null,
249
244
  groupType: availableItem ? availableItem.groupType : null,
250
- isError: !availableItem || !orderInventory.releaseQty || !orderInventory.packingType ? true : false
245
+ isError: !availableItem ? true : false
251
246
  }
252
247
 
253
248
  newOrderInventories.push(newOrderInventory)
@@ -301,132 +296,128 @@ export class OtherQuery {
301
296
  @Arg('partnerBizplaceId') partnerBizplaceId: string,
302
297
  @Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
303
298
  ): Promise<OrderProduct[]> {
304
- try {
305
- const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
306
- context.state
299
+ const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
300
+ context.state
307
301
 
308
- const productDetailRepo = tx.getRepository(ProductDetail)
302
+ const productDetailRepo = tx.getRepository(ProductDetail)
309
303
 
310
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
311
- let foundPermittedBizplace: Bizplace
312
- let companyBizplace: Bizplace
304
+ let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
305
+ let foundPermittedBizplace: Bizplace
306
+ let companyBizplace: Bizplace
313
307
 
314
- if (partnerBizplaceId) {
315
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
308
+ if (partnerBizplaceId) {
309
+ foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
316
310
 
317
- if (foundPermittedBizplace) {
318
- if (!foundPermittedBizplace.company?.id) {
319
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
320
- relations: ['domain', 'company', 'company.domain']
321
- })
322
- }
323
- const companyDomain: Domain = foundPermittedBizplace.company.domain
324
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
311
+ if (foundPermittedBizplace) {
312
+ if (!foundPermittedBizplace.company?.id) {
313
+ foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
314
+ relations: ['domain', 'company', 'company.domain']
315
+ })
325
316
  }
317
+ const companyDomain: Domain = foundPermittedBizplace.company.domain
318
+ companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
326
319
  }
320
+ }
327
321
 
328
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
329
- if (bizplace) bizplaces.push(bizplace)
330
-
331
- let strictProduct = 'false'
322
+ const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
323
+ if (bizplace) bizplaces.push(bizplace)
332
324
 
333
- const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
334
- where: { domain, category: 'id-rule', name: 'strict-product-selection' }
335
- })
325
+ let strictProduct: boolean = false
336
326
 
337
- if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
327
+ const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
328
+ where: { domain, category: 'id-rule', name: 'strict-product-selection' }
329
+ })
338
330
 
339
- const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
340
- where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
341
- })
331
+ if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
342
332
 
343
- if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
333
+ const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
334
+ where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
335
+ })
344
336
 
345
- let newOrderProducts: any[] = []
337
+ if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
346
338
 
347
- for (var i = 0; i < orderProducts.length; i++) {
348
- const orderProduct = orderProducts[i]
349
- const productSKU: string = orderProduct.productSKU
350
- const foundProduct: Product = await tx.getRepository(Product).findOne({
351
- where: {
352
- sku: productSKU,
353
- bizplace: companyBizplace
354
- }
355
- })
339
+ let newOrderProducts: any[] = []
356
340
 
357
- let newOrderProduct: any
341
+ for (var i = 0; i < orderProducts.length; i++) {
342
+ const orderProduct = orderProducts[i]
343
+ const productSKU: string = orderProduct.productSKU
344
+ const foundProduct: Product = await tx.getRepository(Product).findOne({
345
+ where: {
346
+ sku: productSKU,
347
+ bizplace: companyBizplace
348
+ }
349
+ })
358
350
 
359
- if (foundProduct) {
360
- let productDetail: ProductDetail
361
- const hasConditions: boolean = Boolean(
362
- (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
363
- (orderProduct?.uom && orderProduct?.uom.trim() != '') ||
364
- orderProduct?.uomValue
365
- )
366
- let productDetailCondition: any = { product: foundProduct }
351
+ let newOrderProduct: any
367
352
 
368
- if (hasConditions && strictProduct == 'true') {
369
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
370
- productDetailCondition.packingType = orderProduct.packingType.trim()
353
+ if (foundProduct) {
354
+ let productDetail: ProductDetail
355
+ const hasConditions: boolean = Boolean(
356
+ (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
357
+ (orderProduct?.uom && orderProduct?.uom.trim() != '')
358
+ )
359
+ let productDetailCondition: any = { product: foundProduct }
371
360
 
372
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
361
+ if (hasConditions) {
362
+ if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
363
+ productDetailCondition.packingType = orderProduct.packingType.trim()
373
364
 
374
- if (orderProduct?.uomValue) productDetailCondition.uomValue = orderProduct.uomValue
375
- } else {
376
- productDetailCondition.isDefault = true
377
- }
365
+ if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
366
+ } else {
367
+ productDetailCondition.isDefault = true
368
+ }
378
369
 
379
- productDetail = await productDetailRepo.findOne({
380
- where: productDetailCondition
381
- })
370
+ productDetail = await productDetailRepo.findOne({
371
+ where: productDetailCondition
372
+ })
382
373
 
383
- if (!productDetail) throw new Error(i18next.t('error.product_not_found'))
384
-
385
- //check if is strict product selection for uom value, uom, packing type
386
- const uomValue: number = strictProduct == 'true' ? productDetail.uomValue : orderProduct.uomValue
387
-
388
- const uom = strictProduct == 'true' ? productDetail.uom : orderProduct.uom
389
-
390
- const packingType = strictProduct == 'true' ? productDetail.packingType : orderProduct.packingType
391
-
392
- newOrderProduct = {
393
- ...orderProduct,
394
- packingType,
395
- packingSize: productDetail ? productDetail.packingSize : orderProduct.packingSize,
396
- uom,
397
- uomValue,
398
- productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
399
- productBrand: foundProduct?.brand ? foundProduct.brand : null,
400
- product: {
401
- id: foundProduct.id,
402
- name: foundProduct.name,
403
- sku: foundProduct.sku,
404
- type: foundProduct.type,
405
- brand: foundProduct.brand,
406
- primaryUnit: productDetail ? productDetail.uom : null,
407
- primaryValue: productDetail ? productDetail.uomValue : null
408
- },
409
- productDetail,
410
- totalUomValue:
411
- orderProduct.packQty > 0
412
- ? uomValue
413
- ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${uom}`
414
- : null
374
+ const uomValue: number =
375
+ strictProduct == true
376
+ ? productDetail?.uomValue
377
+ ? productDetail.uomValue
378
+ : null
379
+ : orderProduct?.uomValue
380
+ ? orderProduct.uomValue
381
+ : productDetail.uomValue
382
+
383
+ newOrderProduct = {
384
+ ...orderProduct,
385
+ packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
386
+ packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
387
+ uom: productDetail?.uom ? productDetail.uom : null,
388
+ uomValue: uomValue,
389
+ productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
390
+ productBrand: foundProduct?.brand ? foundProduct.brand : null,
391
+ isError: productDetail ? false : true,
392
+ product: {
393
+ id: foundProduct.id,
394
+ name: foundProduct.name,
395
+ sku: foundProduct.sku,
396
+ type: foundProduct.type,
397
+ brand: foundProduct.brand,
398
+ primaryUnit: productDetail?.uom ? productDetail.uom : null,
399
+ primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
400
+ },
401
+ totalUomValue:
402
+ orderProduct.packQty > 0
403
+ ? uomValue
404
+ ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
415
405
  : null
416
- }
417
- } else {
418
- throw new Error(i18next.t('error.product_not_found'))
406
+ : null
407
+ }
408
+ } else {
409
+ newOrderProduct = {
410
+ ...orderProduct,
411
+ productName: orderProduct.productSKU,
412
+ isError: true
419
413
  }
420
-
421
- newOrderProducts.push(newOrderProduct)
422
414
  }
423
415
 
424
- return newOrderProducts
425
- } catch (e) {
426
- return e
416
+ newOrderProducts.push(newOrderProduct)
427
417
  }
428
- }
429
418
 
419
+ return newOrderProducts
420
+ }
430
421
  @Directive('@privilege(category: "order_customer", privilege: "query")')
431
422
  @Directive('@transaction')
432
423
  @Query(returns => [InventoryProductGroup])
@@ -435,129 +426,126 @@ export class OtherQuery {
435
426
  @Arg('partnerBizplaceId') partnerBizplaceId: string,
436
427
  @Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
437
428
  ): Promise<OrderProduct[]> {
438
- try {
439
- const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
440
- context.state
429
+ const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
430
+ context.state
441
431
 
442
- const productDetailRepo = tx.getRepository(ProductDetail)
432
+ const productDetailRepo = tx.getRepository(ProductDetail)
443
433
 
444
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
445
- let foundPermittedBizplace: Bizplace
446
- let companyBizplace: Bizplace
434
+ let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
435
+ let foundPermittedBizplace: Bizplace
436
+ let companyBizplace: Bizplace
447
437
 
448
- if (partnerBizplaceId) {
449
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
438
+ if (partnerBizplaceId) {
439
+ foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
450
440
 
451
- if (foundPermittedBizplace) {
452
- if (!foundPermittedBizplace.company?.id) {
453
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
454
- relations: ['domain', 'company', 'company.domain']
455
- })
456
- }
457
- const companyDomain: Domain = foundPermittedBizplace.company.domain
458
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
441
+ if (foundPermittedBizplace) {
442
+ if (!foundPermittedBizplace.company?.id) {
443
+ foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
444
+ relations: ['domain', 'company', 'company.domain']
445
+ })
459
446
  }
447
+ const companyDomain: Domain = foundPermittedBizplace.company.domain
448
+ companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
460
449
  }
450
+ }
461
451
 
462
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
463
- if (bizplace) bizplaces.push(bizplace)
464
-
465
- let strictProduct: boolean = false
452
+ const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
453
+ if (bizplace) bizplaces.push(bizplace)
466
454
 
467
- const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
468
- where: { domain, category: 'id-rule', name: 'strict-product-selection' }
469
- })
455
+ let strictProduct: boolean = false
470
456
 
471
- if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
457
+ const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
458
+ where: { domain, category: 'id-rule', name: 'strict-product-selection' }
459
+ })
472
460
 
473
- const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
474
- where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
475
- })
461
+ if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
476
462
 
477
- if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
463
+ const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
464
+ where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
465
+ })
478
466
 
479
- let newOrderProducts: any[] = []
467
+ if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
480
468
 
481
- for (var i = 0; i < orderProducts.length; i++) {
482
- const orderProduct = orderProducts[i]
483
- const productSKU: string = orderProduct.productSKU
484
- const foundProduct: Product = await tx.getRepository(Product).findOne({
485
- where: {
486
- sku: productSKU,
487
- bizplace: companyBizplace
488
- }
489
- })
469
+ let newOrderProducts: any[] = []
490
470
 
491
- let newOrderProduct: any
471
+ for (var i = 0; i < orderProducts.length; i++) {
472
+ const orderProduct = orderProducts[i]
473
+ const productSKU: string = orderProduct.productSKU
474
+ const foundProduct: Product = await tx.getRepository(Product).findOne({
475
+ where: {
476
+ sku: productSKU,
477
+ bizplace: companyBizplace
478
+ }
479
+ })
492
480
 
493
- if (foundProduct) {
494
- let productDetail: ProductDetail
495
- const hasConditions: boolean = Boolean(
496
- (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
497
- (orderProduct?.uom && orderProduct?.uom.trim() != '')
498
- )
499
- let productDetailCondition: any = { product: foundProduct }
481
+ let newOrderProduct: any
500
482
 
501
- if (hasConditions) {
502
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
503
- productDetailCondition.packingType = orderProduct.packingType.trim()
483
+ if (foundProduct) {
484
+ let productDetail: ProductDetail
485
+ const hasConditions: boolean = Boolean(
486
+ (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
487
+ (orderProduct?.uom && orderProduct?.uom.trim() != '')
488
+ )
489
+ let productDetailCondition: any = { product: foundProduct }
504
490
 
505
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
506
- } else {
507
- productDetailCondition.isDefault = true
508
- }
491
+ if (hasConditions) {
492
+ if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
493
+ productDetailCondition.packingType = orderProduct.packingType.trim()
509
494
 
510
- productDetail = await productDetailRepo.findOne({
511
- where: productDetailCondition
512
- })
495
+ if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
496
+ } else {
497
+ productDetailCondition.isDefault = true
498
+ }
513
499
 
514
- if (!productDetail) throw new Error('Invalid packing type or uom')
500
+ productDetail = await productDetailRepo.findOne({
501
+ where: productDetailCondition
502
+ })
515
503
 
516
- const uomValue: number =
517
- strictProduct == true
518
- ? productDetail?.uomValue
519
- ? productDetail.uomValue
504
+ const uomValue: number =
505
+ strictProduct == true
506
+ ? productDetail?.uomValue
507
+ ? productDetail.uomValue
508
+ : null
509
+ : orderProduct?.uomValue
510
+ ? orderProduct.uomValue
511
+ : productDetail.uomValue
512
+
513
+ newOrderProduct = {
514
+ ...orderProduct,
515
+ packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
516
+ packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
517
+ uom: productDetail?.uom ? productDetail.uom : null,
518
+ uomValue: uomValue,
519
+ productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
520
+ productBrand: foundProduct?.brand ? foundProduct.brand : null,
521
+ isError: productDetail ? false : true,
522
+ product: {
523
+ id: foundProduct.id,
524
+ name: foundProduct.name,
525
+ sku: foundProduct.sku,
526
+ type: foundProduct.type,
527
+ brand: foundProduct.brand,
528
+ primaryUnit: productDetail?.uom ? productDetail.uom : null,
529
+ primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
530
+ },
531
+ totalUomValue:
532
+ orderProduct.packQty > 0
533
+ ? uomValue
534
+ ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
520
535
  : null
521
- : orderProduct?.uomValue
522
- ? orderProduct.uomValue
523
- : productDetail.uomValue
524
-
525
- newOrderProduct = {
526
- ...orderProduct,
527
- packingType: orderProduct?.packingType ? orderProduct.packingType : productDetail.packingType,
528
- packingSize: productDetail?.packingSize ? productDetail.packingSize : null,
529
- uom: productDetail?.uom ? productDetail.uom : null,
530
- uomValue: uomValue,
531
- productName: `${foundProduct.name}(${foundProduct.description}(${foundProduct.sku}))`,
532
- productBrand: foundProduct?.brand ? foundProduct.brand : null,
533
- isError: productDetail ? false : true,
534
- product: {
535
- id: foundProduct.id,
536
- name: foundProduct.name,
537
- sku: foundProduct.sku,
538
- type: foundProduct.type,
539
- brand: foundProduct.brand,
540
- primaryUnit: productDetail?.uom ? productDetail.uom : null,
541
- primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
542
- },
543
- productDetail,
544
- totalUomValue:
545
- orderProduct.packQty > 0
546
- ? uomValue
547
- ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${productDetail.uom}`
548
- : null
549
- : null
550
- }
551
- } else {
552
- throw new Error(`(${orderProduct.productSKU}) sku not found`)
536
+ : null
537
+ }
538
+ } else {
539
+ newOrderProduct = {
540
+ ...orderProduct,
541
+ productName: orderProduct.productSKU,
542
+ isError: true
553
543
  }
554
-
555
- newOrderProducts.push(newOrderProduct)
556
544
  }
557
545
 
558
- return newOrderProducts
559
- } catch (e) {
560
- return e
546
+ newOrderProducts.push(newOrderProduct)
561
547
  }
548
+
549
+ return newOrderProducts
562
550
  }
563
551
  }
@@ -1,5 +1,5 @@
1
1
  import { Field, Float, Int, ObjectType } from 'type-graphql'
2
- import { Product, ProductDetail } from '@things-factory/product-base'
2
+ import { Product } from '@things-factory/product-base'
3
3
  import { ScalarDate } from '@things-factory/shell'
4
4
 
5
5
  @ObjectType()
@@ -19,9 +19,6 @@ export class InventoryProductGroup {
19
19
  @Field({ nullable: true })
20
20
  productId: string
21
21
 
22
- @Field({ nullable: true })
23
- productDetailId: string
24
-
25
22
  @Field({ nullable: true })
26
23
  batchId: string
27
24
 
@@ -105,7 +102,4 @@ export class InventoryProductGroup {
105
102
 
106
103
  @Field(type => Product, { nullable: true })
107
104
  product: Product
108
-
109
- @Field(type => ProductDetail, { nullable: true })
110
- productDetail: ProductDetail
111
105
  }
@@ -69,14 +69,7 @@ export class PurchaseOrderMutation {
69
69
 
70
70
  const findPurchaseOrder: PurchaseOrder = await getRepository(PurchaseOrder).findOne({
71
71
  where: { domain, id },
72
- relations: [
73
- 'orderProducts',
74
- 'orderProducts.product',
75
- 'orderProducts.productDetail',
76
- 'bufferLocation',
77
- 'bizplace',
78
- 'domain'
79
- ]
72
+ relations: ['orderProducts', 'orderProducts.product', 'bufferLocation', 'bizplace', 'domain']
80
73
  })
81
74
 
82
75
  // const findPurchaseOrder: PurchaseOrder = await tx.getRepository(PurchaseOrder).findOne({id}, { relations:['bizplace']})
@@ -425,7 +418,6 @@ export async function upsertPurchaseOrderProducts(
425
418
  const bizplaceRepo: Repository<Product> = tx?.getRepository(Bizplace) || getRepository(Bizplace)
426
419
  const orderProductRepo: Repository<OrderProduct> = tx?.getRepository(OrderProduct) || getRepository(OrderProduct)
427
420
  const productRepo: Repository<Product> = tx?.getRepository(Product) || getRepository(Product)
428
- const productDetailRepo: Repository<Product> = tx?.getRepository(ProductDetail) || getRepository(ProductDetail)
429
421
 
430
422
  // // Remove all existing order products that do not exist in current input
431
423
  let removeOP = purchaseOrder.orderProducts.filter(
@@ -451,7 +443,6 @@ export async function upsertPurchaseOrderProducts(
451
443
  bizplace: bizplace,
452
444
  name: op?.id ? op.name : OrderNoGenerator.orderProduct(),
453
445
  product: await productRepo.findOne(op.product.id),
454
- productDetail: await productDetailRepo.findOne(op.productDetail.id),
455
446
  packingSize: foundProductDetail?.packingSize || 1,
456
447
  purchaseOrder: purchaseOrder,
457
448
  status: purchaseOrder.status,
@@ -62,7 +62,6 @@ export async function getPurchaseOrderFunction(_: any, name: any, context: any,
62
62
  'supplier',
63
63
  'orderProducts',
64
64
  'orderProducts.product',
65
- 'orderProducts.productDetail',
66
65
  'otherCharges',
67
66
  'bufferLocation',
68
67
  'bizplace',