@pmcretail/mapper-library 0.0.11 → 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.
@@ -3516,8 +3516,8 @@ class RJMapperBuilderClass {
3516
3516
  }
3517
3517
  this.initilizeItemCount();
3518
3518
  this.setLineNumberForProducts();
3519
- this.createdAt = this.getdate(this.transactionDocument.createdAt);
3520
- this.updatedAt = this.getdate(this.transactionDocument.updatedAt);
3519
+ this.createdAt = this.getDate(this.transactionDocument.createdAt);
3520
+ this.updatedAt = this.getDate(this.transactionDocument.updatedAt);
3521
3521
  }
3522
3522
  /**
3523
3523
  * @template THIS
@@ -3601,6 +3601,12 @@ class RJMapperBuilderClass {
3601
3601
  (/** @type {?} */ (this)).rjObject['ProductSale'].push(data);
3602
3602
  (/** @type {?} */ (this)).getModifierItem(lineDiscount.length > 0 ? lineDiscount[0] : null, element.itemLineId);
3603
3603
  }));
3604
+ /** @type {?} */
3605
+ let transactionPromotion = [];
3606
+ if ((/** @type {?} */ (this)).transactionDocument.basket.transactionPromotion && (/** @type {?} */ (this)).transactionDocument.basket.transactionPromotion.length > 0) {
3607
+ transactionPromotion = (/** @type {?} */ (this)).transactionDocument.basket.transactionPromotion;
3608
+ (/** @type {?} */ (this)).getTransactionPromotion(transactionPromotion);
3609
+ }
3604
3610
  }
