@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.
@@ -7093,7 +7093,8 @@
7093
7093
  * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
7094
7094
  */
7095
7095
  var WebReturnMapperBuilderClass = /** @class */ (function () {
7096
- function WebReturnMapperBuilderClass(document) {
7096
+ function WebReturnMapperBuilderClass(document, currencyPipe) {
7097
+ this.currencyPipe = currencyPipe;
7097
7098
  this.webReturnObject = {
7098
7099
  id: '',
7099
7100
  orgCode: "",
@@ -7122,6 +7123,7 @@
7122
7123
  if (document) {
7123
7124
  this.document = document;
7124
7125
  }
7126
+ this.numberUtilService = new NumberUtilService(currencyPipe);
7125
7127
  }
7126
7128
  /**
7127
7129
  * @template THIS
@@ -7164,7 +7166,7 @@
7164
7166
  (/** @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) : '';
7165
7167
  (/** @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) : '';
7166
7168
  // basketSummary
7167
- (/** @type {?} */ (this)).webReturnObject.basketSummary['discountTotal'] = Number((/** @type {?} */ (this)).document.discount_amount ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_amount) : 0);
7169
+ (/** @type {?} */ (this)).webReturnObject.basketSummary['discountTotal'] = Math.abs(Number((/** @type {?} */ (this)).document.discount_amount ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_amount) : 0));
7168
7170
  (/** @type {?} */ (this)).webReturnObject.basketSummary['VATTotal'] = Number((/** @type {?} */ (this)).document.base_total_paid ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.base_total_paid) : 0);
7169
7171
  (/** @type {?} */ (this)).webReturnObject.basketSummary['saleTotal'] = Number((/** @type {?} */ (this)).document.base_total_invoiced ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.base_total_invoiced) : 0);
7170
7172
  (/** @type {?} */ (this)).webReturnObject.basketSummary['basketTotal'] = Number((/** @type {?} */ (this)).document.base_total_paid ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.base_total_paid) : 0);
@@ -7178,23 +7180,25 @@
7178
7180
  // }
7179
7181
  // this.webReturnObject.basket['lineDiscount'].push(lineDiscount);
7180
7182
  // basket transaction discount
7181
- (/** @type {?} */ (this)).webReturnObject.basket['transactionDiscount'] = [];
7182
- /** @type {?} */
7183
- var transactionDiscount = {
7184
- discountAmount: ((/** @type {?} */ (this)).document && (/** @type {?} */ (this)).document.discount_amount) ? Number((/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_amount)) : 0
7185
- };
7186
- (/** @type {?} */ (this)).webReturnObject.basket['transactionDiscount'].push(transactionDiscount);
7187
7183
  // basket products
7188
7184
  (/** @type {?} */ (this)).webReturnObject.basket['products'] = [];
