@pmcretail/mapper-library 0.0.38 → 0.0.39

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.
@@ -6873,7 +6873,8 @@ if (false) {
6873
6873
  * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
6874
6874
  */
6875
6875
  var WebReturnMapperBuilderClass = /** @class */ (function () {
6876
- function WebReturnMapperBuilderClass(document) {
6876
+ function WebReturnMapperBuilderClass(document, currencyPipe) {
6877
+ this.currencyPipe = currencyPipe;
6877
6878
  this.webReturnObject = {
6878
6879
  id: '',
6879
6880
  orgCode: "",
@@ -6902,6 +6903,7 @@ var WebReturnMapperBuilderClass = /** @class */ (function () {
6902
6903
  if (document) {
6903
6904
  this.document = document;
6904
6905
  }
6906
+ this.numberUtilService = new NumberUtilService(currencyPipe);
6905
6907
  }
6906
6908
  /**
6907
6909
  * @template THIS
@@ -6944,7 +6946,7 @@ var WebReturnMapperBuilderClass = /** @class */ (function () {
6944
6946
  (/** @type {?} */ (this)).webReturnObject['customer']['shippingAddress']['postCode'] = ((/** @type {?} */ (this)).document.shipping_address && (/** @type {?} */ (this)).document.shipping_address.postcode) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.shipping_address.postcode) : '';
6945
6947
  (/** @type {?} */ (this)).webReturnObject['customer']['shippingAddress']['country'] = ((/** @type {?} */ (this)).document.shipping_address && (/** @type {?} */ (this)).document.shipping_address.country) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.shipping_address.country) : '';
6946
6948
  // basketSummary
6947
- (/** @type {?} */ (this)).webReturnObject.basketSummary['discountTotal'] = Number((/** @type {?} */ (this)).document.discount_amount ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_amount) : 0);
6949
+ (/** @type {?} */ (this)).webReturnObject.basketSummary['discountTotal'] = Math.abs(Number((/** @type {?} */ (this)).document.discount_amount ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_amount) : 0));
6948
6950
  (/** @type {?} */ (this)).webReturnObject.basketSummary['VATTotal'] = Number((/** @type {?} */ (this)).document.base_total_paid ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.base_total_paid) : 0);
6949
6951
  (/** @type {?} */ (this)).webReturnObject.basketSummary['saleTotal'] = Number((/** @type {?} */ (this)).document.base_total_invoiced ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.base_total_invoiced) : 0);
6950
6952
  (/** @type {?} */ (this)).webReturnObject.basketSummary['basketTotal'] = Number((/** @type {?} */ (this)).document.base_total_paid ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.base_total_paid) : 0);
@@ -6958,23 +6960,25 @@ var WebReturnMapperBuilderClass = /** @class */ (function () {
6958
6960
  // }
6959
6961
  // this.webReturnObject.basket['lineDiscount'].push(lineDiscount);
6960
6962
  // basket transaction discount
6961
- (/** @type {?} */ (this)).webReturnObject.basket['transactionDiscount'] = [];
6962
- /** @type {?} */
6963
- var transactionDiscount = {
6964
- discountAmount: ((/** @type {?} */ (this)).document && (/** @type {?} */ (this)).document.discount_amount) ? Number((/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_amount)) : 0
6965
- };
6966
- (/** @type {?} */ (this)).webReturnObject.basket['transactionDiscount'].push(transactionDiscount);
6967
6963
  // basket products
6968
6964
  (/** @type {?} */ (this)).webReturnObject.basket['products'] = [];
6965
+ (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'] = [];
6966
+ (/** @type {?} */ (this)).webReturnObject.basket['transactionDiscount'] = [];
6967
+ (/** @type {?} */ (this)).webReturnObject.basket['transactionPromotion'] = [];
6968
+ // let transactionDiscount = {
6969
+ // discountAmount: (this.document && this.document.discount_amount) ? Number(this.getText(this.document.discount_amount)) : 0
6970
+ // }
6971
+ // this.webReturnObject.basket['transactionDiscount'].push(transactionDiscount);
6969
6972
  /** @type {?} */
6970
6973
  var product = {};
6971
6974
  if ((/** @type {?} */ (this)).document.items && (/** @type {?} */ (this)).document.items.item) {
6972
6975
  if ((/** @type {?} */ (this)).document.items.item instanceof Array) {
6973
6976
  (/** @type {?} */ (this)).document.items.item.forEach((/**
6974
6977
  * @param {?} element
6978
+ * @param {?} index
6975
6979
  * @return {?}
6976
6980
  */
6977
- function (element) {
6981
+ function (element, index) {
6978
6982
  /** @type {?} */
6979
6983
  var qty = (/** @type {?} */ (_this)).getText(element.qty_ordered) ? Number((/** @type {?} */ (_this)).getText(element.qty_ordered)) : 0;
6980
6984
  /** @type {?} */
@@ -6988,11 +6992,30 @@ var WebReturnMapperBuilderClass = /** @class */ (function () {
6988
6992
  refundedQuantity: (element.qty_refunded) ? Number((/** @type {?} */ (_this)).getText(element.qty_refunded)) : 0,
6989
6993
  //price: (element.original_price) ? Number(this.getText(element.original_price)) : 0,
6990
6994
  price: price,
6991
- itemLineId: (element.item_id) ? Number((/** @type {?} */ (_this)).getText(element.item_id)) : 0,
6995
+ itemLineId: (index + 1).toString(),
6992
6996
  // totalLinePrice: (element.row_invoiced) ? Number(this.getText(element.row_invoiced)) : 0,
6993
6997
  totalLinePrice: ((qty - refundQty) * price),
6994
6998
  };
6999
+ /** @type {?} */
7000
+ var promotionAmount = (/** @type {?} */ (_this)).getText(element.discount_amount) ? Number((/** @type {?} */ (_this)).getText(element.discount_amount)) : 0;
7001
+ /** @type {?} */
7002
+ var appliedIDs = (/** @type {?} */ (_this)).getText(element.applied_rule_ids) ? (/** @type {?} */ (_this)).getText(element.applied_rule_ids) : '';
6995
7003
  if (product && product.price != 0) {
7004
+ if (promotionAmount) {
7005
+ /** @type {?} */
7006
+ var trigger = (/** @type {?} */ ({}));
7007
+ trigger.itemLineId = product.itemLineId;
7008
+ trigger.quantity = product.quantity ? product.quantity : 0;
7009
+ /** @type {?} */
7010
+ var promotion = {
7011
+ promotionAmount: promotionAmount,
7012
+ promotionId: appliedIDs,
7013
+ itemLineId: product.itemLineId,
7014
+ promotionLinePrice: product.totalLinePrice - promotionAmount,
7015
+ trigger: trigger
7016
+ };
7017
+ (/** @type {?} */ (_this)).webReturnObject.basket['linePromotion'].push(promotion);
7018
+ }
6996
7019
  (/** @type {?} */ (_this)).webReturnObject.basket['products'].push(product);
6997
7020
  }
6998
7021
  }));
@@ -7011,17 +7034,206 @@ var WebReturnMapperBuilderClass = /** @class */ (function () {
7011
7034
  refundedQuantity: ((/** @type {?} */ (this)).document.items && (/** @type {?} */ (this)).document.items.item && (/** @type {?} */ (this)).document.items.item.qty_refunded) ? Number((/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.qty_refunded)) : 0,
7012
7035
  // price: (this.document.items && this.document.items.item && this.document.items.item.original_price) ? Number(this.getText(this.document.items.item.original_price)) : 0,
7013
7036
  price: price,
7014
- itemLineId: ((/** @type {?} */ (this)).document.items && (/** @type {?} */ (this)).document.items.item && (/** @type {?} */ (this)).document.items.item.item_id) ? Number((/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.item_id)) : 0,
7037
+ itemLineId: "1",
7015
7038
  // totalLinePrice: (this.document.items && this.document.items.item && this.document.items.item.row_invoiced) ? Number(this.getText(this.document.items.item.row_invoiced)) : 0,
7016
7039
  totalLinePrice: ((qty - refundQty) * price),
7017
7040
  };
7041
+ /** @type {?} */
7042
+ var promotionAmount = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.discount_amount) ? Number((/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.discount_amount)) : 0;
7043
+ /** @type {?} */
7044
+ var appliedIDs_1 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.applied_rule_ids) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.applied_rule_ids) : '';
7018
7045
  if (product && product.price != 0) {
7046
+ if (promotionAmount) {
7047
+ /** @type {?} */
7048
+ var trigger = (/** @type {?} */ ({}));
7049
+ trigger.itemLineId = product.itemLineId;
7050
+ trigger.quantity = product.quantity ? product.quantity : 0;
7051
+ /** @type {?} */
7052
+ var promotion = {
7053
+ promotionAmount: promotionAmount,
7054
+ promotionId: appliedIDs_1,
7055
+ itemLineId: product.itemLineId,
7056
+ promotionLinePrice: product.totalLinePrice - promotionAmount,
7057
+ trigger: trigger
7058
+ };
7059
+ (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'].push(promotion);
7060
+ }
7019
7061
  (/** @type {?} */ (this)).webReturnObject.basket['products'].push(product);
7020
7062
  }
7021
7063
  }
7064
+ /** @type {?} */
7065
+ var couponCode_1 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.coupon_code) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.coupon_code) : 0;
7066
+ /** @type {?} */
7067
+ var appliedIDs_2 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.applied_rule_ids) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.applied_rule_ids) : '';
7068
+ /** @type {?} */
7069
+ var discountDescription_1 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_description) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_description) : '';
7070
+ /** @type {?} */
7071
+ var couponTriggerPromotions_1 = (/** @type {?} */ ([]));
7072
+ if (couponCode_1 && appliedIDs_2) {
7073
+ /** @type {?} */
7074
+ var transactionPromotion = (/** @type {?} */ ({}));
7075
+ if ((/** @type {?} */ (this)).webReturnObject.basket['linePromotion'] && (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'].length > 0) {
7076
+ (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'].forEach((/**
7077
+ * @param {?} promotion
7078
+ * @return {?}
7079
+ */
7080
+ function (promotion) {
7081
+ if (promotion.promotionId === appliedIDs_2) {
7082
+ /** @type {?} */
7083
+ var trigger = (/** @type {?} */ ({}));
7084
+ trigger.itemLineId = promotion.itemLineId;
7085
+ trigger.quantity = promotion.trigger.quantity;
7086
+ trigger.totalQuantity = promotion.trigger.quantity;
7087
+ trigger.promotionAmount = promotion.promotionAmount;
7088
+ trigger.refundedReason = couponCode_1;
7089
+ trigger.refundedReasonDescription = discountDescription_1;
7090
+ trigger.promotionId = promotion.promotionId;
7091
+ couponTriggerPromotions_1.push(trigger);
7092
+ (/** @type {?} */ (_this)).webReturnObject.basket['linePromotion'] = (/** @type {?} */ (_this)).webReturnObject.basket['linePromotion'].filter((/**
7093
+ * @param {?} x
7094
+ * @return {?}
7095
+ */
7096
+ function (x) { return x.itemLineId !== promotion.itemLineId; }));
7097
+ }
7098
+ }));
7099
+ }
7100
+ if (couponTriggerPromotions_1.length > 0) {
7101
+ transactionPromotion.displayText = couponTriggerPromotions_1[0].refundedReasonDescription;
7102
+ transactionPromotion.name = couponTriggerPromotions_1[0].refundedReason;
7103
+ transactionPromotion.promotionAmount = -(couponTriggerPromotions_1.reduce((/**
7104
+ * @param {?} n
7105
+ * @param {?} __1
7106
+ * @return {?}
7107
+ */
7108
+ function (n, _a) {
7109
+ var promotionAmount = _a.promotionAmount;
7110
+ return n + promotionAmount;
7111
+ }), 0));
7112
+ transactionPromotion.promotionId = couponTriggerPromotions_1[0].promotionId;
7113
+ transactionPromotion.promotionInfo = couponTriggerPromotions_1[0].refundedReasonDescription;
7114
+ transactionPromotion.couponCode = couponCode_1;
7115
+ transactionPromotion.itemLineIds = [];
7116
+ transactionPromotion.type = PROMOTION_TYPE.COUPON;
7117
+ transactionPromotion.subLevelType = PROMOTION_LEVEL.LINE;
7118
+ transactionPromotion.trigger = couponTriggerPromotions_1;
7119
+ }
7120
+ console.log("e-basket: update LinePromotion With Coupon", JSON.stringify(transactionPromotion));
7121
+ if (!(/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion) {
7122
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = [];
7123
+ }
7124
+ if (transactionPromotion && transactionPromotion.promotionId) {
7125
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion.push(transactionPromotion);
7126
+ }
7127
+ }
7128
+ (/** @type {?} */ (this)).updateTransactionPromotionPrtionCalc();
7022
7129
  }
7023
7130
  return (/** @type {?} */ (this));
7024
7131
  };
