@things-factory/sales-base 4.3.212 → 4.3.213

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.
@@ -50,7 +50,6 @@ export class ArrivalNoticeMutation {
50
50
  @Mutation(returns => Boolean)
51
51
  async deleteArrivalNotice(@Arg('name') name: string, @Ctx() context: any): Promise<Boolean> {
52
52
  const { tx, user, domain }: { tx: EntityManager; user: User; domain: Domain } = context.state
53
-
54
53
  return await deleteArrivalNotice(tx, name, user, domain)
55
54
  }
56
55
 
@@ -81,7 +80,6 @@ export class ArrivalNoticeMutation {
81
80
  async confirmArrivalNotice(@Arg('name') name: string, @Ctx() context: any): Promise<ArrivalNotice> {
82
81
  const { tx }: { tx: EntityManager } = context.state
83
82
  const arrivalNotice: ArrivalNotice = await confirmArrivalNoticeFunction(name, context, tx)
84
-
85
83
  // If current GAN has cross docking
86
84
  if (arrivalNotice.crossDocking) {
87
85
  const { releaseGood } = await tx.getRepository(ArrivalNotice).findOne(arrivalNotice.id, {
@@ -399,11 +397,11 @@ export async function deleteArrivalNotice(
399
397
  user: User,
400
398
  domain: Domain
401
399
  ): Promise<boolean> {
400
+ try{
402
401
  let foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
403
402
  where: { domain, name },
404
403
  relations: ['bizplace', 'releaseGood', 'orderProducts', 'orderVass', 'collectionOrders', 'creator', 'updater']
405
404
  })
406
-
407
405
  if (!foundArrivalNotice) throw new Error(`Arrival notice doesn't exists.`)
408
406
 
409
407
  const foundJS: JobSheet = await tx.getRepository(JobSheet).findOne({
@@ -412,17 +410,24 @@ export async function deleteArrivalNotice(
412
410
  arrivalNoticeRefNo: foundArrivalNotice.name
413
411
  }
414
412
  })
415
-
416
- if (foundJS) await tx.getRepository(JobSheet).delete({ arrivalNoticeRefNo: foundArrivalNotice.name })
413
+
414
+ if (foundJS){
415
+ await tx.getRepository(JobSheet).createQueryBuilder()
416
+ .delete()
417
+ .from(JobSheet)
418
+ .where('id = :id', { id: foundJS.id })
419
+ .execute()
420
+ }
417
421
 
418
422
  const foundOPs: OrderProduct[] = foundArrivalNotice.orderProducts
419
423
  const foundOVs: OrderVas[] = foundArrivalNotice.orderVass
420
424
 
421
425
  // 1. delete order products
422
- const productIds = foundOPs.map((product: OrderProduct) => product.id)
423
- if (productIds.length) {
424
- await tx.getRepository(OrderProduct).delete({ id: In(productIds) })
425
- }
426
+ await tx.getRepository(OrderProduct).createQueryBuilder('op')
427
+ .delete()
428
+ .from(OrderProduct)
429
+ .where('arrival_notice_id = :arrivalNoticeId', { arrivalNoticeId: foundArrivalNotice.id })
430
+ .execute()
426
431
 
427
432
  // 2. delete order vass
428
433
  const vasIds = foundOVs.map((vas: OrderVas) => vas.id)
@@ -448,6 +453,9 @@ export async function deleteArrivalNotice(
448
453
  await tx.getRepository(ArrivalNotice).delete({ domain, name })
449
454
  }
450
455
  return true
456
+ } catch(e) {
457
+ console.log(e)
458
+ }
451
459
  }
452
460
 
453
461
  export async function generateArrivalNoticeFunction(
@@ -567,6 +575,7 @@ export async function confirmArrivalNoticeFunction(
567
575
  context: any,
568
576
  tx?: EntityManager
569
577
  ): Promise<ArrivalNotice> {
578
+ try{
570
579
  const { user, domain }: { user: User; domain: Domain } = context.state
571
580
 
572
581
  const foundArrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({
@@ -602,6 +611,7 @@ export async function confirmArrivalNoticeFunction(
602
611
  })
603
612
 
604
613
  // If status of GAN is PENDING_RECEIVE then directly to assign warehouse
614
+
605
615
  if (ganProcessingSetting) {
606
616
  let setting = !isNaN(partnerGanProcessingSetting?.value)
607
617
  ? partnerGanProcessingSetting?.value
@@ -620,18 +630,20 @@ export async function confirmArrivalNoticeFunction(
620
630
  if (!foundArrivalNotice) throw new Error(`Arrival notice doesn't exists.`)
621
631
 
622
632
  // 1. GAN Status change (PENDING => PENDING_RECEIVE)
623
- let arrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).save({
624
- ...foundArrivalNotice,
633
+ await tx.getRepository(ArrivalNotice).update({ id: foundArrivalNotice.id },{
625
634
  status: anStatus,
626
635
  updater: user,
627
636
  acceptedBy: acceptedByUser,
628
637
  acceptedAt: acceptedTime
629
638
  })
630
639
 
631
- foundOPs = foundOPs.map((op: OrderProduct) => {
632
- return { ...op, status: opStatus }
633
- })
634
- await tx.getRepository(OrderProduct).save(foundOPs)
640
+ let arrivalNotice: ArrivalNotice = await tx.getRepository(ArrivalNotice).findOne({where: { id: foundArrivalNotice.id }})
641
+
642
+ await tx.getRepository(OrderProduct).createQueryBuilder()
643
+ .update(OrderProduct)
644
+ .set({ status: opStatus })
645
+ .whereInIds(foundOPs.map(op => op.id))
646
+ .execute();
635
647
 
636
648
  // 2. Update order vas status if it exists.
637
649
  if (foundOVs && foundOVs.length) {
@@ -660,7 +672,6 @@ export async function confirmArrivalNoticeFunction(
660
672
  return 'ur.roles_id IN ' + subQuery
661
673
  })
662
674
  .getRawMany()
663
-
664
675
  // send notification to Office Admin Users
665
676
  if (users?.length && context.header?.referer) {
666
677
  const receivers: any[] = users.map(user => user.id)
@@ -670,7 +681,6 @@ export async function confirmArrivalNoticeFunction(
670
681
  url: context.header.referer,
671
682
  data: { url: context.header.referer }
672
683
  }
673
-
674
684
  /**
675
685
  * @notes Temporary off sendNotification due to suspect of causing wms down
676
686
  */
@@ -683,6 +693,9 @@ export async function confirmArrivalNoticeFunction(
683
693
  }
684
694
 
685
695
  return arrivalNotice
696
+ } catch (e) {
697
+ console.log(e)
698
+ }
686
699
  }
687
700
 
688
701
  export async function receiveArrivalNoticeFunction(_: any, name: String, context: any): Promise<ArrivalNotice> {
@@ -953,8 +966,8 @@ export async function rejectArrivalNotice(
953
966
  }
954
967
 
955
968
  /**
956
- * @notes Temporary off sendNotification due to suspect of causing wms down
957
- */
969
+ * @notes Temporary off sendNotification due to suspect of causing wms down
970
+ */
958
971
 
959
972
  // await sendNotification({
960
973
  // receivers,
@@ -972,8 +985,6 @@ export async function addArrivalNoticeProducts(
972
985
  user: User,
973
986
  tx?: EntityManager
974
987
  ): Promise<void> {
975
- const productRepo: Repository<Product> = tx?.getRepository(Product) || getRepository(Product)
976
- const productDetailRepo: Repository<ProductDetail> = tx?.getRepository(ProductDetail) || getRepository(ProductDetail)
977
988
  const orderProductRepo: Repository<OrderProduct> = tx?.getRepository(OrderProduct) || getRepository(OrderProduct)
978
989
 
979
990
  if (!arrivalNotice?.bizplace || !arrivalNotice?.orderProducts?.length) {
@@ -983,23 +994,44 @@ export async function addArrivalNoticeProducts(
983
994
  })
984
995
  }
985
996
 
986
- const createdOrderProducts: OrderProduct[] = await Promise.all(
987
- newOrderProducts.map(async (op: OrderProduct) => {
988
- return {
989
- ...op,
990
- domain,
991
- bizplace: arrivalNotice.bizplace,
992
- name: OrderNoGenerator.orderProduct(),
993
- product: await productRepo.findOne(op.product.id),
994
- productDetail: await productDetailRepo.findOne(op.productDetail.id),
995
- arrivalNotice,
996
- creator: user
997
- }
997
+ let createdOrderProducts: any[] = []
998
+
999
+ for (let index = 0; index < newOrderProducts.length; index++) {
1000
+ const op = newOrderProducts[index];
1001
+
1002
+ createdOrderProducts.push({
1003
+ name: OrderNoGenerator.orderProduct(),
1004
+ product_id: op.product.id,
1005
+ product_detail_id: op.productDetail.id,
1006
+ batch_id: op.batchId,
1007
+ batch_id_ref: op.batchIdRef,
1008
+ packing_type: op.packingType,
1009
+ packing_size: op.packingSize,
1010
+ uom: op.uom,
1011
+ uom_value: op.uomValue,
1012
+ pack_qty: op.packQty,
1013
+ total_uom_value: op.totalUomValue,
1014
+ unit_price: op.unitPrice,
1015
+ remark: op.remark,
1016
+ manufacture_date: op.manufactureDate,
1017
+ status: op.status,
1018
+ domain_id: domain.id,
1019
+ bizplace_id: arrivalNotice.bizplace,
1020
+ arrival_notice_id: arrivalNotice.id,
1021
+ creator_id: user.id,
1022
+ updater_id: user.id
1023
+
998
1024
  })
999
- )
1025
+ }
1000
1026
 
1001
- debug('gan-created-order-products', createdOrderProducts)
1002
- await orderProductRepo.save(createdOrderProducts)
1027
+ await orderProductRepo.query(
1028
+ `
1029
+ INSERT INTO order_products ("name", "product_detail_id", "product_id", "batch_id", "batch_id_ref", "packing_type", "packing_size", "uom", "uom_value", "pack_qty", "total_uom_value", "unit_price", "remark", "manufacture_date", "status", "domain_id", "bizplace_id", "arrival_notice_id", "creator_id", "updater_id")
1030
+ SELECT "name", "product_detail_id", "product_id", "batch_id", "batch_id_ref", "packing_type", "packing_size", "uom", "uom_value", "pack_qty", "total_uom_value", "unit_price", "remark", "manufacture_date", "status", "domain_id", "bizplace_id", "arrival_notice_id", "creator_id", "updater_id"
1031
+ FROM JSON_POPULATE_RECORDSET(NULL::order_products, $1) op
1032
+ `,
1033
+ [JSON.stringify(createdOrderProducts)]
1034
+ )
1003
1035
  }
1004
1036
 
1005
1037
  export async function editArrivalNoticeProducts(
@@ -49,12 +49,16 @@ export class ArrivalNoticeQuery {
49
49
 
50
50
  //separate query to improve typeorm mapping performance. Search for Related Order Product
51
51
  let orderProducts = await getRepository(OrderProduct).find({ where: { arrivalNotice: foundGAN }, relations: ['product', 'productDetail'] })
52
- foundGAN.orderProducts = orderProducts
53
-
52
+ foundGAN.orderProducts = await Promise.all(orderProducts.map(async (orderProduct) => {
53
+ orderProduct.unitPrice = orderProduct?.unitPrice ? parseFloat(orderProduct.unitPrice.toFixed(2)) : null;
54
+ orderProduct.adjustedUnitPrice = orderProduct?.adjustedUnitPrice ? parseFloat(orderProduct.adjustedUnitPrice.toFixed(2)) : null;
55
+ return orderProduct;
56
+ }))
57
+
54
58
  //separate query to improve typeorm mapping performance. Search for Related Order Inventory
55
59
  let orderInventories = await getRepository(OrderInventory).find({ where: { arrivalNotice: foundGAN }, relations: ['inventory', 'inventory.product', 'inventory.location'] })
56
60
  foundGAN.orderInventories = orderInventories
57
-
61
+
58
62
  if (name && !foundGAN) throw new Error(`Failed to find arrival notice with ${name}`)
59
63
 
60
64
  if (foundGAN) {
@@ -75,41 +79,6 @@ export class ArrivalNoticeQuery {
75
79
  }
76
80
  })
77
81
  : []
78
-
79
- // add productDetails data to orderProduct.product
80
- foundGAN.orderProducts = await Promise.all(
81
- foundGAN.orderProducts.map(async (orderProduct: OrderProduct) => {
82
- orderProduct.product['productDetails'] = await getRepository(ProductDetail).find({
83
- where: {
84
- product: orderProduct.product.id,
85
- packingType: orderProduct.packingType,
86
- packingSize: orderProduct.packingSize
87
- }
88
- })
89
- orderProduct.unitPrice = orderProduct?.unitPrice ? parseFloat(orderProduct.unitPrice.toFixed(2)) : null
90
- orderProduct.adjustedUnitPrice = orderProduct?.adjustedUnitPrice
91
- ? parseFloat(orderProduct.adjustedUnitPrice.toFixed(2))
92
- : null
93
- return orderProduct
94
- })
95
- )
96
-
97
- // add productDetails data to orderInventory.inventory.product if orderInventory is exist
98
- if (foundGAN.orderInventories && foundGAN.orderInventories.length) {
99
- foundGAN.orderInventories = await Promise.all(
100
- foundGAN.orderInventories.map(async (orderInventory: OrderInventory) => {
101
- orderInventory.inventory.product['productDetails'] = await getRepository(ProductDetail).find({
102
- where: {
103
- product: orderInventory.inventory.product.id,
104
- packingType: orderInventory.inventory.packingType,
105
- packingSize: orderInventory.inventory.packingSize
106
- }
107
- })
108
- return orderInventory
109
- })
110
- )
111
- }
112
-
113
82
  return {
114
83
  ...foundGAN,
115
84
  attachment: [...foundPOAttachments, ...foundAttachments]
@@ -354,7 +354,7 @@ export async function getDraftReleaseGoodFunction(_: any, name: any, context: an
354
354
  remainUomValueWithUom: foundProductInv ? foundProductInv.remainUomValueWithUom : 0,
355
355
  status: foundProductInv?.transferQty
356
356
  ? DRAFT_RELEASE_ORDER_STATUS.TRANSFER
357
- : foundProductInv?.remainQty || 0 < itm.releaseQty
357
+ : (foundProductInv?.remainQty || 0) < itm.releaseQty
358
358
  ? DRAFT_RELEASE_ORDER_STATUS.INSUFFICIENT
359
359
  : DRAFT_RELEASE_ORDER_STATUS.DRAFT
360
360
  }
@@ -66,6 +66,11 @@ import { Replenishment } from '../replenishment/replenishment'
66
66
  orderInventory.uom
67
67
  ])
68
68
  @Index('ix_order-inventory_5', (orderInventory: OrderInventory) => [orderInventory.releaseGood])
69
+
70
+
71
+ @Index('ix_order-inventory_6', (orderInventory: OrderInventory) => [orderInventory.id], {
72
+ unique: true
73
+ })
69
74
  @ObjectType()
70
75
  export class OrderInventory {
71
76
  @PrimaryGeneratedColumn('uuid')
@@ -212,11 +212,11 @@ export class OtherQuery {
212
212
  productDetail: availableItem ? { id: availableItem.productDetailId } : null,
213
213
  inventory: availableItem
214
214
  ? {
215
- ...availableItem,
216
- remainQty: availableItem ? availableItem.remainQty : null,
217
- remainUomValue: availableItem ? availableItem.remainUomValue : null,
218
- remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : ''
219
- }
215
+ ...availableItem,
216
+ remainQty: availableItem ? availableItem.remainQty : null,
217
+ remainUomValue: availableItem ? availableItem.remainUomValue : null,
218
+ remainUomValueWithUom: availableItem ? availableItem.remainUomValueWithUom : ''
219
+ }
220
220
  : null,
221
221
  productId: availableItem ? availableItem.productId : null,
222
222
  productDetailID: availableItem ? availableItem.productDetailId : null,
@@ -299,8 +299,6 @@ export class OtherQuery {
299
299
  const { domain, user, tx, bizplace }: { domain: Domain; user: User; tx: EntityManager; bizplace: Bizplace } =
300
300
  context.state
301
301
 
302
- const productDetailRepo = tx.getRepository(ProductDetail)
303
-
304
302
  let permittedBizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)
305
303
  let foundPermittedBizplace: Bizplace
306
304
  let companyBizplace: Bizplace
@@ -336,90 +334,118 @@ export class OtherQuery {
336
334
 
337
335
  if (partnerStrictProductSelectionSetting) strictProduct = partnerStrictProductSelectionSetting.value
338
336
 
339
- let newOrderProducts: any[] = []
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
337
+ const json_op = JSON.stringify(
338
+ orderProducts.map(orderProduct => {
339
+ return {
340
+ sku: orderProduct.productSKU,
341
+ packing_type: orderProduct.packingType,
342
+ pack_qty: orderProduct.packQty,
343
+ pallet_qty: orderProduct.palletQty,
344
+ unit_price: orderProduct.unitPrice,
345
+ batch_id: orderProduct.batchId,
346
+ uom: orderProduct.uom,
347
+ uom_value: orderProduct.uomValue
348
348
  }
349
349
  })
350
+ )
350
351
 
351
- let newOrderProduct: any
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
- orderProduct?.uomValue
359
- )
360
- let productDetailCondition: any = { product: foundProduct }
361
-
362
- if (hasConditions && strictProduct == 'true') {
363
- if (orderProduct?.packingType && orderProduct.packingType.trim() != '')
364
- productDetailCondition.packingType = orderProduct.packingType.trim()
365
-
366
- if (orderProduct?.uom && orderProduct.uom.trim() != '') productDetailCondition.uom = orderProduct.uom.trim()
367
-
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
- })
376
-
377
- //check if is strict product selection for uom value, uom, packing type
378
- const uomValue: number =
379
- strictProduct == 'true' && productDetail ? productDetail.uomValue : orderProduct.uomValue
380
-
381
- const uom = strictProduct == 'true' && productDetail ? productDetail.uom : orderProduct.uom
382
-
383
- const packingType =
384
- strictProduct == 'true' && productDetail ? 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
- costPrice: foundProduct.costPrice
403
- },
404
- productDetail,
405
- totalUomValue:
406
- orderProduct.packQty > 0
407
- ? uomValue
408
- ? `${(orderProduct.packQty * uomValue).toFixed(2)} ${uom}`
409
- : null
410
- : null,
411
- isError: productDetail ? false : true
412
- }
413
- } else {
414
- newOrderProduct = {
415
- ...orderProduct,
416
- productName: orderProduct.productSKU,
417
- isError: true
352
+ // create temp table to hold the input data
353
+ await tx.query(`
354
+ CREATE TEMP TABLE raw_order_products(
355
+ sku VARCHAR(150),
356
+ packing_type VARCHAR(50),
357
+ pack_qty FLOAT,
358
+ pallet_qty FLOAT,
359
+ unit_price FLOAT,
360
+ batch_id VARCHAR(50),
361
+ uom VARCHAR(10),
362
+ uom_value FLOAT
363
+ );
364
+ `)
365
+
366
+ // insert input data into temp table
367
+ await tx.query(`
368
+ INSERT INTO raw_order_products
369
+ SELECT * FROM JSON_POPULATE_RECORDSET(NULL::raw_order_products, $1) js
370
+ `, [json_op])
371
+
372
+ // find closest matching product details from input data
373
+ await tx.query(`
374
+ create temp table matching_product_details as (
375
+ select row_number() over(partition by rop.sku order by is_default desc) as rn,
376
+ rop.sku as "rop_sku", rop.packing_type as "rop_packing_type", rop.uom as "rop_uom", rop.uom_value as "rop_uom_value", pd.*
377
+ from product_details pd
378
+ inner join products p on p.id = pd.product_id AND p.bizplace_id = $1
379
+ inner join raw_order_products rop ON LOWER(rop.sku) = LOWER(p.sku)
380
+ where
381
+ pd.packing_type = coalesce(rop.packing_type, pd.packing_type)
382
+ and pd.uom = coalesce(rop.uom, pd.uom)
383
+ and pd.uom_value = coalesce(rop.uom_value, pd.uom_value)
384
+ )`, [companyBizplace.id])
385
+
386
+ // massage data into defined structure
387
+ let results = await tx.query(`
388
+ select *,
389
+ case when "packQty" > 0 and "uomValue" is not null then "packQty" * "uomValue" else null end as "totalUomValue"
390
+ from (
391
+ SELECT
392
+ js.sku,
393
+ js.pack_qty as "packQty",
394
+ js.pallet_qty as "palletQty",
395
+ js.unit_price as "unitPrice",
396
+ js.batch_id as "batchId",
397
+ p.id AS "productId",
398
+ p.name as "productName",
399
+ p.brand as "productBrand",
400
+ p.type as "productType",
401
+ coalesce(mpd.uom, pdd.uom) as "productPrimaryUnit",
402
+ coalesce(mpd.uom_value, pdd.uom_value) as "productPrimaryValue",
403
+ coalesce(mpd.packing_size, pdd.packing_size) as "packingSize",
404
+ ${strictProduct.toLowerCase() === 'false' ? `
405
+ coalesce(js.packing_type, mpd.packing_type, pdd.packing_type) as "packingType",
406
+ coalesce(js.uom, mpd.uom, js.uom) as "uom",
407
+ coalesce(js.uom_value, mpd.uom_value, js.uom_value) as "uomValue",
408
+ ` : `
409
+ coalesce(mpd.packing_type, pdd.packing_type) as "packingType",
410
+ coalesce(mpd.uom, js.uom) as "uom",
411
+ coalesce(mpd.uom_value, js.uom_value) as "uomValue",
412
+ `}
413
+ coalesce(mpd.id, pdd.id) AS "productDetailId",
414
+ coalesce(mpd.cost_price, pdd.cost_price) AS "productDetailCostPrice",
415
+ CASE WHEN p.id is null then js.sku else concat(p.name,' (',p.description,' (',js.sku,'))') end as "productName",
416
+ CASE WHEN p.id is null or coalesce(mpd.id, pdd.id) is null then true else false end as "isError"
417
+ FROM raw_order_products js
418
+ LEFT JOIN products p ON LOWER(js.sku) = LOWER(p.sku) AND p.bizplace_id = $1
419
+ left join matching_product_details mpd on mpd.rn = 1 and mpd.rop_sku = js.sku and mpd.rop_packing_type = js.packing_type and mpd.rop_uom = js.uom
420
+ left join product_details pdd on p.id = pdd.product_id and pdd.is_default = true
421
+ ) dt
422
+ `, [companyBizplace.id])
423
+
424
+ // remove all temp table
425
+ await tx.query(`DROP TABLE matching_product_details`)
426
+ await tx.query(`DROP TABLE raw_order_products`)
427
+
428
+ // build output structure
429
+ const newOrderProducts: any[] = results.map(result => {
430
+ return {
431
+ ...result,
432
+ product: {
433
+ id: result.productId,
434
+ name: result.productName,
435
+ sku: result.productSku,
436
+ description: result.productDescription,
437
+ type: result.productType,
438
+ brand: result.productBrand,
439
+ primaryUnit: result.productPrimaryUnit,
440
+ primaryValue: result.productPrimaryValue,
441
+ costPrice: result.productDetailCostPrice,
442
+ },
443
+ productDetail: {
444
+ id: result.productDetailId,
445
+ costPrice: result.productDetailCostPrice,
418
446
  }
419
447
  }
420
-
421
- newOrderProducts.push(newOrderProduct)
422
- }
448
+ })
423
449
 
424
450
  return newOrderProducts
425
451
  } catch (e) {
@@ -494,7 +520,7 @@ export class OtherQuery {
494
520
  let productDetail: ProductDetail
495
521
  const hasConditions: boolean = Boolean(
496
522
  (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
497
- (orderProduct?.uom && orderProduct?.uom.trim() != '')
523
+ (orderProduct?.uom && orderProduct?.uom.trim() != '')
498
524
  )
499
525
  let productDetailCondition: any = { product: foundProduct }
500
526
 
@@ -519,8 +545,8 @@ export class OtherQuery {
519
545
  ? productDetail.uomValue
520
546
  : null
521
547
  : orderProduct?.uomValue
522
- ? orderProduct.uomValue
523
- : productDetail.uomValue
548
+ ? orderProduct.uomValue
549
+ : productDetail.uomValue
524
550
 
525
551
  newOrderProduct = {
526
552
  ...orderProduct,