@pmcretail/mapper-library 0.0.12 → 0.0.13

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.
@@ -4890,16 +4890,16 @@ var RJMapperBuilderClass = /** @class */ (function () {
4890
4890
  function (element) {
4891
4891
  /** @type {?} */
4892
4892
  var obj = {};
4893
- obj['XMLSchemaVersion'] = 1;
4894
- obj['NetValue'] = element.discountAmount < 0 ? element.discountAmount : -element.discountAmount;
4895
- obj['EffectiveNetValue'] = element.discountAmount < 0 ? element.discountAmount : -element.discountAmount;
4896
- obj['Description'] = element.reasonCode;
4893
+ obj['XMLSchemaVersion'] = "1";
4894
+ obj['NetValue'] = (/** @type {?} */ (_this)).convertToString(element.discountAmount < 0 ? element.discountAmount : -element.discountAmount);
4895
+ obj['EffectiveNetValue'] = (/** @type {?} */ (_this)).convertToString(element.discountAmount < 0 ? element.discountAmount : -element.discountAmount);
4896
+ obj['Description'] = element.reasonDisplayText;
4897
4897
  obj['UserID'] = (/** @type {?} */ (_this)).transactionDocument.userName;
4898
4898
  obj['ReasonCodeID'] = element.reasonCode;
4899
- obj['DiscountType'] = element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1; // todo - compare values
4900
- obj['RoundingRule'] = 2;
4901
- obj['ModifiedLineNumber '] = element.itemLineIds;
4902
- obj['LineNumber'] = (/** @type {?} */ (_this)).generateLineNumber();
4899
+ obj['DiscountType'] = (/** @type {?} */ (_this)).convertToString(element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1); // todo - compare values
4900
+ obj['RoundingRule'] = (/** @type {?} */ (_this)).convertToString(2);
4901
+ obj['ModifiedLineNumber'] = element.itemLineIds;
4902
+ obj['LineNumber'] = (/** @type {?} */ (_this)).convertToString((/** @type {?} */ (_this)).generateLineNumber());
4903
4903
  // obj['DiscountedValue'] = obj['discountAmount'] // todo - confirm value before discount;
4904
4904
  // obj['DiscountPercentage'] = obj['discountAmount'] / 100 ; // todo - optional
4905
4905
  (/** @type {?} */ (_this)).rjObject['BasketDiscount'].push(obj);
@@ -4979,56 +4979,52 @@ var RJMapperBuilderClass = /** @class */ (function () {
4979
4979
  obj['TaxPercentage'] = element.VAT.toFixed(2); // todo
4980
4980
  (/** @type {?} */ (_this)).rjObject['Trailer']['TaxItem'].push(obj);
4981
4981
  }));
4982
- // TODO: make Trailer object from promotion
4983
- (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'] = [];
4984
- (/** @type {?} */ (this)).transactionDocument.basket.linePromotion.forEach((/**
4985
- * @param {?} element
4986
- * @return {?}
4987
- */
4988
- function (element) {
4989
- /** @type {?} */
4990
- var obj = {};
4991
- obj['PromotionID'] = element.promotionId;
4992
- obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
4993
- obj['PromotionQuantity'] = ""; // todo - not avaialble
4994
- obj['PromotionDescription'] = element.displayText;
4995
- obj['PromotionHit']['XMLSchemaVersion'] = (/** @type {?} */ (_this)).transactionDocument.storeId;
4996
- obj['PromotionHit']['HitNumber'] = ""; // todo;
4997
- obj['PromotionHit']['HitQuantity'] = ""; // todo;
4998
- obj['PromotionHit']['HitSaving'] = ""; // todo;
4999
- obj['PromotionHit']['PromotionTrigger'] = [];
5000
- element.trigger.forEach((/**
5001
- * @param {?} subElement
4982
+ // TODO: make Trailer object from promotion
4983
+ if ((/** @type {?} */ (this)).transactionDocument.basket.linePromotion.length > 0) {
4984
+ (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'] = [];
4985
+ (/** @type {?} */ (this)).transactionDocument.basket.linePromotion.forEach((/**
4986
+ * @param {?} element
5002
4987
  * @return {?}
5003
4988
  */
5004
- function (subElement) {
5005
- /** @type {?} */
5006
- var objSub = {};
4989
+ function (element) {
4990
+ console.log('element', element);
5007
4991
  /** @type {?} */
5008
- var product = (/** @type {?} */ (_this)).transactionDocument.basket.products.find((/**
5009
- * @param {?} item
5010
- * @return {?}
5011
- */
5012
- function (item) { return item.lineItemId == subElement.itemLineId; }));
5013
- objSub['XMLSchemaVersion'] = (/** @type {?} */ (_this)).xmlSchemaVersion;
5014
- objSub['ProductID'] = (/** @type {?} */ (_this)).transactionDocument.basket.products.find((/**
5015
- * @param {?} item
4992
+ var obj = {};
4993
+ obj['PromotionID'] = element.promotionId;
4994
+ obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
4995
+ obj['PromotionQuantity'] = ""; // todo - not avaialble
4996
+ obj['PromotionDescription'] = element.displayText;
4997
+ obj['PromotionHit'] = {};
4998
+ obj['PromotionHit']['XMLSchemaVersion'] = (/** @type {?} */ (_this)).xmlSchemaVersion;
4999
+ obj['PromotionHit']['HitNumber'] = ""; // todo;
5000
+ obj['PromotionHit']['HitQuantity'] = ""; // todo;
5001
+ obj['PromotionHit']['HitSaving'] = ""; // todo;
5002
+ obj['PromotionHit']['PromotionTrigger'] = {};
5003
+ element.trigger.forEach((/**
5004
+ * @param {?} subElement
5016
5005
  * @return {?}
5017
5006
  */
5018
- function (item) { return item.itemLineId === subElement.itemLineId; })).SKU;
5019
- objSub['UnitValue'] = (/** @type {?} */ (_this)).convertToString(element.promotionLinePrice / product.quantity);
5020
- objSub['LineNumber'] = (/** @type {?} */ (_this)).convertToString(subElement.itemLineId);
5021
- objSub['Quantity'] = (/** @type {?} */ (_this)).convertToString(subElement.quantity.toFixed(1));
5022
- objSub['TaxCode'] = (/** @type {?} */ (_this)).transactionDocument.basket.taxBreakdown.taxLines.find((/**
5023
- * @param {?} item
5024
- * @return {?}
5025
- */
5026
- function (item) { return item.itemLineId == element.itemLineId; })).VATCode; // todo
5027
- obj['PromotionHit']['PromotionTrigger'].push(objSub);
5007
+ function (subElement) {
5008
+ /** @type {?} */
5009
+ var product = (/** @type {?} */ (_this)).transactionDocument.basket.products.find((/**
5010
+ * @param {?} item
5011
+ * @return {?}
5012
+ */
5013
+ function (item) { return item.itemLineId == subElement.itemLineId; }));
5014
+ obj['PromotionHit']['PromotionTrigger']['XMLSchemaVersion'] = (/** @type {?} */ (_this)).xmlSchemaVersion;
5015
+ obj['PromotionHit']['PromotionTrigger']['ProductID'] = product.SKU;
5016
+ obj['PromotionHit']['PromotionTrigger']['UnitValue'] = (/** @type {?} */ (_this)).convertToString(element.promotionLinePrice / product.quantity);
5017
+ obj['PromotionHit']['PromotionTrigger']['LineNumber'] = (/** @type {?} */ (_this)).convertToString(subElement.itemLineId);
5018
+ obj['PromotionHit']['PromotionTrigger']['Quantity'] = (/** @type {?} */ (_this)).convertToString(subElement.quantity.toFixed(1));
5019
+ obj['PromotionHit']['PromotionTrigger']['TaxCode'] = (/** @type {?} */ (_this)).transactionDocument.basket.taxBreakdown.taxLines.find((/**
5020
+ * @param {?} item
5021
+ * @return {?}
5022
+ */
5023
+ function (item) { return item.itemLineId == element.itemLineId; })).VATCode; // todo
5024
+ }));
5025
+ (/** @type {?} */ (_this)).rjObject['Trailer']['PromotionItem'].push(obj);
5028
5026
  }));
5029
- (/** @type {?} */ (_this)).rjObject['Trailer']['PromotionItem'].push(obj);
5030
- }));
5031
- //console.log(this.rjObject);
5027
+ }
5032
5028
  return (/** @type {?} */ (this));
5033
5029
  };
5034
5030
  /**
@@ -5375,16 +5371,14 @@ var RJMapperBuilderClass = /** @class */ (function () {
5375
5371
  /**
5376
5372
  * @template THIS
5377
5373
  * @this {THIS}
5378
- * @param {?} value
5379
5374
  * @return {THIS}
5380
5375
  */
5381
5376
  RJMapperBuilderClass.prototype.setCashierID = /**
5382
5377
  * @template THIS
5383
5378
  * @this {THIS}
5384
- * @param {?} value
5385
5379
  * @return {THIS}
5386
5380
  */
5387
- function (value) {
5381
+ function () {
5388
5382
  (/** @type {?} */ (this)).cashierId = ((/** @type {?} */ (this)).transactionDocument && (/** @type {?} */ (this)).transactionDocument.userName) ? (/** @type {?} */ (this)).transactionDocument.userName : '';
5389
5383
  return (/** @type {?} */ (this));
5390
5384
  };
@@ -5550,7 +5544,7 @@ var RJMapperBuilderClass = /** @class */ (function () {
5550
5544
  obj['DateTimeCreated'] = this.createdAt;
5551
5545
  obj['ExtendedValue'] = this.removeDecimal(element['totalLinePrice'] * -1);
5552
5546
  obj['UnitPrice'] = this.removeDecimal(element['price']);
5553
- obj['Quantity'] = element['refundedQuantity'] < 0 ? element['refundedQuantity'].toFixed(1) : (-element['refundedQuantity']).toFixed(1);
5547
+ obj['Quantity'] = this.getQuantity(element);
5554
5548
  obj['OriginalTaxAmountSet'] = 1;
5555
5549
  obj['ProductID'] = element['SKU'];
5556
5550
  obj['HandKeyed'] = 1;
@@ -5558,7 +5552,7 @@ var RJMapperBuilderClass = /** @class */ (function () {
5558
5552
  obj['Return'] = {};
5559
5553
  obj['Return']['ReturnReasonID'] = element['refundedReason'];
5560
5554
  obj['Return']['ReturnDescription'] = element['refundedReasonDescription'];
5561
- obj['Return']['ReturnToStock'] = element['refundedQuantity'] > 0 ? element['refundedQuantity'].toFixed(1) : -1 * element['refundedQuantity'].toFixed(1);
5555
+ obj['Return']['ReturnToStock'] = this.getQuantity(element);
5562
5556
  obj['TaxCode'] = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((/**
5563
5557
  * @param {?} item
5564
5558
  * @return {?}
@@ -5831,6 +5825,25 @@ var RJMapperBuilderClass = /** @class */ (function () {
5831
5825
  this.rjObject['BasketDiscount']['RoundingRule'] = 2;
5832
5826
  }
5833
5827
  };
5828
+ /**
5829
+ * @param {?} element
5830
+ * @return {?}
5831
+ */
5832
+ RJMapperBuilderClass.prototype.getQuantity = /**
5833
+ * @param {?} element
5834
+ * @return {?}
5835
+ */
5836
+ function (element) {
5837
+ /** @type {?} */
5838
+ var quantity;
5839
+ if (this.transactionDocument.unreferencedRefund) {
5840
+ quantity = element['quantity'] < 0 ? element['quantity'].toFixed(1) : (-element['quantity']).toFixed(1);
5841
+ }
5842
+ else {
5843
+ quantity = element['refundedQuantity'] < 0 ? element['refundedQuantity'].toFixed(1) : (-element['refundedQuantity']).toFixed(1);
5844
+ }
5845
+ return quantity;
5846
+ };
5834
5847
  return RJMapperBuilderClass;
5835
5848
  }());
5836
5849
  if (false) {