@things-factory/sales-base 4.1.22 → 4.1.23

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.
@@ -49,38 +49,44 @@ class EcommerceController extends order_controller_1.OrderController {
49
49
  where: { domain: companyDomain, sku: inventoryProduct.sku },
50
50
  relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
51
51
  });
52
- let marketplaceProductVariation = marketplaceProductVariations.filter(productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id)[0];
52
+ let storeProductVariations = marketplaceProductVariations.filter(productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id);
53
53
  let percentageValue = 100;
54
- if (marketplaceProductVariation) {
55
- if (marketplaceSetting) {
56
- percentageValue = parseInt(marketplaceSetting.value);
57
- }
58
- let productVariationLocationId = marketplaceProductVariation === null || marketplaceProductVariation === void 0 ? void 0 : marketplaceProductVariation.locationId;
59
- let adjustQty = Math.floor(inventoryProduct.qty * (percentageValue / 100));
60
- if (marketplaceStore.platform === 'shopify') {
61
- let locationIds = JSON.parse(productVariationLocationId);
62
- adjustQty = adjustQty - marketplaceProductVariation.qty;
63
- if ((_a = locationIds[0]) === null || _a === void 0 ? void 0 : _a.location_id)
64
- productVariationLocationId = locationIds[0].location_id;
65
- }
66
- let validMarketplaceDistributors = [];
67
- if (marketplaceStore.marketplaceDistributors) {
68
- validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(distributor => distributor.status === 'ACTIVE');
69
- }
70
- await integration_marketplace_1.StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
71
- {
72
- itemId: marketplaceProductVariation.marketplaceProduct.itemId,
73
- variationId: marketplaceProductVariation.variationId,
74
- variationSku: marketplaceProductVariation.variationSku,
75
- qty: adjustQty,
76
- locationId: productVariationLocationId,
77
- inventoryItemId: marketplaceProductVariation.inventoryItemId,
78
- distributors: validMarketplaceDistributors
54
+ if (storeProductVariations) {
55
+ for (let k = 0; k < storeProductVariations.length; k++) {
56
+ let storeProductVariation = storeProductVariations[k];
57
+ if (marketplaceSetting) {
58
+ percentageValue = parseInt(marketplaceSetting.value);
79
59
  }
80
- ]);
81
- marketplaceProductVariation.qty = Math.floor(inventoryProduct.qty * (percentageValue / 100));
82
- marketplaceProductVariation.updater = this.user;
83
- await this.trxMgr.getRepository(marketplace_base_1.MarketplaceProductVariation).save(marketplaceProductVariation);
60
+ let remainQty = Math.floor((inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100));
61
+ if (remainQty < 0)
62
+ remainQty = 0;
63
+ let productVariationLocationId = storeProductVariation === null || storeProductVariation === void 0 ? void 0 : storeProductVariation.locationId;
64
+ let adjustQty = remainQty;
65
+ if (marketplaceStore.platform === 'shopify') {
66
+ let locationIds = JSON.parse(productVariationLocationId);
67
+ adjustQty = adjustQty - storeProductVariation.qty;
68
+ if ((_a = locationIds[0]) === null || _a === void 0 ? void 0 : _a.location_id)
69
+ productVariationLocationId = locationIds[0].location_id;
70
+ }
71
+ let validMarketplaceDistributors = [];
72
+ if (marketplaceStore.marketplaceDistributors) {
73
+ validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(distributor => distributor.status === 'ACTIVE');
74
+ }
75
+ await integration_marketplace_1.StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
76
+ {
77
+ itemId: storeProductVariation.marketplaceProduct.itemId,
78
+ variationId: storeProductVariation.variationId,
79
+ variationSku: storeProductVariation.variationSku,
80
+ qty: adjustQty,
81
+ locationId: productVariationLocationId,
82
+ inventoryItemId: storeProductVariation.inventoryItemId,
83
+ distributors: validMarketplaceDistributors
84
+ }
85
+ ]);
86
+ storeProductVariation.qty = remainQty;
87
+ storeProductVariation.updater = this.user;
88
+ await this.trxMgr.getRepository(marketplace_base_1.MarketplaceProductVariation).save(storeProductVariation);
89
+ }
84
90
  }
