@things-factory/sales-base 4.3.102 → 4.3.105-alpha.0

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