@pmcretail/mapper-library 0.0.30 → 0.0.32

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.
@@ -706,6 +706,16 @@
706
706
  Trigger.prototype.quantity;
707
707
  /** @type {?|undefined} */
708
708
  Trigger.prototype.totalQuantity;
709
+ /** @type {?|undefined} */
710
+ Trigger.prototype.linePromotionAmount;
711
+ /** @type {?|undefined} */
712
+ Trigger.prototype.promotionAmount;
713
+ /** @type {?|undefined} */
714
+ Trigger.prototype.refundedReason;
715
+ /** @type {?|undefined} */
716
+ Trigger.prototype.refundedReasonDescription;
717
+ /** @type {?|undefined} */
718
+ Trigger.prototype.promotionId;
709
719
  }
710
720
  /**
711
721
  * Transaction Promotion
@@ -727,6 +737,14 @@
727
737
  TransactionPromotion.prototype.promotionType;
728
738
  /** @type {?} */
729
739
  TransactionPromotion.prototype.itemLineIds;
740
+ /** @type {?|undefined} */
741
+ TransactionPromotion.prototype.type;
742
+ /** @type {?|undefined} */
743
+ TransactionPromotion.prototype.subLevelType;
744
+ /** @type {?|undefined} */
745
+ TransactionPromotion.prototype.trigger;
746
+ /** @type {?|undefined} */
747
+ TransactionPromotion.prototype.couponCode;
730
748
  }
731
749
  /**
732
750
  * @record
@@ -889,6 +907,8 @@
889
907
  TransactionDocument.prototype.isChecked;
890
908
  /** @type {?|undefined} */
891
909
  TransactionDocument.prototype.externalTransactionDetails;
910
+ /** @type {?|undefined} */
911
+ TransactionDocument.prototype.refundRequest;
892
912
  }
893
913
  /**
894
914
  * @record
@@ -1462,6 +1482,8 @@
1462
1482
  ProductItem.prototype.tax_class_id;
1463
1483
  /** @type {?|undefined} */
1464
1484
  ProductItem.prototype.tax_rate;
1485
+ /** @type {?|undefined} */
1486
+ ProductItem.prototype.c_osuObjectData;
1465
1487
  }
1466
1488
  /**
1467
1489
  * @record
@@ -1670,6 +1692,15 @@
1670
1692
  /** @enum {string} */
1671
1693
  var PROVIDERS = {
1672
1694
  SALESFORCE: "Salesforce",
1695
+ };
1696
+ /** @enum {string} */
1697
+ var PROMOTION_LEVEL = {
1698
+ LINE: "LINE",
1699
+ TRANSACTION: "TRANSACTION",
1700
+ };
1701
+ /** @enum {string} */
1702
+ var PROMOTION_TYPE = {
1703
+ COUPON: "COUPON",
1673
1704
  };
1674
1705
 
1675
1706
  /**
@@ -2774,7 +2805,8 @@
2774
2805
  * @return {?}
2775
2806
  */
2776
2807
  function (no) {
2777
- return Number(this.getFlooredFixed(no, 2));
2808
+ // SEAM-11411 - Had to change 2nd param to 3 to fix rounding issue (FIXME - Needs a new story for refactoring)
2809
+ return Number(this.getFlooredFixed(no, 3));
2778
2810
  };
2779
2811
  /**
2780
2812
  * @param {?} v
@@ -7407,7 +7439,8 @@
7407
7439
  * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
7408
7440
  */
