@pmcretail/mapper-library 0.0.13 → 0.0.14

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.
@@ -3572,6 +3572,11 @@ class RJMapperBuilderClass {
3572
3572
  * @return {THIS}
3573
3573
  */
3574
3574
  rjMapper() {
3575
+ /** @type {?} */
3576
+ var transactionDiscount = [];
3577
+ if ((/** @type {?} */ (this)).transactionDocument.basket.transactionDiscount && (/** @type {?} */ (this)).transactionDocument.basket.transactionDiscount.length > 0) {
3578
+ transactionDiscount = (/** @type {?} */ (this)).transactionDocument.basket.transactionDiscount;
3579
+ }
3575
3580
  if ((/** @type {?} */ (this)).transactionDocument.type === TRANSACTION_TYPE.SALE) {
3576
3581
  (/** @type {?} */ (this)).rjObject['ProductSale'] = [];
3577
3582
  (/** @type {?} */ (this)).rjObject['ModifierItem'] = [];
@@ -3597,7 +3602,7 @@ class RJMapperBuilderClass {
3597
3602
  }
3598
3603
  }
3599
3604
  /** @type {?} */
3600
- let data = (/** @type {?} */ (this)).addProduct(element, (lineDiscount.length > 0 ? lineDiscount[0] : null));
3605
+ let data = (/** @type {?} */ (this)).addProduct(element, (lineDiscount.length > 0 ? lineDiscount[0] : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
3601
3606
  (/** @type {?} */ (this)).rjObject['ProductSale'].push(data);
3602
3607
  (/** @type {?} */ (this)).getModifierItem(lineDiscount.length > 0 ? lineDiscount[0] : null, element.itemLineId);
3603
3608
  }));
@@ -3617,7 +3622,7 @@ class RJMapperBuilderClass {
3617
3622
  */
3618
3623
  (element) => {
3619
3624
  /** @type {?} */
3620
- let data = (/** @type {?} */ (this)).returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null));
3625
+ let data = (/** @type {?} */ (this)).returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
3621
3626
  (/** @type {?} */ (this)).rjObject['ProductReturn'].push(data);
3622
3627
  (/** @type {?} */ (this)).getModifierItem(element.lineDiscount, element.itemLineId);
3623
3628
  }));
@@ -3633,7 +3638,7 @@ class RJMapperBuilderClass {
3633
3638
  */
3634
3639
  (element) => {
3635
3640
  /** @type {?} */
3636
- let data = (/** @type {?} */ (this)).returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null));
3641
+ let data = (/** @type {?} */ (this)).returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
3637
3642
  /** @type {?} */
3638
3643
  let obj = {
3639
3644
  "OriginalReceiptSupplied": 0,
@@ -3660,7 +3665,7 @@ class RJMapperBuilderClass {
3660
3665
  (element) => {
3661
3666
  if (element.refundedQuantity > 0) {
3662
3667
  /** @type {?} */
3663
- let returnProduct = (/** @type {?} */ (this)).returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null));
3668
+ let returnProduct = (/** @type {?} */ (this)).returnProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
3664
3669
  /** @type {?} */
3665
3670
  let obj = {
3666
3671
  "OriginalReceiptSupplied": 0,
@@ -3674,7 +3679,7 @@ class RJMapperBuilderClass {
3674
3679
  }
3675
3680
  else {
3676
3681
  /** @type {?} */
3677
- let addProduct = (/** @type {?} */ (this)).addProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null));
3682
+ let addProduct = (/** @type {?} */ (this)).addProduct(element, (element.hasOwnProperty('lineDiscount') ? element.lineDiscount : null), (transactionDiscount.length > 0 ? transactionDiscount : null));
3678
3683
  (/** @type {?} */ (this)).rjObject['ProductSale'].push(addProduct);
3679
3684
  }
3680
3685
  (/** @type {?} */ (this)).getModifierItem(element.lineDiscount, element.itemLineId);
@@ -3698,18 +3703,24 @@ class RJMapperBuilderClass {
3698
3703
  (element) => {
3699
3704
  /** @type {?} */
3700
3705
  let obj = {};
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);
3706
+ obj['XMLSchemaVersion'] = (/** @type {?} */ (this)).xmlSchemaVersion;
3707
+ obj['NetValue'] = (/** @type {?} */ (this)).convertToString(element.discountAmount * -1);
3708
+ obj['EffectiveNetValue'] = (/** @type {?} */ (this)).convertToString(element.discountAmount * -1);
3704
3709
  obj['Description'] = element.reasonDisplayText;
3705
3710
  obj['UserID'] = (/** @type {?} */ (this)).transactionDocument.userName;
3706
3711
  obj['ReasonCodeID'] = element.reasonCode;
3707
- obj['DiscountType'] = (/** @type {?} */ (this)).convertToString(element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1); // todo - compare values
3712
+ obj['DiscountType'] = (/** @type {?} */ (this)).convertToString(element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase() ? 0 : 1);
3708
3713
  obj['RoundingRule'] = (/** @type {?} */ (this)).convertToString(2);
3709
3714
  obj['ModifiedLineNumber'] = element.itemLineIds;
3710
3715
  obj['LineNumber'] = (/** @type {?} */ (this)).convertToString((/** @type {?} */ (this)).generateLineNumber());
3711
- // obj['DiscountedValue'] = obj['discountAmount'] // todo - confirm value before discount;
3712
- // obj['DiscountPercentage'] = obj['discountAmount'] / 100 ; // todo - optional
3716
+ obj['DiscountedValue'] = (/** @type {?} */ (this)).transactionDocument.basketSummary.basketTotal + (/** @type {?} */ (this)).transactionDocument.basketSummary.discountTotal;
3717
+ if (element.discountType.toUpperCase() == DISCOUNTTYPE.PERCENT.toUpperCase()) {
3718
+ obj['DiscountPercentage'] = (/** @type {?} */ (this)).convertToString((element.discountAmount / (/** @type {?} */ (this)).transactionDocument.basketSummary.basketTotal).toFixed(1));
3719
+ }
3720
+ if ((/** @type {?} */ (this)).transactionDocument.type === 'REFUND') {
3721
+ obj['NetValue'] = (/** @type {?} */ (this)).convertToString(element.discountAmount < 0 ? -element.discountAmount : element.discountAmount);
3722
+ obj['EffectiveNetValue'] = (/** @type {?} */ (this)).convertToString(element.discountAmount < 0 ? -element.discountAmount : element.discountAmount);
3723
+ }
3713
3724
  (/** @type {?} */ (this)).rjObject['BasketDiscount'].push(obj);
3714
3725
  }));
