@things-factory/sales-base 4.3.76 → 4.3.79-alpha.1

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 (63) hide show
  1. package/dist-server/service/arrival-notice/arrival-notice.js +5 -0
  2. package/dist-server/service/arrival-notice/arrival-notice.js.map +1 -1
  3. package/dist-server/service/draft-release-good/draft-release-good-mutation.js +3 -8
  4. package/dist-server/service/draft-release-good/draft-release-good-mutation.js.map +1 -1
  5. package/dist-server/service/draft-release-good/draft-release-good-query.js +4 -7
  6. package/dist-server/service/draft-release-good/draft-release-good-query.js.map +1 -1
  7. package/dist-server/service/draft-release-good/draft-release-good.js +5 -0
  8. package/dist-server/service/draft-release-good/draft-release-good.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 +4 -4
  12. package/dist-server/service/order-inventory/order-inventory-types.js +18 -10
  13. package/dist-server/service/order-inventory/order-inventory-types.js.map +1 -1
  14. package/dist-server/service/order-inventory/order-inventory.js +8 -3
  15. package/dist-server/service/order-inventory/order-inventory.js.map +1 -1
  16. package/dist-server/service/order-product/order-product-query.js +1 -0
  17. package/dist-server/service/order-product/order-product-query.js.map +1 -1
  18. package/dist-server/service/order-product/order-product-types.js +14 -10
  19. package/dist-server/service/order-product/order-product-types.js.map +1 -1
  20. package/dist-server/service/order-vas/order-vas.js +8 -3
  21. package/dist-server/service/order-vas/order-vas.js.map +1 -1
  22. package/dist-server/service/others/other-query.js +3 -1
  23. package/dist-server/service/others/other-query.js.map +1 -1
  24. package/dist-server/service/others/other-types.js +4 -0
  25. package/dist-server/service/others/other-types.js.map +1 -1
  26. package/dist-server/service/purchase-order/purchase-order-mutation.js +10 -2
  27. package/dist-server/service/purchase-order/purchase-order-mutation.js.map +1 -1
  28. package/dist-server/service/purchase-order/purchase-order-query.js +1 -0
  29. package/dist-server/service/purchase-order/purchase-order-query.js.map +1 -1
  30. package/dist-server/service/release-good/release-good-mutation.js +187 -49
  31. package/dist-server/service/release-good/release-good-mutation.js.map +1 -1
  32. package/dist-server/service/release-good/release-good-query.js +4 -6
  33. package/dist-server/service/release-good/release-good-query.js.map +1 -1
  34. package/dist-server/service/release-good/release-good-types.js +8 -4
  35. package/dist-server/service/release-good/release-good-types.js.map +1 -1
  36. package/dist-server/service/release-good/release-good.js +13 -0
  37. package/dist-server/service/release-good/release-good.js.map +1 -1
  38. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js +8 -3
  39. package/dist-server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.js.map +1 -1
  40. package/dist-server/utils/inventory-util.js +33 -102
  41. package/dist-server/utils/inventory-util.js.map +1 -1
  42. package/package.json +13 -13
  43. package/server/service/arrival-notice/arrival-notice.ts +4 -0
  44. package/server/service/draft-release-good/draft-release-good-mutation.ts +10 -12
  45. package/server/service/draft-release-good/draft-release-good-query.ts +5 -5
  46. package/server/service/draft-release-good/draft-release-good.ts +4 -0
  47. package/server/service/invoice-product/invoice-product.ts +5 -1
  48. package/server/service/order-inventory/order-inventory-query.ts +4 -4
  49. package/server/service/order-inventory/order-inventory-types.ts +6 -0
  50. package/server/service/order-inventory/order-inventory.ts +5 -1
  51. package/server/service/order-product/order-product-query.ts +1 -0
  52. package/server/service/order-product/order-product-types.ts +3 -0
  53. package/server/service/order-vas/order-vas.ts +6 -1
  54. package/server/service/others/other-query.ts +6 -3
  55. package/server/service/others/other-types.ts +3 -0
  56. package/server/service/purchase-order/purchase-order-mutation.ts +10 -1
  57. package/server/service/purchase-order/purchase-order-query.ts +1 -0
  58. package/server/service/release-good/release-good-mutation.ts +221 -50
  59. package/server/service/release-good/release-good-query.ts +4 -7
  60. package/server/service/release-good/release-good-types.ts +4 -3
  61. package/server/service/release-good/release-good.ts +14 -6
  62. package/server/service/reverse-kitting-order-inventory/reverse-kitting-order-inventory.ts +5 -1
  63. package/server/utils/inventory-util.ts +67 -147