7409
7441
  var WebReturnSalesforceMapperBuilderClass = /** @class */ (function () {
7410
- function WebReturnSalesforceMapperBuilderClass(orderDetails) {
7442
+ function WebReturnSalesforceMapperBuilderClass(orderDetails, currencyPipe) {
7443
+ this.currencyPipe = currencyPipe;
7411
7444
  this.webReturnObject = {
7412
7445
  id: '',
7413
7446
  orgCode: "",
@@ -7438,6 +7471,7 @@
7438
7471
  if (orderDetails) {
7439
7472
  this.orderDetails = orderDetails;
7440
7473
  }
7474
+ this.numberUtilService = new NumberUtilService(currencyPipe);
7441
7475
  }
7442
7476
  /**
7443
7477
  * @template THIS
@@ -7576,7 +7610,7 @@
7576
7610
  quantity: product.quantity ? product.quantity : 0,
7577
7611
  refundedQuantity: 0,
7578
7612
  price: product.base_price ? product.base_price : 0,
7579
- itemLineId: index + 1,
7613
+ itemLineId: (index + 1).toString(),
7580
7614
  deliveryMethod: (/** @type {?} */ (_this)).getDeliveryMethod().toString(),
7581
7615
  totalLinePrice: product.price ? product.price : 0
7582
7616
  };
@@ -7617,23 +7651,25 @@
7617
7651
  * @return {?}
7618
7652
  */
7619
7653
  function (promotion) {
7620
- /** @type {?} */
7621
- var linePromotionObj = (/** @type {?} */ ({}));
7622
- /** @type {?} */
7623
- var trigger = (/** @type {?} */ ({}));
7624
- trigger.itemLineId = product.item_id;
7625
- trigger.quantity = product.quantity ? product.quantity : 0;
7626
- linePromotionObj.trigger = (/** @type {?} */ ([]));
7627
- linePromotionObj.trigger.push(trigger);
7628
- linePromotionObj.itemLineId = index + 1;
7629
- linePromotionObj.promotionId = promotion.promotion_id ? promotion.promotion_id : '';
7630
- linePromotionObj.displayText = promotion.item_text ? promotion.item_text : '';
7631
- linePromotionObj.promotionType = promotion.applied_discount && promotion.applied_discount.type ? promotion.applied_discount.type : '';
7632
- linePromotionObj.promotionAmount = promotion.price ? Math.abs(promotion.price) : 0;
7633
- linePromotionObj.name = promotion.item_text ? promotion.item_text : '';
7634
- linePromotionObj.promotionInfo = promotion.item_text ? promotion.item_text : '';
7635
- linePromotionObj.promotionLinePrice = product.price_after_item_discount ? product.price_after_item_discount : 0;
7636
- linePromotionArray.push(linePromotionObj);
7654
+ if (!promotion.coupon_code) {
7655
+ /** @type {?} */
7656
+ var linePromotionObj = (/** @type {?} */ ({}));
7657
+ /** @type {?} */
7658
+ var trigger = (/** @type {?} */ ({}));
7659
+ trigger.itemLineId = product.item_id;
7660
+ trigger.quantity = product.quantity ? product.quantity : 0;
7661
+ linePromotionObj.trigger = (/** @type {?} */ ([]));
7662
+ linePromotionObj.trigger.push(trigger);
7663
+ linePromotionObj.itemLineId = index + 1;
7664
+ linePromotionObj.promotionId = promotion.promotion_id ? promotion.promotion_id : '';
7665
+ linePromotionObj.displayText = promotion.item_text ? promotion.item_text : '';
7666
+ linePromotionObj.promotionType = promotion.applied_discount && promotion.applied_discount.type ? promotion.applied_discount.type : '';
7667
+ linePromotionObj.promotionAmount = promotion.price ? Math.abs(promotion.price) : 0;
7668
+ linePromotionObj.name = promotion.coupon_code ? promotion.coupon_code : (promotion.item_text ? promotion.item_text : '');
7669
+ linePromotionObj.promotionInfo = promotion.item_text ? promotion.item_text : '';
7670
+ linePromotionObj.promotionLinePrice = product.price - Math.abs(promotion.price);
7671
+ linePromotionArray.push(linePromotionObj);
7672
+ }
7637
7673
  }));
7638
7674
  }
7639
7675
  }));
@@ -7653,38 +7689,265 @@
7653
7689
  * @return {THIS}
7654
7690
  */