7185
+ (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'] = [];
7186
+ (/** @type {?} */ (this)).webReturnObject.basket['transactionDiscount'] = [];
7187
+ (/** @type {?} */ (this)).webReturnObject.basket['transactionPromotion'] = [];
7188
+ // let transactionDiscount = {
7189
+ // discountAmount: (this.document && this.document.discount_amount) ? Number(this.getText(this.document.discount_amount)) : 0
7190
+ // }
7191
+ // this.webReturnObject.basket['transactionDiscount'].push(transactionDiscount);
7189
7192
  /** @type {?} */
7190
7193
  var product = {};
7191
7194
  if ((/** @type {?} */ (this)).document.items && (/** @type {?} */ (this)).document.items.item) {
7192
7195
  if ((/** @type {?} */ (this)).document.items.item instanceof Array) {
7193
7196
  (/** @type {?} */ (this)).document.items.item.forEach((/**
7194
7197
  * @param {?} element
7198
+ * @param {?} index
7195
7199
  * @return {?}
7196
7200
  */
7197
- function (element) {
7201
+ function (element, index) {
7198
7202
  /** @type {?} */
7199
7203
  var qty = (/** @type {?} */ (_this)).getText(element.qty_ordered) ? Number((/** @type {?} */ (_this)).getText(element.qty_ordered)) : 0;
7200
7204
  /** @type {?} */
@@ -7208,11 +7212,30 @@
7208
7212
  refundedQuantity: (element.qty_refunded) ? Number((/** @type {?} */ (_this)).getText(element.qty_refunded)) : 0,
7209
7213
  //price: (element.original_price) ? Number(this.getText(element.original_price)) : 0,
7210
7214
  price: price,
7211
- itemLineId: (element.item_id) ? Number((/** @type {?} */ (_this)).getText(element.item_id)) : 0,
7215
+ itemLineId: (index + 1).toString(),
7212
7216
  // totalLinePrice: (element.row_invoiced) ? Number(this.getText(element.row_invoiced)) : 0,
7213
7217
  totalLinePrice: ((qty - refundQty) * price),
7214
7218
  };
7219
+ /** @type {?} */
7220
+ var promotionAmount = (/** @type {?} */ (_this)).getText(element.discount_amount) ? Number((/** @type {?} */ (_this)).getText(element.discount_amount)) : 0;
7221
+ /** @type {?} */
7222
+ var appliedIDs = (/** @type {?} */ (_this)).getText(element.applied_rule_ids) ? (/** @type {?} */ (_this)).getText(element.applied_rule_ids) : '';
7215
7223
  if (product && product.price != 0) {
7224
+ if (promotionAmount) {
7225
+ /** @type {?} */
7226
+ var trigger = (/** @type {?} */ ({}));
7227
+ trigger.itemLineId = product.itemLineId;
7228
+ trigger.quantity = product.quantity ? product.quantity : 0;
7229
+ /** @type {?} */
7230
+ var promotion = {
7231
+ promotionAmount: promotionAmount,
7232
+ promotionId: appliedIDs,
7233
+ itemLineId: product.itemLineId,
7234
+ promotionLinePrice: product.totalLinePrice - promotionAmount,
7235
+ trigger: trigger
7236
+ };
7237
+ (/** @type {?} */ (_this)).webReturnObject.basket['linePromotion'].push(promotion);
7238
+ }
7216
7239
  (/** @type {?} */ (_this)).webReturnObject.basket['products'].push(product);
7217
7240
  }
7218
7241
  }));
@@ -7231,17 +7254,206 @@
7231
7254
  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,
7232
7255
  // price: (this.document.items && this.document.items.item && this.document.items.item.original_price) ? Number(this.getText(this.document.items.item.original_price)) : 0,
7233
7256
  price: price,
7234
- 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,
7257
+ itemLineId: "1",
7235
7258
  // totalLinePrice: (this.document.items && this.document.items.item && this.document.items.item.row_invoiced) ? Number(this.getText(this.document.items.item.row_invoiced)) : 0,
7236
7259
  totalLinePrice: ((qty - refundQty) * price),
7237
7260
  };
7261
+ /** @type {?} */
7262
+ var promotionAmount = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.discount_amount) ? Number((/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.items.item.discount_amount)) : 0;
7263
+ /** @type {?} */
7264
+ 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) : '';
7238
7265
  if (product && product.price != 0) {
7266
+ if (promotionAmount) {
7267
+ /** @type {?} */
7268
+ var trigger = (/** @type {?} */ ({}));
7269
+ trigger.itemLineId = product.itemLineId;
7270
+ trigger.quantity = product.quantity ? product.quantity : 0;
7271
+ /** @type {?} */
7272
+ var promotion = {
7273
+ promotionAmount: promotionAmount,
7274
+ promotionId: appliedIDs_1,
7275
+ itemLineId: product.itemLineId,
7276
+ promotionLinePrice: product.totalLinePrice - promotionAmount,
7277
+ trigger: trigger
7278
+ };
7279
+ (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'].push(promotion);
7280
+ }
7239
7281
  (/** @type {?} */ (this)).webReturnObject.basket['products'].push(product);
7240
7282
  }
7241
7283
  }
