@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.
@@ -3698,16 +3698,16 @@ class RJMapperBuilderClass {
3698
3698
  (element) => {
3699
3699
  /** @type {?} */
3700
3700
  let obj = {};
3701
- obj['XMLSchemaVersion'] = 1;
3702
- obj['NetValue'] = element.discountAmount < 0 ? element.discountAmount : -element.discountAmount;
3703
- obj['EffectiveNetValue'] = element.discountAmount < 0 ? element.discountAmount : -element.discountAmount;
3704
- obj['Description'] = element.reasonCode;
3701
+ obj['XMLSchemaVersion'] = "1";
3702
+ obj['NetValue'] = (/** @type {?} */ (this)).convertToString(element.discountAmount < 0 ? element.discountAmount : -element.discountAmount);
3703
+ obj['EffectiveNetValue'] = (/** @type {?} */ (this)).convertToString(element.discountAmount < 0 ? element.discountAmount : -element.discountAmount);
3704
+ obj['Description'] = element.reasonDisplayText;
3705
3705
  obj['UserID'] = (/** @type {?} */ (this)).transactionDocument.userName;
3706
3706
  obj['ReasonCodeID'] = element.reasonCode;
3707
- obj['DiscountType'] = element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1; // todo - compare values
3708
- obj['RoundingRule'] = 2;
3709
- obj['ModifiedLineNumber '] = element.itemLineIds;
3710
- obj['LineNumber'] = (/** @type {?} */ (this)).generateLineNumber();
3707
+ obj['DiscountType'] = (/** @type {?} */ (this)).convertToString(element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1); // todo - compare values
3708
+ obj['RoundingRule'] = (/** @type {?} */ (this)).convertToString(2);
3709
+ obj['ModifiedLineNumber'] = element.itemLineIds;
3710
+ obj['LineNumber'] = (/** @type {?} */ (this)).convertToString((/** @type {?} */ (this)).generateLineNumber());
3711
3711
  // obj['DiscountedValue'] = obj['discountAmount'] // todo - confirm value before discount;
3712
3712
  // obj['DiscountPercentage'] = obj['discountAmount'] / 100 ; // todo - optional
3713
3713
  (/** @type {?} */ (this)).rjObject['BasketDiscount'].push(obj);
@@ -3776,56 +3776,52 @@ class RJMapperBuilderClass {
3776
3776
  obj['TaxPercentage'] = element.VAT.toFixed(2); // todo
3777
3777
  (/** @type {?} */ (this)).rjObject['Trailer']['TaxItem'].push(obj);
3778
3778
  }));
