@pmcretail/mapper-library 0.0.21 → 0.0.23
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.
- package/bundles/pmcretail-mapper-library.umd.js +2 -2
- package/bundles/pmcretail-mapper-library.umd.js.map +1 -1
- package/bundles/pmcretail-mapper-library.umd.min.js +1 -1
- package/bundles/pmcretail-mapper-library.umd.min.js.map +1 -1
- package/esm2015/lib/WebReturn-mapper.class.js +3 -3
- package/esm5/lib/WebReturn-mapper.class.js +3 -3
- package/fesm2015/pmcretail-mapper-library.js +2 -2
- package/fesm2015/pmcretail-mapper-library.js.map +1 -1
- package/fesm5/pmcretail-mapper-library.js +2 -2
- package/fesm5/pmcretail-mapper-library.js.map +1 -1
- package/package.json +1 -1
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */var o=function(){return(o=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(a(arguments[e]));return t}var c=function(){function t(){}return t.prototype.ngOnInit=function(){},t.decorators=[{type:e.Component,args:[{selector:"lib-mapper-library",template:"\n <p>\n mapper-library works!\n </p>\n "}]}],t.ctorParameters=function(){return[]},t}(),u=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[c],imports:[],exports:[c]}]}],t}(),m="SALE",d="REFUND",l="SALE_REFUND",h="SALE_EXCHANGE";var p={DELIVERY:1,DROP_SHIP:2,COLLECT_FROM_STORE:3};p[p.DELIVERY]="DELIVERY",p[p.DROP_SHIP]="DROP_SHIP",p[p.COLLECT_FROM_STORE]="COLLECT_FROM_STORE";var D={PERCENT:"Percent",AMOUNT:"AMOUNT"},b=function(){function t(t){this.numberUtilService=t,this.currentBasket={products:[],transactionDiscount:[],quantity:0,total:0,saleTotal:0,baseCurrency:""},this.basketSource=new n.BehaviorSubject(null),this.basket=this.basketSource.asObservable(),this.productSource=new n.BehaviorSubject(null),this.product=this.productSource.asObservable(),this.peerSource=new n.BehaviorSubject(!1),this.peerSync=this.peerSource.asObservable(),this.scanSource=new n.BehaviorSubject(!1),this.scanner=this.scanSource.asObservable()}return Object.defineProperty(t.prototype,"isMixedBasketSales",{get:function(){return this._isMixedBasketSales},set:function(t){this._isMixedBasketSales=t},enumerable:!0,configurable:!0}),t.prototype.updateBasket=function(t){this.currentBasket=t,this.isMixedBasketSales=this.filterProductListWithWebOrder(!0).length>0,this.basketSource.next(t)},t.prototype.updateBasketTotal=function(t,e){var n,i;t.quantity=0,t.total=0;try{for(var o=r(t.products),a=o.next();!a.done;a=o.next()){var s=a.value;t.quantity=t.quantity+s.quantity,t.total=this.numberUtilService.trimTo2Decimal(t.total)+this.numberUtilService.trimTo2Decimal(s.total)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}console.log("e:basket :basket service : basketDetails updated values for transaction id",t.transactionId,JSON.stringify(t)),t.basketTotal=t.total,e.updateBasket(t)},t.prototype.addlinePromotion=function(t,e){var n,i,o,a;if(console.log("e:basket :basket Service : promotionList and basketDetails for linePromotions",JSON.stringify(t),JSON.stringify(e)),t&&t.result&&t.result.linePromotions&&t.result.linePromotions.length>0)try{for(var s=r(e.products),c=s.next();!c.done;c=s.next()){var u=c.value;try{for(var m=(o=void 0,r(t.result.linePromotions)),d=m.next();!d.done;d=m.next()){var l=d.value;u.itemLineId.toString()===l.itemLineId.toString()&&(u.linePromotions=l)}}catch(t){o={error:t}}finally{try{d&&!d.done&&(a=m.return)&&a.call(m)}finally{if(o)throw o.error}}}}catch(t){n={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return e},t.prototype.addTransactionPromotion=function(t,e){var n=this;return console.log("e:basket :basket Service : promotionList and basketDetails for transactionPromotion",JSON.stringify(t),JSON.stringify(e),JSON.stringify(e.transactionPromotion)),t&&t.result&&t.result.transactionPromotion&&t.result.transactionPromotion.length>0&&t.result.transactionPromotion.forEach((function(t){var i=Object.assign({},t);i.itemLineIds=e.products.map((function(t){return t.itemLineId})),e.transactionPromotion||(e.transactionPromotion=[]),e.transactionPromotion.push(i),e=n.transactionPromotionProductPortionCalc(e,i)})),console.log("basket details in refund calculation file",JSON.stringify(e)),e},t.prototype.updateProductTotalForSummary=function(t){var e,n;t.total=0,t.quantity=0;try{for(var i=r(t.products),o=i.next();!o.done;o=i.next()){var a=o.value;a.linePromotions?a.total=a.linePromotions.promotionLinePrice:a.lineDiscount&&!a.linePromotions?a.total=a.lineDiscount.discountedLinePrice:a.total=a.totalLinePrice,a.total=a.total-Math.abs(a.refundedTotal?a.refundedTotal:0),t.total+=a.total,t.quantity=t.quantity+(a.quantity-(a.refundedQuantity?a.refundedQuantity:0)),console.log("e-basket:ExchangeSummaryScreen:update basketdetails total :"+t.total+" Product line ID : "+a.itemLineId+" product total : "+a.total,"quantity : "+t.quantity)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return this.updateBasketTotalForSummary(t)},t.prototype.updateBasketTotalForSummary=function(t){return t.basketTotal=t.total,console.info("ebasket : basket Service : update Basket Total for transaction transactionDiscount ",JSON.stringify(t.transactionDiscount)),console.info("ebasket : basket Service : update Basket Total for transaction transactionPromotion ",JSON.stringify(t.transactionPromotion)),t=this.updateTransactionPromotion(t),(t=this.updateTransactionDiscount(t)).basketTotal=Number(t.basketTotal.toFixed(2)),console.info("ebasket : basket Service : update Basket Total: basketTotal after promotion applied for basketTotal",t.basketTotal),t},t.prototype.updateTransactionDiscount=function(t){if(t.transactionDiscount&&t.transactionDiscount.length>0){var e=t.transactionDiscount.reduce((function(t,e){return t+e.discountAmount}),0);console.log("ebasket : basket Service : discountTotal ",e),t.basketTotal=t.basketTotal-Math.abs(e)}return t},t.prototype.updateTransactionPromotion=function(t){if(t.transactionPromotion&&t.transactionPromotion.length>0){var e=t.transactionPromotion.reduce((function(t,e){return t+e.promotionAmount}),0);t.basketTotal=t.basketTotal-Math.abs(e)}return t},t.prototype.updateBasketTotalWithoutDiscount=function(t){var e,n;t.total=0,t.quantity=0;try{for(var i=r(t.products),o=i.next();!o.done;o=i.next()){var a=o.value;a.linePromotions?a.total=a.linePromotions.promotionLinePrice:a.lineDiscount&&!a.linePromotions?a.total=a.lineDiscount.discountedLinePrice||0:a.total=a.totalLinePrice,a.total=a.total-Math.abs(a.refundedTotal?a.refundedTotal:0),t.total+=a.total,t.quantity=t.quantity+(a.quantity-(a.refundedQuantity?a.refundedQuantity:0)),console.log("e-basket:basket service:update basketdetails total :"+JSON.stringify(t)+t.total+" Product line ID : "+a.itemLineId+" product total : "+a.total)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return t.basketTotal=t.total,t},t.prototype.updateBasketTotalWithDiscounts=function(t){if(console.log("e:basket :RefundBasketScreen : this.basketDetails new values",t,JSON.stringify(t.basketTotal)),t.transactionPromotion&&t.transactionPromotion.length>0){var e=t.transactionPromotion.reduce((function(t,e){return t+e.promotionAmount}),0);t.basketTotal=t.basketTotal-e}if(t.transactionDiscount&&t.transactionDiscount.length>0){e=t.transactionDiscount.reduce((function(t,e){return t+e.discountAmount}),0);t.basketTotal=t.basketTotal-e}return console.log("e:basket :RefundBasketScreen : basket new values",JSON.stringify(t)),t},t.prototype.transactionDiscountAndPromotionProductortionCalculation=function(t){var e=this;return t.transactionDiscount&&t.transactionDiscount.length>0&&t.transactionDiscount.forEach((function(n){return t=e.transactionDiscountProductPortionCalc(t,n)})),t.transactionPromotion&&t.transactionPromotion.length>0&&t.transactionPromotion.forEach((function(n){t=e.transactionPromotionProductPortionCalc(t,n)})),console.log("ebasket: basket item discount protion calculation",t,t.products),t},t.prototype.transactionPromotionProductPortionCalc=function(t,e){var n=this,i=0,o=0;return t.products.forEach((function(t){if(e.itemLineIds.includes(t.itemLineId)){t=n.validateProductItemDiscount(t);var o=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);i+=t.total-n.numberUtilService.trimTo2Decimal2(o)}})),console.log("ebasket: trnsactionPromotion: "+JSON.stringify(e)+", selected products total: "+i),t.products.forEach((function(t){t=n.validateProductItemDiscount(t);var r=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);e.itemLineIds.includes(t.itemLineId)&&(o=(t.total-n.numberUtilService.trimTo2Decimal2(r))/i*100,t.itemDiscounts.trnPromotionsPortion+=e.promotionAmount*o/100,t.itemDiscounts.trnPromotionsPortion=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion))})),t},t.prototype.transactionDiscountProductPortionCalc=function(t,e){var n=this,i=0,o=0;return t.products.forEach((function(t){if(e.itemLineIds.includes(t.itemLineId)){t=n.validateProductItemDiscount(t);var o=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);i+=t.total-n.numberUtilService.trimTo2Decimal2(o)}})),console.log("ebasket: trnsactionDiscount: "+JSON.stringify(e)+", selected products total: "+i),t.products.forEach((function(t){t=n.validateProductItemDiscount(t),console.log(t.discountable,"ebasket : basket service : discountable in basket service");var r=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);e.itemLineIds.includes(t.itemLineId)&&1==t.discountable&&(o=(t.total-n.numberUtilService.trimTo2Decimal2(r))/i*100,t.itemDiscounts.trnDiscountsPortion+=e.discountAmount*o/100,t.itemDiscounts.trnDiscountsPortion=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion))})),t},t.prototype.validateProductItemDiscount=function(t){return t.itemDiscounts||(t.itemDiscounts={trnDiscountsPortion:0,trnPromotionsPortion:0,refundPortion:0}),t},t.prototype.markProduct=function(t){this.productSource.next(t)},t.prototype.stopPeerSyncProcess=function(t){this.peerSource.next(t)},t.prototype.scanStart=function(t){this.scanSource.next(t)},t.prototype.promotionRemainingCalculation=function(t){var e=0;return t.forEach((function(t){e+=t.promotionAmount})),e},t.prototype.discountRemainingCalculation=function(t){var e=0;return t.forEach((function(t){e+=t.discountAmount})),e},t.prototype.discountRefundedCalculation=function(t){var e=0;return t.forEach((function(t){t.discountAmount<0&&(e+=t.discountAmount)})),e},t.prototype.generateNewItemLineId=function(t){var e=0;t.length>0&&(e=t.map((function(t){return t.itemLineId})).reduce((function(t,e){return Math.max(t,e)})));return e+1},t.prototype.updateBasketProductDataAsPerQuantity=function(t,e){return console.log("ebasket: updateBasketProductDataAsPerQuantity : "+e+" product: "+JSON.stringify(t)),t.quantity=e,t.hasOwnProperty("lineDiscount")?(t.lineDiscount.discountedLinePrice=Number(this.numberUtilService.getFlooredFixed(t.lineDiscount.unitPrice*e,2)),t.lineDiscount.discountAmount=t.totalLinePrice-t.lineDiscount.discountedLinePrice):t.totalLinePrice=e*this.numberUtilService.trimTo2Decimal(t.selectedPrice),t.lineDiscount?t.total=t.lineDiscount.discountedLinePrice:t.total=t.totalLinePrice,console.log("ebasket: updateBasketProductDataAsPerQuantity : "+e+" product: "+JSON.stringify(t)),t},t.prototype.filterProductListWithWebOrder=function(t){return console.log("ebasket: filterProductListWithWebOrder hit",JSON.stringify(this.currentBasket.products)),t?this.currentBasket.products.filter((function(t){return t.isWebOrder})):this.currentBasket.products.filter((function(t){return!t.isWebOrder}))},t.prototype.filterProductListWithDelivery=function(){return console.log("ebasket: filterProductListWithDelivery hit",JSON.stringify(this.currentBasket.products)),this.currentBasket.products.filter((function(t){return t.deliveryMethod===p.DELIVERY.toString()}))},t.prototype.filterProductListWithDeliveryGroup=function(t,e){return console.log("ebasket: filterProductListWithDeliveryGroup hit",JSON.stringify(e)),e.filter((function(e){return e.deliveryGroup===t}))},t.prototype.generateNewDeliveryGroupNumber=function(t){var e=0;t.length>0&&(e=t.map((function(t){return t.deliveryGroup?parseInt(t.deliveryGroup):0})).reduce((function(t,e){return Math.max(t,e)})));return(e+1).toString()},t.prototype.getDeliveryGroupNumbers=function(t){console.log("getDeliveryGroupNumbers initiating : ",JSON.stringify(t));var e=[];if(t.length>0){var n=t.map((function(t){return t.deliveryGroup?parseInt(t.deliveryGroup):"1"===t.deliveryMethod?1:0}));e=Array.from(new Set(n)).sort((function(t,e){return t-e})),console.log("getDeliveryGroupNumbers : ",JSON.stringify(e))}return e},t.prototype.updateProductsWithNewDeliveryGroupNumber=function(t){console.log("updateProductsWithNewDeliveryGroupNumber initiating : ",JSON.stringify(t));var e=this.generateNewDeliveryGroupNumber(this.currentBasket.products);t.length>0&&this.currentBasket.products.forEach((function(n){t.forEach((function(t){n.itemLineId===t.itemLineId&&(n.deliveryGroup=e)}))})),this.updateBasket(this.currentBasket)},t.prototype.calculateEstimatedTime=function(t){try{var e,n=0,i="Hours";return t.forEach((function(t){"weeks"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value)*7,n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("week",n,i)):"days"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value),n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("days",n,i)):"months"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value)*30,n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("months",n,i)):"years"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value)*365,n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("years",n,i)):(e=Number(t.leadTime.value),n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("hours",n,i))})),"days"===i.toLocaleLowerCase()?n/=24:"weeks"===i.toLocaleLowerCase()?n/=168:"months"===i.toLocaleLowerCase()?n/=720:"years"===i.toLocaleLowerCase()&&(n/=8760),{value:n.toString(),type:i}}catch(t){console.log("error in calculateEstimatedTime",t)}return 0},t.prototype.updateProductsWithDeliveryGroupNumber=function(t,e){console.log("updateProductsWithDeliveryGroupNumber initiating"),this.currentBasket.products.forEach((function(n){n.deliveryGroup===t&&(n.deliveryGroup=e)})),this.updateBasket(this.currentBasket)},t.prototype.getDeliveryInfo=function(){var t=this;console.log("getDeliveryGroupInfor initiating");try{var e={groups:[]};return this.getDeliveryGroupNumbers(this.currentBasket.products).forEach((function(n){var i={groupNumber:n,items:[],estimate:{type:"Hours",value:"0"}};t.currentBasket.products.forEach((function(t){t.deliveryGroup===n.toString()&&i.items.push(t)})),i.estimate=t.calculateEstimatedTime(i.items),e.groups.push(i)})),e}catch(t){console.log("error",t)}},t}();var f=function(){function t(t){this.cp=t}return t.prototype.trimTo2Decimal=function(t){return t},t.prototype.trimTo2Decimal2=function(t){return Number(this.getFlooredFixed(t,2))},t.prototype.getFlooredFixed=function(t,e){return(Math.floor(t*Math.pow(10,e))/Math.pow(10,e)).toFixed(e)},t.prototype.AppendWithCurrencySymbol=function(t,e){var n="";if(t){parseFloat(t.toString().replace(",",""));n=this.cp.transform(Number(t).toFixed(2),e.toLocaleUpperCase(),"symbol"),console.log("AppendWithCurrencySymbol :"+n)}else n=this.cp.transform("0.00",e.toLocaleUpperCase(),"symbol");return n},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:i.CurrencyPipe}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(i.CurrencyPipe))},token:t,providedIn:"root"}),t}();var T=function(){function t(t,e,n){this.currencyPipe=e,this.basketService=n,this.numberUtilService=new f(e),this.basketService=new b(this.numberUtilService),this.storeInfo=JSON.parse(localStorage.getItem("storeInfo")||"{}"),this.transactionDocument=t||{transactionId:"",offlineTransactionId:"",transactionRef:"",dateTime:"",orgCode:"",storeId:"",storeNodeId:"",storeNodeStructure:"",deviceId:"",terminalId:"",userId:"",initiatingModule:"eBasket",export:!1,basket:{},basketSummary:{},baseCurrency:"",type:"",operationStatus:"",createdAt:"",updatedAt:"",id:"",currentTransactionDetails:{},saleTotal:0}}return t.prototype.transactionRef=function(){var t=JSON.parse(localStorage.getItem("storeInfo")||"{}"),e=new Date,n=(65536*(1+Math.random())|0).toString(16).substring(1);return this.transactionDocument.transactionRef=t.orgCode+t.storeId+e.toISOString()+n,console.log("ebasket: transaction ref created",this.transactionDocument.transactionRef),this},t.prototype.transactionId=function(t,e){return void 0===e&&(e=!0),e&&(this.transactionDocument.transactionId=t),this},t.prototype.offlineTransactionId=function(t,e){return e||(this.transactionDocument.offlineTransactionId=t),this},t.prototype.storeNodeId=function(t){return this.transactionDocument.storeNodeId=t,this},t.prototype.storeNodeStructure=function(t){return this.transactionDocument.storeNodeStructure=t,this},t.prototype.orgCode=function(t){return this.transactionDocument.orgCode=t,this},t.prototype.storeId=function(t){return this.transactionDocument.storeId=t,this},t.prototype.dateTime=function(){var t=new Date;return this.transactionDocument.dateTime=t.toISOString(),this},t.prototype.deviceId=function(t){return this.transactionDocument.deviceId=t,this},t.prototype.terminalId=function(t){return this.transactionDocument.terminalId=t,this},t.prototype.export=function(t){return this.transactionDocument.export=t,this},t.prototype.basket=function(t){var e=this;return console.log("ebasket: basket details update in transaction document",JSON.stringify(t)),this.transactionDocument.subsidiaryId=t.subsidiaryId||localStorage.getItem("subsidiaryId")||"",this.transactionDocument.basket.products=[],this.transactionDocument.basket.lineDiscount=[],this.transactionDocument.basket.linePromotion=[],this.transactionDocument.basket.transactionPromotion=[],t.products.forEach((function(n,i){var o={itemDiscounts:{}};o.SKU=n.SKU,o.excludePromotion=n.excludePromotion,o.barCode=n.barcode,o.barcodes=n.barcodes,o.description=n.description,o.itemLineId=n.itemLineId?n.itemLineId.toString():""+(i+1),o.price=n.selectedPrice,o.quantity=n.quantity,o.totalLinePrice=n.quantity*n.selectedPrice,o.imageUrls=n.imageUrls,o.selectedRRPPrice=n.selectedRRPPrice,o.fullfilmentId=n.fullfilmentId?n.fullfilmentId:e.storeInfo.storeId,o.fullfilmentLocationName=n.fullfilmentLocationName,o.deliveryGroup=n.deliveryGroup,o.leadTime=n.leadTime,o.deliveryMethod=n.deliveryMethod,o.giftCard=n.giftCard,o.giftCardExpiryDate=n.giftCardExpiryDate,o.giftCardNumberIssued=n.giftCardNumberIssued,o.giftCardRecipientEmail=n.giftCardRecipientEmail,o.giftCardRecipientName=n.giftCardRecipientName,n.refundedQuantity>0&&(o.refundedQuantity=n.refundedQuantity,o.refundedPromotionalQuantity=n.refundPromotionalQuantity,o.refunded=n.refunded,o.refundedReasonDescription=n.refundedReasonDescription,o.refundedReason=n.refundedReason,o.refundedReasonDescription||(o.refundedReasonDescription=o.refundedReason),o.refundedTotal=n.refundedTotal,o.isLastExchanged=n.isLastExchanged),n.exchange&&(o.exchange=n.exchange),n.lineDiscount&&(o.lineDiscount=n.lineDiscount),o.itemDiscounts=n.itemDiscounts,e.transactionDocument.basket.products.push(o),e.lineDiscount(t)})),console.info("ebasket: transactiondocument basket details updated",JSON.stringify(this.transactionDocument.basket)),this},t.prototype.currentTransactionDetails=function(t){var e,n=this;if(console.log("ebasket: current transaction details for exchanges",t),this.transactionDocument.currentTransactionDetails.products=[],this.transactionDocument.currentTransactionDetails.linePromotion=[],this.transactionDocument.currentTransactionDetails.lineDiscount=[],this.transactionDocument.currentTransactionDetails.transactionDiscount=[],this.transactionDocument.currentTransactionDetails.products=t.products,this.transactionDocument.currentTransactionDetails.products=this.transactionDocument.currentTransactionDetails.products.filter((function(t){return 0!=t.refundedQuantity})),this.transactionDocument.currentTransactionDetails.products.forEach((function(t){t.refundedQuantity&&(t.quantity=t.refundedQuantity,t.totalLinePrice=Math.abs(t.refundedTotal),t.total=t.totalLinePrice,t.quantity===t.refundedQuantity&&(t.refunded=!0)),t.linePromotions&&!t.refundedQuantity&&n.transactionDocument.currentTransactionDetails.linePromotion.push(t.linePromotions),t.lineDiscount&&!t.refundedQuantity&&n.transactionDocument.currentTransactionDetails.lineDiscount.push(t.lineDiscount)})),console.log("ebasket: current transaction details after removing old products",this.transactionDocument.currentTransactionDetails.products),t.transactionDiscount&&t.transactionDiscount.length>0&&(e=this.transactionDocument.currentTransactionDetails.transactionDiscount).push.apply(e,s(t.transactionDiscount)),this.transactionDocument.currentTransactionDetails.basketSummary={},this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal=this.numberUtilService.trimTo2Decimal2(this.updateSaleTotal(this.transactionDocument.currentTransactionDetails)),this.transactionDocument.currentTransactionDetails.basketSummary.totalItems=t.quantity,this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal=t.basketTotal,this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal=this.updateCurrentTransactionDetailsRefundTotal(),this.transactionDocument.type===h)this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal=this.numberUtilService.trimTo2Decimal2(this.updateCurrentTransactionDetailsDiscountTotal());else if(this.transactionDocument.currentTransactionDetails.transactionDiscount&&this.transactionDocument.currentTransactionDetails.transactionDiscount.length>0){var i=0;this.transactionDocument.currentTransactionDetails.transactionDiscount.forEach((function(t){i+=t.discountAmount})),this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal=Math.abs(i)}else this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal=0;return console.log("ebasket:this.transactionDocument.currentTransactionDetails",JSON.stringify(this.transactionDocument.currentTransactionDetails)),this},t.prototype.updateCurrentTransactionDetailsTaxBreakdown=function(t){var e=this,n={taxLines:[],totalTaxableAmount:0};return this.transactionDocument.currentTransactionDetails.transactionDiscount&&this.transactionDocument.currentTransactionDetails.transactionDiscount.length>0&&this.transactionDocument.currentTransactionDetails.transactionDiscount.forEach((function(t){t.discountAmount})),this.transactionDocument.currentTransactionDetails.products&&this.transactionDocument.currentTransactionDetails.products.length>0&&this.transactionDocument.currentTransactionDetails.products.forEach((function(i){var o={itemLineId:i.itemLineId,VAT:i.selectedVAT?i.selectedVAT:0,VATCode:i.selectedVATCode,taxLineTotal:0,taxableAmount:i.total,PreTax:0};console.info("Product contribution : item line ID :current transaction Details",i.itemLineId,"tax line :",JSON.stringify(o),JSON.stringify(t.basketTotal)),i.refundedQuantity&&i.refundedQuantity>0?o.taxableAmount=-Math.abs(o.taxableAmount-i.itemDiscounts.currentRefundPortion):o.taxableAmount=o.taxableAmount-i.itemDiscounts.trnDiscountsPortion-i.itemDiscounts.trnPromotionsPortion,o.PreTax=e.numberUtilService.trimTo2Decimal2(100*o.taxableAmount/(100+o.VAT)),n.totalTaxableAmount+=o.taxableAmount,o.taxableAmount=e.numberUtilService.trimTo2Decimal2(o.taxableAmount),o.taxLineTotal=e.numberUtilService.trimTo2Decimal2(o.taxableAmount-o.PreTax),n.taxLines.push(o)})),n.totalTaxableAmount=this.numberUtilService.trimTo2Decimal2(n.totalTaxableAmount),this.transactionDocument.currentTransactionDetails.taxBreakdown=n,this.transactionDocument.currentTransactionDetails.taxBreakdown&&this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines&&this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.length>0?this.transactionDocument.currentTransactionDetails.basketSummary.VATTotal=this.numberUtilService.trimTo2Decimal2(this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.reduce((function(t,e){return t+e.taxLineTotal}),0)):this.transactionDocument.currentTransactionDetails.basketSummary.VATTotal=0,console.log("eBasket:after calculating tax currenttransactionDetails",this.transactionDocument.currentTransactionDetails),this},t.prototype.updateCurrentTransactionDetailsTotalTaxSummary=function(){var t=this;console.log("Total Tax Summery Request :",JSON.stringify(this.transactionDocument.currentTransactionDetails.taxBreakdown));var e,n=[];return console.log("Tax Lines for Total Tax Summery :",JSON.stringify(this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines)),this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.forEach((function(e){var i={VATCode:"",VAT:-12345,PreTaxSum:0,TaxSum:0,TXrateSum:0};i.VATCode=e.VATCode,i.VAT=e.VAT,i.PreTaxSum=t.numberUtilService.trimTo2Decimal2(e.PreTax),i.TaxSum=t.numberUtilService.trimTo2Decimal2(e.taxLineTotal),i.TXrateSum=t.numberUtilService.trimTo2Decimal2(i.PreTaxSum+i.TaxSum),n.push(i)})),console.log("Total Tax Summery Without Grouped : ",JSON.stringify(n)),e=n.reduce((function(t,e){var n=t.findIndex((function(t){return t.VAT===e.VAT}));return-1===n?t.push(e):(t[n].VATCode=e.VATCode,t[n].VAT=e.VAT,t[n].PreTaxSum+=e.PreTaxSum,t[n].TaxSum+=e.TaxSum,t[n].TXrateSum+=e.TXrateSum),t}),[]),console.log("Total Tax Summer Group :",JSON.stringify(e)),this.transactionDocument.currentTransactionDetails.totalTaxSummary=e,this},t.prototype.updateCurrentTransactionDetailsDiscountTotal=function(){var t=this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal?this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal:0;console.log("e-basket: transaction builder updateCurrentTransactionDetailsDiscountTotal: discountTotal",t,this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal,this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal);var e=Math.abs(Math.abs(this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal)-(Math.abs(this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal)+Math.abs(t)));return console.log("e-basket: transaction builder updateCurrentTransactionDetailsDiscountTotal: discountTotal",e),Number(e.toFixed(2))},t.prototype.updateCurrentTransactionDetailsRefundTotal=function(){for(var t=0,e=0;e<this.transactionDocument.currentTransactionDetails.products.length;e++){var n=this.transactionDocument.currentTransactionDetails.products[e];n.refundedTotal&&(t+=n.refundedTotal),console.log("ebasket : transaction Service: totalRefund for Current TransactionDetails"+t)}return t},t.prototype.basketSummary=function(t){return this.transactionDocument.basketSummary.basketTotal=this.numberUtilService.trimTo2Decimal(t.basketTotal),this.transactionDocument.basketSummary.saleTotal=this.numberUtilService.trimTo2Decimal2(this.updateSaleTotal(t)),this.transactionDocument.basketSummary.refundTotal=this.getRefundTotal(),(this.transactionDocument.basket.lineDiscount||this.transactionDocument.basket.linePromotion)&&(this.transactionDocument.basketSummary.discountTotal=this.numberUtilService.trimTo2Decimal2(this.updateDiscountTotal())),this.transactionDocument.basketSummary.totalItems=t.quantity,this.transactionDocument.basket.taxBreakdown?this.transactionDocument.basketSummary.VATTotal=this.numberUtilService.trimTo2Decimal2(this.transactionDocument.basket.taxBreakdown.taxLines.reduce((function(t,e){return t+e.taxLineTotal}),0)):this.transactionDocument.basketSummary.VATTotal=0,console.info("ebasket: basketsummary updated in transaction document: ",JSON.stringify(this.transactionDocument.basketSummary)),this},t.prototype.lineDiscount=function(t){this.transactionDocument.basket.lineDiscount=[];for(var e=0;e<t.products.length;e++){var n=t.products[e];n.lineDiscount&&(this.transactionDocument.basket.lineDiscount.push(n.lineDiscount),this.transactionDocument.basket.lineDiscount=this.transactionDocument.basket.lineDiscount.reduce((function(t,e){return t.find((function(t){return t.itemLineId===e.itemLineId}))||t.push(e),t}),[]))}return this},t.prototype.exchange=function(t){this.transactionDocument.basket.exchange=t.exchange&&t.exchange.length>0?s(t.exchange):[];for(var e=function(e){var i=t.products[e];if(null!=i.exchange&&!n.transactionDocument.basket.exchange.some((function(t){return t.exchangeId===i.exchange.exchangeId}))){for(var o=[],r=0;r<i.exchange.newItems.length;r++){var a=i.exchange.newItems[r],c={lineItemId:a.itemLineId,Quantity:a.quantity};o.push(c)}i.exchange.newItems=s(o),n.transactionDocument.basket.exchange.push(i.exchange)}console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.basket exchange",JSON.stringify(n.transactionDocument.basket.exchange))},n=this,i=0;i<t.products.length;i++)e(i);return this},t.prototype.addExchangeData=function(t){return this.transactionDocument.basket.exchange=t.basket.exchange?s(t.basket.exchange):null,this},t.prototype.linePromotion=function(t){this.transactionDocument.basket.linePromotion=[];for(var e=0;e<t.products.length;e++){var n=t.products[e];n.linePromotions&&(this.transactionDocument.basket.linePromotion.push(n.linePromotions),this.transactionDocument.basket.linePromotion=this.transactionDocument.basket.linePromotion.reduce((function(t,e){return t.find((function(t){return t.itemLineId===e.itemLineId}))||t.push(e),t}),[]))}return this},t.prototype.transactionPromotion=function(t){return t.transactionPromotion&&(this.transactionDocument.basket.transactionPromotion=t.transactionPromotion,console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.basket.transactionPromotion",JSON.stringify(this.transactionDocument.basket.transactionPromotion))),this},t.prototype.transactionDiscount=function(t){return t.transactionDiscount&&(this.transactionDocument.basket.transactionDiscount=t.transactionDiscount,console.log("e-basket :TransactionDocumentBuilder: transaction Discount",JSON.stringify(this.transactionDocument.basket.transactionDiscount))),this},t.prototype.paymentDetails=function(t){return console.info("ebasket : payment details after transaction completed",JSON.stringify(t)),this.transactionDocument.paymentDetails=t,this},t.prototype.splitPayment=function(t){return this.transactionDocument.splitPayment=t,this},t.prototype.isPaymentCompleted=function(t){return this.transactionDocument.isPaymentCompleted=t,this},t.prototype.baseCurrency=function(t){return this.transactionDocument.baseCurrency=t,this},t.prototype.giftOption=function(t){return console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.giftoption",t),t&&(this.transactionDocument.giftedReceipt=t),this},t.prototype.type=function(t){return this.transactionDocument.type=t,this},t.prototype.operationStatus=function(t){return this.transactionDocument.operationStatus=t,this},t.prototype.createdAt=function(){var t=new Date;return this.transactionDocument.createdAt=t.toISOString(),this.transactionDocument.updatedAt=t.toISOString(),this},t.prototype.updatedAt=function(){var t=new Date;return this.transactionDocument.updatedAt=t.toISOString(),this},t.prototype.transactionCompletedAt=function(){var t=new Date;return this.transactionDocument.transCompletedAt=t.toISOString(),this},t.prototype.build=function(){return this.transactionDocument},t.prototype.saleTotalInRefund=function(t){return this.transactionDocument.saleTotal=t,this},t.prototype.getBasketDetails=function(){var t=this;console.info("ebasket: Getting Basket for transactionDocument",JSON.stringify(this.transactionDocument));var e={subsidiaryId:this.transactionDocument.subsidiaryId,transactionDiscount:this.transactionDocument.basket.transactionDiscount,transactionPromotion:this.transactionDocument.basket.transactionPromotion,transactionId:this.transactionDocument.transactionId,offlineTransactionId:this.transactionDocument.offlineTransactionId,total:this.transactionDocument.basketSummary.basketTotal,basketTotal:this.transactionDocument.basketSummary.basketTotal,discountTotal:this.transactionDocument.basketSummary.discountTotal,saleTotal:this.transactionDocument.basketSummary.saleTotal,refundTotal:this.transactionDocument.basketSummary.refundTotal,quantity:this.transactionDocument.basketSummary.totalItems,products:[],baseCurrency:this.transactionDocument.baseCurrency,customer:this.transactionDocument.customer};return e.products=[],this.transactionDocument.basket.products.forEach((function(n,i){console.log(JSON.stringify(n),"ebasket: basket detail update in basket");var o={};o.SKU=n.SKU,o.barcode=n.barCode,o.barcodes=n.barcodes,o.description=n.description,o.imageUrls=n.imageUrls,o.currency=t.transactionDocument.baseCurrency,o.totalLinePrice=n.totalLinePrice,o.itemLineId=Number(n.itemLineId),o.excludePromotion=n.excludePromotion,o.selectedPrice=n.price,o.quantity=n.quantity,o.total=n.totalLinePrice,o.selectedRRPPrice=n.selectedRRPPrice,o.fullfilmentId=n.fullfilmentId,o.fullfilmentLocationName=n.fullfilmentLocationName,o.deliveryGroup=n.deliveryGroup||"1",o.leadTime=n.leadTime,o.deliveryMethod=n.deliveryMethod||p.COLLECT_FROM_STORE.toString(),o.fullfilmentId!=t.transactionDocument.storeId&&(o.isWebOrder=!0),o.giftCard=n.giftCard,o.giftCardExpiryDate=n.giftCardExpiryDate,o.giftCardNumberIssued=n.giftCardNumberIssued,o.giftCardRecipientEmail=n.giftCardRecipientEmail,o.giftCardRecipientName=n.giftCardRecipientName,t.transactionDocument.basket.lineDiscount&&t.transactionDocument.basket.lineDiscount.length>0&&t.transactionDocument.basket.lineDiscount.forEach((function(t){n.itemLineId===t.itemLineId.toString()&&(o.lineDiscount=t,o.total=t.discountedLinePrice)})),t.transactionDocument.basket.linePromotion&&t.transactionDocument.basket.linePromotion.length>0&&t.transactionDocument.basket.linePromotion.forEach((function(t){n.itemLineId===t.itemLineId.toString()&&(o.linePromotions=t,o.total=t.promotionLinePrice)})),t.transactionDocument.basket.taxBreakdown&&t.transactionDocument.basket.taxBreakdown.taxLines.length>0&&t.transactionDocument.basket.taxBreakdown.taxLines.forEach((function(t){n.itemLineId&&n.itemLineId===t.itemLineId.toString()&&(o.selectedVAT=t.VAT,o.selectedVATCode=t.VATCode)})),t.transactionDocument.type===d?o.total=n.refundedTotal:(t.transactionDocument.type===l||h)&&n.refundedQuantity>0&&(o.refundedReasonDescription=n.refundedReasonDescription,o.refundedReason=n.refundedReason,o.refundedReasonDescription||(o.refundedReasonDescription=o.refundedReason),o.refundedQuantity=n.refundedQuantity,o.refundPromotionalQuantity=n.refundedPromotionalQuantity,o.refundedTotal=n.refundedTotal,o.total-=Math.abs(o.refundedTotal),o.isLastExchanged=n.isLastExchanged),t.transactionDocument.type===d&&o.total>0&&(o.total*=-1),e.products.push(o)})),(e=this.getTransactionDiscountAndTransactionPromotionPortion(e)).total=(e.basketTotal||0)+this.getTotalDiscountWithTransactionDiscountsAndPromotions(e),this.transactionDocument.type===l&&(e.quantity=this.getRefundedTotalWithQuantity(e)),console.info("ebasket: Basket created successfully",JSON.stringify(e)),e},t.prototype.getTransactionDiscountAndTransactionPromotionPortion=function(t){var e=this;return t.transactionDiscount&&t.transactionDiscount.length>0&&t.transactionDiscount.forEach((function(n){n.itemLineIds||(n.itemLineIds=t.products.map((function(t){return t.itemLineId}))),t=e.basketService.transactionDiscountProductPortionCalc(t,n)})),t.transactionPromotion&&t.transactionPromotion.length>0&&t.transactionPromotion.forEach((function(n){if(!n.itemLineIds){var i=t.products.filter((function(t){return!1===t.excludePromotion}));n.itemLineIds=i.map((function(t){return t.itemLineId}))}t=e.basketService.transactionPromotionProductPortionCalc(t,n)})),t},t.prototype.getTotalDiscountWithTransactionDiscountsAndPromotions=function(t){var e=0;return t.transactionPromotion&&t.transactionPromotion.length>0&&(e+=t.transactionPromotion.reduce((function(t,e){return t+e.promotionAmount}),0)),t.transactionDiscount&&t.transactionDiscount.length>0&&(e+=t.transactionDiscount.reduce((function(t,e){return t+e.discountAmount}),0)),console.log("ebasket : TransactionDocumentBuilder : Transaction discount Total:",e),e},t.prototype.appendCurrencySymbol=function(t,e){if(e>=0){var n=t+e;return console.log(n,"ebasket: add currency with value"),n}n="-"+(t+-1*e);return console.log(n,"-(currency+(value*-1))"),n},t.prototype.updateSaleTotal=function(t){return t.products.reduce((function(t,e){return t+e.totalLinePrice}),0)},t.prototype.getTotalWithLineDiscountAndLinePromotionApplied=function(t){var e,n,i=0;try{for(var o=r(t.products),a=o.next();!a.done;a=o.next()){var s=a.value;i+=s.total,console.log("e-basket:update product Total:"+i,JSON.stringify(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i},t.prototype.getRefundedTotalWithQuantity=function(t){for(var e=0,n=0;n<t.products.length;n++){var i=t.products[n];i.refundedReasonDescription?e+=i.quantity-i.refundedQuantity:e+=i.quantity}return e},t.prototype.updateDiscountTotal=function(){var t=this.transactionDocument.basketSummary.refundTotal?this.transactionDocument.basketSummary.refundTotal:0;console.info("e-basket: transaction builder: refundTotal",JSON.stringify(t),JSON.stringify(this.transactionDocument.basketSummary));var e=Math.abs(Math.abs(this.transactionDocument.basketSummary.saleTotal)-(Math.abs(this.transactionDocument.basketSummary.basketTotal)+Math.abs(t)));return console.log("e-basket: transaction builder: discountTotal",JSON.stringify(e)),Number(e.toFixed(2))},t.prototype.updateReasonCode=function(t){return this.transactionDocument.reasonCode=t.code,this.transactionDocument.reasonDescription=t.name,this},t.prototype.updateManagerOverride=function(t){return this.transactionDocument.override=t,this},t.prototype.updateUserID=function(t){return this.transactionDocument.userId=t,this},t.prototype.updateUserName=function(t){return this.transactionDocument.userName=t,this},t.prototype.addCustomerDetails=function(t){return this.transactionDocument.customer=t,this},t.prototype.updateTaxBreakdown=function(t){var e=this,n={taxLines:[],totalTaxableAmount:0};return t.products.forEach((function(t){var i={itemLineId:t.itemLineId,VAT:t.selectedVAT?t.selectedVAT:0,VATCode:t.selectedVATCode,taxLineTotal:0,taxableAmount:t.total,PreTax:0};console.info("Product contribution : item line ID :",t.itemLineId,"tax line :",JSON.stringify(i));var o=(t=e.basketService.validateProductItemDiscount(t)).itemDiscounts.trnDiscountsPortion+t.itemDiscounts.trnPromotionsPortion-t.itemDiscounts.refundPortion;console.info("Product contribution : item line ID :",t.itemLineId,"contribution :",JSON.stringify(o)),i.taxableAmount-=o,i.PreTax=e.numberUtilService.trimTo2Decimal2(100*i.taxableAmount/(100+i.VAT)),n.totalTaxableAmount+=i.taxableAmount,i.taxableAmount=e.numberUtilService.trimTo2Decimal2(i.taxableAmount),i.taxLineTotal=e.numberUtilService.trimTo2Decimal2(i.taxableAmount-i.PreTax),n.taxLines.push(i)})),n.totalTaxableAmount=this.numberUtilService.trimTo2Decimal2(n.totalTaxableAmount),this.transactionDocument.basket.taxBreakdown=n,this},t.prototype.updateTotalTaxSummary=function(){var t=this;console.log("Total Tax Summery Request :",JSON.stringify(this.transactionDocument.basket.taxBreakdown));var e,n=[];return console.log("Tax Lines for Total Tax Summery :",JSON.stringify(this.transactionDocument.basket.taxBreakdown.taxLines)),this.transactionDocument.basket.taxBreakdown.taxLines.forEach((function(e){var i={VATCode:"",VAT:-12345,PreTaxSum:0,TaxSum:0,TXrateSum:0};i.VATCode=e.VATCode,i.VAT=e.VAT,i.PreTaxSum=t.numberUtilService.trimTo2Decimal2(e.PreTax),i.TaxSum=t.numberUtilService.trimTo2Decimal2(e.taxLineTotal),i.TXrateSum=t.numberUtilService.trimTo2Decimal2(i.PreTaxSum+i.TaxSum),n.push(i)})),console.log("Total Tax Summery Without Grouped : ",JSON.stringify(n)),e=n.reduce((function(t,e){var n=t.findIndex((function(t){return t.VAT===e.VAT}));return-1===n?t.push(e):(t[n].VATCode=e.VATCode,t[n].VAT=e.VAT,t[n].PreTaxSum+=e.PreTaxSum,t[n].TaxSum+=e.TaxSum,t[n].TXrateSum+=e.TXrateSum),t}),[]),console.log("Total Tax Summer Group :",e),this.transactionDocument.basket.totalTaxSummary=e,this},t.prototype.addOriginalTransId=function(t){return this.transactionDocument.type!==d&&this.transactionDocument.type!==l&&this.transactionDocument.type!==h||(this.transactionDocument.originalTransId=t.transactionId,t.apiResponse&&t.apiResponse.internalId&&(this.transactionDocument.originalExternalId=t.apiResponse.internalId.toString())),this},t.prototype.addUnreferencedRefund=function(){return this.transactionDocument.unreferencedRefund=!0,this},t.prototype.getRefundTotal=function(){for(var t=0,e=0;e<this.transactionDocument.basket.products.length;e++){var n=this.transactionDocument.basket.products[e];n.refundedTotal&&(t+=n.refundedTotal),console.log("ebasket : transaction Service: totalRefund"+t)}return t},t.prototype.docId=function(t){return this.transactionDocument.id=t,this},t}();var y=function(){function t(t){this.itemCount=0,this.largestNumber=0,this.rjObject={},this.transactionDocument=t||{transactionId:"",offlineTransactionId:"",transactionRef:"",dateTime:"",orgCode:"",storeId:"",storeNodeId:"",storeNodeStructure:"",deviceId:"",terminalId:"",userId:"",initiatingModule:"eBasket",export:!1,basket:{},basketSummary:{},baseCurrency:"",type:"",operationStatus:"",createdAt:"",updatedAt:"",id:"",currentTransactionDetails:{},saleTotal:0},this.initilizeItemCount(),this.setLineNumberForProducts(),this.createdAt=this.getDate(this.transactionDocument.createdAt),this.updatedAt=this.getDate(this.transactionDocument.updatedAt)}return t.prototype.getPosbasketInfo=function(){return this.rjObject.Keyword=this.generateKeyword(),this.rjObject.ID=this.generateId(this.createdAt),this.rjObject.XMLSchemaVersion="2",this.rjObject.LastUpdated=this.updatedAt,this.rjObject.MajorVersion=this.majorVersion,this.rjObject.MinorVersion=this.minorVersion,this.rjObject.ManifestVersion=this.manifestVersion,this.rjObject.DatabaseSchemaVersion=this.databaseSchemaVersion,this.rjObject.BasketType=this.basketType,this.rjObject.State=this.getState(),this.rjObject.ExternalState=this.externalState,this},t.prototype.getheaderInfo=function(){return this.rjObject.Header={},this.rjObject.Header.TimeZoneOffset=this.convertToString(this.generateTimezoneoffset(this.transactionDocument.createdAt)),this.rjObject.Header.DateTimeCreated=this.createdAt,this.rjObject.Header.OriginatedBy={},this.rjObject.Header.OriginatedBy.DeviceID=this.deviceId,this.rjObject.Header.OriginatedBy.CashierID=this.cashierId,this.rjObject.Header.OriginatedBy.CompanyID=this.companyId,this.rjObject.Header.OriginatedBy.StoreID=this.transactionDocument.storeId,this.rjObject.Header.OriginatedBy.BranchID=this.branchId,this.rjObject.Header.OriginatedBy.TerminalNumber=this.terminalNumber,this.rjObject.Header.OriginatedBy.TransactionNumber=this.transactionNumber,this.rjObject.Header.TaxMethodID=this.taxMethodId,this.rjObject.Header.DynamicStockLookup=this.generateDynamicStockLookUp(),this.rjObject.Header.BasketLanguageID=this.basketLanguageId,this.rjObject.Header.BasketCountryID=this.basketCountryId,this.rjObject.Header.BasketCurrencyID=this.transactionDocument.baseCurrency,this.rjObject.Header.TradingRegionID=this.tradingRegionId,this.rjObject.Header.Eurozone=" ",this.rjObject.Header.EuroBaseExchangeRate="",this.rjObject.Header.PrintableName=this.transactionDocument.userName,this},t.prototype.rjMapper=function(){var t=this,e=[];if(this.transactionDocument.basket.transactionDiscount&&this.transactionDocument.basket.transactionDiscount.length>0&&(e=this.transactionDocument.basket.transactionDiscount),this.transactionDocument.type===m){this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(n){var i=[];if(t.transactionDocument.basket.lineDiscount&&t.transactionDocument.basket.lineDiscount.length>0&&(i=t.transactionDocument.basket.lineDiscount.filter((function(t){return t.itemLineId===n.itemLineId}))).length>0){var o=t.transactionDocument.basket.lineDiscount.indexOf(i[0]);o>-1&&t.transactionDocument.basket.lineDiscount.splice(o,1)}var r=t.addProduct(n,i.length>0?i[0]:null,e.length>0?e:null);t.rjObject.ProductSale.push(r),t.getModifierItem(i.length>0?i[0]:null,n.itemLineId)}));var n=[];this.transactionDocument.basket.transactionPromotion&&this.transactionDocument.basket.transactionPromotion.length>0&&(n=this.transactionDocument.basket.transactionPromotion,this.getTransactionPromotion(n))}else if(this.transactionDocument.type===d)this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(n){var i=t.returnProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);t.rjObject.ProductReturn.push(i),t.getModifierItem(n.lineDiscount,n.itemLineId)}));else if(this.transactionDocument.type===l){this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],(new T).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(n){var i=t.returnProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);i.Return=o({},i.Return,{OriginalReceiptSupplied:0,OriginalBranchID:0,OriginalTerminalNumber:0,OriginalTransactionNumber:0,OriginalCashierNumber:0}),t.rjObject.ProductReturn.push(i),t.getModifierItem(n.lineDiscount,n.itemLineId)}))}else if(this.transactionDocument.type===h){this.rjObject.ProductReturn=[],this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],(new T).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(n){if(n.refundedQuantity>0){var i=t.returnProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);i.Return=o({},i.Return,{OriginalReceiptSupplied:0,OriginalBranchID:0,OriginalTerminalNumber:0,OriginalTransactionNumber:0,OriginalCashierNumber:0}),t.rjObject.ProductReturn.push(i)}else{var r=t.addProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);t.rjObject.ProductSale.push(r)}t.getModifierItem(n.lineDiscount,n.itemLineId)}))}return(this)},t.prototype.getBasketDiscount=function(){var t=this;return this.transactionDocument.basket.transactionDiscount?(this.rjObject.BasketDiscount=[],this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={};n.XMLSchemaVersion=t.xmlSchemaVersion,n.DeviceID=t.deviceId,n.DateTimeCreated=t.updatedAt,n.NetValue=t.convertToString(-1*e.discountAmount),n.EffectiveNetValue=t.convertToString(-1*e.discountAmount),n.Description=e.reasonDisplayText,n.UserID=t.transactionDocument.userName,n.ReasonCodeID=e.reasonCode,n.DiscountType=t.convertToString(e.discountType.toUpperCase()==D.PERCENT.toUpperCase()?0:1),n.RoundingRule=t.convertToString(2),n.ModifiedLineNumber=e.itemLineIds,n.LineNumber=t.convertToString(t.generateLineNumber()),n.DiscountedValue=t.transactionDocument.basketSummary.basketTotal+t.transactionDocument.basketSummary.discountTotal,e.discountType.toUpperCase()==D.PERCENT.toUpperCase()&&(n.DiscountPercentage=t.convertToString((e.discountAmount/t.transactionDocument.basketSummary.basketTotal).toFixed(1))),"REFUND"===t.transactionDocument.type&&(n.NetValue=t.convertToString(e.discountAmount<0?-e.discountAmount:e.discountAmount),n.EffectiveNetValue=t.convertToString(e.discountAmount<0?-e.discountAmount:e.discountAmount)),t.rjObject.BasketDiscount.push(n)})),this):this},t.prototype.getModifierItem=function(t,e){if(t&&e){var n={XMLSchemaVersion:1};n.LineNumber=this.generateLineNumber(),n.NetValue=0,n.EffectiveNetValue=0,n.Description=t.percentageDiscountReasonName?t.percentageDiscountReasonName:t.priceOverrideReasonName,n.DeviceID=this.deviceId,n.UserID=this.transactionDocument.userName,n.DateTimeCreated=this.updatedAt,n.AuthorisingUserID=this.transactionDocument.userName,n.ReasonCodeID=t.percentageDiscountReasonCode?t.percentageDiscountReasonCode:t.priceOverrideReasonCode,n.ModifiedLineNumber=e,n.ModifiedIndex=1,this.rjObject.ModifierItem.push(n)}},t.prototype.getTrailerInfo=function(){var t=this;return this.rjObject.Trailer={},this.rjObject.Trailer.DateTimeCompleted=this.updatedAt,this.rjObject.Trailer.CompletedBy={},this.rjObject.Trailer.CompletedBy.DeviceID=this.deviceId,this.rjObject.Trailer.CompletedBy.CashierID=this.cashierId,this.rjObject.Trailer.CompletedBy.StoreID=this.transactionDocument.storeId,this.rjObject.Trailer.CompletedBy.BranchID=this.branchId,this.rjObject.Trailer.CompletedBy.TerminalNumber=this.terminalNumber,this.rjObject.Trailer.CompletedBy.TransactionNumber=this.transactionNumber,this.rjObject.Trailer.Total=this.convertToString(100*this.transactionDocument.basketSummary.basketTotal),this.rjObject.Trailer.ItemCount=this.itemCount,this.rjObject.Trailer.ItemQuantity=this.convertToString(this.transactionDocument.basketSummary.totalItems),this.rjObject.Trailer.NetItemQuantity=this.convertToString(this.transactionDocument.basketSummary.totalItems),this.rjObject.Trailer.TaxTotal=this.convertToString(this.removeDecimal(this.transactionDocument.basketSummary.VATTotal)),this.rjObject.Trailer.SequenceDeviceID=this.deviceId,this.rjObject.Trailer.SequenceNumber="snsn",this.rjObject.Trailer.TaxItem=[],this.transactionDocument.basket.taxBreakdown.taxLines.forEach((function(e){var n={};n.XMLSchemaVersion=t.xmlSchemaVersion,n.TaxRate=t.convertToString(e.VATCode),n.TaxableTotal=t.convertToString(t.removeDecimal(e.taxableAmount)),n.TaxTotal=t.convertToString(t.removeDecimal(t.removeDecimal(e.taxLineTotal))),n.TaxDescription=t.convertToString(e.VATCode),n.TaxIncluded="1",n.TaxPercentage=t.addDecimal(e.VAT.toFixed(2)).toFixed(2),t.rjObject.Trailer.TaxItem.push(n)})),(this.transactionDocument.basket.linePromotion.length>0||this.transactionDocument.basket.linePromotion.length>0)&&(this.rjObject.Trailer.PromotionItem=[],this.transactionDocument.basket.linePromotion.length>0&&this.transactionDocument.basket.linePromotion.forEach((function(e){var n={};n.PromotionID=e.promotionId,n.PromotionSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionQuantity="1",n.PromotionDescription=e.displayText,n.PromotionHit={},n.PromotionHit.XMLSchemaVersion=t.xmlSchemaVersion,n.PromotionHit.HitNumber="1",n.PromotionHit.HitQuantity="1",n.PromotionHit.HitSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionHit.PromotionTrigger={};var i=t.transactionDocument.basket.products.find((function(t){return t.itemLineId==e.itemLineId}));n.PromotionHit.PromotionTrigger.XMLSchemaVersion=t.xmlSchemaVersion,n.PromotionHit.PromotionTrigger.ProductID=i.SKU,n.PromotionHit.PromotionTrigger.UnitValue=t.convertToString(e.promotionLinePrice/i.quantity),n.PromotionHit.PromotionTrigger.LineNumber=t.getNumber(i.SKU),n.PromotionHit.PromotionTrigger.Quantity=t.convertToString(i.quantity.toFixed(1)),n.PromotionHit.PromotionTrigger.TaxCode=t.transactionDocument.basket.taxBreakdown.taxLines.find((function(t){return t.itemLineId==e.itemLineId})).VATCode,t.rjObject.Trailer.PromotionItem.push(n)})),this.transactionDocument.basket.transactionPromotion.length>0&&this.transactionDocument.basket.transactionPromotion.forEach((function(e){var n={};n.PromotionID=e.promotionId,n.PromotionSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionQuantity="1",n.PromotionDescription=e.displayText,n.PromotionHit={},n.PromotionHit.XMLSchemaVersion=t.xmlSchemaVersion,n.PromotionHit.HitNumber="1",n.PromotionHit.HitQuantity="1",n.PromotionHit.HitSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionHit.PromotionTrigger=[],t.transactionDocument.basket.products.forEach((function(i){var o={};e.itemLineIds.forEach((function(r){JSON.stringify(r)===i.itemLineId&&(o.XMLSchemaVersion=t.xmlSchemaVersion,o.ProductID=i.SKU,o.UnitValue=t.convertToString(e.promotionLinePrice/i.quantity),o.LineNumber=t.getNumber(i.SKU),o.Quantity=t.convertToString(i.quantity),o.TaxCode=t.transactionDocument.basket.taxBreakdown.taxLines.find((function(t){return t.itemLineId==i.itemLineId})).VATCode,n.PromotionHit.PromotionTrigger.push(o))}))})),t.rjObject.Trailer.PromotionItem.push(n)}))),this},t.prototype.getTenderInfo=function(){var t=this;return this.transactionDocument.paymentDetails&&this.transactionDocument.paymentDetails.length>0&&this.transactionDocument.paymentDetails.forEach((function(e){if(e.externalTenderKey)if(t.rjObject[e.externalTenderKey]=[],"GIFT CARD"===e.paymentType.toUpperCase()){var n={XMLSchemaVersion:t.xmlSchemaVersion,LineNumber:t.generateLineNumber(),NetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,GiftVoucherSalesAllowed:"",AllowRechargeableVoucherSales:"",GiftVoucherID:""};t.rjObject[e.externalTenderKey].push(n)}else{var i={XMLSchemaVersion:"1",LineNumber:t.generateLineNumber(),NetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,IncludeInTransactionTotalCheck:"1",AllowRechargeableVoucherSales:"1",OpenDrawerAtEnd:"1"};t.rjObject[e.externalTenderKey].push(i)}else if(t.rjObject.CashTender=[],"GIFT CARD"===e.paymentType.toUpperCase()){n={XMLSchemaVersion:t.xmlSchemaVersion,LineNumber:t.generateLineNumber(),NetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,GiftVoucherSalesAllowed:"",AllowRechargeableVoucherSales:"",GiftVoucherID:""};t.rjObject.CashTender.push(n)}else{i={XMLSchemaVersion:"1",LineNumber:t.generateLineNumber(),NetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,IncludeInTransactionTotalCheck:"1",AllowRechargeableVoucherSales:"1",OpenDrawerAtEnd:"1"};t.rjObject.CashTender.push(i)}})),this},t.prototype.getNumber=function(t){for(var e,n=0;n<this.rjObject.ProductSale.length;n++){var i=this.rjObject.ProductSale[n];if(JSON.stringify(t)===JSON.stringify(i.ProductID)){e=i.LineNumber;break}}return e},t.prototype.setLineNumberForProducts=function(){var t=[];t=this.transactionDocument.basket.products.map((function(t){return parseInt(t.itemLineId)})),this.largestNumber=t.reduce((function(t,e){return Math.max(t,e)}))},t.prototype.generateLineNumber=function(){return this.largestNumber+=1,this.itemCount+=1,this.largestNumber},t.prototype.initilizeItemCount=function(){this.itemCount=this.transactionDocument.basket.products.length},t.prototype.build=function(){return this.rjObject},t.prototype.getDescription=function(t){return"CARD"===t.paymentType.toUpperCase()?t.cardType:t.paymentType},t.prototype.getMMGROUPID=function(t){if(t&&t.length>0){var e=t.filter((function(t){return"MMGROUPID"===t.name}));if(e&&e.length>0)return e[0].value}},t.prototype.setDeviceInfo=function(t){return this.deviceId=t,this},t.prototype.removeDecimal=function(t){return 100*t},t.prototype.addDecimal=function(t){return t/100},t.prototype.setTransactionNumber=function(t){return this.transactionNumber=t,this},t.prototype.setManifestVersion=function(t){return this.manifestVersion=t,this},t.prototype.setDatabaseSchemaVersion=function(t){return this.databaseSchemaVersion=t,this},t.prototype.setBasketType=function(t){return this.basketType=t,this},t.prototype.setTradingRegionID=function(t){return this.tradingRegionId=t,this},t.prototype.setCompanyID=function(t){return this.companyId=t,this},t.prototype.setTaxMethodID=function(t){return this.taxMethodId=t,this},t.prototype.setMajorVersion=function(t){return this.majorVersion=t,this},t.prototype.setMinorVersion=function(t){return this.minorVersion=t,this},t.prototype.setXMLSchemaVersion=function(t){return this.xmlSchemaVersion=t,this},t.prototype.setExternalState=function(t){return this.externalState=t,this},t.prototype.setCashierID=function(){return this.cashierId=this.transactionDocument&&this.transactionDocument.userName?this.transactionDocument.userName:"",this},t.prototype.setTerminalNumber=function(t){return this.terminalNumber=t,this},t.prototype.setBasketLanguageID=function(t){return this.basketLanguageId=t,this},t.prototype.setBasketCountryID=function(t){return this.basketCountryId=t,this},t.prototype.setBasketCurrencyID=function(t){return this.basketCurrencyId=t,this},t.prototype.setBranchID=function(t){return this.branchId=t,this},t.prototype.setSalesPersonName=function(t){return this.salesPersonName=t,this},t.prototype.generateId=function(t){var e=t.replace(/[^0-9]/g,"");return(this.deviceId+"|"+e+"|"+this.transactionNumber).toString()},t.prototype.generateTimezoneoffset=function(t){return new Date(t||"").getTimezoneOffset()},t.prototype.generateKeyword=function(){return(this.companyId+"|"+this.transactionDocument.storeId+"|"+this.terminalNumber+"|"+this.transactionNumber).toString()},t.prototype.getState=function(){return"PAY_SUCCESS"===this.transactionDocument.operationStatus?"Completed":"Cancelled"},t.prototype.returnProduct=function(t,e,n){var i=this,o={},r=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId}));if(o.XMLSchemaVersion=this.xmlSchemaVersion,o.LineNumber=t.itemLineId,o.NetValue=this.removeDecimal(t.refundedTotal),o.EffectiveNetValue=this.removeDecimal(t.refundedTotal),o.Description=t.description,o.DeviceID=this.transactionDocument.terminalId,o.UserID=this.transactionDocument.userName,o.DateTimeCreated=this.createdAt,o.ExtendedValue=this.removeDecimal(-1*t.totalLinePrice),o.UnitPrice=this.removeDecimal(t.price),o.Quantity=this.getQuantity(t),o.OriginalTaxAmountSet=1,o.ProductID=t.SKU,o.HandKeyed=1,o.LongDescription=t.description,o.Return={},o.Return.ReturnReasonID=t.refundedReason,o.Return.ReturnDescription=t.refundedReasonDescription,o.Return.ReturnToStock=this.getQuantity(t),o.TaxCode=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})).VATCode,o.DisplayTaxCode="",o.ProductAttributes="",o.Perishable=this.getMMGROUPID(t.attributes),o.MMGroupID=this.getMMGROUPID(t.attributes),o.CustomerDetails="",o.TotalPromotionSaving=t.promotionAmount||-1,o.OriginalTaxAmount=this.convertToString(this.removeDecimal(-1*this.getOriginalTax(t,r.VAT)).toFixed(2)),o.taxAmount=this.removeDecimal(r.taxLineTotal<0?r.taxLineTotal:-r.taxLineTotal),e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(o.Discount={},o.Discount.ModifierValue=-1*this.removeDecimal(e.discountAmount),o.Discount.ModifierDateTime=o.DateTimeCreated,o.Discount.ModifierReasonID=e.percentageDiscountReasonCode,o.Discount.ModifierDescription=e.percentageDiscountReasonName,o.Discount.AuthorisingUserID=this.transactionDocument.userName,o.Discount.DiscountType=e.discountType,o.Discount.XMLSchemaVersion=1,o.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),o.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),o.Discount.DiscountPercentage=e.percentageDiscountValue,o.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(o.PriceOverride={},o.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),o.PriceOverride.ModifierDateTime=o.DateTimeCreated,o.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,o.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,o.PriceOverride.AuthorisingUserID=this.transactionDocument.userName,o.PriceOverride.XMLSchemaVersion=1,o.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),o.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),o.NetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),o.EffectiveNetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),o.ExtendedValue=-1*((e.discountedLinePrice||0)+e.discountAmount),o.UnitPrice=-1*((e.discountedLinePrice||0)+e.discountAmount)),n){o.BasketDiscountModifier=[],this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={};e.itemLineIds.forEach((function(r){if(r==t.itemLineId){var a=i.convertToString(-1*e.discountAmount);n.BasketDiscountLineNumber=i.getLineNumber(e,a),n.XMLSchemaVersion=i.xmlSchemaVersion,n.DiscountedValue=i.getDiscountedValue(t.totalLinePrice,e.discountAmount),o.BasketDiscountModifier.push(n)}}))}));var a=0;o.BasketDiscountModifier.forEach((function(t){a+=t.DiscountedValue})),o.EffectiveNetValue=o.EffectiveNetValue+a}return this.transactionDocument.basket.transactionPromotion.length>0&&(o.PromotionSaving=[],this.transactionDocument.basket.transactionPromotion.forEach((function(e){var n={};e.itemLineIds.forEach((function(r){r==t.itemLineId&&(n.ModifierValue=e.promotionAmount,n.ModifierDateTime=i.transactionDocument.createdAt,n.ModifierDescription=e.displayText,n.XMLSchemaVersion=i.xmlSchemaVersion,n.PromotionID=e.promotionId,n.PromotionDescription=e.displayText,n.HitNumber="1",n.PromotionHitProductQuantity=i.getQuantity(t),n.PromotionHitQuantity=-1*i.getQuantity(t),o.PromotionSaving.push(n))}))}))),o},t.prototype.addProduct=function(t,e,n){var i=this,o=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})),r={XMLSchemaVersion:this.xmlSchemaVersion,LineNumber:t.itemLineId,NetValue:this.removeDecimal(t.totalLinePrice),EffectiveNetValue:this.removeDecimal(t.totalLinePrice),Description:t.description,DeviceID:this.deviceId,UserID:this.transactionDocument.userName,DateTimeCreated:this.createdAt,ExtendedValue:this.removeDecimal(t.price),UnitPrice:this.removeDecimal(t.price),Quantity:t.quantity,SalespersonID:this.transactionDocument.userName,SalespersonName:this.salesPersonName,TaxCode:this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})).VATCode,TaxModifiable:"1",OriginalTaxAmount:this.convertToString(this.removeDecimal(this.getOriginalTax(t,o.VAT)).toFixed(2)),TaxAmount:this.convertToString(this.removeDecimal(o.taxLineTotal)),OriginalTaxAmountSet:"1",ProductID:t.SKU,HandKeyed:"1",CustomerDetails:"",Perishable:this.getMMGROUPID(t.attributes),MMGroupID:this.getMMGROUPID(t.attributes)};if(e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(r.Discount={},r.Discount.ModifierValue=-1*this.removeDecimal(e.discountAmount),r.Discount.ModifierDateTime=r.DateTimeCreated,r.Discount.ModifierReasonID=e.percentageDiscountReasonCode,r.Discount.ModifierDescription=e.percentageDiscountReasonName,r.Discount.AuthorisingUserID=this.transactionDocument.userName,r.Discount.DiscountType=e.discountType,r.Discount.XMLSchemaVersion=1,r.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),r.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),r.Discount.DiscountPercentage=e.percentageDiscountValue,r.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(r.PriceOverride={},r.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),r.PriceOverride.ModifierDateTime=r.DateTimeCreated,r.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,r.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,r.PriceOverride.AuthorisingUserID=this.transactionDocument.userName,r.PriceOverride.XMLSchemaVersion=this.xmlSchemaVersion,r.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),r.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),r.NetValue=(e.discountedLinePrice||0)+e.discountAmount,r.EffectiveNetValue=(e.discountedLinePrice||0)+e.discountAmount,r.ExtendedValue=(e.discountedLinePrice||0)+e.discountAmount,r.UnitPrice=(e.discountedLinePrice||0)+e.discountAmount),n){r.BasketDiscountModifier=[],this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={};e.itemLineIds.forEach((function(o){if(o==t.itemLineId){var a=i.convertToString(-1*e.discountAmount);n.XMLSchemaVersion=i.xmlSchemaVersion,n.DiscountedValue=-i.getDiscountedValue(t.totalLinePrice,e.discountAmount),n.BasketDiscountLineNumber=i.getLineNumber(e,a),r.BasketDiscountModifier.push(n)}}))}));var a=0;r.BasketDiscountModifier.forEach((function(t){a+=t.DiscountedValue})),r.EffectiveNetValue=r.EffectiveNetValue+a}if(this.transactionDocument.basket.transactionPromotion.length>0||this.transactionDocument.basket.linePromotion.length>0){r.DistributedPromotionSaving=[],this.transactionDocument.basket.transactionPromotion.length>0&&this.transactionDocument.basket.transactionPromotion.forEach((function(e){var n={};e.itemLineIds.forEach((function(o){o==t.itemLineId&&(n.PromotionID=e.promotionId,n.Hit="1",n.Saving=i.getSaving(t.totalLinePrice,e.promotionAmount),n.ISaving=i.getSaving(t.totalLinePrice,e.promotionAmount),r.DistributedPromotionSaving.push(n))}))})),this.transactionDocument.basket.linePromotion.length>0&&this.transactionDocument.basket.linePromotion.forEach((function(e){var n={};t.itemLineId==e.itemLineId&&(n.PromotionID=e.promotionId,n.Hit="1",n.Saving=e.promotionLinePrice,n.ISaving=e.promotionLinePrice,r.DistributedPromotionSaving.push(n))}));var s=0;r.DistributedPromotionSaving.forEach((function(t){s+=t.Saving})),r.EffectiveNetValue=r.EffectiveNetValue+s}return r},t.prototype.getSaving=function(t,e){return t*e/this.transactionDocument.basketSummary.saleTotal},t.prototype.getLineNumber=function(t,e){for(var n,i=0;i<this.rjObject.BasketDiscount.length;i++){var o=this.rjObject.BasketDiscount[i];if(t.reasonCode===o.ReasonCodeID&&e===o.NetValue){n=o.LineNumber;break}}return n},t.prototype.getDiscountedValue=function(t,e){return t*e/this.transactionDocument.basketSummary.saleTotal*100},t.prototype.getOriginalTax=function(t,e){var n=100*t.price/(100+e);return t.price-n},t.prototype.convertToString=function(t){try{return t=JSON.stringify(t)}catch(e){console.log(t,"can not be converted in string",e)}},t.prototype.generateDynamicStockLookUp=function(){var t="0";return this.transactionDocument.basket.products.forEach((function(e){"1"!==e.deliveryMethod&&"2"!==e.deliveryMethod||(t="1")})),t},t.prototype.getDate=function(t){var e=-1*this.generateTimezoneoffset(t),n=Math.abs(Math.floor(e/60)),i=Math.abs(e)-60*n,o="+";return e<0&&(o="-"),(t.substring(0,19)+o+String(n).padStart(2,"0")+":"+String(i).padStart(2,"0")).toString()},t.prototype.getTransactionPromotion=function(t){t&&t.length>0&&(this.rjObject.PromoVoucherItem={},this.rjObject.PromoVoucherItem.XMLSchemaVersion=this.xmlSchemaVersion,this.rjObject.PromoVoucherItem.LineNumber=this.generateLineNumber(),this.rjObject.PromoVoucherItem.NetValue=-1*this.removeDecimal(t[0].promotionLinePrice),this.rjObject.PromoVoucherItem.EffectiveNetValue=-1*this.removeDecimal(t[0].promotionLinePrice),this.rjObject.PromoVoucherItem.Description=t[0].promotionInfo,this.rjObject.PromoVoucherItem.DeviceID=this.deviceId,this.rjObject.PromoVoucherItem.UserID=this.transactionDocument.userName,this.rjObject.PromoVoucherItem.DateTimeCreated=this.createdAt,this.rjObject.PromoVoucherItem.ProductId="",this.rjObject.PromoVoucherItem.SerialNumber="",this.rjObject.PromoVoucherItem.MMGroupId="")},t.prototype.getQuantity=function(t){return this.transactionDocument.unreferencedRefund?t.quantity<0?t.quantity:-t.quantity:t.refundedQuantity<0?t.refundedQuantity:-t.refundedQuantity},t}();var g=function(){function t(t){this.webReturnObject={id:"",orgCode:"",storeId:"",storeNodeId:"",storeNodeStructure:"",deviceId:"",terminalId:"",initiatingModule:"",export:!1,basket:{},basketSummary:{},baseCurrency:"",customer:{firstName:"",lastName:"",email:"",postCode:"",id:"",billingAddress:{},shippingAddress:{}}},t&&(this.document=t)}return t.prototype.WebReturnMapper=function(){var t=this;this.webReturnObject.type="WEB_RETURNS",this.webReturnObject.datetime=this.getUTCDateTime(this.getText(this.document.updated_at)),this.webReturnObject.baseCurrency=this.getText(this.document.base_currency_code),this.webReturnObject.storeId=this.getText(this.document.store_id),this.webReturnObject.subsidiaryId="1",this.webReturnObject.initiatingModule="MAGENTO",this.webReturnObject.createdAt=this.getUTCDateTime(this.getText(this.document.created_at)),this.webReturnObject.updatedAt=this.getUTCDateTime(this.getText(this.document.updated_at)),this.webReturnObject.export=!0,this.webReturnObject.transCompletedAt=this.getUTCDateTime(this.getText(this.document.updated_at)),this.webReturnObject.externalTransactionId=this.getText(this.document.order_id),this.webReturnObject.customer.firstName=this.getText(this.document.customer_firstname)||"",this.webReturnObject.customer.lastName=this.getText(this.document.customer_lastname)||"",this.webReturnObject.customer.email=this.getText(this.document.customer_email)||"",this.webReturnObject.customer.postCode="",this.webReturnObject.customer.billingAddress.address1=this.document.billing_address&&this.document.billing_address.street?this.getText(this.document.billing_address.street):"",this.webReturnObject.customer.billingAddress.city=this.document.billing_address&&this.document.billing_address.city?this.getText(this.document.billing_address.city):"",this.webReturnObject.customer.billingAddress.county=this.document.billing_address&&this.document.billing_address.region?this.getText(this.document.billing_address.region):"",this.webReturnObject.customer.billingAddress.postCode=this.document.billing_address&&this.document.billing_address.postcode?this.getText(this.document.billing_address.postcode):"",this.webReturnObject.customer.billingAddress.country=this.document.billing_address&&this.document.billing_address.country?this.getText(this.document.billing_address.country):"",this.webReturnObject.customer.shippingAddress.address1=this.document.shipping_address&&this.document.shipping_address.street?this.getText(this.document.shipping_address.street):"",this.webReturnObject.customer.shippingAddress.city=this.document.shipping_address&&this.document.shipping_address.city?this.getText(this.document.shipping_address.city):"",this.webReturnObject.customer.shippingAddress.county=this.document.shipping_address&&this.document.shipping_address.region?this.getText(this.document.shipping_address.region):"",this.webReturnObject.customer.shippingAddress.postCode=this.document.shipping_address&&this.document.shipping_address.postcode?this.getText(this.document.shipping_address.postcode):"",this.webReturnObject.customer.shippingAddress.country=this.document.shipping_address&&this.document.shipping_address.country?this.getText(this.document.shipping_address.country):"",this.webReturnObject.basketSummary.discountTotal=Number(this.document.discount_amount?this.getText(this.document.discount_amount):0),this.webReturnObject.basketSummary.VATTotal=Number(this.document.base_total_paid?this.getText(this.document.base_total_paid):0),this.webReturnObject.basketSummary.saleTotal=Number(this.document.base_total_invoiced?this.getText(this.document.base_total_invoiced):0),this.webReturnObject.basketSummary.basketTotal=Number(this.document.base_total_paid?this.getText(this.document.base_total_paid):0),this.webReturnObject.basketSummary.totalItems=Number(this.document.total_qty_ordered?this.getText(this.document.total_qty_ordered):0),this.webReturnObject.basketSummary.refundTotal=Number(this.document.base_total_refunded?this.getText(this.document.base_total_refunded):0),this.webReturnObject.basket.lineDiscount=[];var e={itemLineId:this.document.items&&this.document.items.item&&this.document.items.item.item_id?this.getText(this.document.items.item.item_id):0,discountAmount:this.document.items&&this.document.items.item&&this.document.items.item.discount_amount?Number(this.getText(this.document.items.item.discount_amount)):0};this.webReturnObject.basket.lineDiscount.push(e),this.webReturnObject.basket.transactionDiscount=[];var n={discountAmount:this.document&&this.document.discount_amount?Number(this.getText(this.document.discount_amount)):0};this.webReturnObject.basket.transactionDiscount.push(n),this.webReturnObject.basket.products=[];var i={};return this.document.items&&this.document.items.item&&this.document.items.item&&(this.document.items.item instanceof Array?this.document.items.item.forEach((function(e){(i={description:e.name?t.getText(e.name):"",SKU:e.sku?t.getText(e.sku):"",quantity:e.qty_ordered?Number(t.getText(e.qty_ordered)):0,refundedQuantity:e.qty_refunded?Number(t.getText(t.document.items.item.qty_refunded)):0,price:e.original_price?Number(t.getText(e.original_price)):0,itemLineId:e.item_id?Number(t.getText(e.item_id)):0,totalLinePrice:(e.qty_ordered-e.qty_refunded)*e.base_original_price||0})&&0!=i.price&&t.webReturnObject.basket.products.push(i)})):(i={description:this.document.items&&this.document.items.item&&this.document.items.item.name?this.getText(this.document.items.item.name):"",SKU:this.document.items&&this.document.items.item&&this.document.items.item.sku?this.getText(this.document.items.item.sku):"",quantity:this.document.items&&this.document.items.item&&this.document.items.item.qty_ordered?Number(this.getText(this.document.items.item.qty_ordered)):0,refundedQuantity:this.document.items&&this.document.items.item&&this.document.items.item.qty_refunded?Number(this.getText(this.document.items.item.qty_refunded)):0,price:this.document.items&&this.document.items.item&&this.document.items.item.original_price?Number(this.getText(this.document.items.item.original_price)):0,itemLineId:this.document.items&&this.document.items.item&&this.document.items.item.item_id?Number(this.getText(this.document.items.item.item_id)):0,totalLinePrice:(this.document.items.item.qty_ordered-this.document.items.item.qty_refunded)*this.document.items.item.base_original_price||0})&&0!=i.price&&this.webReturnObject.basket.products.push(i)),this},t.prototype.deviceId=function(t){return this.webReturnObject.deviceId=t,this},t.prototype.terminalId=function(t){return this.webReturnObject.terminalId=t,this},t.prototype.orgCode=function(t){return this.webReturnObject.orgCode=t,this},t.prototype.storeId=function(t){return this.webReturnObject.storeId=t,this},t.prototype.storeNodeId=function(t){return this.webReturnObject.storeNodeId=t,this},t.prototype.storeNodeStructure=function(t){return this.webReturnObject.storeNodeStructure=t,this},t.prototype.docId=function(t){return this.webReturnObject.id=t,this},t.prototype.updateUserID=function(t){return this.webReturnObject.userId=t,this},t.prototype.updateUserName=function(t){return this.webReturnObject.userName=t,this},t.prototype.build=function(){return this.webReturnObject},t.prototype.getText=function(t){return t&&t.text?t.text:t},t.prototype.getUTCDateTime=function(t){if(t)return new Date(t).toISOString()},t}();t.MapperLibraryComponent=c,t.MapperLibraryModule=u,t.RJMapperBuilderClass=y,t.WebReturnMapperBuilderClass=g,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */var o=function(){return(o=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],i=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,o,r=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(t){o={error:t}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a}function s(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(a(arguments[e]));return t}var c=function(){function t(){}return t.prototype.ngOnInit=function(){},t.decorators=[{type:e.Component,args:[{selector:"lib-mapper-library",template:"\n <p>\n mapper-library works!\n </p>\n "}]}],t.ctorParameters=function(){return[]},t}(),u=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[c],imports:[],exports:[c]}]}],t}(),m="SALE",d="REFUND",l="SALE_REFUND",h="SALE_EXCHANGE";var p={DELIVERY:1,DROP_SHIP:2,COLLECT_FROM_STORE:3};p[p.DELIVERY]="DELIVERY",p[p.DROP_SHIP]="DROP_SHIP",p[p.COLLECT_FROM_STORE]="COLLECT_FROM_STORE";var D={PERCENT:"Percent",AMOUNT:"AMOUNT"},b=function(){function t(t){this.numberUtilService=t,this.currentBasket={products:[],transactionDiscount:[],quantity:0,total:0,saleTotal:0,baseCurrency:""},this.basketSource=new n.BehaviorSubject(null),this.basket=this.basketSource.asObservable(),this.productSource=new n.BehaviorSubject(null),this.product=this.productSource.asObservable(),this.peerSource=new n.BehaviorSubject(!1),this.peerSync=this.peerSource.asObservable(),this.scanSource=new n.BehaviorSubject(!1),this.scanner=this.scanSource.asObservable()}return Object.defineProperty(t.prototype,"isMixedBasketSales",{get:function(){return this._isMixedBasketSales},set:function(t){this._isMixedBasketSales=t},enumerable:!0,configurable:!0}),t.prototype.updateBasket=function(t){this.currentBasket=t,this.isMixedBasketSales=this.filterProductListWithWebOrder(!0).length>0,this.basketSource.next(t)},t.prototype.updateBasketTotal=function(t,e){var n,i;t.quantity=0,t.total=0;try{for(var o=r(t.products),a=o.next();!a.done;a=o.next()){var s=a.value;t.quantity=t.quantity+s.quantity,t.total=this.numberUtilService.trimTo2Decimal(t.total)+this.numberUtilService.trimTo2Decimal(s.total)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}console.log("e:basket :basket service : basketDetails updated values for transaction id",t.transactionId,JSON.stringify(t)),t.basketTotal=t.total,e.updateBasket(t)},t.prototype.addlinePromotion=function(t,e){var n,i,o,a;if(console.log("e:basket :basket Service : promotionList and basketDetails for linePromotions",JSON.stringify(t),JSON.stringify(e)),t&&t.result&&t.result.linePromotions&&t.result.linePromotions.length>0)try{for(var s=r(e.products),c=s.next();!c.done;c=s.next()){var u=c.value;try{for(var m=(o=void 0,r(t.result.linePromotions)),d=m.next();!d.done;d=m.next()){var l=d.value;u.itemLineId.toString()===l.itemLineId.toString()&&(u.linePromotions=l)}}catch(t){o={error:t}}finally{try{d&&!d.done&&(a=m.return)&&a.call(m)}finally{if(o)throw o.error}}}}catch(t){n={error:t}}finally{try{c&&!c.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return e},t.prototype.addTransactionPromotion=function(t,e){var n=this;return console.log("e:basket :basket Service : promotionList and basketDetails for transactionPromotion",JSON.stringify(t),JSON.stringify(e),JSON.stringify(e.transactionPromotion)),t&&t.result&&t.result.transactionPromotion&&t.result.transactionPromotion.length>0&&t.result.transactionPromotion.forEach((function(t){var i=Object.assign({},t);i.itemLineIds=e.products.map((function(t){return t.itemLineId})),e.transactionPromotion||(e.transactionPromotion=[]),e.transactionPromotion.push(i),e=n.transactionPromotionProductPortionCalc(e,i)})),console.log("basket details in refund calculation file",JSON.stringify(e)),e},t.prototype.updateProductTotalForSummary=function(t){var e,n;t.total=0,t.quantity=0;try{for(var i=r(t.products),o=i.next();!o.done;o=i.next()){var a=o.value;a.linePromotions?a.total=a.linePromotions.promotionLinePrice:a.lineDiscount&&!a.linePromotions?a.total=a.lineDiscount.discountedLinePrice:a.total=a.totalLinePrice,a.total=a.total-Math.abs(a.refundedTotal?a.refundedTotal:0),t.total+=a.total,t.quantity=t.quantity+(a.quantity-(a.refundedQuantity?a.refundedQuantity:0)),console.log("e-basket:ExchangeSummaryScreen:update basketdetails total :"+t.total+" Product line ID : "+a.itemLineId+" product total : "+a.total,"quantity : "+t.quantity)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return this.updateBasketTotalForSummary(t)},t.prototype.updateBasketTotalForSummary=function(t){return t.basketTotal=t.total,console.info("ebasket : basket Service : update Basket Total for transaction transactionDiscount ",JSON.stringify(t.transactionDiscount)),console.info("ebasket : basket Service : update Basket Total for transaction transactionPromotion ",JSON.stringify(t.transactionPromotion)),t=this.updateTransactionPromotion(t),(t=this.updateTransactionDiscount(t)).basketTotal=Number(t.basketTotal.toFixed(2)),console.info("ebasket : basket Service : update Basket Total: basketTotal after promotion applied for basketTotal",t.basketTotal),t},t.prototype.updateTransactionDiscount=function(t){if(t.transactionDiscount&&t.transactionDiscount.length>0){var e=t.transactionDiscount.reduce((function(t,e){return t+e.discountAmount}),0);console.log("ebasket : basket Service : discountTotal ",e),t.basketTotal=t.basketTotal-Math.abs(e)}return t},t.prototype.updateTransactionPromotion=function(t){if(t.transactionPromotion&&t.transactionPromotion.length>0){var e=t.transactionPromotion.reduce((function(t,e){return t+e.promotionAmount}),0);t.basketTotal=t.basketTotal-Math.abs(e)}return t},t.prototype.updateBasketTotalWithoutDiscount=function(t){var e,n;t.total=0,t.quantity=0;try{for(var i=r(t.products),o=i.next();!o.done;o=i.next()){var a=o.value;a.linePromotions?a.total=a.linePromotions.promotionLinePrice:a.lineDiscount&&!a.linePromotions?a.total=a.lineDiscount.discountedLinePrice||0:a.total=a.totalLinePrice,a.total=a.total-Math.abs(a.refundedTotal?a.refundedTotal:0),t.total+=a.total,t.quantity=t.quantity+(a.quantity-(a.refundedQuantity?a.refundedQuantity:0)),console.log("e-basket:basket service:update basketdetails total :"+JSON.stringify(t)+t.total+" Product line ID : "+a.itemLineId+" product total : "+a.total)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return t.basketTotal=t.total,t},t.prototype.updateBasketTotalWithDiscounts=function(t){if(console.log("e:basket :RefundBasketScreen : this.basketDetails new values",t,JSON.stringify(t.basketTotal)),t.transactionPromotion&&t.transactionPromotion.length>0){var e=t.transactionPromotion.reduce((function(t,e){return t+e.promotionAmount}),0);t.basketTotal=t.basketTotal-e}if(t.transactionDiscount&&t.transactionDiscount.length>0){e=t.transactionDiscount.reduce((function(t,e){return t+e.discountAmount}),0);t.basketTotal=t.basketTotal-e}return console.log("e:basket :RefundBasketScreen : basket new values",JSON.stringify(t)),t},t.prototype.transactionDiscountAndPromotionProductortionCalculation=function(t){var e=this;return t.transactionDiscount&&t.transactionDiscount.length>0&&t.transactionDiscount.forEach((function(n){return t=e.transactionDiscountProductPortionCalc(t,n)})),t.transactionPromotion&&t.transactionPromotion.length>0&&t.transactionPromotion.forEach((function(n){t=e.transactionPromotionProductPortionCalc(t,n)})),console.log("ebasket: basket item discount protion calculation",t,t.products),t},t.prototype.transactionPromotionProductPortionCalc=function(t,e){var n=this,i=0,o=0;return t.products.forEach((function(t){if(e.itemLineIds.includes(t.itemLineId)){t=n.validateProductItemDiscount(t);var o=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);i+=t.total-n.numberUtilService.trimTo2Decimal2(o)}})),console.log("ebasket: trnsactionPromotion: "+JSON.stringify(e)+", selected products total: "+i),t.products.forEach((function(t){t=n.validateProductItemDiscount(t);var r=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);e.itemLineIds.includes(t.itemLineId)&&(o=(t.total-n.numberUtilService.trimTo2Decimal2(r))/i*100,t.itemDiscounts.trnPromotionsPortion+=e.promotionAmount*o/100,t.itemDiscounts.trnPromotionsPortion=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion))})),t},t.prototype.transactionDiscountProductPortionCalc=function(t,e){var n=this,i=0,o=0;return t.products.forEach((function(t){if(e.itemLineIds.includes(t.itemLineId)){t=n.validateProductItemDiscount(t);var o=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);i+=t.total-n.numberUtilService.trimTo2Decimal2(o)}})),console.log("ebasket: trnsactionDiscount: "+JSON.stringify(e)+", selected products total: "+i),t.products.forEach((function(t){t=n.validateProductItemDiscount(t),console.log(t.discountable,"ebasket : basket service : discountable in basket service");var r=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion)+n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnPromotionsPortion)-n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.refundPortion);e.itemLineIds.includes(t.itemLineId)&&1==t.discountable&&(o=(t.total-n.numberUtilService.trimTo2Decimal2(r))/i*100,t.itemDiscounts.trnDiscountsPortion+=e.discountAmount*o/100,t.itemDiscounts.trnDiscountsPortion=n.numberUtilService.trimTo2Decimal2(t.itemDiscounts.trnDiscountsPortion))})),t},t.prototype.validateProductItemDiscount=function(t){return t.itemDiscounts||(t.itemDiscounts={trnDiscountsPortion:0,trnPromotionsPortion:0,refundPortion:0}),t},t.prototype.markProduct=function(t){this.productSource.next(t)},t.prototype.stopPeerSyncProcess=function(t){this.peerSource.next(t)},t.prototype.scanStart=function(t){this.scanSource.next(t)},t.prototype.promotionRemainingCalculation=function(t){var e=0;return t.forEach((function(t){e+=t.promotionAmount})),e},t.prototype.discountRemainingCalculation=function(t){var e=0;return t.forEach((function(t){e+=t.discountAmount})),e},t.prototype.discountRefundedCalculation=function(t){var e=0;return t.forEach((function(t){t.discountAmount<0&&(e+=t.discountAmount)})),e},t.prototype.generateNewItemLineId=function(t){var e=0;t.length>0&&(e=t.map((function(t){return t.itemLineId})).reduce((function(t,e){return Math.max(t,e)})));return e+1},t.prototype.updateBasketProductDataAsPerQuantity=function(t,e){return console.log("ebasket: updateBasketProductDataAsPerQuantity : "+e+" product: "+JSON.stringify(t)),t.quantity=e,t.hasOwnProperty("lineDiscount")?(t.lineDiscount.discountedLinePrice=Number(this.numberUtilService.getFlooredFixed(t.lineDiscount.unitPrice*e,2)),t.lineDiscount.discountAmount=t.totalLinePrice-t.lineDiscount.discountedLinePrice):t.totalLinePrice=e*this.numberUtilService.trimTo2Decimal(t.selectedPrice),t.lineDiscount?t.total=t.lineDiscount.discountedLinePrice:t.total=t.totalLinePrice,console.log("ebasket: updateBasketProductDataAsPerQuantity : "+e+" product: "+JSON.stringify(t)),t},t.prototype.filterProductListWithWebOrder=function(t){return console.log("ebasket: filterProductListWithWebOrder hit",JSON.stringify(this.currentBasket.products)),t?this.currentBasket.products.filter((function(t){return t.isWebOrder})):this.currentBasket.products.filter((function(t){return!t.isWebOrder}))},t.prototype.filterProductListWithDelivery=function(){return console.log("ebasket: filterProductListWithDelivery hit",JSON.stringify(this.currentBasket.products)),this.currentBasket.products.filter((function(t){return t.deliveryMethod===p.DELIVERY.toString()}))},t.prototype.filterProductListWithDeliveryGroup=function(t,e){return console.log("ebasket: filterProductListWithDeliveryGroup hit",JSON.stringify(e)),e.filter((function(e){return e.deliveryGroup===t}))},t.prototype.generateNewDeliveryGroupNumber=function(t){var e=0;t.length>0&&(e=t.map((function(t){return t.deliveryGroup?parseInt(t.deliveryGroup):0})).reduce((function(t,e){return Math.max(t,e)})));return(e+1).toString()},t.prototype.getDeliveryGroupNumbers=function(t){console.log("getDeliveryGroupNumbers initiating : ",JSON.stringify(t));var e=[];if(t.length>0){var n=t.map((function(t){return t.deliveryGroup?parseInt(t.deliveryGroup):"1"===t.deliveryMethod?1:0}));e=Array.from(new Set(n)).sort((function(t,e){return t-e})),console.log("getDeliveryGroupNumbers : ",JSON.stringify(e))}return e},t.prototype.updateProductsWithNewDeliveryGroupNumber=function(t){console.log("updateProductsWithNewDeliveryGroupNumber initiating : ",JSON.stringify(t));var e=this.generateNewDeliveryGroupNumber(this.currentBasket.products);t.length>0&&this.currentBasket.products.forEach((function(n){t.forEach((function(t){n.itemLineId===t.itemLineId&&(n.deliveryGroup=e)}))})),this.updateBasket(this.currentBasket)},t.prototype.calculateEstimatedTime=function(t){try{var e,n=0,i="Hours";return t.forEach((function(t){"weeks"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value)*7,n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("week",n,i)):"days"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value),n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("days",n,i)):"months"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value)*30,n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("months",n,i)):"years"===t.leadTime.type.toLocaleLowerCase()?(e=24*Number(t.leadTime.value)*365,n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("years",n,i)):(e=Number(t.leadTime.value),n=Math.max(n,e),i=n===e?t.leadTime.type:i,console.log("hours",n,i))})),"days"===i.toLocaleLowerCase()?n/=24:"weeks"===i.toLocaleLowerCase()?n/=168:"months"===i.toLocaleLowerCase()?n/=720:"years"===i.toLocaleLowerCase()&&(n/=8760),{value:n.toString(),type:i}}catch(t){console.log("error in calculateEstimatedTime",t)}return 0},t.prototype.updateProductsWithDeliveryGroupNumber=function(t,e){console.log("updateProductsWithDeliveryGroupNumber initiating"),this.currentBasket.products.forEach((function(n){n.deliveryGroup===t&&(n.deliveryGroup=e)})),this.updateBasket(this.currentBasket)},t.prototype.getDeliveryInfo=function(){var t=this;console.log("getDeliveryGroupInfor initiating");try{var e={groups:[]};return this.getDeliveryGroupNumbers(this.currentBasket.products).forEach((function(n){var i={groupNumber:n,items:[],estimate:{type:"Hours",value:"0"}};t.currentBasket.products.forEach((function(t){t.deliveryGroup===n.toString()&&i.items.push(t)})),i.estimate=t.calculateEstimatedTime(i.items),e.groups.push(i)})),e}catch(t){console.log("error",t)}},t}();var f=function(){function t(t){this.cp=t}return t.prototype.trimTo2Decimal=function(t){return t},t.prototype.trimTo2Decimal2=function(t){return Number(this.getFlooredFixed(t,2))},t.prototype.getFlooredFixed=function(t,e){return(Math.floor(t*Math.pow(10,e))/Math.pow(10,e)).toFixed(e)},t.prototype.AppendWithCurrencySymbol=function(t,e){var n="";if(t){parseFloat(t.toString().replace(",",""));n=this.cp.transform(Number(t).toFixed(2),e.toLocaleUpperCase(),"symbol"),console.log("AppendWithCurrencySymbol :"+n)}else n=this.cp.transform("0.00",e.toLocaleUpperCase(),"symbol");return n},t.decorators=[{type:e.Injectable,args:[{providedIn:"root"}]}],t.ctorParameters=function(){return[{type:i.CurrencyPipe}]},t.ngInjectableDef=e.ɵɵdefineInjectable({factory:function(){return new t(e.ɵɵinject(i.CurrencyPipe))},token:t,providedIn:"root"}),t}();var T=function(){function t(t,e,n){this.currencyPipe=e,this.basketService=n,this.numberUtilService=new f(e),this.basketService=new b(this.numberUtilService),this.storeInfo=JSON.parse(localStorage.getItem("storeInfo")||"{}"),this.transactionDocument=t||{transactionId:"",offlineTransactionId:"",transactionRef:"",dateTime:"",orgCode:"",storeId:"",storeNodeId:"",storeNodeStructure:"",deviceId:"",terminalId:"",userId:"",initiatingModule:"eBasket",export:!1,basket:{},basketSummary:{},baseCurrency:"",type:"",operationStatus:"",createdAt:"",updatedAt:"",id:"",currentTransactionDetails:{},saleTotal:0}}return t.prototype.transactionRef=function(){var t=JSON.parse(localStorage.getItem("storeInfo")||"{}"),e=new Date,n=(65536*(1+Math.random())|0).toString(16).substring(1);return this.transactionDocument.transactionRef=t.orgCode+t.storeId+e.toISOString()+n,console.log("ebasket: transaction ref created",this.transactionDocument.transactionRef),this},t.prototype.transactionId=function(t,e){return void 0===e&&(e=!0),e&&(this.transactionDocument.transactionId=t),this},t.prototype.offlineTransactionId=function(t,e){return e||(this.transactionDocument.offlineTransactionId=t),this},t.prototype.storeNodeId=function(t){return this.transactionDocument.storeNodeId=t,this},t.prototype.storeNodeStructure=function(t){return this.transactionDocument.storeNodeStructure=t,this},t.prototype.orgCode=function(t){return this.transactionDocument.orgCode=t,this},t.prototype.storeId=function(t){return this.transactionDocument.storeId=t,this},t.prototype.dateTime=function(){var t=new Date;return this.transactionDocument.dateTime=t.toISOString(),this},t.prototype.deviceId=function(t){return this.transactionDocument.deviceId=t,this},t.prototype.terminalId=function(t){return this.transactionDocument.terminalId=t,this},t.prototype.export=function(t){return this.transactionDocument.export=t,this},t.prototype.basket=function(t){var e=this;return console.log("ebasket: basket details update in transaction document",JSON.stringify(t)),this.transactionDocument.subsidiaryId=t.subsidiaryId||localStorage.getItem("subsidiaryId")||"",this.transactionDocument.basket.products=[],this.transactionDocument.basket.lineDiscount=[],this.transactionDocument.basket.linePromotion=[],this.transactionDocument.basket.transactionPromotion=[],t.products.forEach((function(n,i){var o={itemDiscounts:{}};o.SKU=n.SKU,o.excludePromotion=n.excludePromotion,o.barCode=n.barcode,o.barcodes=n.barcodes,o.description=n.description,o.itemLineId=n.itemLineId?n.itemLineId.toString():""+(i+1),o.price=n.selectedPrice,o.quantity=n.quantity,o.totalLinePrice=n.quantity*n.selectedPrice,o.imageUrls=n.imageUrls,o.selectedRRPPrice=n.selectedRRPPrice,o.fullfilmentId=n.fullfilmentId?n.fullfilmentId:e.storeInfo.storeId,o.fullfilmentLocationName=n.fullfilmentLocationName,o.deliveryGroup=n.deliveryGroup,o.leadTime=n.leadTime,o.deliveryMethod=n.deliveryMethod,o.giftCard=n.giftCard,o.giftCardExpiryDate=n.giftCardExpiryDate,o.giftCardNumberIssued=n.giftCardNumberIssued,o.giftCardRecipientEmail=n.giftCardRecipientEmail,o.giftCardRecipientName=n.giftCardRecipientName,n.refundedQuantity>0&&(o.refundedQuantity=n.refundedQuantity,o.refundedPromotionalQuantity=n.refundPromotionalQuantity,o.refunded=n.refunded,o.refundedReasonDescription=n.refundedReasonDescription,o.refundedReason=n.refundedReason,o.refundedReasonDescription||(o.refundedReasonDescription=o.refundedReason),o.refundedTotal=n.refundedTotal,o.isLastExchanged=n.isLastExchanged),n.exchange&&(o.exchange=n.exchange),n.lineDiscount&&(o.lineDiscount=n.lineDiscount),o.itemDiscounts=n.itemDiscounts,e.transactionDocument.basket.products.push(o),e.lineDiscount(t)})),console.info("ebasket: transactiondocument basket details updated",JSON.stringify(this.transactionDocument.basket)),this},t.prototype.currentTransactionDetails=function(t){var e,n=this;if(console.log("ebasket: current transaction details for exchanges",t),this.transactionDocument.currentTransactionDetails.products=[],this.transactionDocument.currentTransactionDetails.linePromotion=[],this.transactionDocument.currentTransactionDetails.lineDiscount=[],this.transactionDocument.currentTransactionDetails.transactionDiscount=[],this.transactionDocument.currentTransactionDetails.products=t.products,this.transactionDocument.currentTransactionDetails.products=this.transactionDocument.currentTransactionDetails.products.filter((function(t){return 0!=t.refundedQuantity})),this.transactionDocument.currentTransactionDetails.products.forEach((function(t){t.refundedQuantity&&(t.quantity=t.refundedQuantity,t.totalLinePrice=Math.abs(t.refundedTotal),t.total=t.totalLinePrice,t.quantity===t.refundedQuantity&&(t.refunded=!0)),t.linePromotions&&!t.refundedQuantity&&n.transactionDocument.currentTransactionDetails.linePromotion.push(t.linePromotions),t.lineDiscount&&!t.refundedQuantity&&n.transactionDocument.currentTransactionDetails.lineDiscount.push(t.lineDiscount)})),console.log("ebasket: current transaction details after removing old products",this.transactionDocument.currentTransactionDetails.products),t.transactionDiscount&&t.transactionDiscount.length>0&&(e=this.transactionDocument.currentTransactionDetails.transactionDiscount).push.apply(e,s(t.transactionDiscount)),this.transactionDocument.currentTransactionDetails.basketSummary={},this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal=this.numberUtilService.trimTo2Decimal2(this.updateSaleTotal(this.transactionDocument.currentTransactionDetails)),this.transactionDocument.currentTransactionDetails.basketSummary.totalItems=t.quantity,this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal=t.basketTotal,this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal=this.updateCurrentTransactionDetailsRefundTotal(),this.transactionDocument.type===h)this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal=this.numberUtilService.trimTo2Decimal2(this.updateCurrentTransactionDetailsDiscountTotal());else if(this.transactionDocument.currentTransactionDetails.transactionDiscount&&this.transactionDocument.currentTransactionDetails.transactionDiscount.length>0){var i=0;this.transactionDocument.currentTransactionDetails.transactionDiscount.forEach((function(t){i+=t.discountAmount})),this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal=Math.abs(i)}else this.transactionDocument.currentTransactionDetails.basketSummary.discountTotal=0;return console.log("ebasket:this.transactionDocument.currentTransactionDetails",JSON.stringify(this.transactionDocument.currentTransactionDetails)),this},t.prototype.updateCurrentTransactionDetailsTaxBreakdown=function(t){var e=this,n={taxLines:[],totalTaxableAmount:0};return this.transactionDocument.currentTransactionDetails.transactionDiscount&&this.transactionDocument.currentTransactionDetails.transactionDiscount.length>0&&this.transactionDocument.currentTransactionDetails.transactionDiscount.forEach((function(t){t.discountAmount})),this.transactionDocument.currentTransactionDetails.products&&this.transactionDocument.currentTransactionDetails.products.length>0&&this.transactionDocument.currentTransactionDetails.products.forEach((function(i){var o={itemLineId:i.itemLineId,VAT:i.selectedVAT?i.selectedVAT:0,VATCode:i.selectedVATCode,taxLineTotal:0,taxableAmount:i.total,PreTax:0};console.info("Product contribution : item line ID :current transaction Details",i.itemLineId,"tax line :",JSON.stringify(o),JSON.stringify(t.basketTotal)),i.refundedQuantity&&i.refundedQuantity>0?o.taxableAmount=-Math.abs(o.taxableAmount-i.itemDiscounts.currentRefundPortion):o.taxableAmount=o.taxableAmount-i.itemDiscounts.trnDiscountsPortion-i.itemDiscounts.trnPromotionsPortion,o.PreTax=e.numberUtilService.trimTo2Decimal2(100*o.taxableAmount/(100+o.VAT)),n.totalTaxableAmount+=o.taxableAmount,o.taxableAmount=e.numberUtilService.trimTo2Decimal2(o.taxableAmount),o.taxLineTotal=e.numberUtilService.trimTo2Decimal2(o.taxableAmount-o.PreTax),n.taxLines.push(o)})),n.totalTaxableAmount=this.numberUtilService.trimTo2Decimal2(n.totalTaxableAmount),this.transactionDocument.currentTransactionDetails.taxBreakdown=n,this.transactionDocument.currentTransactionDetails.taxBreakdown&&this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines&&this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.length>0?this.transactionDocument.currentTransactionDetails.basketSummary.VATTotal=this.numberUtilService.trimTo2Decimal2(this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.reduce((function(t,e){return t+e.taxLineTotal}),0)):this.transactionDocument.currentTransactionDetails.basketSummary.VATTotal=0,console.log("eBasket:after calculating tax currenttransactionDetails",this.transactionDocument.currentTransactionDetails),this},t.prototype.updateCurrentTransactionDetailsTotalTaxSummary=function(){var t=this;console.log("Total Tax Summery Request :",JSON.stringify(this.transactionDocument.currentTransactionDetails.taxBreakdown));var e,n=[];return console.log("Tax Lines for Total Tax Summery :",JSON.stringify(this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines)),this.transactionDocument.currentTransactionDetails.taxBreakdown.taxLines.forEach((function(e){var i={VATCode:"",VAT:-12345,PreTaxSum:0,TaxSum:0,TXrateSum:0};i.VATCode=e.VATCode,i.VAT=e.VAT,i.PreTaxSum=t.numberUtilService.trimTo2Decimal2(e.PreTax),i.TaxSum=t.numberUtilService.trimTo2Decimal2(e.taxLineTotal),i.TXrateSum=t.numberUtilService.trimTo2Decimal2(i.PreTaxSum+i.TaxSum),n.push(i)})),console.log("Total Tax Summery Without Grouped : ",JSON.stringify(n)),e=n.reduce((function(t,e){var n=t.findIndex((function(t){return t.VAT===e.VAT}));return-1===n?t.push(e):(t[n].VATCode=e.VATCode,t[n].VAT=e.VAT,t[n].PreTaxSum+=e.PreTaxSum,t[n].TaxSum+=e.TaxSum,t[n].TXrateSum+=e.TXrateSum),t}),[]),console.log("Total Tax Summer Group :",JSON.stringify(e)),this.transactionDocument.currentTransactionDetails.totalTaxSummary=e,this},t.prototype.updateCurrentTransactionDetailsDiscountTotal=function(){var t=this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal?this.transactionDocument.currentTransactionDetails.basketSummary.refundTotal:0;console.log("e-basket: transaction builder updateCurrentTransactionDetailsDiscountTotal: discountTotal",t,this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal,this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal);var e=Math.abs(Math.abs(this.transactionDocument.currentTransactionDetails.basketSummary.saleTotal)-(Math.abs(this.transactionDocument.currentTransactionDetails.basketSummary.basketTotal)+Math.abs(t)));return console.log("e-basket: transaction builder updateCurrentTransactionDetailsDiscountTotal: discountTotal",e),Number(e.toFixed(2))},t.prototype.updateCurrentTransactionDetailsRefundTotal=function(){for(var t=0,e=0;e<this.transactionDocument.currentTransactionDetails.products.length;e++){var n=this.transactionDocument.currentTransactionDetails.products[e];n.refundedTotal&&(t+=n.refundedTotal),console.log("ebasket : transaction Service: totalRefund for Current TransactionDetails"+t)}return t},t.prototype.basketSummary=function(t){return this.transactionDocument.basketSummary.basketTotal=this.numberUtilService.trimTo2Decimal(t.basketTotal),this.transactionDocument.basketSummary.saleTotal=this.numberUtilService.trimTo2Decimal2(this.updateSaleTotal(t)),this.transactionDocument.basketSummary.refundTotal=this.getRefundTotal(),(this.transactionDocument.basket.lineDiscount||this.transactionDocument.basket.linePromotion)&&(this.transactionDocument.basketSummary.discountTotal=this.numberUtilService.trimTo2Decimal2(this.updateDiscountTotal())),this.transactionDocument.basketSummary.totalItems=t.quantity,this.transactionDocument.basket.taxBreakdown?this.transactionDocument.basketSummary.VATTotal=this.numberUtilService.trimTo2Decimal2(this.transactionDocument.basket.taxBreakdown.taxLines.reduce((function(t,e){return t+e.taxLineTotal}),0)):this.transactionDocument.basketSummary.VATTotal=0,console.info("ebasket: basketsummary updated in transaction document: ",JSON.stringify(this.transactionDocument.basketSummary)),this},t.prototype.lineDiscount=function(t){this.transactionDocument.basket.lineDiscount=[];for(var e=0;e<t.products.length;e++){var n=t.products[e];n.lineDiscount&&(this.transactionDocument.basket.lineDiscount.push(n.lineDiscount),this.transactionDocument.basket.lineDiscount=this.transactionDocument.basket.lineDiscount.reduce((function(t,e){return t.find((function(t){return t.itemLineId===e.itemLineId}))||t.push(e),t}),[]))}return this},t.prototype.exchange=function(t){this.transactionDocument.basket.exchange=t.exchange&&t.exchange.length>0?s(t.exchange):[];for(var e=function(e){var i=t.products[e];if(null!=i.exchange&&!n.transactionDocument.basket.exchange.some((function(t){return t.exchangeId===i.exchange.exchangeId}))){for(var o=[],r=0;r<i.exchange.newItems.length;r++){var a=i.exchange.newItems[r],c={lineItemId:a.itemLineId,Quantity:a.quantity};o.push(c)}i.exchange.newItems=s(o),n.transactionDocument.basket.exchange.push(i.exchange)}console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.basket exchange",JSON.stringify(n.transactionDocument.basket.exchange))},n=this,i=0;i<t.products.length;i++)e(i);return this},t.prototype.addExchangeData=function(t){return this.transactionDocument.basket.exchange=t.basket.exchange?s(t.basket.exchange):null,this},t.prototype.linePromotion=function(t){this.transactionDocument.basket.linePromotion=[];for(var e=0;e<t.products.length;e++){var n=t.products[e];n.linePromotions&&(this.transactionDocument.basket.linePromotion.push(n.linePromotions),this.transactionDocument.basket.linePromotion=this.transactionDocument.basket.linePromotion.reduce((function(t,e){return t.find((function(t){return t.itemLineId===e.itemLineId}))||t.push(e),t}),[]))}return this},t.prototype.transactionPromotion=function(t){return t.transactionPromotion&&(this.transactionDocument.basket.transactionPromotion=t.transactionPromotion,console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.basket.transactionPromotion",JSON.stringify(this.transactionDocument.basket.transactionPromotion))),this},t.prototype.transactionDiscount=function(t){return t.transactionDiscount&&(this.transactionDocument.basket.transactionDiscount=t.transactionDiscount,console.log("e-basket :TransactionDocumentBuilder: transaction Discount",JSON.stringify(this.transactionDocument.basket.transactionDiscount))),this},t.prototype.paymentDetails=function(t){return console.info("ebasket : payment details after transaction completed",JSON.stringify(t)),this.transactionDocument.paymentDetails=t,this},t.prototype.splitPayment=function(t){return this.transactionDocument.splitPayment=t,this},t.prototype.isPaymentCompleted=function(t){return this.transactionDocument.isPaymentCompleted=t,this},t.prototype.baseCurrency=function(t){return this.transactionDocument.baseCurrency=t,this},t.prototype.giftOption=function(t){return console.log("e-basket :TransactionDocumentBuilder: this.transactionDocument.giftoption",t),t&&(this.transactionDocument.giftedReceipt=t),this},t.prototype.type=function(t){return this.transactionDocument.type=t,this},t.prototype.operationStatus=function(t){return this.transactionDocument.operationStatus=t,this},t.prototype.createdAt=function(){var t=new Date;return this.transactionDocument.createdAt=t.toISOString(),this.transactionDocument.updatedAt=t.toISOString(),this},t.prototype.updatedAt=function(){var t=new Date;return this.transactionDocument.updatedAt=t.toISOString(),this},t.prototype.transactionCompletedAt=function(){var t=new Date;return this.transactionDocument.transCompletedAt=t.toISOString(),this},t.prototype.build=function(){return this.transactionDocument},t.prototype.saleTotalInRefund=function(t){return this.transactionDocument.saleTotal=t,this},t.prototype.getBasketDetails=function(){var t=this;console.info("ebasket: Getting Basket for transactionDocument",JSON.stringify(this.transactionDocument));var e={subsidiaryId:this.transactionDocument.subsidiaryId,transactionDiscount:this.transactionDocument.basket.transactionDiscount,transactionPromotion:this.transactionDocument.basket.transactionPromotion,transactionId:this.transactionDocument.transactionId,offlineTransactionId:this.transactionDocument.offlineTransactionId,total:this.transactionDocument.basketSummary.basketTotal,basketTotal:this.transactionDocument.basketSummary.basketTotal,discountTotal:this.transactionDocument.basketSummary.discountTotal,saleTotal:this.transactionDocument.basketSummary.saleTotal,refundTotal:this.transactionDocument.basketSummary.refundTotal,quantity:this.transactionDocument.basketSummary.totalItems,products:[],baseCurrency:this.transactionDocument.baseCurrency,customer:this.transactionDocument.customer};return e.products=[],this.transactionDocument.basket.products.forEach((function(n,i){console.log(JSON.stringify(n),"ebasket: basket detail update in basket");var o={};o.SKU=n.SKU,o.barcode=n.barCode,o.barcodes=n.barcodes,o.description=n.description,o.imageUrls=n.imageUrls,o.currency=t.transactionDocument.baseCurrency,o.totalLinePrice=n.totalLinePrice,o.itemLineId=Number(n.itemLineId),o.excludePromotion=n.excludePromotion,o.selectedPrice=n.price,o.quantity=n.quantity,o.total=n.totalLinePrice,o.selectedRRPPrice=n.selectedRRPPrice,o.fullfilmentId=n.fullfilmentId,o.fullfilmentLocationName=n.fullfilmentLocationName,o.deliveryGroup=n.deliveryGroup||"1",o.leadTime=n.leadTime,o.deliveryMethod=n.deliveryMethod||p.COLLECT_FROM_STORE.toString(),o.fullfilmentId!=t.transactionDocument.storeId&&(o.isWebOrder=!0),o.giftCard=n.giftCard,o.giftCardExpiryDate=n.giftCardExpiryDate,o.giftCardNumberIssued=n.giftCardNumberIssued,o.giftCardRecipientEmail=n.giftCardRecipientEmail,o.giftCardRecipientName=n.giftCardRecipientName,t.transactionDocument.basket.lineDiscount&&t.transactionDocument.basket.lineDiscount.length>0&&t.transactionDocument.basket.lineDiscount.forEach((function(t){n.itemLineId===t.itemLineId.toString()&&(o.lineDiscount=t,o.total=t.discountedLinePrice)})),t.transactionDocument.basket.linePromotion&&t.transactionDocument.basket.linePromotion.length>0&&t.transactionDocument.basket.linePromotion.forEach((function(t){n.itemLineId===t.itemLineId.toString()&&(o.linePromotions=t,o.total=t.promotionLinePrice)})),t.transactionDocument.basket.taxBreakdown&&t.transactionDocument.basket.taxBreakdown.taxLines.length>0&&t.transactionDocument.basket.taxBreakdown.taxLines.forEach((function(t){n.itemLineId&&n.itemLineId===t.itemLineId.toString()&&(o.selectedVAT=t.VAT,o.selectedVATCode=t.VATCode)})),t.transactionDocument.type===d?o.total=n.refundedTotal:(t.transactionDocument.type===l||h)&&n.refundedQuantity>0&&(o.refundedReasonDescription=n.refundedReasonDescription,o.refundedReason=n.refundedReason,o.refundedReasonDescription||(o.refundedReasonDescription=o.refundedReason),o.refundedQuantity=n.refundedQuantity,o.refundPromotionalQuantity=n.refundedPromotionalQuantity,o.refundedTotal=n.refundedTotal,o.total-=Math.abs(o.refundedTotal),o.isLastExchanged=n.isLastExchanged),t.transactionDocument.type===d&&o.total>0&&(o.total*=-1),e.products.push(o)})),(e=this.getTransactionDiscountAndTransactionPromotionPortion(e)).total=(e.basketTotal||0)+this.getTotalDiscountWithTransactionDiscountsAndPromotions(e),this.transactionDocument.type===l&&(e.quantity=this.getRefundedTotalWithQuantity(e)),console.info("ebasket: Basket created successfully",JSON.stringify(e)),e},t.prototype.getTransactionDiscountAndTransactionPromotionPortion=function(t){var e=this;return t.transactionDiscount&&t.transactionDiscount.length>0&&t.transactionDiscount.forEach((function(n){n.itemLineIds||(n.itemLineIds=t.products.map((function(t){return t.itemLineId}))),t=e.basketService.transactionDiscountProductPortionCalc(t,n)})),t.transactionPromotion&&t.transactionPromotion.length>0&&t.transactionPromotion.forEach((function(n){if(!n.itemLineIds){var i=t.products.filter((function(t){return!1===t.excludePromotion}));n.itemLineIds=i.map((function(t){return t.itemLineId}))}t=e.basketService.transactionPromotionProductPortionCalc(t,n)})),t},t.prototype.getTotalDiscountWithTransactionDiscountsAndPromotions=function(t){var e=0;return t.transactionPromotion&&t.transactionPromotion.length>0&&(e+=t.transactionPromotion.reduce((function(t,e){return t+e.promotionAmount}),0)),t.transactionDiscount&&t.transactionDiscount.length>0&&(e+=t.transactionDiscount.reduce((function(t,e){return t+e.discountAmount}),0)),console.log("ebasket : TransactionDocumentBuilder : Transaction discount Total:",e),e},t.prototype.appendCurrencySymbol=function(t,e){if(e>=0){var n=t+e;return console.log(n,"ebasket: add currency with value"),n}n="-"+(t+-1*e);return console.log(n,"-(currency+(value*-1))"),n},t.prototype.updateSaleTotal=function(t){return t.products.reduce((function(t,e){return t+e.totalLinePrice}),0)},t.prototype.getTotalWithLineDiscountAndLinePromotionApplied=function(t){var e,n,i=0;try{for(var o=r(t.products),a=o.next();!a.done;a=o.next()){var s=a.value;i+=s.total,console.log("e-basket:update product Total:"+i,JSON.stringify(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i},t.prototype.getRefundedTotalWithQuantity=function(t){for(var e=0,n=0;n<t.products.length;n++){var i=t.products[n];i.refundedReasonDescription?e+=i.quantity-i.refundedQuantity:e+=i.quantity}return e},t.prototype.updateDiscountTotal=function(){var t=this.transactionDocument.basketSummary.refundTotal?this.transactionDocument.basketSummary.refundTotal:0;console.info("e-basket: transaction builder: refundTotal",JSON.stringify(t),JSON.stringify(this.transactionDocument.basketSummary));var e=Math.abs(Math.abs(this.transactionDocument.basketSummary.saleTotal)-(Math.abs(this.transactionDocument.basketSummary.basketTotal)+Math.abs(t)));return console.log("e-basket: transaction builder: discountTotal",JSON.stringify(e)),Number(e.toFixed(2))},t.prototype.updateReasonCode=function(t){return this.transactionDocument.reasonCode=t.code,this.transactionDocument.reasonDescription=t.name,this},t.prototype.updateManagerOverride=function(t){return this.transactionDocument.override=t,this},t.prototype.updateUserID=function(t){return this.transactionDocument.userId=t,this},t.prototype.updateUserName=function(t){return this.transactionDocument.userName=t,this},t.prototype.addCustomerDetails=function(t){return this.transactionDocument.customer=t,this},t.prototype.updateTaxBreakdown=function(t){var e=this,n={taxLines:[],totalTaxableAmount:0};return t.products.forEach((function(t){var i={itemLineId:t.itemLineId,VAT:t.selectedVAT?t.selectedVAT:0,VATCode:t.selectedVATCode,taxLineTotal:0,taxableAmount:t.total,PreTax:0};console.info("Product contribution : item line ID :",t.itemLineId,"tax line :",JSON.stringify(i));var o=(t=e.basketService.validateProductItemDiscount(t)).itemDiscounts.trnDiscountsPortion+t.itemDiscounts.trnPromotionsPortion-t.itemDiscounts.refundPortion;console.info("Product contribution : item line ID :",t.itemLineId,"contribution :",JSON.stringify(o)),i.taxableAmount-=o,i.PreTax=e.numberUtilService.trimTo2Decimal2(100*i.taxableAmount/(100+i.VAT)),n.totalTaxableAmount+=i.taxableAmount,i.taxableAmount=e.numberUtilService.trimTo2Decimal2(i.taxableAmount),i.taxLineTotal=e.numberUtilService.trimTo2Decimal2(i.taxableAmount-i.PreTax),n.taxLines.push(i)})),n.totalTaxableAmount=this.numberUtilService.trimTo2Decimal2(n.totalTaxableAmount),this.transactionDocument.basket.taxBreakdown=n,this},t.prototype.updateTotalTaxSummary=function(){var t=this;console.log("Total Tax Summery Request :",JSON.stringify(this.transactionDocument.basket.taxBreakdown));var e,n=[];return console.log("Tax Lines for Total Tax Summery :",JSON.stringify(this.transactionDocument.basket.taxBreakdown.taxLines)),this.transactionDocument.basket.taxBreakdown.taxLines.forEach((function(e){var i={VATCode:"",VAT:-12345,PreTaxSum:0,TaxSum:0,TXrateSum:0};i.VATCode=e.VATCode,i.VAT=e.VAT,i.PreTaxSum=t.numberUtilService.trimTo2Decimal2(e.PreTax),i.TaxSum=t.numberUtilService.trimTo2Decimal2(e.taxLineTotal),i.TXrateSum=t.numberUtilService.trimTo2Decimal2(i.PreTaxSum+i.TaxSum),n.push(i)})),console.log("Total Tax Summery Without Grouped : ",JSON.stringify(n)),e=n.reduce((function(t,e){var n=t.findIndex((function(t){return t.VAT===e.VAT}));return-1===n?t.push(e):(t[n].VATCode=e.VATCode,t[n].VAT=e.VAT,t[n].PreTaxSum+=e.PreTaxSum,t[n].TaxSum+=e.TaxSum,t[n].TXrateSum+=e.TXrateSum),t}),[]),console.log("Total Tax Summer Group :",e),this.transactionDocument.basket.totalTaxSummary=e,this},t.prototype.addOriginalTransId=function(t){return this.transactionDocument.type!==d&&this.transactionDocument.type!==l&&this.transactionDocument.type!==h||(this.transactionDocument.originalTransId=t.transactionId,t.apiResponse&&t.apiResponse.internalId&&(this.transactionDocument.originalExternalId=t.apiResponse.internalId.toString())),this},t.prototype.addUnreferencedRefund=function(){return this.transactionDocument.unreferencedRefund=!0,this},t.prototype.getRefundTotal=function(){for(var t=0,e=0;e<this.transactionDocument.basket.products.length;e++){var n=this.transactionDocument.basket.products[e];n.refundedTotal&&(t+=n.refundedTotal),console.log("ebasket : transaction Service: totalRefund"+t)}return t},t.prototype.docId=function(t){return this.transactionDocument.id=t,this},t}();var y=function(){function t(t){this.itemCount=0,this.largestNumber=0,this.rjObject={},this.transactionDocument=t||{transactionId:"",offlineTransactionId:"",transactionRef:"",dateTime:"",orgCode:"",storeId:"",storeNodeId:"",storeNodeStructure:"",deviceId:"",terminalId:"",userId:"",initiatingModule:"eBasket",export:!1,basket:{},basketSummary:{},baseCurrency:"",type:"",operationStatus:"",createdAt:"",updatedAt:"",id:"",currentTransactionDetails:{},saleTotal:0},this.initilizeItemCount(),this.setLineNumberForProducts(),this.createdAt=this.getDate(this.transactionDocument.createdAt),this.updatedAt=this.getDate(this.transactionDocument.updatedAt)}return t.prototype.getPosbasketInfo=function(){return this.rjObject.Keyword=this.generateKeyword(),this.rjObject.ID=this.generateId(this.createdAt),this.rjObject.XMLSchemaVersion="2",this.rjObject.LastUpdated=this.updatedAt,this.rjObject.MajorVersion=this.majorVersion,this.rjObject.MinorVersion=this.minorVersion,this.rjObject.ManifestVersion=this.manifestVersion,this.rjObject.DatabaseSchemaVersion=this.databaseSchemaVersion,this.rjObject.BasketType=this.basketType,this.rjObject.State=this.getState(),this.rjObject.ExternalState=this.externalState,this},t.prototype.getheaderInfo=function(){return this.rjObject.Header={},this.rjObject.Header.TimeZoneOffset=this.convertToString(this.generateTimezoneoffset(this.transactionDocument.createdAt)),this.rjObject.Header.DateTimeCreated=this.createdAt,this.rjObject.Header.OriginatedBy={},this.rjObject.Header.OriginatedBy.DeviceID=this.deviceId,this.rjObject.Header.OriginatedBy.CashierID=this.cashierId,this.rjObject.Header.OriginatedBy.CompanyID=this.companyId,this.rjObject.Header.OriginatedBy.StoreID=this.transactionDocument.storeId,this.rjObject.Header.OriginatedBy.BranchID=this.branchId,this.rjObject.Header.OriginatedBy.TerminalNumber=this.terminalNumber,this.rjObject.Header.OriginatedBy.TransactionNumber=this.transactionNumber,this.rjObject.Header.TaxMethodID=this.taxMethodId,this.rjObject.Header.DynamicStockLookup=this.generateDynamicStockLookUp(),this.rjObject.Header.BasketLanguageID=this.basketLanguageId,this.rjObject.Header.BasketCountryID=this.basketCountryId,this.rjObject.Header.BasketCurrencyID=this.transactionDocument.baseCurrency,this.rjObject.Header.TradingRegionID=this.tradingRegionId,this.rjObject.Header.Eurozone=" ",this.rjObject.Header.EuroBaseExchangeRate="",this.rjObject.Header.PrintableName=this.transactionDocument.userName,this},t.prototype.rjMapper=function(){var t=this,e=[];if(this.transactionDocument.basket.transactionDiscount&&this.transactionDocument.basket.transactionDiscount.length>0&&(e=this.transactionDocument.basket.transactionDiscount),this.transactionDocument.type===m){this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(n){var i=[];if(t.transactionDocument.basket.lineDiscount&&t.transactionDocument.basket.lineDiscount.length>0&&(i=t.transactionDocument.basket.lineDiscount.filter((function(t){return t.itemLineId===n.itemLineId}))).length>0){var o=t.transactionDocument.basket.lineDiscount.indexOf(i[0]);o>-1&&t.transactionDocument.basket.lineDiscount.splice(o,1)}var r=t.addProduct(n,i.length>0?i[0]:null,e.length>0?e:null);t.rjObject.ProductSale.push(r),t.getModifierItem(i.length>0?i[0]:null,n.itemLineId)}));var n=[];this.transactionDocument.basket.transactionPromotion&&this.transactionDocument.basket.transactionPromotion.length>0&&(n=this.transactionDocument.basket.transactionPromotion,this.getTransactionPromotion(n))}else if(this.transactionDocument.type===d)this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(n){var i=t.returnProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);t.rjObject.ProductReturn.push(i),t.getModifierItem(n.lineDiscount,n.itemLineId)}));else if(this.transactionDocument.type===l){this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],(new T).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(n){var i=t.returnProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);i.Return=o({},i.Return,{OriginalReceiptSupplied:0,OriginalBranchID:0,OriginalTerminalNumber:0,OriginalTransactionNumber:0,OriginalCashierNumber:0}),t.rjObject.ProductReturn.push(i),t.getModifierItem(n.lineDiscount,n.itemLineId)}))}else if(this.transactionDocument.type===h){this.rjObject.ProductReturn=[],this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],(new T).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(n){if(n.refundedQuantity>0){var i=t.returnProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);i.Return=o({},i.Return,{OriginalReceiptSupplied:0,OriginalBranchID:0,OriginalTerminalNumber:0,OriginalTransactionNumber:0,OriginalCashierNumber:0}),t.rjObject.ProductReturn.push(i)}else{var r=t.addProduct(n,n.hasOwnProperty("lineDiscount")?n.lineDiscount:null,e.length>0?e:null);t.rjObject.ProductSale.push(r)}t.getModifierItem(n.lineDiscount,n.itemLineId)}))}return(this)},t.prototype.getBasketDiscount=function(){var t=this;return this.transactionDocument.basket.transactionDiscount?(this.rjObject.BasketDiscount=[],this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={};n.XMLSchemaVersion=t.xmlSchemaVersion,n.DeviceID=t.deviceId,n.DateTimeCreated=t.updatedAt,n.NetValue=t.convertToString(-1*e.discountAmount),n.EffectiveNetValue=t.convertToString(-1*e.discountAmount),n.Description=e.reasonDisplayText,n.UserID=t.transactionDocument.userName,n.ReasonCodeID=e.reasonCode,n.DiscountType=t.convertToString(e.discountType.toUpperCase()==D.PERCENT.toUpperCase()?0:1),n.RoundingRule=t.convertToString(2),n.ModifiedLineNumber=e.itemLineIds,n.LineNumber=t.convertToString(t.generateLineNumber()),n.DiscountedValue=t.transactionDocument.basketSummary.basketTotal+t.transactionDocument.basketSummary.discountTotal,e.discountType.toUpperCase()==D.PERCENT.toUpperCase()&&(n.DiscountPercentage=t.convertToString((e.discountAmount/t.transactionDocument.basketSummary.basketTotal).toFixed(1))),"REFUND"===t.transactionDocument.type&&(n.NetValue=t.convertToString(e.discountAmount<0?-e.discountAmount:e.discountAmount),n.EffectiveNetValue=t.convertToString(e.discountAmount<0?-e.discountAmount:e.discountAmount)),t.rjObject.BasketDiscount.push(n)})),this):this},t.prototype.getModifierItem=function(t,e){if(t&&e){var n={XMLSchemaVersion:1};n.LineNumber=this.generateLineNumber(),n.NetValue=0,n.EffectiveNetValue=0,n.Description=t.percentageDiscountReasonName?t.percentageDiscountReasonName:t.priceOverrideReasonName,n.DeviceID=this.deviceId,n.UserID=this.transactionDocument.userName,n.DateTimeCreated=this.updatedAt,n.AuthorisingUserID=this.transactionDocument.userName,n.ReasonCodeID=t.percentageDiscountReasonCode?t.percentageDiscountReasonCode:t.priceOverrideReasonCode,n.ModifiedLineNumber=e,n.ModifiedIndex=1,this.rjObject.ModifierItem.push(n)}},t.prototype.getTrailerInfo=function(){var t=this;return this.rjObject.Trailer={},this.rjObject.Trailer.DateTimeCompleted=this.updatedAt,this.rjObject.Trailer.CompletedBy={},this.rjObject.Trailer.CompletedBy.DeviceID=this.deviceId,this.rjObject.Trailer.CompletedBy.CashierID=this.cashierId,this.rjObject.Trailer.CompletedBy.StoreID=this.transactionDocument.storeId,this.rjObject.Trailer.CompletedBy.BranchID=this.branchId,this.rjObject.Trailer.CompletedBy.TerminalNumber=this.terminalNumber,this.rjObject.Trailer.CompletedBy.TransactionNumber=this.transactionNumber,this.rjObject.Trailer.Total=this.convertToString(100*this.transactionDocument.basketSummary.basketTotal),this.rjObject.Trailer.ItemCount=this.itemCount,this.rjObject.Trailer.ItemQuantity=this.convertToString(this.transactionDocument.basketSummary.totalItems),this.rjObject.Trailer.NetItemQuantity=this.convertToString(this.transactionDocument.basketSummary.totalItems),this.rjObject.Trailer.TaxTotal=this.convertToString(this.removeDecimal(this.transactionDocument.basketSummary.VATTotal)),this.rjObject.Trailer.SequenceDeviceID=this.deviceId,this.rjObject.Trailer.SequenceNumber="snsn",this.rjObject.Trailer.TaxItem=[],this.transactionDocument.basket.taxBreakdown.taxLines.forEach((function(e){var n={};n.XMLSchemaVersion=t.xmlSchemaVersion,n.TaxRate=t.convertToString(e.VATCode),n.TaxableTotal=t.convertToString(t.removeDecimal(e.taxableAmount)),n.TaxTotal=t.convertToString(t.removeDecimal(t.removeDecimal(e.taxLineTotal))),n.TaxDescription=t.convertToString(e.VATCode),n.TaxIncluded="1",n.TaxPercentage=t.addDecimal(e.VAT.toFixed(2)).toFixed(2),t.rjObject.Trailer.TaxItem.push(n)})),(this.transactionDocument.basket.linePromotion.length>0||this.transactionDocument.basket.linePromotion.length>0)&&(this.rjObject.Trailer.PromotionItem=[],this.transactionDocument.basket.linePromotion.length>0&&this.transactionDocument.basket.linePromotion.forEach((function(e){var n={};n.PromotionID=e.promotionId,n.PromotionSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionQuantity="1",n.PromotionDescription=e.displayText,n.PromotionHit={},n.PromotionHit.XMLSchemaVersion=t.xmlSchemaVersion,n.PromotionHit.HitNumber="1",n.PromotionHit.HitQuantity="1",n.PromotionHit.HitSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionHit.PromotionTrigger={};var i=t.transactionDocument.basket.products.find((function(t){return t.itemLineId==e.itemLineId}));n.PromotionHit.PromotionTrigger.XMLSchemaVersion=t.xmlSchemaVersion,n.PromotionHit.PromotionTrigger.ProductID=i.SKU,n.PromotionHit.PromotionTrigger.UnitValue=t.convertToString(e.promotionLinePrice/i.quantity),n.PromotionHit.PromotionTrigger.LineNumber=t.getNumber(i.SKU),n.PromotionHit.PromotionTrigger.Quantity=t.convertToString(i.quantity.toFixed(1)),n.PromotionHit.PromotionTrigger.TaxCode=t.transactionDocument.basket.taxBreakdown.taxLines.find((function(t){return t.itemLineId==e.itemLineId})).VATCode,t.rjObject.Trailer.PromotionItem.push(n)})),this.transactionDocument.basket.transactionPromotion.length>0&&this.transactionDocument.basket.transactionPromotion.forEach((function(e){var n={};n.PromotionID=e.promotionId,n.PromotionSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionQuantity="1",n.PromotionDescription=e.displayText,n.PromotionHit={},n.PromotionHit.XMLSchemaVersion=t.xmlSchemaVersion,n.PromotionHit.HitNumber="1",n.PromotionHit.HitQuantity="1",n.PromotionHit.HitSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionHit.PromotionTrigger=[],t.transactionDocument.basket.products.forEach((function(i){var o={};e.itemLineIds.forEach((function(r){JSON.stringify(r)===i.itemLineId&&(o.XMLSchemaVersion=t.xmlSchemaVersion,o.ProductID=i.SKU,o.UnitValue=t.convertToString(e.promotionLinePrice/i.quantity),o.LineNumber=t.getNumber(i.SKU),o.Quantity=t.convertToString(i.quantity),o.TaxCode=t.transactionDocument.basket.taxBreakdown.taxLines.find((function(t){return t.itemLineId==i.itemLineId})).VATCode,n.PromotionHit.PromotionTrigger.push(o))}))})),t.rjObject.Trailer.PromotionItem.push(n)}))),this},t.prototype.getTenderInfo=function(){var t=this;return this.transactionDocument.paymentDetails&&this.transactionDocument.paymentDetails.length>0&&this.transactionDocument.paymentDetails.forEach((function(e){if(e.externalTenderKey)if(t.rjObject[e.externalTenderKey]=[],"GIFT CARD"===e.paymentType.toUpperCase()){var n={XMLSchemaVersion:t.xmlSchemaVersion,LineNumber:t.generateLineNumber(),NetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,GiftVoucherSalesAllowed:"",AllowRechargeableVoucherSales:"",GiftVoucherID:""};t.rjObject[e.externalTenderKey].push(n)}else{var i={XMLSchemaVersion:"1",LineNumber:t.generateLineNumber(),NetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:t.convertToString(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,IncludeInTransactionTotalCheck:"1",AllowRechargeableVoucherSales:"1",OpenDrawerAtEnd:"1"};t.rjObject[e.externalTenderKey].push(i)}else if(t.rjObject.CashTender=[],"GIFT CARD"===e.paymentType.toUpperCase()){n={XMLSchemaVersion:t.xmlSchemaVersion,LineNumber:t.generateLineNumber(),NetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,GiftVoucherSalesAllowed:"",AllowRechargeableVoucherSales:"",GiftVoucherID:""};t.rjObject.CashTender.push(n)}else{i={XMLSchemaVersion:"1",LineNumber:t.generateLineNumber(),NetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),EffectiveNetValue:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),Description:t.getDescription(e),DeviceID:t.deviceId,UserID:t.transactionDocument.userName,DateTimeCreated:t.updatedAt,TenderType:e.externalTenderType?e.externalTenderType:"",TenderSubType:e.externalSubTenderType?e.externalSubTenderType:"",TenderAmount:JSON.stringify(-1*t.removeDecimal(Math.round(e.amount))),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,IncludeInTransactionTotalCheck:"1",AllowRechargeableVoucherSales:"1",OpenDrawerAtEnd:"1"};t.rjObject.CashTender.push(i)}})),this},t.prototype.getNumber=function(t){for(var e,n=0;n<this.rjObject.ProductSale.length;n++){var i=this.rjObject.ProductSale[n];if(JSON.stringify(t)===JSON.stringify(i.ProductID)){e=i.LineNumber;break}}return e},t.prototype.setLineNumberForProducts=function(){var t=[];t=this.transactionDocument.basket.products.map((function(t){return parseInt(t.itemLineId)})),this.largestNumber=t.reduce((function(t,e){return Math.max(t,e)}))},t.prototype.generateLineNumber=function(){return this.largestNumber+=1,this.itemCount+=1,this.largestNumber},t.prototype.initilizeItemCount=function(){this.itemCount=this.transactionDocument.basket.products.length},t.prototype.build=function(){return this.rjObject},t.prototype.getDescription=function(t){return"CARD"===t.paymentType.toUpperCase()?t.cardType:t.paymentType},t.prototype.getMMGROUPID=function(t){if(t&&t.length>0){var e=t.filter((function(t){return"MMGROUPID"===t.name}));if(e&&e.length>0)return e[0].value}},t.prototype.setDeviceInfo=function(t){return this.deviceId=t,this},t.prototype.removeDecimal=function(t){return 100*t},t.prototype.addDecimal=function(t){return t/100},t.prototype.setTransactionNumber=function(t){return this.transactionNumber=t,this},t.prototype.setManifestVersion=function(t){return this.manifestVersion=t,this},t.prototype.setDatabaseSchemaVersion=function(t){return this.databaseSchemaVersion=t,this},t.prototype.setBasketType=function(t){return this.basketType=t,this},t.prototype.setTradingRegionID=function(t){return this.tradingRegionId=t,this},t.prototype.setCompanyID=function(t){return this.companyId=t,this},t.prototype.setTaxMethodID=function(t){return this.taxMethodId=t,this},t.prototype.setMajorVersion=function(t){return this.majorVersion=t,this},t.prototype.setMinorVersion=function(t){return this.minorVersion=t,this},t.prototype.setXMLSchemaVersion=function(t){return this.xmlSchemaVersion=t,this},t.prototype.setExternalState=function(t){return this.externalState=t,this},t.prototype.setCashierID=function(){return this.cashierId=this.transactionDocument&&this.transactionDocument.userName?this.transactionDocument.userName:"",this},t.prototype.setTerminalNumber=function(t){return this.terminalNumber=t,this},t.prototype.setBasketLanguageID=function(t){return this.basketLanguageId=t,this},t.prototype.setBasketCountryID=function(t){return this.basketCountryId=t,this},t.prototype.setBasketCurrencyID=function(t){return this.basketCurrencyId=t,this},t.prototype.setBranchID=function(t){return this.branchId=t,this},t.prototype.setSalesPersonName=function(t){return this.salesPersonName=t,this},t.prototype.generateId=function(t){var e=t.replace(/[^0-9]/g,"");return(this.deviceId+"|"+e+"|"+this.transactionNumber).toString()},t.prototype.generateTimezoneoffset=function(t){return new Date(t||"").getTimezoneOffset()},t.prototype.generateKeyword=function(){return(this.companyId+"|"+this.transactionDocument.storeId+"|"+this.terminalNumber+"|"+this.transactionNumber).toString()},t.prototype.getState=function(){return"PAY_SUCCESS"===this.transactionDocument.operationStatus?"Completed":"Cancelled"},t.prototype.returnProduct=function(t,e,n){var i=this,o={},r=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId}));if(o.XMLSchemaVersion=this.xmlSchemaVersion,o.LineNumber=t.itemLineId,o.NetValue=this.removeDecimal(t.refundedTotal),o.EffectiveNetValue=this.removeDecimal(t.refundedTotal),o.Description=t.description,o.DeviceID=this.transactionDocument.terminalId,o.UserID=this.transactionDocument.userName,o.DateTimeCreated=this.createdAt,o.ExtendedValue=this.removeDecimal(-1*t.totalLinePrice),o.UnitPrice=this.removeDecimal(t.price),o.Quantity=this.getQuantity(t),o.OriginalTaxAmountSet=1,o.ProductID=t.SKU,o.HandKeyed=1,o.LongDescription=t.description,o.Return={},o.Return.ReturnReasonID=t.refundedReason,o.Return.ReturnDescription=t.refundedReasonDescription,o.Return.ReturnToStock=this.getQuantity(t),o.TaxCode=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})).VATCode,o.DisplayTaxCode="",o.ProductAttributes="",o.Perishable=this.getMMGROUPID(t.attributes),o.MMGroupID=this.getMMGROUPID(t.attributes),o.CustomerDetails="",o.TotalPromotionSaving=t.promotionAmount||-1,o.OriginalTaxAmount=this.convertToString(this.removeDecimal(-1*this.getOriginalTax(t,r.VAT)).toFixed(2)),o.taxAmount=this.removeDecimal(r.taxLineTotal<0?r.taxLineTotal:-r.taxLineTotal),e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(o.Discount={},o.Discount.ModifierValue=-1*this.removeDecimal(e.discountAmount),o.Discount.ModifierDateTime=o.DateTimeCreated,o.Discount.ModifierReasonID=e.percentageDiscountReasonCode,o.Discount.ModifierDescription=e.percentageDiscountReasonName,o.Discount.AuthorisingUserID=this.transactionDocument.userName,o.Discount.DiscountType=e.discountType,o.Discount.XMLSchemaVersion=1,o.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),o.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),o.Discount.DiscountPercentage=e.percentageDiscountValue,o.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(o.PriceOverride={},o.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),o.PriceOverride.ModifierDateTime=o.DateTimeCreated,o.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,o.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,o.PriceOverride.AuthorisingUserID=this.transactionDocument.userName,o.PriceOverride.XMLSchemaVersion=1,o.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),o.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),o.NetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),o.EffectiveNetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),o.ExtendedValue=-1*((e.discountedLinePrice||0)+e.discountAmount),o.UnitPrice=-1*((e.discountedLinePrice||0)+e.discountAmount)),n){o.BasketDiscountModifier=[],this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={};e.itemLineIds.forEach((function(r){if(r==t.itemLineId){var a=i.convertToString(-1*e.discountAmount);n.BasketDiscountLineNumber=i.getLineNumber(e,a),n.XMLSchemaVersion=i.xmlSchemaVersion,n.DiscountedValue=i.getDiscountedValue(t.totalLinePrice,e.discountAmount),o.BasketDiscountModifier.push(n)}}))}));var a=0;o.BasketDiscountModifier.forEach((function(t){a+=t.DiscountedValue})),o.EffectiveNetValue=o.EffectiveNetValue+a}return this.transactionDocument.basket.transactionPromotion.length>0&&(o.PromotionSaving=[],this.transactionDocument.basket.transactionPromotion.forEach((function(e){var n={};e.itemLineIds.forEach((function(r){r==t.itemLineId&&(n.ModifierValue=e.promotionAmount,n.ModifierDateTime=i.transactionDocument.createdAt,n.ModifierDescription=e.displayText,n.XMLSchemaVersion=i.xmlSchemaVersion,n.PromotionID=e.promotionId,n.PromotionDescription=e.displayText,n.HitNumber="1",n.PromotionHitProductQuantity=i.getQuantity(t),n.PromotionHitQuantity=-1*i.getQuantity(t),o.PromotionSaving.push(n))}))}))),o},t.prototype.addProduct=function(t,e,n){var i=this,o=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})),r={XMLSchemaVersion:this.xmlSchemaVersion,LineNumber:t.itemLineId,NetValue:this.removeDecimal(t.totalLinePrice),EffectiveNetValue:this.removeDecimal(t.totalLinePrice),Description:t.description,DeviceID:this.deviceId,UserID:this.transactionDocument.userName,DateTimeCreated:this.createdAt,ExtendedValue:this.removeDecimal(t.price),UnitPrice:this.removeDecimal(t.price),Quantity:t.quantity,SalespersonID:this.transactionDocument.userName,SalespersonName:this.salesPersonName,TaxCode:this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})).VATCode,TaxModifiable:"1",OriginalTaxAmount:this.convertToString(this.removeDecimal(this.getOriginalTax(t,o.VAT)).toFixed(2)),TaxAmount:this.convertToString(this.removeDecimal(o.taxLineTotal)),OriginalTaxAmountSet:"1",ProductID:t.SKU,HandKeyed:"1",CustomerDetails:"",Perishable:this.getMMGROUPID(t.attributes),MMGroupID:this.getMMGROUPID(t.attributes)};if(e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(r.Discount={},r.Discount.ModifierValue=-1*this.removeDecimal(e.discountAmount),r.Discount.ModifierDateTime=r.DateTimeCreated,r.Discount.ModifierReasonID=e.percentageDiscountReasonCode,r.Discount.ModifierDescription=e.percentageDiscountReasonName,r.Discount.AuthorisingUserID=this.transactionDocument.userName,r.Discount.DiscountType=e.discountType,r.Discount.XMLSchemaVersion=1,r.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),r.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),r.Discount.DiscountPercentage=e.percentageDiscountValue,r.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(r.PriceOverride={},r.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),r.PriceOverride.ModifierDateTime=r.DateTimeCreated,r.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,r.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,r.PriceOverride.AuthorisingUserID=this.transactionDocument.userName,r.PriceOverride.XMLSchemaVersion=this.xmlSchemaVersion,r.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),r.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),r.NetValue=(e.discountedLinePrice||0)+e.discountAmount,r.EffectiveNetValue=(e.discountedLinePrice||0)+e.discountAmount,r.ExtendedValue=(e.discountedLinePrice||0)+e.discountAmount,r.UnitPrice=(e.discountedLinePrice||0)+e.discountAmount),n){r.BasketDiscountModifier=[],this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={};e.itemLineIds.forEach((function(o){if(o==t.itemLineId){var a=i.convertToString(-1*e.discountAmount);n.XMLSchemaVersion=i.xmlSchemaVersion,n.DiscountedValue=-i.getDiscountedValue(t.totalLinePrice,e.discountAmount),n.BasketDiscountLineNumber=i.getLineNumber(e,a),r.BasketDiscountModifier.push(n)}}))}));var a=0;r.BasketDiscountModifier.forEach((function(t){a+=t.DiscountedValue})),r.EffectiveNetValue=r.EffectiveNetValue+a}if(this.transactionDocument.basket.transactionPromotion.length>0||this.transactionDocument.basket.linePromotion.length>0){r.DistributedPromotionSaving=[],this.transactionDocument.basket.transactionPromotion.length>0&&this.transactionDocument.basket.transactionPromotion.forEach((function(e){var n={};e.itemLineIds.forEach((function(o){o==t.itemLineId&&(n.PromotionID=e.promotionId,n.Hit="1",n.Saving=i.getSaving(t.totalLinePrice,e.promotionAmount),n.ISaving=i.getSaving(t.totalLinePrice,e.promotionAmount),r.DistributedPromotionSaving.push(n))}))})),this.transactionDocument.basket.linePromotion.length>0&&this.transactionDocument.basket.linePromotion.forEach((function(e){var n={};t.itemLineId==e.itemLineId&&(n.PromotionID=e.promotionId,n.Hit="1",n.Saving=e.promotionLinePrice,n.ISaving=e.promotionLinePrice,r.DistributedPromotionSaving.push(n))}));var s=0;r.DistributedPromotionSaving.forEach((function(t){s+=t.Saving})),r.EffectiveNetValue=r.EffectiveNetValue+s}return r},t.prototype.getSaving=function(t,e){return t*e/this.transactionDocument.basketSummary.saleTotal},t.prototype.getLineNumber=function(t,e){for(var n,i=0;i<this.rjObject.BasketDiscount.length;i++){var o=this.rjObject.BasketDiscount[i];if(t.reasonCode===o.ReasonCodeID&&e===o.NetValue){n=o.LineNumber;break}}return n},t.prototype.getDiscountedValue=function(t,e){return t*e/this.transactionDocument.basketSummary.saleTotal*100},t.prototype.getOriginalTax=function(t,e){var n=100*t.price/(100+e);return t.price-n},t.prototype.convertToString=function(t){try{return t=JSON.stringify(t)}catch(e){console.log(t,"can not be converted in string",e)}},t.prototype.generateDynamicStockLookUp=function(){var t="0";return this.transactionDocument.basket.products.forEach((function(e){"1"!==e.deliveryMethod&&"2"!==e.deliveryMethod||(t="1")})),t},t.prototype.getDate=function(t){var e=-1*this.generateTimezoneoffset(t),n=Math.abs(Math.floor(e/60)),i=Math.abs(e)-60*n,o="+";return e<0&&(o="-"),(t.substring(0,19)+o+String(n).padStart(2,"0")+":"+String(i).padStart(2,"0")).toString()},t.prototype.getTransactionPromotion=function(t){t&&t.length>0&&(this.rjObject.PromoVoucherItem={},this.rjObject.PromoVoucherItem.XMLSchemaVersion=this.xmlSchemaVersion,this.rjObject.PromoVoucherItem.LineNumber=this.generateLineNumber(),this.rjObject.PromoVoucherItem.NetValue=-1*this.removeDecimal(t[0].promotionLinePrice),this.rjObject.PromoVoucherItem.EffectiveNetValue=-1*this.removeDecimal(t[0].promotionLinePrice),this.rjObject.PromoVoucherItem.Description=t[0].promotionInfo,this.rjObject.PromoVoucherItem.DeviceID=this.deviceId,this.rjObject.PromoVoucherItem.UserID=this.transactionDocument.userName,this.rjObject.PromoVoucherItem.DateTimeCreated=this.createdAt,this.rjObject.PromoVoucherItem.ProductId="",this.rjObject.PromoVoucherItem.SerialNumber="",this.rjObject.PromoVoucherItem.MMGroupId="")},t.prototype.getQuantity=function(t){return this.transactionDocument.unreferencedRefund?t.quantity<0?t.quantity:-t.quantity:t.refundedQuantity<0?t.refundedQuantity:-t.refundedQuantity},t}();var g=function(){function t(t){this.webReturnObject={id:"",orgCode:"",storeId:"",storeNodeId:"",storeNodeStructure:"",deviceId:"",terminalId:"",initiatingModule:"",export:!1,basket:{},basketSummary:{},baseCurrency:"",customer:{firstName:"",lastName:"",email:"",postCode:"",id:"",billingAddress:{},shippingAddress:{}}},t&&(this.document=t)}return t.prototype.WebReturnMapper=function(){var t=this;this.webReturnObject.type="WEB_RETURNS",this.webReturnObject.datetime=this.getUTCDateTime(this.getText(this.document.updated_at)),this.webReturnObject.baseCurrency=this.getText(this.document.base_currency_code),this.webReturnObject.storeId=this.getText(this.document.store_id),this.webReturnObject.subsidiaryId="1",this.webReturnObject.initiatingModule="MAGENTO",this.webReturnObject.createdAt=this.getUTCDateTime(this.getText(this.document.created_at)),this.webReturnObject.updatedAt=this.getUTCDateTime(this.getText(this.document.updated_at)),this.webReturnObject.export=!0,this.webReturnObject.transCompletedAt=this.getUTCDateTime(this.getText(this.document.updated_at)),this.webReturnObject.externalTransactionId=this.getText(this.document.order_id),this.webReturnObject.customer.firstName=this.getText(this.document.customer_firstname)||"",this.webReturnObject.customer.lastName=this.getText(this.document.customer_lastname)||"",this.webReturnObject.customer.email=this.getText(this.document.customer_email)||"",this.webReturnObject.customer.postCode="",this.webReturnObject.customer.billingAddress.address1=this.document.billing_address&&this.document.billing_address.street?this.getText(this.document.billing_address.street):"",this.webReturnObject.customer.billingAddress.city=this.document.billing_address&&this.document.billing_address.city?this.getText(this.document.billing_address.city):"",this.webReturnObject.customer.billingAddress.county=this.document.billing_address&&this.document.billing_address.region?this.getText(this.document.billing_address.region):"",this.webReturnObject.customer.billingAddress.postCode=this.document.billing_address&&this.document.billing_address.postcode?this.getText(this.document.billing_address.postcode):"",this.webReturnObject.customer.billingAddress.country=this.document.billing_address&&this.document.billing_address.country?this.getText(this.document.billing_address.country):"",this.webReturnObject.customer.shippingAddress.address1=this.document.shipping_address&&this.document.shipping_address.street?this.getText(this.document.shipping_address.street):"",this.webReturnObject.customer.shippingAddress.city=this.document.shipping_address&&this.document.shipping_address.city?this.getText(this.document.shipping_address.city):"",this.webReturnObject.customer.shippingAddress.county=this.document.shipping_address&&this.document.shipping_address.region?this.getText(this.document.shipping_address.region):"",this.webReturnObject.customer.shippingAddress.postCode=this.document.shipping_address&&this.document.shipping_address.postcode?this.getText(this.document.shipping_address.postcode):"",this.webReturnObject.customer.shippingAddress.country=this.document.shipping_address&&this.document.shipping_address.country?this.getText(this.document.shipping_address.country):"",this.webReturnObject.basketSummary.discountTotal=Number(this.document.discount_amount?this.getText(this.document.discount_amount):0),this.webReturnObject.basketSummary.VATTotal=Number(this.document.base_total_paid?this.getText(this.document.base_total_paid):0),this.webReturnObject.basketSummary.saleTotal=Number(this.document.base_total_invoiced?this.getText(this.document.base_total_invoiced):0),this.webReturnObject.basketSummary.basketTotal=Number(this.document.base_total_paid?this.getText(this.document.base_total_paid):0),this.webReturnObject.basketSummary.totalItems=Number(this.document.total_qty_ordered?this.getText(this.document.total_qty_ordered):0),this.webReturnObject.basketSummary.refundTotal=Number(this.document.base_total_refunded?this.getText(this.document.base_total_refunded):0),this.webReturnObject.basket.lineDiscount=[];var e={itemLineId:this.document.items&&this.document.items.item&&this.document.items.item.item_id?this.getText(this.document.items.item.item_id):0,discountAmount:this.document.items&&this.document.items.item&&this.document.items.item.discount_amount?Number(this.getText(this.document.items.item.discount_amount)):0};this.webReturnObject.basket.lineDiscount.push(e),this.webReturnObject.basket.transactionDiscount=[];var n={discountAmount:this.document&&this.document.discount_amount?Number(this.getText(this.document.discount_amount)):0};this.webReturnObject.basket.transactionDiscount.push(n),this.webReturnObject.basket.products=[];var i={};return this.document.items&&this.document.items.item&&this.document.items.item&&(this.document.items.item instanceof Array?this.document.items.item.forEach((function(e){(i={description:e.name?t.getText(e.name):"",SKU:e.sku?t.getText(e.sku):"",quantity:e.qty_ordered?Number(t.getText(e.qty_ordered)):0,refundedQuantity:e.qty_refunded?Number(t.getText(t.document.items.item.qty_refunded)):0,price:e.original_price?Number(t.getText(e.original_price)):0,itemLineId:e.item_id?Number(t.getText(e.item_id)):0,totalLinePrice:(e.qty_ordered-e.qty_refunded)*e.base_original_price})&&0!=i.price&&t.webReturnObject.basket.products.push(i)})):(i={description:this.document.items&&this.document.items.item&&this.document.items.item.name?this.getText(this.document.items.item.name):"",SKU:this.document.items&&this.document.items.item&&this.document.items.item.sku?this.getText(this.document.items.item.sku):"",quantity:this.document.items&&this.document.items.item&&this.document.items.item.qty_ordered?Number(this.getText(this.document.items.item.qty_ordered)):0,refundedQuantity:this.document.items&&this.document.items.item&&this.document.items.item.qty_refunded?Number(this.getText(this.document.items.item.qty_refunded)):0,price:this.document.items&&this.document.items.item&&this.document.items.item.original_price?Number(this.getText(this.document.items.item.original_price)):0,itemLineId:this.document.items&&this.document.items.item&&this.document.items.item.item_id?Number(this.getText(this.document.items.item.item_id)):0,totalLinePrice:(this.document.items.item.qty_ordered-this.document.items.item.qty_refunded)*this.document.items.item.base_original_price})&&0!=i.price&&this.webReturnObject.basket.products.push(i)),this},t.prototype.deviceId=function(t){return this.webReturnObject.deviceId=t,this},t.prototype.terminalId=function(t){return this.webReturnObject.terminalId=t,this},t.prototype.orgCode=function(t){return this.webReturnObject.orgCode=t,this},t.prototype.storeId=function(t){return this.webReturnObject.storeId=t,this},t.prototype.storeNodeId=function(t){return this.webReturnObject.storeNodeId=t,this},t.prototype.storeNodeStructure=function(t){return this.webReturnObject.storeNodeStructure=t,this},t.prototype.docId=function(t){return this.webReturnObject.id=t,this},t.prototype.updateUserID=function(t){return this.webReturnObject.userId=t,this},t.prototype.updateUserName=function(t){return this.webReturnObject.userName=t,this},t.prototype.build=function(){return this.webReturnObject},t.prototype.getText=function(t){return t&&t.text?t.text:t},t.prototype.getUTCDateTime=function(t){if(t)return new Date(t).toISOString()},t}();t.MapperLibraryComponent=c,t.MapperLibraryModule=u,t.RJMapperBuilderClass=y,t.WebReturnMapperBuilderClass=g,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
16
16
|
//# sourceMappingURL=pmcretail-mapper-library.umd.min.js.map
|