@pmcretail/mapper-library 0.0.30 → 0.0.31

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,263 @@
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
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion.push(transactionPromotion);
7821
+ return (/** @type {?} */ (this));
7822
+ }
7823
+ catch (error) {
7824
+ console.log("Ebasket: Salesforce: linePromotion mapping=> failed:", error);
7825
+ console.log("Ebasket: Salesforce: linePromotion mapping=> failed:", JSON.stringify(error));
7826
+ throw new Error(error);
7827
+ }
7828
+ };
7829
+ /**
7830
+ * @template THIS
7831
+ * @this {THIS}
7832
+ * @return {THIS}
7833
+ */
7834
+ WebReturnSalesforceMapperBuilderClass.prototype.updateTransactionPromotionPrtionCalc = /**
7835
+ * @template THIS
7836
+ * @this {THIS}
7837
+ * @return {THIS}
7838
+ */
7839
+ function () {
7840
+ var _this = this;
7841
+ /** @type {?} */
7842
+ var doc;
7843
+ if ((/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion) {
7844
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion.forEach((/**
7845
+ * @param {?} tr
7846
+ * @return {?}
7847
+ */
7848
+ function (tr) {
7849
+ doc =
7850
+ (/** @type {?} */ (_this)).transactionPromotionProductPortionCalc((/** @type {?} */ (_this)).webReturnObject, tr);
7682
7851
  }));
7852
+ (/** @type {?} */ (this)).webReturnObject = doc;
7683
7853
  }
7684
- (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = transactionPromotionArray;
7685
- console.log("Mapper library: WebReturnSalesforceMapperBuilderClass: transactionPromotion mapping ended...");
7686
7854
  return (/** @type {?} */ (this));
7687
7855
  };
7856
+ /**
7857
+ * @param {?} txDoc
7858
+ * @param {?} promotion
7859
+ * @return {?}
7860
+ */
7861
+ WebReturnSalesforceMapperBuilderClass.prototype.transactionPromotionProductPortionCalc = /**
7862
+ * @param {?} txDoc
7863
+ * @param {?} promotion
7864
+ * @return {?}
7865
+ */
7866
+ function (txDoc, promotion) {
7867
+ var _this = this;
7868
+ /** @type {?} */
7869
+ var total = 0;
7870
+ /** @type {?} */
7871
+ var percentage = 0;
7872
+ {
7873
+ console.log("ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: " + JSON.stringify(promotion));
7874
+ if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
7875
+ txDoc.basket.products.forEach((/**
7876
+ * @param {?} product
7877
+ * @return {?}
7878
+ */
7879
+ function (product) {
7880
+ product = _this.validateProductItemDiscount(product);
7881
+ if (promotion.trigger && promotion.trigger.length > 0) {
7882
+ promotion.trigger.forEach((/**
7883
+ * @param {?} t
7884
+ * @return {?}
7885
+ */
7886
+ function (t) {
7887
+ if (t.itemLineId === product.itemLineId.toString()) {
7888
+ product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
7889
+ }
7890
+ }));
7891
+ }
7892
+ }));
7893
+ }
7894
+ else {
7895
+ txDoc.basket.products.forEach((/**
7896
+ * @param {?} p
7897
+ * @return {?}
7898
+ */
7899
+ function (p) {
7900
+ if (promotion.itemLineIds && promotion.itemLineIds.includes(p.itemLineId) && !p.giftCard) {
7901
+ p = _this.validateProductItemDiscount(p);
7902
+ /** @type {?} */
7903
+ var productContributionInTotal = _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnDiscountsPortion) +
7904
+ _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.trnPromotionsPortion) -
7905
+ _this.numberUtilService.trimTo2Decimal2(p.itemDiscounts.refundPortion);
7906
+ total += (p.total - _this.numberUtilService.trimTo2Decimal2(productContributionInTotal));
7907
+ }
7908
+ }));
7909
+ console.log("ebasket: trnsactionPromotion: " + JSON.stringify(promotion) + ", selected products total: " + total);
7910
+ txDoc.basket.products.forEach((/**
7911
+ * @param {?} product
7912
+ * @return {?}
7913
+ */
7914
+ function (product) {
7915
+ product = _this.validateProductItemDiscount(product);
7916
+ /** @type {?} */
7917
+ var productContributionInTotal = _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnDiscountsPortion) +
7918
+ _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion) -
7919
+ _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.refundPortion);
7920
+ if (promotion.itemLineIds.includes(product.itemLineId)) {
7921
+ percentage = ((product.total - _this.numberUtilService.trimTo2Decimal2(productContributionInTotal)) / total) * 100;
7922
+ product.itemDiscounts.trnPromotionsPortion +=
7923
+ (promotion.promotionAmount * percentage) / 100;
7924
+ product.itemDiscounts.trnPromotionsPortion = _this.numberUtilService.trimTo2Decimal2(product.itemDiscounts.trnPromotionsPortion);
7925
+ }
7926
+ }));
7927
+ }
7928
+ }
7929
+ return txDoc;
7930
+ };
7931
+ /**
7932
+ * @param {?} product
7933
+ * @return {?}
7934
+ */
7935
+ WebReturnSalesforceMapperBuilderClass.prototype.validateProductItemDiscount = /**
7936
+ * @param {?} product
7937
+ * @return {?}
7938
+ */
7939
+ function (product) {
7940
+ if (!product.itemDiscounts) {
7941
+ product.itemDiscounts = {
7942
+ trnDiscountsPortion: 0,
7943
+ trnPromotionsPortion: 0,
7944
+ refundPortion: 0,
7945
+ };
7946
+ }
7947
+ return product;
7948
+ };
7688
7949
  /**
7689
7950
  * @template THIS
7690
7951
  * @this {THIS}
@@ -8019,6 +8280,13 @@
8019
8280
  * @private
8020
8281
  */
8021
8282
  WebReturnSalesforceMapperBuilderClass.prototype.webReturnObject;
8283
+ /** @type {?} */
8284
+ WebReturnSalesforceMapperBuilderClass.prototype.numberUtilService;
8285
+ /**
8286
+ * @type {?}
8287
+ * @private
8288
+ */
8289
+ WebReturnSalesforceMapperBuilderClass.prototype.currencyPipe;
8022
8290
  }
8023
8291
 
8024
8292
  exports.MapperLibraryComponent = MapperLibraryComponent;