7284
+ /** @type {?} */
7285
+ var couponCode_1 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.coupon_code) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.coupon_code) : 0;
7286
+ /** @type {?} */
7287
+ var appliedIDs_2 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.applied_rule_ids) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.applied_rule_ids) : '';
7288
+ /** @type {?} */
7289
+ var discountDescription_1 = (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_description) ? (/** @type {?} */ (this)).getText((/** @type {?} */ (this)).document.discount_description) : '';
7290
+ /** @type {?} */
7291
+ var couponTriggerPromotions_1 = (/** @type {?} */ ([]));
7292
+ if (couponCode_1 && appliedIDs_2) {
7293
+ /** @type {?} */
7294
+ var transactionPromotion = (/** @type {?} */ ({}));
7295
+ if ((/** @type {?} */ (this)).webReturnObject.basket['linePromotion'] && (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'].length > 0) {
7296
+ (/** @type {?} */ (this)).webReturnObject.basket['linePromotion'].forEach((/**
7297
+ * @param {?} promotion
7298
+ * @return {?}
7299
+ */
7300
+ function (promotion) {
7301
+ if (promotion.promotionId === appliedIDs_2) {
7302
+ /** @type {?} */
7303
+ var trigger = (/** @type {?} */ ({}));
7304
+ trigger.itemLineId = promotion.itemLineId;
7305
+ trigger.quantity = promotion.trigger.quantity;
7306
+ trigger.totalQuantity = promotion.trigger.quantity;
7307
+ trigger.promotionAmount = promotion.promotionAmount;
7308
+ trigger.refundedReason = couponCode_1;
7309
+ trigger.refundedReasonDescription = discountDescription_1;
7310
+ trigger.promotionId = promotion.promotionId;
7311
+ couponTriggerPromotions_1.push(trigger);
7312
+ (/** @type {?} */ (_this)).webReturnObject.basket['linePromotion'] = (/** @type {?} */ (_this)).webReturnObject.basket['linePromotion'].filter((/**
7313
+ * @param {?} x
7314
+ * @return {?}
7315
+ */
7316
+ function (x) { return x.itemLineId !== promotion.itemLineId; }));
7317
+ }
7318
+ }));
7319
+ }
7320
+ if (couponTriggerPromotions_1.length > 0) {
7321
+ transactionPromotion.displayText = couponTriggerPromotions_1[0].refundedReasonDescription;
7322
+ transactionPromotion.name = couponTriggerPromotions_1[0].refundedReason;
7323
+ transactionPromotion.promotionAmount = -(couponTriggerPromotions_1.reduce((/**
7324
+ * @param {?} n
7325
+ * @param {?} __1
7326
+ * @return {?}
7327
+ */
7328
+ function (n, _a) {
7329
+ var promotionAmount = _a.promotionAmount;
7330
+ return n + promotionAmount;
7331
+ }), 0));
7332
+ transactionPromotion.promotionId = couponTriggerPromotions_1[0].promotionId;
7333
+ transactionPromotion.promotionInfo = couponTriggerPromotions_1[0].refundedReasonDescription;
7334
+ transactionPromotion.couponCode = couponCode_1;
7335
+ transactionPromotion.itemLineIds = [];
7336
+ transactionPromotion.type = PROMOTION_TYPE.COUPON;
7337
+ transactionPromotion.subLevelType = PROMOTION_LEVEL.LINE;
7338
+ transactionPromotion.trigger = couponTriggerPromotions_1;
7339
+ }
7340
+ console.log("e-basket: update LinePromotion With Coupon", JSON.stringify(transactionPromotion));
7341
+ if (!(/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion) {
7342
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion = [];
7343
+ }
7344
+ if (transactionPromotion && transactionPromotion.promotionId) {
7345
+ (/** @type {?} */ (this)).webReturnObject.basket.transactionPromotion.push(transactionPromotion);
7346
+ }
7347
+ }
7348
+ (/** @type {?} */ (this)).updateTransactionPromotionPrtionCalc();
7242
7349
  }
7243
7350
  return (/** @type {?} */ (this));
7244
7351
  };