7655
7691
  function () {
7656
- var _this = this;
7657
7692
  console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: transactionPromotion mapping started...");
7658
7693
  /** @type {?} */
7659
- var transactionPromotionArray = (/** @type {?} */ ([]));
7660
- (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = (/** @type {?} */ ([]));
7661
- if ((/** @type {?} */ (this)).orderDetails.order_price_adjustments && (/** @type {?} */ (this)).orderDetails.order_price_adjustments.length > 0) {
7662
- (/** @type {?} */ (this)).orderDetails.order_price_adjustments.forEach((/**
7663
- * @param {?} transactionPromotion
7664
- * @return {?}
7665
- */
7666
- function (transactionPromotion) {
7667
- /** @type {?} */
7668
- var transactionPromotionObj = (/** @type {?} */ ({}));
7669
- transactionPromotionObj.displayText = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7670
- transactionPromotionObj.name = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7671
- transactionPromotionObj.promotionAmount = transactionPromotion.price ? Math.abs(transactionPromotion.price) : 0;
7672
- transactionPromotionObj.promotionId = transactionPromotion.promotion_id ? transactionPromotion.promotion_id : '';
7673
- transactionPromotionObj.promotionInfo = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7674
- transactionPromotionObj.promotionType = transactionPromotion.applied_discount && transactionPromotion.applied_discount.type ? transactionPromotion.applied_discount.type : '';
7675
- transactionPromotionObj.itemLineIds = (/** @type {?} */ (_this)).orderDetails.product_items.map((/**
7694
+ var transactionPromotionArray = (/** @type {?} */ (this)).getTransactionPromotions((/** @type {?} */ (this)).orderDetails);
7695
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = transactionPromotionArray;
7696
+ console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: transactionPromotion mapping ended...");
7697
+ return (/** @type {?} */ (this));
7698
+ };
7699
+ /**
7700
+ * @param {?} basket
7701
+ * @return {?}
7702
+ */
7703
+ WebReturnSalesforceMapperBuilderClass.prototype.getTransactionPromotions = /**
7704
+ * @param {?} basket
7705
+ * @return {?}
7706
+ */
7707
+ function (basket) {
7708
+ var _this = this;
7709
+ try {
7710
+ /** @type {?} */
7711
+ var transactionPromotionArray_1 = (/** @type {?} */ ([]));
7712
+ if (basket.order_price_adjustments && basket.order_price_adjustments.length > 0) {
7713
+ basket.order_price_adjustments.forEach((/**
7714
+ * @param {?} transactionPromotion
7715
+ * @return {?}
7716
+ */
7717
+ function (transactionPromotion) {
7718
+ /** @type {?} */
7719
+ var transactionPromotionObj = (/** @type {?} */ ({}));
7720
+ transactionPromotionObj.displayText = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7721
+ transactionPromotionObj.name = transactionPromotion.coupon_code ? transactionPromotion.coupon_code : (transactionPromotion.item_text ? transactionPromotion.item_text : '');
7722
+ transactionPromotionObj.promotionAmount = transactionPromotion.price ? -Math.abs(transactionPromotion.price) : 0;
7723
+ transactionPromotionObj.promotionId = transactionPromotion.promotion_id ? transactionPromotion.promotion_id : '';
7724
+ transactionPromotionObj.promotionInfo = transactionPromotion.item_text ? transactionPromotion.item_text : '';
7725
+ transactionPromotionObj.promotionType = transactionPromotion.applied_discount && transactionPromotion.applied_discount.type ? transactionPromotion.applied_discount.type : '';
7726
+ transactionPromotionObj.itemLineIds = _this.orderDetails.product_items.map((/**
7727
+ * @param {?} product
7728
+ * @param {?} index
7729
+ * @return {?}
7730
+ */
7731
+ function (product, index) { return index + 1; }));
7732
+ if (transactionPromotion.coupon_code) {
7733
+ transactionPromotionObj.type = PROMOTION_TYPE.COUPON;
7734
+ transactionPromotionObj.couponCode = transactionPromotion.coupon_code;
7735
+ transactionPromotionObj.subLevelType = PROMOTION_LEVEL.TRANSACTION;
7736
+ }
7737
+ transactionPromotionArray_1.push(transactionPromotionObj);
7738
+ }));
7739
+ }
7740
+ console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: getTransactionPromotions : ", JSON.stringify(transactionPromotionArray_1));
7741
+ return transactionPromotionArray_1;
7742
+ }
7743
+ catch (error) {
7744
+ console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: failed:", error);
7745
+ console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: failed:", JSON.stringify(error));
7746
+ throw new Error(error);
7747
+ }
7748
+ };
7749
+ /**
7750
+ * @template THIS
7751
+ * @this {THIS}
7752
+ * @return {THIS}
7753
+ */
7754
+ WebReturnSalesforceMapperBuilderClass.prototype.updateLinePromotionWithCoupon = /**
7755
+ * @template THIS
7756
+ * @this {THIS}
7757
+ * @return {THIS}
7758
+ */
7759
+ function () {
7760
+ try {
7761
+ /** @type {?} */
7762
+ var transactionPromotion = (/** @type {?} */ ({}));
7763
+ /** @type {?} */
7764
+ var triggerPromotion_1 = (/** @type {?} */ ([]));
7765
+ if ((/** @type {?} */ (this)).orderDetails.product_items && (/** @type {?} */ (this)).orderDetails.product_items.length > 0) {
7766
+ (/** @type {?} */ (this)).orderDetails.product_items.forEach((/**
7676
7767
  * @param {?} product
7677
7768
  * @param {?} index
7678
7769
  * @return {?}
7679
7770
  */
7680
- function (product, index) { return index + 1; }));
7681
- transactionPromotionArray.push(transactionPromotionObj);
7771
+ function (product, index) {
7772
+ product.item_id = (index + 1).toString();
7773
+ if (product.price_adjustments && product.price_adjustments.length > 0) {
7774
+ product.price_adjustments.forEach((/**
7775
+ * @param {?} promotion
7776
+ * @return {?}
7777
+ */
7778
+ function (promotion) {
7779
+ if (promotion.coupon_code) {
7780
+ /** @type {?} */
7781
+ var trigger = (/** @type {?} */ ({}));
7782
+ trigger.itemLineId = product.item_id;
7783
+ trigger.quantity = product.quantity ? product.quantity : 0;
7784
+ trigger.totalQuantity = product.quantity ? product.quantity : 0;
7785
+ trigger.promotionAmount = promotion.price ? Math.abs(promotion.price) : 0;
7786
+ trigger.refundedReason = promotion.coupon_code ? promotion.coupon_code : '';
7787
+ trigger.refundedReasonDescription = promotion.item_text ? promotion.item_text : '';
7788
+ trigger.promotionId = promotion.promotion_id;
7789
+ triggerPromotion_1.push(trigger);
7790
+ }
7791
+ }));
7792
+ }
7793
+ }));
7794
+ }
7795
+ if (triggerPromotion_1.length > 0) {
7796
+ transactionPromotion.displayText = triggerPromotion_1[0].refundedReasonDescription;
7797
+ transactionPromotion.name = triggerPromotion_1[0].refundedReason;
7798
+ transactionPromotion.promotionAmount = -(triggerPromotion_1.reduce((/**
7799
+ * @param {?} n
7800
+ * @param {?} __1
7801
+ * @return {?}
7802
+ */
7803
+ function (n, _a) {
7804
+ var promotionAmount = _a.promotionAmount;
7805
+ return n + promotionAmount;
7806
+ }), 0));
7807
+ transactionPromotion.promotionId = triggerPromotion_1[0].promotionId;
7808
+ transactionPromotion.promotionInfo = triggerPromotion_1[0].refundedReasonDescription;
7809
+ transactionPromotion.couponCode = triggerPromotion_1[0].refundedReason;
7810
+ transactionPromotion.itemLineIds = [];
7811
+ transactionPromotion.type = PROMOTION_TYPE.COUPON;
7812
+ transactionPromotion.subLevelType = PROMOTION_LEVEL.LINE;
7813
+ transactionPromotion.trigger = triggerPromotion_1;
7814
+ }
7815
+ console.log("linePromotion mapping ended...");
7816
+ console.log("e-basket: updateLinePromotionWithCoupon", JSON.stringify(transactionPromotion));
7817
+ if (!(/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion) {
7818
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = [];
7819
+ }
7820
+ if (transactionPromotion && transactionPromotion.promotionId) {
7821
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion.push(transactionPromotion);
7822
+ }
7823
+ return (/** @type {?} */ (this));
7824
+ }
7825
+ catch (error) {
7826
+ console.log("Ebasket: Salesforce: linePromotion mapping=> failed:", error);
7827
+ console.log("Ebasket: Salesforce: linePromotion mapping=> failed:", JSON.stringify(error));
7828
+ throw new Error(error);
7829
+ }
7830
+ };
7831
+ /**
7832
+ * @template THIS
7833
+ * @this {THIS}
7834
+ * @return {THIS}
7835
+ */
7836
+ WebReturnSalesforceMapperBuilderClass.prototype.updateTransactionPromotionPrtionCalc = /**
7837
+ * @template THIS
7838
+ * @this {THIS}
7839
+ * @return {THIS}
7840
+ */
7841
+ function () {
7842
+ var _this = this;
7843
+ /** @type {?} */
7844
+ var doc;
7845
+ if ((/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion) {
7846
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion.forEach((/**
7847
+ * @param {?} tr
7848
+ * @return {?}
7849
+ */
7850
+ function (tr) {
7851
+ doc =
7852
+ (/** @type {?} */ (_this)).transactionPromotionProductPortionCalc((/** @type {?} */ (_this)).webReturnObject, tr);
7682
7853
  }));
7854
+ (/** @type {?} */ (this)).webReturnObject = doc;
7683
7855
  }
7684
- (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = transactionPromotionArray;
7685
- console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: transactionPromotion mapping ended...");
7686
7856
  return (/** @type {?} */ (this));
7687
7857
  };
7858
+ /**
7859
+ * @param {?} txDoc
7860
+ * @param {?} promotion
7861
+ * @return {?}
7862
+ */
7863
+ WebReturnSalesforceMapperBuilderClass.prototype.transactionPromotionProductPortionCalc = /**
7864
+ * @param {?} txDoc
7865
+ * @param {?} promotion
7866
+ * @return {?}
7867
+ */
7868
+ function (txDoc, promotion) {
7869
+ var _this = this;
7870
+ /** @type {?} */
7871
+ var total = 0;
7872
+ /** @type {?} */
7873
+ var percentage = 0;
7874
+ {
7875
+ console.log("ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: " + JSON.stringify(promotion));
7876
+ if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
7877
+ txDoc.basket.products.forEach((/**
7878
+ * @param {?} product
7879
+ * @return {?}
7880
+ */
7881
+ function (product) {
7882
+ product = _this.validateProductItemDiscount(product);
7883
+ if (promotion.trigger && promotion.trigger.length > 0) {
7884
+ promotion.trigger.forEach((/**
7885
+ * @param {?} t
7886
+ * @return {?}
7887
+ */
7888
+ function (t) {
7889
+ if (t.itemLineId === product.itemLineId.toString()) {
7890
+ product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
7891
+ }
7892
+ }));
7893
+ }
7894
+ }));
7895
+ }
7896
+ else {
7897
+ txDoc.basket.products.forEach((/**
7898
+ * @param {?} p
7899
+ * @return {?}
7900
+ */
7901
+ function (p) {
7902
+ if (promotion.itemLineIds && promotion.itemLineIds.includes(p.itemLineId) && !p.giftCard) {
7903
+ p = _this.validateProductItemDiscount(p);
7904
+ /** @type {?} */
7905
+ var productContributionInTotal = _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnDiscountsPortion) +
7906
+ _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnPromotionsPortion) -
7907
+ _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.refundPortion);
7908
+ total += (p.total - _this.numberUtilService.trimTo2Decimal2(productContributionInTotal));
7909
+ }
7910
+ }));
7911
+ console.log("ebasket: trnsactionPromotion: " + JSON.stringify(promotion) + ", selected products total: " + total);
7912
+ txDoc.basket.products.forEach((/**
7913
+ * @param {?} product
7914
+ * @return {?}
7915
+ */
7916
+ function (product) {
7917
+ product = _this.validateProductItemDiscount(product);
7918
+ /** @type {?} */
7919
+ var productContributionInTotal = _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnDiscountsPortion) +
7920
+ _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion) -
7921
+ _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.refundPortion);
7922
+ if (promotion.itemLineIds.includes(product.itemLineId)) {
7923
+ percentage = ((product.total - _this.numberUtilService.trimTo2Decimal2(productContributionInTotal)) / total) * 100;
7924
+ product.itemDiscounts.trnPromotionsPortion +=
7925
+ (promotion.promotionAmount * percentage) / 100;
7926
+ product.itemDiscounts.trnPromotionsPortion = _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion);
7927
+ }
7928
+ }));
7929
+ }
7930
+ }
7931
+ return txDoc;
7932
+ };
7933
+ /**
7934
+ * @param {?} product
7935
+ * @return {?}
7936
+ */
7937
+ WebReturnSalesforceMapperBuilderClass.prototype.validateProductItemDiscount = /**
7938
+ * @param {?} product
7939
+ * @return {?}
7940
+ */
7941
+ function (product) {
7942
+ if (!product.itemDiscounts) {
7943
+ product.itemDiscounts = {
7944
+ trnDiscountsPortion: 0,
7945
+ trnPromotionsPortion: 0,
7946
+ refundPortion: 0,
7947
+ };
7948
+ }
7949
+ return product;
7950
+ };
7688
7951
  /**
7689
7952
  * @template THIS
7690
7953
  * @this {THIS}
@@ -8019,6 +8282,13 @@
8019
8282
  * @private
8020
8283
  */
8021
8284
  WebReturnSalesforceMapperBuilderClass.prototype.webReturnObject;
8285
+ /** @type {?} */
8286
+ WebReturnSalesforceMapperBuilderClass.prototype.numberUtilService;
8287
+ /**
8288
+ * @type {?}
8289
+ * @private
8290
+ */
8291
+ WebReturnSalesforceMapperBuilderClass.prototype.currencyPipe;
8022
8292
  }
8023
8293
 
8024
8294
  exports.MapperLibraryComponent = MapperLibraryComponent;