@@ -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,10 @@ 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
+
344
348
  @Field({ nullable: true })
345
349
  dispatchedAt: Date
346
350
 
@@ -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')
@@ -84,6 +84,9 @@ export class OrderProductPatch {
84
84
  @Field(type => ObjectRef, { nullable: true })
85
85
  toInventory: ObjectRef
86
86
 
87
+ @Field(type => ObjectRef, { nullable: true })
88
+ productDetail: ObjectRef
89
+
87
90
  @Field(type => InboundProduct, { nullable: true })
88
91
  product: InboundProduct
89
92
 
@@ -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
  }
@@ -200,6 +200,7 @@ export class OtherQuery {
200
200
  const newOrderInventory: any = {
201
201
  product:
202
202
  total > 0 ? { id: items[0].productId, sku: items[0].productSKU, name: items[0].productName } : { id: null },
203
+ productDetail: total > 0 ? { id: items[0].productDetailId } : { id: null },
203
204
  inventory:
204
205
  total > 0
205
206
  ? {
@@ -210,6 +211,7 @@ export class OtherQuery {
210
211
  }
211
212
  : null,
212
213
  productId: total > 0 ? items[0].productId : null,
214
+ productDetailID: total > 0 ? items[0].productDetailId : null,
213
215
  productSKU: total > 0 ? items[0].productSKU : orderInventory.productSKU,
214
216
  productName: total > 0 ? items[0].productName : null,
215
217
  uom: total > 0 ? items[0].uom : null,
@@ -472,7 +474,7 @@ export class OtherQuery {
472
474
  let productDetail: ProductDetail
473
475
  const hasConditions: boolean = Boolean(
474
476
  (orderProduct?.packingType && orderProduct?.packingType.trim() != '') ||
475
- (orderProduct?.uom && orderProduct?.uom.trim() != '')
477
+ (orderProduct?.uom && orderProduct?.uom.trim() != '')
476
478
  )
477
479
  let productDetailCondition: any = { product: foundProduct }
478
480
 
@@ -495,8 +497,8 @@ export class OtherQuery {
495
497
  ? productDetail.uomValue
496
498
  : null
497
499
  : orderProduct?.uomValue
498
- ? orderProduct.uomValue
499
- : productDetail.uomValue
500
+ ? orderProduct.uomValue
501
+ : productDetail.uomValue
500
502
 
501
503
  newOrderProduct = {
502
504
  ...orderProduct,
@@ -516,6 +518,7 @@ export class OtherQuery {
516
518
  primaryUnit: productDetail?.uom ? productDetail.uom : null,
517
519
  primaryValue: productDetail?.uomValue ? productDetail.uomValue : null
518
520
  },
521
+ productDetail,
519
522
  totalUomValue:
520
523
  orderProduct.packQty > 0
521
524
  ? uomValue
@@ -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
 
@@ -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',
@@ -3,7 +3,7 @@ import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'
3
3
  import { EntityManager, getConnection, getRepository, In, Not, Repository } from 'typeorm'
4
4
 
5
5
  import { Attachment, createAttachments } from '@things-factory/attachment-base'
6
- import { Partner, Role, User } from '@things-factory/auth-base'
6
+ import { ApplicationType, Partner, Role, User } from '@things-factory/auth-base'
7
7
  import {
8
8
  Bizplace,
9
9
  getDomainUsers,
@@ -14,10 +14,9 @@ import {
14
14
  import { generateId } from '@things-factory/id-rule-base'
15
15
  import { MarketplaceStore } from '@things-factory/integration-marketplace'
16
16
  import { Sellercraft, SellercraftStatus } from '@things-factory/integration-sellercraft'
17
- import { Sftp } from '@things-factory/integration-sftp'
18
17
  import { MarketplaceOrder, MarketplaceProductVariation } from '@things-factory/marketplace-base'
19
18
  // import { sendNotification } from '@things-factory/notification'
20
- import { Product, ProductBundleSetting } from '@things-factory/product-base'
19
+ import { Product, ProductBundleSetting, ProductDetail } from '@things-factory/product-base'
21
20
  import { PartnerSetting, Setting } from '@things-factory/setting-base'
22
21
  import { Domain } from '@things-factory/shell'
23
22
  import { Inventory } from '@things-factory/warehouse-base'
@@ -485,20 +484,18 @@ export async function generateReleaseGoodFunction(
485
484
  await InventoryUtil.validateWarehousePartnersProductsQuantity(domain, bizplace, orderInventories, context, tx)
486
485
  /** End Validate Release Order Product Quantity Section */
487
486
 
488
- if (releaseGood.type == 'b2c') {
489
- const sellercraft: Sellercraft = await tx
490
- .getRepository(Sellercraft)
491
- .findOne({ domain: bizplace.domain, status: SellercraftStatus.ACTIVE })
487
+ const orderSource: string = releaseGood.source
488
+ switch (orderSource) {
489
+ case ApplicationType.SELLERCRAFT:
490
+ const sellercraft: Sellercraft = await tx
491
+ .getRepository(Sellercraft)
492
+ .findOne({ domain: bizplace.domain, status: SellercraftStatus.ACTIVE })
492
493
 
493
- let customerAvailableSftp: Sftp = await tx.getRepository(Sftp).findOne({
494
- where: { domain: bizplace.domain }
495
- })
496
-
497
- if (sellercraft) {
498
494
  const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
499
495
  await sellercraftCtrl.checkExistingReleaseGood(sellercraft, releaseGood)
500
- } else if (customerAvailableSftp) {
501
- } else {
496
+ break
497
+
498
+ case ApplicationType.MMS:
502
499
  const refNo: string = releaseGood.refNo
503
500
  const foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
504
501
  where: {
@@ -532,9 +529,62 @@ export async function generateReleaseGoodFunction(
532
529
  throw new Error('Existing release order found')
533
530
  }
534
531
  }
535
- }
532
+ break
533
+
534
+ default:
535
+ break
536
536
  }
537
537
 
538
+ // if (releaseGood.type == 'b2c') {
539
+ // const sellercraft: Sellercraft = await tx
540
+ // .getRepository(Sellercraft)
541
+ // .findOne({ domain: bizplace.domain, status: SellercraftStatus.ACTIVE })
542
+
543
+ // let customerAvailableSftp: Sftp = await tx.getRepository(Sftp).findOne({
544
+ // where: { domain: bizplace.domain }
545
+ // })
546
+
547
+ // if (sellercraft) {
548
+ // const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
549
+ // await sellercraftCtrl.checkExistingReleaseGood(sellercraft, releaseGood)
550
+ // } else if (customerAvailableSftp) {
551
+ // } else {
552
+ // const refNo: string = releaseGood.refNo
553
+ // const foundReleaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).findOne({
554
+ // where: {
555
+ // domain: warehouseDomain,
556
+ // refNo,
557
+ // status: Not(In([ORDER_STATUS.CANCELLED, ORDER_STATUS.PENDING_CANCEL]))
558
+ // },
559
+ // relations: ['bizplace', 'bizplace.domain', 'bizplace.company', 'bizplace.company.domain']
560
+ // })
561
+
562
+ // if (foundReleaseGood) {
563
+ // const customerCompanyDomain: Domain = foundReleaseGood.bizplace.company.domain
564
+ // const marketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
565
+ // where: { orderNo: refNo, domain: customerCompanyDomain }
566
+ // })
567
+
568
+ // // Need to restructure the validation
569
+ // if (marketplaceOrder?.isSplitted) {
570
+ // const refNo2: string = releaseGood.refNo2
571
+ // const foundSplittedReleaseGood = await tx.getRepository(ReleaseGood).findOne({
572
+ // where: {
573
+ // domain: warehouseDomain,
574
+ // refNo2,
575
+ // status: Not(In([ORDER_STATUS.CANCELLED, ORDER_STATUS.PENDING_CANCEL]))
576
+ // },
577
+ // relations: ['bizplace', 'bizplace.domain', 'bizplace.company', 'bizplace.company.domain']
578
+ // })
579
+
580
+ // if (foundSplittedReleaseGood) throw new Error('Existing release order found')
581
+ // } else {
582
+ // throw new Error('Existing release order found')
583
+ // }
584
+ // }
585
+ // }
586
+ // }
587
+
538
588
  let newReleaseGood: ReleaseGood = new ReleaseGood()
539
589
 
540
590
  /** Generate Shipping Order */
@@ -672,7 +722,7 @@ export async function generateReleaseGoodFunction(
672
722
 
673
723
  const pbSettings: ProductBundleSetting[] = await tx.getRepository(ProductBundleSetting).find({
674
724
  where: { productBundle: oi.product.id },
675
- relations: ['product', 'productBundle']
725
+ relations: ['product', 'productBundle', 'productDetail']
676
726
  })
677
727
 
678
728
  pbSettings.forEach(pbs => {
@@ -686,6 +736,9 @@ export async function generateReleaseGoodFunction(
686
736
  id: pbs.product.id,
687
737
  name: pbs.product.name,
688
738
  groupType: PRODUCT_GROUP_TYPE.SINGLE
739
+ },
740
+ productDetail: {
741
+ id: pbs.productDetail.id
689
742
  }
690
743
  }
691
744
  splitBundleOIs.push(splitOI)
@@ -700,6 +753,10 @@ export async function generateReleaseGoodFunction(
700
753
  newReleaseGood = await tx.getRepository(ReleaseGood).save(newReleaseGood)
701
754
 
702
755
  for (let oi of orderInventories) {
756
+ let productDetail: any = await tx
757
+ .getRepository(ProductDetail)
758
+ .findOne(oi.productDetail.id, { relations: ['product'] })
759
+
703
760
  let newOrderInv: OrderInventory = Object.assign({}, oi)
704
761
  newOrderInv = {
705
762
  ...newOrderInv,
@@ -708,7 +765,8 @@ export async function generateReleaseGoodFunction(
708
765
  status: ORDER_INVENTORY_STATUS.PENDING,
709
766
  name: OrderNoGenerator.orderInventory(),
710
767
  releaseGood: newReleaseGood,
711
- product: await tx.getRepository(Product).findOne(oi.product.id),
768
+ product: productDetail.product,
769
+ productDetail,
712
770
  creator: user,
713
771
  updater: user
714
772
  }
@@ -746,9 +804,9 @@ export async function generateReleaseGoodFunction(
746
804
  }
747
805
 
748
806
  let assignedOrderInventories: OrderInventory[] = await InventoryUtil.autoAssignInventoryForRelease(
749
- newOrderInv.product,
750
807
  oi,
751
- oi.packingType,
808
+ productDetail.product,
809
+ productDetail,
752
810
  locationSortingRules,
753
811
  bizplace,
754
812
  warehouseDomain,
@@ -887,16 +945,28 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
887
945
  let foundOVs: OrderVas[] = foundReleaseGood.orderVass
888
946
  let customerBizplace: Bizplace = foundReleaseGood.bizplace
889
947
  const companyDomain: Domain = customerBizplace?.company.domain
890
- const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({
891
- where: { domain: foundReleaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE },
892
- relations: ['domain']
893
- })
894
948
 
895
- if (foundReleaseGood.type == 'b2c') {
896
- if (sellercraft) {
949
+ const orderSource: string = foundReleaseGood.source
950
+ switch (orderSource) {
951
+ case ApplicationType.SELLERCRAFT:
952
+ const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({
953
+ where: { domain: foundReleaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE },
954
+ relations: ['domain']
955
+ })
956
+
897
957
  const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
898
- foundReleaseGood = await sellercraftCtrl.packOrder(sellercraft, { ...foundReleaseGood, orderProducts: foundOPs })
899
- } else {
958
+ if (foundReleaseGood.type == 'b2c') {
959
+ foundReleaseGood = await sellercraftCtrl.packOrder(sellercraft, {
960
+ ...foundReleaseGood,
961
+ orderProducts: foundOPs
962
+ })
963
+ } else if (foundReleaseGood.type == 'b2b') {
964
+ await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'CONFIRM_ORDER')
965
+ }
966
+
967
+ break
968
+
969
+ case ApplicationType.MMS:
900
970
  // find for any existing marketplace store connections
901
971
  let marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
902
972
  where: { domain: companyDomain, status: 'ACTIVE' },
@@ -959,16 +1029,94 @@ export async function confirmReleaseGood(name: string, context: any, tx?: Entity
959
1029
  const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
960
1030
  await ecommerceCtrl.updateProductVariationStock(marketplaceStores, productIds, companyDomain)
961
1031
  }
962
- }
963
- }
1032
+ break
964
1033
 
965
- if (foundReleaseGood.type == 'b2b') {
966
- if (sellercraft) {
967
- const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
968
- await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'CONFIRM_ORDER')
969
- }
1034
+ default:
1035
+ break
970
1036
  }
971
1037
 
1038
+ // const sellercraft: Sellercraft = await tx.getRepository(Sellercraft).findOne({
1039
+ // where: { domain: foundReleaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE },
1040
+ // relations: ['domain']
1041
+ // })
1042
+
1043
+ // if (foundReleaseGood.type == 'b2c') {
1044
+ // if (sellercraft) {
1045
+ // const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
1046
+ // foundReleaseGood = await sellercraftCtrl.packOrder(sellercraft, { ...foundReleaseGood, orderProducts: foundOPs })
1047
+ // } else {
1048
+ // // find for any existing marketplace store connections
1049
+ // let marketplaceStores: MarketplaceStore[] = await tx.getRepository(MarketplaceStore).find({
1050
+ // where: { domain: companyDomain, status: 'ACTIVE' },
1051
+ // relations: ['marketplaceDistributors']
1052
+ // })
1053
+
1054
+ // const foundMarketplaceOrder: MarketplaceOrder = await tx.getRepository(MarketplaceOrder).findOne({
1055
+ // where: { domain: companyDomain, orderNo: foundReleaseGood.refNo },
1056
+ // relations: ['marketplaceStore']
1057
+ // })
1058
+
1059
+ // let matchedMarketplaceStore: MarketplaceStore
1060
+ // if (foundMarketplaceOrder) {
1061
+ // matchedMarketplaceStore = marketplaceStores.filter(
1062
+ // marketplaceStore => marketplaceStore.id == foundMarketplaceOrder.marketplaceStore.id
1063
+ // )[0]
1064
+ // }
1065
+
1066
+ // let combinedOrderInventories: any[] = foundOIs.map(oi => {
1067
+ // return {
1068
+ // sku: oi.product.sku,
1069
+ // releaseQty: oi.releaseQty
1070
+ // }
1071
+ // })
1072
+
1073
+ // if (foundBundleInfo?.length) {
1074
+ // foundBundleInfo.map(bundle => {
1075
+ // combinedOrderInventories.push({
1076
+ // sku: bundle.sku,
1077
+ // releaseQty: bundle.releaseQty
1078
+ // })
1079
+ // })
1080
+ // }
1081
+
1082
+ // for (let oi of combinedOrderInventories) {
1083
+ // let foundMarketplaceProductVariations: MarketplaceProductVariation[] = await tx
1084
+ // .getRepository(MarketplaceProductVariation)
1085
+ // .find({
1086
+ // where: { domain: companyDomain, sku: oi.sku },
1087
+ // relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
1088
+ // })
1089
+
1090
+ // if (foundMarketplaceProductVariations) {
1091
+ // await Promise.all(
1092
+ // foundMarketplaceProductVariations.map(async variation => {
1093
+ // if (variation.marketplaceProduct.marketplaceStore.reserveEnabled) {
1094
+ // variation.reserveQty -= oi.releaseQty
1095
+ // }
1096
+
1097
+ // await tx.getRepository(MarketplaceProductVariation).save(variation)
1098
+ // })
1099
+ // )
1100
+ // }
1101
+ // }
1102
+
1103
+ // if (marketplaceStores?.length && marketplaceStores.some(store => store.isAutoUpdateStockQty)) {
1104
+ // marketplaceStores = marketplaceStores.filter(marketplaceStore => marketplaceStore.isAutoUpdateStockQty)
1105
+ // let productIds: string[] = foundOIs.map(oi => oi.product.id)
1106
+ // productIds = Array.from(new Set([...productIds]))
1107
+ // const ecommerceCtrl: EcommerceController = new EcommerceController(tx, domain, user)
1108
+ // await ecommerceCtrl.updateProductVariationStock(marketplaceStores, productIds, companyDomain)
1109
+ // }
1110
+ // }
1111
+ // }
1112
+
1113
+ // if (foundReleaseGood.type == 'b2b') {
1114
+ // if (sellercraft) {
1115
+ // const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
1116
+ // await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'CONFIRM_ORDER')
1117
+ // }
1118
+ // }
1119
+
972
1120
  // 1. RO Status change (PENDING => PENDING_RECEIVE)
973
1121
  const releaseGood: ReleaseGood = await tx.getRepository(ReleaseGood).save({
974
1122
  ...foundReleaseGood,
@@ -1183,15 +1331,32 @@ export async function rejectReleaseGood(
1183
1331
  }
1184
1332
 
1185
1333
  if (foundOPs && foundOPs.length) {
1186
- const sellercraft: Sellercraft = await tx
1187
- .getRepository(Sellercraft)
1188
- .findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
1334
+ const orderSource: string = releaseGood.source
1335
+ switch (orderSource) {
1336
+ case ApplicationType.SELLERCRAFT:
1337
+ const sellercraft: Sellercraft = await tx
1338
+ .getRepository(Sellercraft)
1339
+ .findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
1340
+
1341
+ if (sellercraft) {
1342
+ const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
1343
+ await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'REJECT_ORDER')
1344
+ }
1345
+ break
1189
1346
 
1190
- if (sellercraft) {
1191
- const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
1192
- await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'REJECT_ORDER')
1347
+ default:
1348
+ break
1193
1349
  }
1194
1350
 
1351
+ // const sellercraft: Sellercraft = await tx
1352
+ // .getRepository(Sellercraft)
1353
+ // .findOne({ domain: releaseGood.bizplace.domain, status: SellercraftStatus.ACTIVE })
1354
+
1355
+ // if (sellercraft) {
1356
+ // const sellercraftCtrl: SellercraftController = new SellercraftController(tx, domain, user)
1357
+ // await sellercraftCtrl.updateSellercraftStock(sellercraft, foundOPs, 'REJECT_ORDER')
1358
+ // }
1359
+
1195
1360
  await tx.getRepository(OrderProduct).save(
1196
1361
  await Promise.all(
1197
1362
  foundOPs.map(async (op: OrderProduct) => {
@@ -1288,6 +1453,7 @@ export async function bulkGenerateReleaseGood(
1288
1453
  phone1: releaseGood?.phone1 || null,
1289
1454
  phone2: releaseGood?.phone2 || null,
1290
1455
  email: releaseGood?.email || null,
1456
+ source: releaseGood?.source || null,
1291
1457
  airwayBill: releaseGood?.airwayBill,
1292
1458
  refNo: releaseGood.refNo,
1293
1459
  refNo2: releaseGood.refNo2,
@@ -1296,8 +1462,8 @@ export async function bulkGenerateReleaseGood(
1296
1462
  ownTransport: releaseGood?.ownTransport || false,
1297
1463
  orderMethod: ORDER_METHOD.SELECT_BY_PRODUCT,
1298
1464
  status: ORDER_STATUS.PENDING,
1299
- creator: user,
1300
- updater: user
1465
+ creator: releaseGood?.creator || user,
1466
+ updater: releaseGood?.updater || user
1301
1467
  }
1302
1468
 
1303
1469
  newReleaseGood = await tx.getRepository(ReleaseGood).save(newReleaseGood)
@@ -1339,12 +1505,17 @@ export async function bulkGenerateReleaseGood(
1339
1505
  }
1340
1506
  }
1341
1507
 
1342
- const product: Product = await tx.getRepository(Product).findOne(oi.productId)
1508
+ let productDetail = oi.orderProduct?.productDetail
1509
+ let product = oi.orderProduct?.product
1510
+ if (!productDetail) {
1511
+ productDetail = await tx.getRepository(ProductDetail).findOne(oi.productDetailId, { relations: ['product'] })
1512
+ product = productDetail.product
1513
+ }
1343
1514
 
1344
1515
  let assignedResult = await InventoryUtil.autoAssignInventoryForRelease(
1345
- product,
1346
1516
  oi,
1347
- oi.packingType,
1517
+ product,
1518
+ productDetail,
1348
1519
  locationSortingRules,
1349
1520
  bizplace,
1350
1521
  warehouseDomain,
@@ -1370,8 +1541,8 @@ export async function bulkGenerateReleaseGood(
1370
1541
  status: ORDER_INVENTORY_STATUS.PENDING,
1371
1542
  name: OrderNoGenerator.orderInventory(),
1372
1543
  releaseGood: newReleaseGood,
1373
- creator: user,
1374
- updater: user
1544
+ creator: newReleaseGood?.creator || user,
1545
+ updater: newReleaseGood?.updater || user
1375
1546
  }
1376
1547
 
1377
1548
  let newOrderProduct: Partial<OrderProduct>
@@ -1393,8 +1564,8 @@ export async function bulkGenerateReleaseGood(
1393
1564
  actualPalletQty: 0,
1394
1565
  status: ORDER_PRODUCT_STATUS.ASSIGNED,
1395
1566
  releaseGood: newReleaseGood,
1396
- creator: user,
1397
- updater: user
1567
+ creator: newReleaseGood?.creator || user,
1568
+ updater: newReleaseGood?.updater || user
1398
1569
  }
1399
1570
 
1400
1571
  newOrderProduct = await tx.getRepository(OrderProduct).save(newOrderProduct)
@@ -1403,7 +1574,7 @@ export async function bulkGenerateReleaseGood(
1403
1574
  ...oi.orderProduct,
1404
1575
  totalUomValue: `${oi.orderProduct.releaseUomValue} ${oi.orderProduct.uom}`,
1405
1576
  status: ORDER_PRODUCT_STATUS.ASSIGNED,
1406
- updater: user
1577
+ updater: newReleaseGood?.updater || user
1407
1578
  })
1408
1579
  }
1409
1580
 
@@ -196,6 +196,7 @@ export class ReleaseGoodQuery {
196
196
  .createQueryBuilder('oi')
197
197
  .leftJoinAndSelect('oi.inventory', 'inventory')
198
198
  .leftJoinAndSelect('oi.product', 'product')
199
+ .leftJoinAndSelect('oi.productDetail', 'productDetail')
199
200
  .leftJoinAndSelect('inventory.location', 'location')
200
201
  .where('oi.domain_id = :domainId', { domainId: domain.id })
201
202
  .andWhere('oi.release_good_id = :releaseGoodId', { releaseGoodId: releaseGood.id })
@@ -226,6 +227,7 @@ export class ReleaseGoodQuery {
226
227
  batchIdRef: inventory.batchIdRef,
227
228
  palletId: inventory.palletId,
228
229
  product: orderInv.product,
230
+ productDetail: orderInv.productDetail,
229
231
  productIdRef: orderInv.product.id,
230
232
  productName: `${orderInv.product.name} (${orderInv.product.description})`,
231
233
  packingType: orderInv.packingType,
@@ -375,10 +377,7 @@ export class ReleaseGoodQuery {
375
377
  params.filters.push({
376
378
  name: typeFilter == 'b2c' ? 'releaseDate' : 'createdAt',
377
379
  operator: 'gte',
378
- value:
379
- typeFilter == 'b2c'
380
- ? releaseDateFrom
381
- : fromDateVal.toISOString(),
380
+ value: typeFilter == 'b2c' ? releaseDateFrom : fromDateVal.toISOString(),
382
381
  relation: false
383
382
  })
384
383
  }
@@ -393,9 +392,7 @@ export class ReleaseGoodQuery {
393
392
  name: typeFilter == 'b2c' ? 'releaseDate' : 'createdAt',
394
393
  operator: typeFilter == 'b2c' ? 'lte' : 'lt',
395
394
  value:
396
- typeFilter == 'b2c'
397
- ? releaseDateTo
398
- : new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
395
+ typeFilter == 'b2c' ? releaseDateTo : new Date(toDateVal.setDate(toDateVal.getDate() + 1)).toISOString(),
399
396
  relation: false
400
397
  })
401
398
  }
@@ -1,6 +1,6 @@
1
1
  import { Field, Float, InputType, Int, ObjectType } from 'type-graphql'
2
2
 
3
- import { Product } from '@things-factory/product-base'
3
+ import { Product, ProductDetail } from '@things-factory/product-base'
4
4
  import { ObjectRef } from '@things-factory/shell'
5
5
  import { Location } from '@things-factory/warehouse-base'
6
6
 
@@ -77,6 +77,9 @@ export class InventoryInfos {
77
77
  @Field(type => Product, { nullable: true })
78
78
  product?: Product
79
79
 
80
+ @Field(type => ProductDetail, { nullable: true })
81
+ productDetail?: ProductDetail
82
+
80
83
  @Field({ nullable: true })
81
84
  packingType?: string
82
85
 
@@ -185,8 +188,6 @@ export class NewReleaseGood {
185
188
  @Field({ nullable: true })
186
189
  orderMethod: string
187
190
 
188
-
189
-
190
191
  @Field({ nullable: true })
191
192
  collectionOrderNo: string
192
193