85
91
  }
86
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ecommerce-controller.js","sourceRoot":"","sources":["../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AC,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,QAAQ,CAC/C,CAAA;qBACF;oBAED,MAAM,kCAAQ,CAAC,gCAAgC,CAAC,gBAAgB,EAAE;wBAChE;4BACE,MAAM,EAAE,2BAA2B,CAAC,kBAAkB,CAAC,MAAM;4BAC7D,WAAW,EAAE,2BAA2B,CAAC,WAAW;4BACpD,YAAY,EAAE,2BAA2B,CAAC,YAAY;4BACtD,GAAG,EAAE,SAAS;4BACd,UAAU,EAAE,0BAA0B;4BACtC,eAAe,EAAE,2BAA2B,CAAC,eAAe;4BAC5D,YAAY,EAAE,4BAA4B;yBAC3C;qBACF,CAAC,CAAA;oBAEF,2BAA2B,CAAC,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,GAAG,CAAC,eAAe,GAAG,GAAG,CAAC,CAAC,CAAA;oBAC5F,2BAA2B,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;oBAC/C,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,8CAA2B,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;iBAC/F;aACF;SACF;IACH,CAAC;CACF;AAzGD,kDAyGC"}
1
+ {"version":3,"file":"ecommerce-controller.js","sourceRoot":"","sources":["../../../server/controllers/ecommerce/ecommerce-controller.ts"],"names":[],"mappings":";;;AAAA,qFAAwG;AACxG,uEAA8E;AAC9E,+DAAsD;AAEtD,mEAA2F;AAE3F,0DAAqD;AAErD,MAAa,mBAAoB,SAAQ,kCAAe;IACtD,KAAK,CAAC,2BAA2B,CAC/B,iBAAqC,EACrC,UAAoB,EACpB,aAAqB;;QAErB,MAAM,iBAAiB,GAAU,MAAM,OAAO,CAAC,GAAG,CAChD,UAAU,CAAC,GAAG,CAAC,KAAK,EAAC,SAAS,EAAC,EAAE;YAC/B,MAAM,OAAO,GAAY,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,sBAAO,CAAC,CAAC,OAAO,CAA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AAC,kBAAkB,CAAC,MAAM;gCACvD,WAAW,EAAE,qBAAqB,CAAC,WAAW;gCAC9C,YAAY,EAAE,qBAAqB,CAAC,YAAY;gCAChD,GAAG,EAAE,SAAS;gCACd,UAAU,EAAE,0BAA0B;gCACtC,eAAe,EAAE,qBAAqB,CAAC,eAAe;gCACtD,YAAY,EAAE,4BAA4B;6BAC3C;yBACF,CAAC,CAAA;wBAEF,qBAAqB,CAAC,GAAG,GAAG,SAAS,CAAA;wBACrC,qBAAqB,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;wBACzC,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,8CAA2B,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;qBACzF;iBACF;aACF;SACF;IACH,CAAC;CACF;AAjHD,kDAiHC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/sales-base",
3
- "version": "4.1.22",
3
+ "version": "4.1.23",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -28,7 +28,7 @@
28
28
  "@things-factory/auth-base": "^4.1.22",
29
29
  "@things-factory/biz-base": "^4.1.22",
30
30
  "@things-factory/code-base": "^4.1.22",
31
- "@things-factory/integration-sftp": "^4.1.22",
31
+ "@things-factory/integration-sftp": "^4.1.23",
32
32
  "@things-factory/notification": "^4.1.22",
33
33
  "@things-factory/product-base": "^4.1.22",
34
34
  "@things-factory/setting-base": "^4.1.22",
@@ -36,5 +36,5 @@
36
36
  "@things-factory/transport-base": "^4.1.22",
37
37
  "@things-factory/warehouse-base": "^4.1.22"
38
38
  },
39
- "gitHead": "e40b890d9a573562872298a6b79b26f600f607bf"
39
+ "gitHead": "f13228576595836d2a4c2e5412adf412c0f82f33"
40
40
  }
@@ -66,47 +66,55 @@ export class EcommerceController extends OrderController {
66
66
  relations: ['marketplaceProduct', 'marketplaceProduct.marketplaceStore']
67
67
  })
