@things-factory/sales-base 4.3.105 → 4.3.113-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 +196 -177
  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 +5 -7
  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 +3 -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 +39 -104
  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 +231 -219
  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 +5 -8
  62. package/server/service/release-good/release-good-types.ts +4 -3
  63. package/server/service/return-order/return-order-mutation.ts +4 -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 +75 -149
  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
@@ -286,6 +286,7 @@ export class OrderInventoryQuery {
286
286
  .leftJoinAndSelect('oi.bizplace', 'bizplace')
287
287
  .leftJoinAndSelect('oi.inventory', 'inventory')
288
288
  .leftJoinAndSelect('inventory.product', 'product')
289
+ .leftJoinAndSelect('inventory.productDetail', 'productDetail')
289
290
  .leftJoinAndSelect('oi.creator', 'creator')
290
291
  .leftJoinAndSelect('oi.updater', 'updater')
291
292
 
@@ -299,6 +300,7 @@ export class OrderInventoryQuery {
299
300
  releaseGoodName: item.releaseGood.name,
300
301
  palletId: item.inventory.palletId,
301
302
  productId: item.inventory.product.id,
303
+ productDetailId: item.inventory.productDetail.id,
302
304
  productName: item.inventory.product.name,
303
305
  productSKU: item.inventory.product.sku,
304
306
  productBrand: item.inventory.product.brand,
@@ -41,6 +41,9 @@ export class NewOrderInventory {
41
41
  @Field(type => NewProduct, { nullable: true })
42
42
  product: NewProduct
43
43
 
44
+ @Field(type => ObjectRef, { nullable: true })
45
+ productDetail: ObjectRef
46
+
44
47
  @Field({ nullable: true })
45
48
  productSKU: string
46
49
 
@@ -200,6 +203,9 @@ export class OrderInventoryPatch {
200
203
  @Field({ nullable: true })
201
204
  productId: string
202
205
 
206
+ @Field({ nullable: true })
207
+ productDetailId: string
208
+
203
209
  @Field({ nullable: true })
204
210
  orderProductId: string
205
211
 
@@ -13,7 +13,7 @@ import {
13
13
 
14
14
  import { User } from '@things-factory/auth-base'
15
15
  import { Bizplace } from '@things-factory/biz-base'
16
- import { Product } from '@things-factory/product-base'
16
+ import { Product, ProductDetail} from '@things-factory/product-base'
17
17
  import { Domain } from '@things-factory/shell'
18
18
  import { Inventory, Location } from '@things-factory/warehouse-base'
19
19
 
@@ -341,6 +341,13 @@ export class OrderInventory {
341
341
  @Field({ nullable: true })
342
342
  loadedAt: Date
343
343
 
344
+ @ManyToOne(type => ProductDetail, { nullable: true })
345
+ @Field({ nullable: true })
346
+ productDetail: ProductDetail
347
+
348
+ @Field({ nullable: true })
349
+ productDetailId: String
350
+
344
351
  @Field({ nullable: true })
345
352
  dispatchedAt: Date
346
353
 
@@ -26,6 +26,7 @@ export class OrderProductQuery {
26
26
 
27
27
  let qb: SelectQueryBuilder<OrderProduct> = await getRepository(OrderProduct).createQueryBuilder('op')
28
28
  qb.leftJoinAndSelect('op.product', 'product')
29
+ .leftJoinAndSelect('op.productDetail', 'productDetail')
29
30
  .leftJoinAndSelect('op.domain', 'domain')
30
31
  .leftJoinAndSelect('op.bizplace', 'bizplace')
31
32
  .leftJoinAndSelect('bizplace.company', 'company')
@@ -90,6 +90,9 @@ export class OrderProductPatch {
90
90
  @Field(type => ObjectRef, { nullable: true })
91
91
  toInventory: ObjectRef
92
92
 
93
+ @Field(type => ObjectRef, { nullable: true })
94
+ productDetail: ObjectRef
95
+
93
96
  @Field(type => InboundProduct, { nullable: true })
94
97
  product: InboundProduct
95
98
 
@@ -231,6 +234,9 @@ export class NewOrderProduct {
231
234
  @Field(type => ObjectRef, { nullable: true })
232
235
  toInventory: ObjectRef
233
236
 
237
+ @Field(type => ObjectRef, { nullable: true })
238
+ productDetail: ObjectRef
239
+
234
240
  @Field(type => InboundProduct, { nullable: true })
235
241
  product: InboundProduct
236
242
 
@@ -12,7 +12,7 @@ import {
12
12
 
13
13
  import { User } from '@things-factory/auth-base'
14
14
  import { Bizplace } from '@things-factory/biz-base'
15
- import { Product } from '@things-factory/product-base'
15
+ import { Product, ProductDetail } from '@things-factory/product-base'
16
16
  import { Domain } from '@things-factory/shell'
17
17
  import { Inventory } from '@things-factory/warehouse-base'
18
18
 
@@ -200,6 +200,10 @@ export class OrderVas {
200
200
  @Field()
201
201
  updatedAt: Date
202
202
 
203
+ @ManyToOne(type => ProductDetail, { nullable: true })
204
+ @Field({ nullable: true })
205
+ productDetail: ProductDetail
206
+
203
207
  @ManyToOne(type => User)
204
208
  @Field(type => User, { nullable: true })
205
209
  creator: User
@@ -213,4 +217,5 @@ export class OrderVas {
213
217
 
214
218
  @RelationId((orderVas: OrderVas) => orderVas.updater)
215
219
  updaterId: string
220
+
216
221
  }
@@ -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,
@@ -187,6 +188,12 @@ export class OtherQuery {
187
188
  operator: 'eq',
188
189
  value: orderInventory.packingType
189
190
  })
191
+ } else {
192
+ filters.push({
193
+ name: 'packingType',
194
+ operator: 'eq',
195
+ value: ''
196
+ })
190
197
  }
191
198
 
192
199
  const params: any = {
@@ -205,32 +212,30 @@ export class OtherQuery {
205
212
 
206
213
  let packageUomValue = availableItem ? availableItem.remainUomValue / availableItem.remainQty : null
207
214
  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,
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,
234
239
  releaseQty: orderInventory.releaseQty
235
240
  ? Number.isInteger(orderInventory.releaseQty)
236
241
  ? orderInventory.releaseQty
@@ -242,7 +247,7 @@ export class OtherQuery {
242
247
  : null
243
248
  : null,
244
249
  groupType: availableItem ? availableItem.groupType : null,
245
- isError: !availableItem ? true : false
250
+ isError: !availableItem || !orderInventory.releaseQty || !orderInventory.packingType ? true : false
246
251
  }
247
252
 
248
253
  newOrderInventories.push(newOrderInventory)
@@ -296,128 +301,132 @@ export class OtherQuery {
296
301
  @Arg('partnerBizplaceId') partnerBizplaceId: string,
297
302
  @Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
298
303
  ): Promise<OrderProduct[]> {
299
- const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
300
- context.state
304
+ try {
305
+ const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
306
+ context.state
301
307
 
302
- const productDetailRepo = tx.getRepository(ProductDetail)
308
+ const productDetailRepo = tx.getRepository(ProductDetail)
303
309
 
304
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
305
- let foundPermittedBizplace: Bizplace
306
- let companyBizplace: Bizplace
310
+ let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
311
+ let foundPermittedBizplace: Bizplace
312
+ let companyBizplace: Bizplace
307
313
 
308
- if (partnerBizplaceId) {
309
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
314
+ if (partnerBizplaceId) {
315
+ foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
310
316
 
311
- if (foundPermittedBizplace) {
312
- if (!foundPermittedBizplace.company?.id) {
313
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
314
- relations: ['domain', 'company', 'company.domain']
315
- })
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 } })
316
325
  }
317
- const companyDomain: Domain = foundPermittedBizplace.company.domain
318
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
319
326
  }
320
- }
321
327
 
322
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
323
- if (bizplace) bizplaces.push(bizplace)
328
+ const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
329
+ if (bizplace) bizplaces.push(bizplace)
324
330
 
325
- let strictProduct: boolean = false
331
+ let strictProduct = 'false'
326
332
 
327
- const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
328
- where: { domain, category: 'id-rule', name: 'strict-product-selection' }
329
- })
333
+ const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
334
+ where: { domain, category: 'id-rule', name: 'strict-product-selection' }
335
+ })
330
336
 
331
- if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
337
+ if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
332
338
 
333
- const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
334
- where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
335
- })
339
+ const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
340
+ where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
341
+ })
336
342
 
337
- if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
343
+ if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
338
344
 
339
- let newOrderProducts: any[] = []
345
+ let newOrderProducts: any[] = []
340
346
 
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
- })
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
+ })
350
356
 