3715
3726
  return (/** @type {?} */ (this));
@@ -3784,7 +3795,6 @@ class RJMapperBuilderClass {
3784
3795
  * @return {?}
3785
3796
  */
3786
3797
  (element) => {
3787
- console.log('element', element);
3788
3798
  /** @type {?} */
3789
3799
  let obj = {};
3790
3800
  obj['PromotionID'] = element.promotionId;
@@ -4168,9 +4178,10 @@ class RJMapperBuilderClass {
4168
4178
  /**
4169
4179
  * @param {?} element
4170
4180
  * @param {?} lineDiscount
4181
+ * @param {?} transactionDiscount
4171
4182
  * @return {?}
4172
4183
  */
4173
- returnProduct(element, lineDiscount) {
4184
+ returnProduct(element, lineDiscount, transactionDiscount) {
4174
4185
  /** @type {?} */
4175
4186
  let obj = {};
4176
4187
  /** @type {?} */
@@ -4245,14 +4256,51 @@ class RJMapperBuilderClass {
4245
4256
  obj.ExtendedValue = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount) * -1;
4246
4257
  obj.UnitPrice = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount) * -1;
4247
4258
  }
4259
+ if (transactionDiscount) {
4260
+ obj['BasketDiscountModifier'] = [];
4261
+ this.transactionDocument.basket.transactionDiscount.forEach((/**
4262
+ * @param {?} e
4263
+ * @return {?}
4264
+ */
4265
+ (e) => {
4266
+ /** @type {?} */
4267
+ let obj1 = {};
4268
+ e.itemLineIds.forEach((/**
4269
+ * @param {?} x
4270
+ * @return {?}
4271
+ */
4272
+ (x) => {
4273
+ if (x == element.itemLineId) {
4274
+ /** @type {?} */
4275
+ var discountAmount = this.convertToString(e.discountAmount * -1);
4276
+ obj1.BasketDiscountLineNumber = this.getLineNumber(e, discountAmount);
4277
+ obj1.XMLSchemaVersion = this.xmlSchemaVersion;
4278
+ obj1.DiscountedValue = this.getDiscountedValue(element.totalLinePrice, e.discountAmount);
4279
+ obj['BasketDiscountModifier'].push(obj1);
4280
+ }
4281
+ }));
4282
+ }));
4283
+ /** @type {?} */
4284
+ var totaltransactionDiscount = 0;
4285
+ obj['BasketDiscountModifier'].forEach((/**
4286
+ * @param {?} value
4287
+ * @return {?}
4288
+ */
4289
+ (value) => {
4290
+ totaltransactionDiscount = totaltransactionDiscount + value.DiscountedValue;
4291
+ }));
4292
+ //update the product price
4293
+ obj['EffectiveNetValue'] = obj.EffectiveNetValue + totaltransactionDiscount;
4294
+ }
4248
4295
  return obj;
4249
4296
  }
4250
4297
  /**
4251
4298
  * @param {?} element
4252
4299
  * @param {?} lineDiscount
4300
+ * @param {?} transactionDiscount
4253
4301
  * @return {?}
4254
4302
  */
4255
- addProduct(element, lineDiscount) {
4303
+ addProduct(element, lineDiscount, transactionDiscount) {
4256
4304
  /** @type {?} */
4257
4305
  let taxTotal = this.transactionDocument.basket['taxBreakdown']['taxLines'].find((/**
4258
4306
  * @param {?} item
@@ -4317,7 +4365,7 @@ class RJMapperBuilderClass {
4317
4365
  obj['PriceOverride'].ModifierReasonID = lineDiscount.priceOverrideReasonCode;
4318
4366
  obj['PriceOverride'].ModifierReasonDescription = lineDiscount.priceOverrideReasonName;
4319
4367
  obj['PriceOverride'].AuthorisingUserID = this.transactionDocument.userName;
4320
- obj['PriceOverride'].XMLSchemaVersion = 1;
4368
+ obj['PriceOverride'].XMLSchemaVersion = this.xmlSchemaVersion;
4321
4369
  obj['PriceOverride'].NewPrice = this.removeDecimal(lineDiscount.unitPrice);
4322
4370
  obj['PriceOverride'].OriginalPrice = this.removeDecimal(lineDiscount.discountedLinePrice || 0 + lineDiscount.discountAmount);
4323
4371
  }
@@ -4327,8 +4375,72 @@ class RJMapperBuilderClass {
4327
4375
  obj['ExtendedValue'] = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount);
4328
4376
  obj['UnitPrice'] = ((lineDiscount.discountedLinePrice || 0) + lineDiscount.discountAmount);
4329
4377
  }
4378
+ if (transactionDiscount) {
4379
+ obj['BasketDiscountModifier'] = [];
4380
+ this.transactionDocument.basket.transactionDiscount.forEach((/**
4381
+ * @param {?} e
4382
+ * @return {?}
4383
+ */
4384
+ (e) => {
4385
+ /** @type {?} */
4386
+ var obj1 = {};
4387
+ e.itemLineIds.forEach((/**
4388
+ * @param {?} x
4389
+ * @return {?}
4390
+ */
4391
+ (x) => {
4392
+ if (x == element.itemLineId) {
4393
+ /** @type {?} */
4394
+ var discountAmount = this.convertToString(e.discountAmount * -1);
4395
+ obj1.XMLSchemaVersion = this.xmlSchemaVersion;
4396
+ obj1.DiscountedValue = -(this.getDiscountedValue(element.totalLinePrice, e.discountAmount).toFixed(0));
4397
+ obj1.BasketDiscountLineNumber = this.getLineNumber(e, discountAmount);
4398
+ obj['BasketDiscountModifier'].push(obj1);
4399
+ }
4400
+ }));
4401
+ }));
4402
+ /** @type {?} */
4403
+ var totaltransactionDiscount = 0;
4404
+ obj['BasketDiscountModifier'].forEach((/**
4405
+ * @param {?} value
4406
+ * @return {?}
4407
+ */
4408
+ (value) => {
4409
+ totaltransactionDiscount = totaltransactionDiscount + value.DiscountedValue;
4410
+ }));
4411
+ //update the product price
4412
+ obj['EffectiveNetValue'] = obj.EffectiveNetValue + totaltransactionDiscount;
4413
+ }
4330
4414
  return obj;
4331
4415
  }
4416
+ /**
4417
+ * @param {?} value
4418
+ * @param {?} discountAmount
4419
+ * @return {?}
4420
+ */
4421
+ getLineNumber(value, discountAmount) {
4422
+ /** @type {?} */
4423
+ let lineNumber;
4424
+ for (let i = 0; i < this.rjObject['BasketDiscount'].length; i++) {
4425
+ /** @type {?} */
4426
+ const element = this.rjObject['BasketDiscount'][i];
4427
+ if (value.reasonCode === element.ReasonCodeID && discountAmount === element.NetValue) {
4428
+ lineNumber = element.LineNumber;
4429
+ break;
4430
+ }
4431
+ }
4432
+ return lineNumber;
4433
+ }
4434
+ /**
4435
+ * @param {?} price
4436
+ * @param {?} discountAmount
4437
+ * @return {?}
4438
+ */
4439
+ getDiscountedValue(price, discountAmount) {
4440
+ /** @type {?} */
4441
+ let DiscountedValue = (price * discountAmount) / this.transactionDocument.basketSummary.saleTotal;
4442
+ return DiscountedValue;
4443
+ }
4332
4444
  /**
4333
4445
  * @param {?} element
4334
4446
  * @param {?} VAT
@@ -4351,7 +4463,7 @@ class RJMapperBuilderClass {
4351
4463
  return value;
4352
4464
  }
4353
4465
  catch (e) {
4354
- console.log(value, ' can not be converted in string', e);
4466
+ console.log(value, 'can not be converted in string', e);
4355
4467
  }
4356
4468
  }
4357
4469
  /**