7132
+ /**
7133
+ * @param {?} product
7134
+ * @return {?}
7135
+ */
7136
+ WebReturnMapperBuilderClass.prototype.validateProductItemDiscount = /**
7137
+ * @param {?} product
7138
+ * @return {?}
7139
+ */
7140
+ function (product) {
7141
+ if (!product.itemDiscounts) {
7142
+ product.itemDiscounts = {
7143
+ trnDiscountsPortion: 0,
7144
+ trnPromotionsPortion: 0,
7145
+ refundPortion: 0,
7146
+ };
7147
+ }
7148
+ return product;
7149
+ };
7150
+ /**
7151
+ * @param {?} txDoc
7152
+ * @param {?} promotion
7153
+ * @return {?}
7154
+ */
7155
+ WebReturnMapperBuilderClass.prototype.transactionPromotionProductPortionCalc = /**
7156
+ * @param {?} txDoc
7157
+ * @param {?} promotion
7158
+ * @return {?}
7159
+ */
7160
+ function (txDoc, promotion) {
7161
+ var _this = this;
7162
+ console.log("ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: " + JSON.stringify(promotion));
7163
+ if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
7164
+ txDoc.basket.products.forEach((/**
7165
+ * @param {?} product
7166
+ * @return {?}
7167
+ */
7168
+ function (product) {
7169
+ product = _this.validateProductItemDiscount(product);
7170
+ if (promotion.trigger && promotion.trigger.length > 0) {
7171
+ promotion.trigger.forEach((/**
7172
+ * @param {?} t
7173
+ * @return {?}
7174
+ */
7175
+ function (t) {
7176
+ if (t.itemLineId === product.itemLineId.toString()) {
7177
+ product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
7178
+ }
7179
+ }));
7180
+ }
7181
+ }));
7182
+ }
7183
+ else {
7184
+ txDoc.basket.products.forEach((/**
7185
+ * @param {?} product
7186
+ * @return {?}
7187
+ */
7188
+ function (product) {
7189
+ product = _this.validateProductItemDiscount(product);
7190
+ if (promotion.itemLineIds.includes(+product.itemLineId)) {
7191
+ /** @type {?} */
7192
+ var discountAmount = 0;
7193
+ if (_this.document.items.item instanceof Array) {
7194
+ /** @type {?} */
7195
+ var productItem = _this.document.items.item.find((/**
7196
+ * @param {?} productItem
7197
+ * @return {?}
7198
+ */
7199
+ function (productItem) { return productItem.sku === product.SKU; }));
7200
+ discountAmount = productItem.discount_amount ? +productItem.discount_amount : 0;
7201
+ }
7202
+ else {
7203
+ discountAmount = _this.document.items.item.sku === product.SKU && _this.document.items.item.discount_amount ?
7204
+ +_this.document.items.item.discount_amount : 0;
7205
+ }
7206
+ /** @type {?} */
7207
+ var transactionPromotionPortion = discountAmount;
7208
+ product.itemDiscounts.trnPromotionsPortion += _this.numberUtilService.trimTo2Decimal2(transactionPromotionPortion);
7209
+ }
7210
+ }));
7211
+ }
7212
+ return txDoc;
7213
+ };
7214
+ /**
7215
+ * @return {?}
7216
+ */
7217
+ WebReturnMapperBuilderClass.prototype.updateTransactionPromotionPrtionCalc = /**
7218
+ * @return {?}
7219
+ */
7220
+ function () {
7221
+ var _this = this;
7222
+ try {
7223
+ if (this.webReturnObject.basket.transactionPromotion && this.webReturnObject.basket.transactionPromotion.length > 0) {
7224
+ this.webReturnObject.basket.transactionPromotion.forEach((/**
7225
+ * @param {?} tr
7226
+ * @return {?}
7227
+ */
7228
+ function (tr) {
7229
+ _this.transactionPromotionProductPortionCalc(_this.webReturnObject, tr);
7230
+ }));
7231
+ }
7232
+ }
7233
+ catch (error) {
7234
+ console.log("updateTransactionPromotionPrtionCalc => failed:", JSON.stringify(error));
7235
+ }
7236
+ };
7025
7237
  /**
7026
7238
  * @template THIS
7027
7239
  * @this {THIS}
@@ -7235,6 +7447,13 @@ if (false) {
7235
7447
  * @private
7236
7448
  */
7237
7449
  WebReturnMapperBuilderClass.prototype.webReturnObject;
7450
+ /** @type {?} */
7451
+ WebReturnMapperBuilderClass.prototype.numberUtilService;
7452
+ /**
7453
+ * @type {?}
7454
+ * @private
7455
+ */
7456
+ WebReturnMapperBuilderClass.prototype.currencyPipe;
7238
7457
  }
7239
7458
 
7240
7459
  /**