3605
3611
  else if ((/** @type {?} */ (this)).transactionDocument.type === TRANSACTION_TYPE.REFUND) {
3606
3612
  (/** @type {?} */ (this)).rjObject['ProductReturn'] = [];
@@ -3682,9 +3688,9 @@ class RJMapperBuilderClass {
3682
3688
  * @return {THIS}
3683
3689
  */
3684
3690
  getBasketDiscount() {
3685
- (/** @type {?} */ (this)).rjObject['BasketDiscount'] = [];
3686
3691
  if (!(/** @type {?} */ (this)).transactionDocument.basket.transactionDiscount)
3687
3692
  return (/** @type {?} */ (this));
3693
+ (/** @type {?} */ (this)).rjObject['BasketDiscount'] = [];
3688
3694
  (/** @type {?} */ (this)).transactionDocument.basket.transactionDiscount.forEach((/**
3689
3695
  * @param {?} element
3690
3696
  * @return {?}
@@ -3692,16 +3698,16 @@ class RJMapperBuilderClass {
3692
3698
  (element) => {
3693
3699
  /** @type {?} */
3694
3700
  let obj = {};
3695
- obj['XMLSchemaVersion'] = 1;
3696
- obj['NetValue'] = element.discountAmount < 0 ? element.discountAmount : -element.discountAmount;
3697
- obj['EffectiveNetValue'] = element.discountAmount < 0 ? element.discountAmount : -element.discountAmount;
3698
- 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;
3699
3705
  obj['UserID'] = (/** @type {?} */ (this)).transactionDocument.userName;
3700
3706
  obj['ReasonCodeID'] = element.reasonCode;
3701
- obj['DiscountType'] = element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1; // todo - compare values
3702
- obj['RoundingRule'] = 2;
3703
- obj['ModifiedLineNumber '] = element.itemLineIds;
3704
- 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());
3705
3711
  // obj['DiscountedValue'] = obj['discountAmount'] // todo - confirm value before discount;
3706
3712
  // obj['DiscountPercentage'] = obj['discountAmount'] / 100 ; // todo - optional
3707
3713
  (/** @type {?} */ (this)).rjObject['BasketDiscount'].push(obj);
@@ -3770,56 +3776,52 @@ class RJMapperBuilderClass {
3770
3776
  obj['TaxPercentage'] = element.VAT.toFixed(2); // todo
3771
3777
  (/** @type {?} */ (this)).rjObject['Trailer']['TaxItem'].push(obj);
3772
3778
  }));
3773
- // TODO: make Trailer object from promotion
3774
- (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'] = [];
3775
- (/** @type {?} */ (this)).transactionDocument.basket.linePromotion.forEach((/**
3776
- * @param {?} element
3777
- * @return {?}
3778
- */
3779
- (element) => {
3780
- /** @type {?} */
3781
- let obj = {};
3782
- obj['PromotionID'] = element.promotionId;
3783
- obj['PromotionSaving'] = element.promotionAmount < 0 ? element.promotionAmount : -element.promotionAmount;
3784
- obj['PromotionQuantity'] = ""; // todo - not avaialble
3785
- obj['PromotionDescription'] = element.displayText;
3786
- obj['PromotionHit']['XMLSchemaVersion'] = (/** @type {?} */ (this)).transactionDocument.storeId;
3787
- obj['PromotionHit']['HitNumber'] = ""; // todo;
3788
- obj['PromotionHit']['HitQuantity'] = ""; // todo;
3789
- obj['PromotionHit']['HitSaving'] = ""; // todo;
3790
- obj['PromotionHit']['PromotionTrigger'] = [];
3791
- element.trigger.forEach((/**
3792
- * @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
3793
3784
  * @return {?}
3794
3785
  */
3795
- (subElement) => {
3796
- /** @type {?} */
3797
- let objSub = {};
3786
+ (element) => {
3787
+ console.log('element', element);
3798
3788
  /** @type {?} */
3799
- let product = (/** @type {?} */ (this)).transactionDocument.basket.products.find((/**
3800
- * @param {?} item
3801
- * @return {?}
3802
- */
3803
- (item) => item.lineItemId == subElement.itemLineId));
3804
- objSub['XMLSchemaVersion'] = (/** @type {?} */ (this)).xmlSchemaVersion;
3805
- objSub['ProductID'] = (/** @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.itemLineId === subElement.itemLineId)).SKU;
3810
- objSub['UnitValue'] = (/** @type {?} */ (this)).convertToString(element.promotionLinePrice / product.quantity);
3811
- objSub['LineNumber'] = (/** @type {?} */ (this)).convertToString(subElement.itemLineId);
3812
- objSub['Quantity'] = (/** @type {?} */ (this)).convertToString(subElement.quantity.toFixed(1));
3813
- objSub['TaxCode'] = (/** @type {?} */ (this)).transactionDocument.basket.taxBreakdown.taxLines.find((/**
3814
- * @param {?} item
3815
- * @return {?}
3816
- */
3817
- (item) => item.itemLineId == element.itemLineId)).VATCode; // todo
3818
- 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);
3819
3823
  }));
3820
- (/** @type {?} */ (this)).rjObject['Trailer']['PromotionItem'].push(obj);
3821
- }));
3822
- //console.log(this.rjObject);
3824
+ }
3823
3825
  return (/** @type {?} */ (this));
3824
3826
  }
3825
3827
  /**
@@ -4068,10 +4070,9 @@ class RJMapperBuilderClass {
4068
4070
  /**
4069
4071
  * @template THIS
4070
4072
  * @this {THIS}
4071
- * @param {?} value
4072
4073
  * @return {THIS}
4073
4074
  */
4074
- setCashierID(value) {
4075
+ setCashierID() {
4075
4076
  (/** @type {?} */ (this)).cashierId = ((/** @type {?} */ (this)).transactionDocument && (/** @type {?} */ (this)).transactionDocument.userName) ? (/** @type {?} */ (this)).transactionDocument.userName : '';
4076
4077
  return (/** @type {?} */ (this));
4077
4078
  }
@@ -4188,7 +4189,7 @@ class RJMapperBuilderClass {
4188
4189
  obj['DateTimeCreated'] = this.createdAt;
4189
4190
  obj['ExtendedValue'] = this.removeDecimal(element['totalLinePrice'] * -1);
4190
4191
  obj['UnitPrice'] = this.removeDecimal(element['price']);
4191
- obj['Quantity'] = element['refundedQuantity'] < 0 ? element['refundedQuantity'].toFixed(1) : -element['refundedQuantity'].toFixed(1);
4192
+ obj['Quantity'] = this.getQuantity(element);
4192
4193
  obj['OriginalTaxAmountSet'] = 1;
4193
4194
  obj['ProductID'] = element['SKU'];
4194
4195
  obj['HandKeyed'] = 1;
@@ -4196,7 +4197,7 @@ class RJMapperBuilderClass {
4196
4197
  obj['Return'] = {};
4197
4198
  obj['Return']['ReturnReasonID'] = element['refundedReason'];
4198
4199
  obj['Return']['ReturnDescription'] = element['refundedReasonDescription'];
4199
- obj['Return']['ReturnToStock'] = element['refundedQuantity'] > 0 ? element['refundedQuantity'].toFixed(1) : -1 * element['refundedQuantity'].toFixed(1);
4200
+ obj['Return']['ReturnToStock'] = this.getQuantity(element);
4200
4201
  obj['TaxCode'] = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((/**
4201
4202
  * @param {?} item
4202
4203
  * @return {?}
@@ -4208,7 +4209,7 @@ class RJMapperBuilderClass {
4208
4209
  obj['MMGroupID'] = this.getAttributes();
4209
4210
  obj['CustomerDetails'] = ""; // todo - blank
4210
4211
  obj['TotalPromotionSaving'] = element['promotionAmount'] || -1; // TODO
4211
- obj['OriginalTaxAmount'] = this.convertToString(this.getoriginltax(element, taxTotal.VAT) * -1);
4212
+ obj['OriginalTaxAmount'] = this.convertToString(this.getOriginalTax(element, taxTotal.VAT) * -1);
4212
4213
  obj['taxAmount'] = taxTotal.taxLineTotal < 0 ? (taxTotal.taxLineTotal) : (-taxTotal.taxLineTotal);
4213
4214
  if (lineDiscount) {
4214
4215
  if (lineDiscount.percentageDiscountReasonName && lineDiscount.percentageDiscountReasonCode) {
@@ -4282,7 +4283,7 @@ class RJMapperBuilderClass {
4282
4283
  (item) => item.itemLineId == element['itemLineId'])).VATCode,
4283
4284
  TaxModifiable: 1,
4284
4285
  //todo
4285
- OriginalTaxAmount: this.convertToString(this.getoriginltax(element, taxTotal.VAT)),
4286
+ OriginalTaxAmount: this.convertToString(this.getOriginalTax(element, taxTotal.VAT)),
4286
4287
  TaxAmount: this.convertToString(taxTotal.taxLineTotal),
4287
4288
  OriginalTaxAmountSet: 1,
4288
4289
  //todo
@@ -4333,7 +4334,7 @@ class RJMapperBuilderClass {
4333
4334
  * @param {?} VAT
4334
4335
  * @return {?}
4335
4336
  */
4336
- getoriginltax(element, VAT) {
4337
+ getOriginalTax(element, VAT) {
4337
4338
  /** @type {?} */
4338
4339
  let pricebeforetax = (element.price * 100) / (100 + VAT);
4339
4340
  /** @type {?} */
@@ -4400,7 +4401,7 @@ class RJMapperBuilderClass {
4400
4401
  * @param {?} date
4401
4402
  * @return {?}
4402
4403
  */
4403
- getdate(date) {
4404
+ getDate(date) {
4404
4405
  /** @type {?} */
4405
4406
  let offset = this.generateTimezoneoffset(date) * -1;
4406
4407
  /** @type {?} */
@@ -4415,9 +4416,47 @@ class RJMapperBuilderClass {
4415
4416
  /** @type {?} */
4416
4417
  let newdate = date.substring(0, 19);
4417
4418
  /** @type {?} */
4418
- let x = (newdate + offsetSign + offsetHours + ':' + offsetMinutes).toString();
4419
+ const x = (newdate + offsetSign + String(offsetHours).padStart(2, '0') + ':' + String(offsetMinutes).padStart(2, '0')).toString();
4419
4420
  return x;
4420
4421
  }
4422
+ /**
4423
+ * @param {?} transactionPromotion
4424
+ * @return {?}
4425
+ */
4426
+ getTransactionPromotion(transactionPromotion) {
4427
+ if (transactionPromotion && transactionPromotion.length > 0) {
4428
+ this.rjObject['BasketDiscount'] = {};
4429
+ this.rjObject['BasketDiscount']['XMLSchemaVersion'] = 1;
4430
+ this.rjObject['BasketDiscount']['LineNumber'] = this.generateLineNumber();
4431
+ this.rjObject['BasketDiscount']['NetValue'] = this.removeDecimal(transactionPromotion[0].promotionLinePrice) * -1;
4432
+ this.rjObject['BasketDiscount']['EffectiveNetValue'] = this.removeDecimal(transactionPromotion[0].promotionLinePrice) * -1;
4433
+ this.rjObject['BasketDiscount']['Description'] = transactionPromotion[0].promotionInfo;
4434
+ this.rjObject['BasketDiscount']['DeviceID'] = this.deviceId;
4435
+ this.rjObject['BasketDiscount']['UserID'] = this.transactionDocument.userName;
4436
+ this.rjObject['BasketDiscount']['DateTimeCreated'] = this.createdAt;
4437
+ this.rjObject['BasketDiscount']['ModifiedLineNumber'] = transactionPromotion[0].itemLineIds;
4438
+ this.rjObject['BasketDiscount']['ReasonCodeID'] = 0;
4439
+ this.rjObject['BasketDiscount']['DiscountType'] = transactionPromotion[0].promotionType == 'TRANSACTION_OFF' ? 1 : 0;
4440
+ this.rjObject['BasketDiscount']['DiscountPercentage'] = 0; //todo
4441
+ this.rjObject['BasketDiscount']['DiscountedValue'] = 0; //todo
4442
+ this.rjObject['BasketDiscount']['RoundingRule'] = 2;
4443
+ }
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
+ }
4421
4460
  }
4422
4461
  if (false) {
4423
4462
  /**
@@ -4540,11 +4579,6 @@ if (false) {
4540
4579
  * @private
4541
4580
  */
4542
4581
  RJMapperBuilderClass.prototype.rjObject;
4543
- /**
4544
- * @type {?}
4545
- * @private
4546
- */
4547
- RJMapperBuilderClass.prototype.paymentTypes;
4548
4582
  }
4549
4583
 
4550
4584
  /**