68
68
 
69
- let marketplaceProductVariation: MarketplaceProductVariation = marketplaceProductVariations.filter(
69
+ let storeProductVariations: MarketplaceProductVariation[] = marketplaceProductVariations.filter(
70
70
  productVariation => productVariation.marketplaceProduct.marketplaceStore.id === marketplaceStore.id
71
- )[0]
71
+ )
72
72
 
73
73
  let percentageValue: number = 100
74
- if (marketplaceProductVariation) {
75
- if (marketplaceSetting) {
76
- percentageValue = parseInt(marketplaceSetting.value)
77
- }
74
+ if (storeProductVariations) {
75
+ for (let k = 0; k < storeProductVariations.length; k++) {
76
+ let storeProductVariation: MarketplaceProductVariation = storeProductVariations[k]
77
+ if (marketplaceSetting) {
78
+ percentageValue = parseInt(marketplaceSetting.value)
79
+ }
78
80
 
79
- let productVariationLocationId = marketplaceProductVariation?.locationId
80
- let adjustQty: number = Math.floor(inventoryProduct.qty * (percentageValue / 100))
81
+ let remainQty: number = Math.floor(
82
+ (inventoryProduct.qty - storeProductVariation.reserveQty) * (percentageValue / 100)
83
+ )
84
+ if (remainQty < 0) remainQty = 0
81
85
 
82
- if (marketplaceStore.platform === 'shopify') {
83
- let locationIds: any[] = JSON.parse(productVariationLocationId)
84
- adjustQty = adjustQty - marketplaceProductVariation.qty
85
- if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
86
- }
86
+ let productVariationLocationId = storeProductVariation?.locationId
87
+ let adjustQty: number = remainQty
87
88
 
88
- let validMarketplaceDistributors: any[] = []
89
- if (marketplaceStore.marketplaceDistributors) {
90
- validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
91
- distributor => distributor.status === 'ACTIVE'
92
- )
93
- }
89
+ if (marketplaceStore.platform === 'shopify') {
90
+ let locationIds: any[] = JSON.parse(productVariationLocationId)
91
+ adjustQty = adjustQty - storeProductVariation.qty
92
+ if (locationIds[0]?.location_id) productVariationLocationId = locationIds[0].location_id
93
+ }
94
94
 
95
- await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
96
- {
97
- itemId: marketplaceProductVariation.marketplaceProduct.itemId,
98
- variationId: marketplaceProductVariation.variationId,
99
- variationSku: marketplaceProductVariation.variationSku,
100
- qty: adjustQty,
101
- locationId: productVariationLocationId,
102
- inventoryItemId: marketplaceProductVariation.inventoryItemId,
103
- distributors: validMarketplaceDistributors
95
+ let validMarketplaceDistributors: any[] = []
96
+ if (marketplaceStore.marketplaceDistributors) {
97
+ validMarketplaceDistributors = marketplaceStore.marketplaceDistributors.filter(
98
+ distributor => distributor.status === 'ACTIVE'
99
+ )
104
100
  }
105
- ])
106
101
 
107
- marketplaceProductVariation.qty = Math.floor(inventoryProduct.qty * (percentageValue / 100))
108
- marketplaceProductVariation.updater = this.user
109
- await this.trxMgr.getRepository(MarketplaceProductVariation).save(marketplaceProductVariation)
102
+ await StoreAPI.updateStoreProductVariationStock(marketplaceStore, [
103
+ {
104
+ itemId: storeProductVariation.marketplaceProduct.itemId,
105
+ variationId: storeProductVariation.variationId,
106
+ variationSku: storeProductVariation.variationSku,
107
+ qty: adjustQty,
108
+ locationId: productVariationLocationId,
109
+ inventoryItemId: storeProductVariation.inventoryItemId,
110
+ distributors: validMarketplaceDistributors
111
+ }
112
+ ])
113
+
114
+ storeProductVariation.qty = remainQty
115
+ storeProductVariation.updater = this.user
116
+ await this.trxMgr.getRepository(MarketplaceProductVariation).save(storeProductVariation)
117
+ }
110
118
  }
111
119
  }
112
120
  }