351
- let newOrderProduct: any
357
+ let newOrderProduct: any
352
358
 
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 }
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 }
360
367
 
361
- if (hasConditions) {
362
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
363
- productDetailCondition.packingType = orderProduct.packingType.trim()
368
+ if (hasConditions && strictProduct == 'true') {
369
+ if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
370
+ productDetailCondition.packingType = orderProduct.packingType.trim()
364
371
 
365
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
366
- } else {
367
- productDetailCondition.isDefault = true
368
- }
372
+ if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
369
373
 
370
- productDetail = await productDetailRepo.findOne({
371
- where: productDetailCondition
372
- })
374
+ if (orderProduct?.uomValue) productDetailCondition.uomValue = orderProduct.uomValue
375
+ } else {
376
+ productDetailCondition.isDefault = true
377
+ }
378
+
379
+ productDetail = await productDetailRepo.findOne({
380
+ where: productDetailCondition
381
+ })
373
382
 
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}`
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
405
415
  : null
406
- : null
407
- }
408
- } else {
409
- newOrderProduct = {
410
- ...orderProduct,
411
- productName: orderProduct.productSKU,
412
- isError: true
416
+ }
417
+ } else {
418
+ throw new Error(i18next.t('error.product_not_found'))
413
419
  }
420
+
421
+ newOrderProducts.push(newOrderProduct)
414
422
  }
415
423
 
416
- newOrderProducts.push(newOrderProduct)
424
+ return newOrderProducts
425
+ } catch (e) {
426
+ return e
417
427
  }
418
-
419
- return newOrderProducts
420
428
  }
429
+
421
430
  @Directive('@privilege(category: "order_customer", privilege: "query")')
422
431
  @Directive('@transaction')
423
432
  @Query(returns => [InventoryProductGroup])
@@ -426,126 +435,129 @@ export class OtherQuery {
426
435
  @Arg('partnerBizplaceId') partnerBizplaceId: string,
427
436
  @Arg('orderProducts', type => [NewOrderProduct], { nullable: true }) orderProducts: NewOrderProduct[]
428
437
  ): Promise<OrderProduct[]> {
429
- const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
430
- context.state
438
+ try {
439
+ const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
440
+ context.state
431
441
 
432
- const productDetailRepo = tx.getRepository(ProductDetail)
442
+ const productDetailRepo = tx.getRepository(ProductDetail)
433
443
 
434
- let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
435
- let foundPermittedBizplace: Bizplace
436
- let companyBizplace: Bizplace
444
+ let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
445
+ let foundPermittedBizplace: Bizplace
446
+ let companyBizplace: Bizplace
437
447
 
438
- if (partnerBizplaceId) {
439
- foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
448
+ if (partnerBizplaceId) {
449
+ foundPermittedBizplace = permittedBizplaces.find(biz => biz.id == partnerBizplaceId)
440
450
 
441
- if (foundPermittedBizplace) {
442
- if (!foundPermittedBizplace.company?.id) {
443
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(foundPermittedBizplace.id, {
444
- relations: ['domain', 'company', 'company.domain']
445
- })
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 } })
446
459
  }
447
- const companyDomain: Domain = foundPermittedBizplace.company.domain
448
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
449
460
  }
450
- }
451
461
 
452
- const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
453
- if (bizplace) bizplaces.push(bizplace)
462
+ const bizplaces: Bizplace[] = [foundPermittedBizplace, companyBizplace]
463
+ if (bizplace) bizplaces.push(bizplace)
454
464
 
455
- let strictProduct: boolean = false
465
+ let strictProduct: boolean = false
456
466
 
457
- const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
458
- where: { domain, category: 'id-rule', name: 'strict-product-selection' }
459
- })
467
+ const strictProductSelectionSetting: Setting = await tx.getRepository(Setting).findOne({
468
+ where: { domain, category: 'id-rule', name: 'strict-product-selection' }
469
+ })
460
470
 
461
- if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
471
+ if (strictProductSelectionSetting) strictProduct = strictProductSelectionSetting.value
462
472
 
463
- const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
464
- where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
465
- })
473
+ const partnerStrictProductSelectionSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
474
+ where: { setting: strictProductSelectionSetting, domain, partnerDomain: foundPermittedBizplace?.domain }
475
+ })
466
476
 
467
- if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
477
+ if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
468
478
 
469
- let newOrderProducts: any[] = []
479
+ let newOrderProducts: any[] = []
470
480
 
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
- })
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
+ })
480
490
 
481
- let newOrderProduct: any
491
+ let newOrderProduct: any
482
492
 
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 }
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 }
490
500
 
491
- if (hasConditions) {
492
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
493
- productDetailCondition.packingType = orderProduct.packingType.trim()
501
+ if (hasConditions) {
502
+ if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
503
+ productDetailCondition.packingType = orderProduct.packingType.trim()
494
504
 
495
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
496
- } else {
497
- productDetailCondition.isDefault = true
498
- }
505
+ if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
506
+ } else {
507
+ productDetailCondition.isDefault = true
508
+ }
499
509
 
500
- productDetail = await productDetailRepo.findOne({
501
- where: productDetailCondition
502
- })
510
+ productDetail = await productDetailRepo.findOne({
511
+ where: productDetailCondition
512
+ })
513
+
514
+ if (!productDetail) throw new Error('Invalid packing type or uom')
503
515
 
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}`
516
+ const uomValue: number =
517
+ strictProduct == true
518
+ ? productDetail?.uomValue
519
+ ? productDetail.uomValue
535
520
  : null
536
- : null
537
- }
538
- } else {
539
- newOrderProduct = {
540
- ...orderProduct,
541
- productName: orderProduct.productSKU,
542
- isError: true
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`)
543
553
  }
554
+
555
+ newOrderProducts.push(newOrderProduct)
544
556
  }
545
557
 
546
- newOrderProducts.push(newOrderProduct)
558
+ return newOrderProducts
559
+ } catch (e) {
560
+ return e
547
561
  }
548
-
549
- return newOrderProducts
550
562
  }
551
563
  }