3779
- // TODO: make Trailer object from promotion
3780
- (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'] = [];
3781
- (/** @type {?} */ (this)).transactionDocument.basket.linePromotion.forEach((/**
3782
- * @param {?} element
3783
- * @return {?}
3784
- */
3785
- (element) => {
3786
- /** @type {?} */
3787
- let obj = {};
3788
- obj['PromotionID'] = element.promotionId;
3789
- obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
3790
- obj['PromotionQuantity'] = ""; // todo - not avaialble
3791
- obj['PromotionDescription'] = element.displayText;
3792
- obj['PromotionHit']['XMLSchemaVersion'] = (/** @type {?} */ (this)).transactionDocument.storeId;
3793
- obj['PromotionHit']['HitNumber'] = ""; // todo;
3794
- obj['PromotionHit']['HitQuantity'] = ""; // todo;
3795
- obj['PromotionHit']['HitSaving'] = ""; // todo;
3796
- obj['PromotionHit']['PromotionTrigger'] = [];
3797
- element.trigger.forEach((/**
3798
- * @param {?} subElement
3779
+ // TODO: make Trailer object from promotion
3780
+ if ((/** @type {?} */ (this)).transactionDocument.basket.linePromotion.length > 0) {
3781
+ (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'] = [];
3782
+ (/** @type {?} */ (this)).transactionDocument.basket.linePromotion.forEach((/**
3783
+ * @param {?} element
3799
3784
  * @return {?}
3800
3785
  */
3801
- (subElement) => {
3802
- /** @type {?} */
3803
- let objSub = {};
3786
+ (element) => {
3787
+ console.log('element', element);
3804
3788
  /** @type {?} */
3805
- let product = (/** @type {?} */ (this)).transactionDocument.basket.products.find((/**
3806
- * @param {?} item
3789
+ let obj = {};
3790
+ obj['PromotionID'] = element.promotionId;
3791
+ obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
3792
+ obj['PromotionQuantity'] = ""; // todo - not avaialble
3793
+ obj['PromotionDescription'] = element.displayText;
3794
+ obj['PromotionHit'] = {};
3795
+ obj['PromotionHit']['XMLSchemaVersion'] = (/** @type {?} */ (this)).xmlSchemaVersion;
3796
+ obj['PromotionHit']['HitNumber'] = ""; // todo;
3797
+ obj['PromotionHit']['HitQuantity'] = ""; // todo;
3798
+ obj['PromotionHit']['HitSaving'] = ""; // todo;
3799
+ obj['PromotionHit']['PromotionTrigger'] = {};
3800
+ element.trigger.forEach((/**
3801
+ * @param {?} subElement
3807
3802
  * @return {?}
3808
3803
  */
3809
- (item) => item.lineItemId == subElement.itemLineId));
3810
- objSub['XMLSchemaVersion'] = (/** @type {?} */ (this)).xmlSchemaVersion;
3811
- objSub['ProductID'] = (/** @type {?} */ (this)).transactionDocument.basket.products.find((/**
3812
- * @param {?} item
3813
- * @return {?}
3814
- */
3815
- (item) => item.itemLineId === subElement.itemLineId)).SKU;
3816
- objSub['UnitValue'] = (/** @type {?} */ (this)).convertToString(element.promotionLinePrice / product.quantity);
3817
- objSub['LineNumber'] = (/** @type {?} */ (this)).convertToString(subElement.itemLineId);
3818
- objSub['Quantity'] = (/** @type {?} */ (this)).convertToString(subElement.quantity.toFixed(1));
3819
- objSub['TaxCode'] = (/** @type {?} */ (this)).transactionDocument.basket.taxBreakdown.taxLines.find((/**
3820
- * @param {?} item
3821
- * @return {?}
3822
- */
3823
- (item) => item.itemLineId == element.itemLineId)).VATCode; // todo
3824
- obj['PromotionHit']['PromotionTrigger'].push(objSub);
3804
+ (subElement) => {
3805
+ /** @type {?} */
3806
+ let product = (/** @type {?} */ (this)).transactionDocument.basket.products.find((/**
3807
+ * @param {?} item
3808
+ * @return {?}
3809
+ */
3810
+ (item) => item.itemLineId == subElement.itemLineId));
3811
+ obj['PromotionHit']['PromotionTrigger']['XMLSchemaVersion'] = (/** @type {?} */ (this)).xmlSchemaVersion;
3812
+ obj['PromotionHit']['PromotionTrigger']['ProductID'] = product.SKU;
3813
+ obj['PromotionHit']['PromotionTrigger']['UnitValue'] = (/** @type {?} */ (this)).convertToString(element.promotionLinePrice / product.quantity);
3814
+ obj['PromotionHit']['PromotionTrigger']['LineNumber'] = (/** @type {?} */ (this)).convertToString(subElement.itemLineId);
3815
+ obj['PromotionHit']['PromotionTrigger']['Quantity'] = (/** @type {?} */ (this)).convertToString(subElement.quantity.toFixed(1));
3816
+ obj['PromotionHit']['PromotionTrigger']['TaxCode'] = (/** @type {?} */ (this)).transactionDocument.basket.taxBreakdown.taxLines.find((/**
3817
+ * @param {?} item
3818
+ * @return {?}
3819
+ */
3820
+ (item) => item.itemLineId == element.itemLineId)).VATCode; // todo
3821
+ }));
3822
+ (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'].push(obj);
3825
3823
  }));
3826
- (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'].push(obj);
3827
- }));
3828
- //console.log(this.rjObject);
3824
+ }
3829
3825
  return (/** @type {?} */ (this));
3830
3826
  }
3831
3827
  /**
@@ -4074,10 +4070,9 @@ class RJMapperBuilderClass {
4074
4070
  /**
4075
4071
  * @template THIS
4076
4072
  * @this {THIS}
4077
- * @param {?} value
4078
4073
  * @return {THIS}
4079
4074
  */
4080
- setCashierID(value) {
4075
+ setCashierID() {
4081
4076
  (/** @type {?} */ (this)).cashierId = ((/** @type {?} */ (this)).transactionDocument && (/** @type {?} */ (this)).transactionDocument.userName) ? (/** @type {?} */ (this)).transactionDocument.userName : '';
4082
4077
  return (/** @type {?} */ (this));
4083
4078
  }
@@ -4194,7 +4189,7 @@ class RJMapperBuilderClass {
4194
4189
  obj['DateTimeCreated'] = this.createdAt;
4195
4190
  obj['ExtendedValue'] = this.removeDecimal(element['totalLinePrice'] * -1);
4196
4191
  obj['UnitPrice'] = this.removeDecimal(element['price']);
4197
- obj['Quantity'] = element['refundedQuantity'] < 0 ? element['refundedQuantity'].toFixed(1) : (-element['refundedQuantity']).toFixed(1);
4192
+ obj['Quantity'] = this.getQuantity(element);
4198
4193
  obj['OriginalTaxAmountSet'] = 1;
4199
4194
  obj['ProductID'] = element['SKU'];
4200
4195
  obj['HandKeyed'] = 1;
@@ -4202,7 +4197,7 @@ class RJMapperBuilderClass {
4202
4197
  obj['Return'] = {};
4203
4198
  obj['Return']['ReturnReasonID'] = element['refundedReason'];
4204
4199
  obj['Return']['ReturnDescription'] = element['refundedReasonDescription'];
4205
- obj['Return']['ReturnToStock'] = element['refundedQuantity'] > 0 ? element['refundedQuantity'].toFixed(1) : -1 * element['refundedQuantity'].toFixed(1);
4200
+ obj['Return']['ReturnToStock'] = this.getQuantity(element);
4206
4201
  obj['TaxCode'] = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((/**
4207
4202
  * @param {?} item
4208
4203
  * @return {?}
@@ -4447,6 +4442,21 @@ class RJMapperBuilderClass {
4447
4442
  this.rjObject['BasketDiscount']['RoundingRule'] = 2;
4448
4443
  }
4449
4444
  }
4445
+ /**
4446
+ * @param {?} element
4447
+ * @return {?}
4448
+ */
4449
+ getQuantity(element) {
4450
+ /** @type {?} */
4451
+ let quantity;
4452
+ if (this.transactionDocument.unreferencedRefund) {
4453
+ quantity = element['quantity'] < 0 ? element['quantity'].toFixed(1) : (-element['quantity']).toFixed(1);
4454
+ }
4455
+ else {
4456
+ quantity = element['refundedQuantity'] < 0 ? element['refundedQuantity'].toFixed(1) : (-element['refundedQuantity']).toFixed(1);
4457
+ }
4458
+ return quantity;
4459
+ }
4450
4460
  }
4451
4461
  if (false) {
4452
4462
  /**