7352
+ /**
7353
+ * @param {?} product
7354
+ * @return {?}
7355
+ */
7356
+ WebReturnMapperBuilderClass.prototype.validateProductItemDiscount = /**
7357
+ * @param {?} product
7358
+ * @return {?}
7359
+ */
7360
+ function (product) {
7361
+ if (!product.itemDiscounts) {
7362
+ product.itemDiscounts = {
7363
+ trnDiscountsPortion: 0,
7364
+ trnPromotionsPortion: 0,
7365
+ refundPortion: 0,
7366
+ };
7367
+ }
7368
+ return product;
7369
+ };
7370
+ /**
7371
+ * @param {?} txDoc
7372
+ * @param {?} promotion
7373
+ * @return {?}
7374
+ */
7375
+ WebReturnMapperBuilderClass.prototype.transactionPromotionProductPortionCalc = /**
7376
+ * @param {?} txDoc
7377
+ * @param {?} promotion
7378
+ * @return {?}
7379
+ */
7380
+ function (txDoc, promotion) {
7381
+ var _this = this;
7382
+ console.log("ebasket: transactionPromotionProductPortionCalc: trnsactionPromotion: " + JSON.stringify(promotion));
7383
+ if (promotion.type === PROMOTION_TYPE.COUPON && promotion.subLevelType === PROMOTION_LEVEL.LINE) {
7384
+ txDoc.basket.products.forEach((/**
7385
+ * @param {?} product
7386
+ * @return {?}
7387
+ */
7388
+ function (product) {
7389
+ product = _this.validateProductItemDiscount(product);
7390
+ if (promotion.trigger && promotion.trigger.length > 0) {
7391
+ promotion.trigger.forEach((/**
7392
+ * @param {?} t
7393
+ * @return {?}
7394
+ */
7395
+ function (t) {
7396
+ if (t.itemLineId === product.itemLineId.toString()) {
7397
+ product.itemDiscounts.trnPromotionsPortion += t.promotionAmount;
7398
+ }
7399
+ }));
7400
+ }
7401
+ }));
7402
+ }
7403
+ else {
7404
+ txDoc.basket.products.forEach((/**
7405
+ * @param {?} product
7406
+ * @return {?}
7407
+ */
7408
+ function (product) {
7409
+ product = _this.validateProductItemDiscount(product);
7410
+ if (promotion.itemLineIds.includes(+product.itemLineId)) {
7411
+ /** @type {?} */
7412
+ var discountAmount = 0;
7413
+ if (_this.document.items.item instanceof Array) {
7414
+ /** @type {?} */
7415
+ var productItem = _this.document.items.item.find((/**
7416
+ * @param {?} productItem
7417
+ * @return {?}
7418
+ */
7419
+ function (productItem) { return productItem.sku === product.SKU; }));
7420
+ discountAmount = productItem.discount_amount ? +productItem.discount_amount : 0;
7421
+ }
7422
+ else {
7423
+ discountAmount = _this.document.items.item.sku === product.SKU && _this.document.items.item.discount_amount ?
7424
+ +_this.document.items.item.discount_amount : 0;
7425
+ }
7426
+ /** @type {?} */
7427
+ var transactionPromotionPortion = discountAmount;
7428
+ product.itemDiscounts.trnPromotionsPortion += _this.numberUtilService.trimTo2Decimal2(transactionPromotionPortion);
7429
+ }
7430
+ }));
7431
+ }
7432
+ return txDoc;
7433
+ };
7434
+ /**
7435
+ * @return {?}
7436
+ */
7437
+ WebReturnMapperBuilderClass.prototype.updateTransactionPromotionPrtionCalc = /**
7438
+ * @return {?}
7439
+ */
7440
+ function () {
7441
+ var _this = this;
7442
+ try {
7443
+ if (this.webReturnObject.basket.transactionPromotion && this.webReturnObject.basket.transactionPromotion.length > 0) {
7444
+ this.webReturnObject.basket.transactionPromotion.forEach((/**
7445
+ * @param {?} tr
7446
+ * @return {?}
7447
+ */
7448
+ function (tr) {
7449
+ _this.transactionPromotionProductPortionCalc(_this.webReturnObject, tr);
7450
+ }));
7451
+ }
7452
+ }
7453
+ catch (error) {
7454
+ console.log("updateTransactionPromotionPrtionCalc => failed:", JSON.stringify(error));
7455
+ }
7456
+ };
7245
7457
  /**
7246
7458
  * @template THIS
7247
7459
  * @this {THIS}
@@ -7455,6 +7667,13 @@
7455
7667
  * @private
7456
7668
  */
7457
7669
  WebReturnMapperBuilderClass.prototype.webReturnObject;
7670
+ /** @type {?} */
7671
+ WebReturnMapperBuilderClass.prototype.numberUtilService;
7672
+ /**
7673
+ * @type {?}
7674
+ * @private
7675
+ */
7676
+ WebReturnMapperBuilderClass.prototype.currencyPipe;
7458
7677
  }
7459
7678
 
7460
7679
  /**