@pmcretail/mapper-library 0.0.2 → 0.0.3
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/README.md +24 -24
- package/bundles/pmcretail-mapper-library.umd.js +4 -3
- 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/RJ-mapper.class.js +5 -4
- package/esm2015/public-api.js +1 -1
- package/esm5/lib/RJ-mapper.class.js +5 -4
- package/esm5/public-api.js +1 -1
- package/fesm2015/pmcretail-mapper-library.js +4 -3
- package/fesm2015/pmcretail-mapper-library.js.map +1 -1
- package/fesm5/pmcretail-mapper-library.js +4 -3
- 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
|
-
***************************************************************************** */function o(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 r(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 a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}var s=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}(),c=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[s],imports:[],exports:[s]}]}],t}(),u="SALE",l="REFUND",m="SALE_REFUND",d="SALE_EXCHANGE";var h={DELIVERY:1,DROP_SHIP:2,COLLECT_FROM_STORE:3};h[h.DELIVERY]="DELIVERY",h[h.DROP_SHIP]="DROP_SHIP",h[h.COLLECT_FROM_STORE]="COLLECT_FROM_STORE";var p={PERCENT:"Percent",AMOUNT:"AMOUNT"},D=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 r=o(t.products),a=r.next();!a.done;a=r.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=r.return)&&i.call(r)}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,r,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=o(e.products),c=s.next();!c.done;c=s.next()){var u=c.value;try{for(var l=(r=void 0,o(t.result.linePromotions)),m=l.next();!m.done;m=l.next()){var d=m.value;u.itemLineId.toString()===d.itemLineId.toString()&&(u.linePromotions=d)}}catch(t){r={error:t}}finally{try{m&&!m.done&&(a=l.return)&&a.call(l)}finally{if(r)throw r.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=o(t.products),r=i.next();!r.done;r=i.next()){var a=r.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{r&&!r.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=o(t.products),r=i.next();!r.done;r=i.next()){var a=r.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{r&&!r.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===h.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 y=function(){function t(t,e,n){this.currencyPipe=e,this.basketService=n,this.numberUtilService=new f(e),this.basketService=new D(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,a(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===d)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?a(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 s=i.exchange.newItems[r],c={lineItemId:s.itemLineId,Quantity:s.quantity};o.push(c)}i.exchange.newItems=a(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?a(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||h.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===l?o.total=n.refundedTotal:(t.transactionDocument.type===m||d)&&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===l&&o.total>0&&(o.total*=-1),e.products.push(o)})),(e=this.getTransactionDiscountAndTransactionPromotionPortion(e)).total=(e.basketTotal||0)+this.getTotalDiscountWithTransactionDiscountsAndPromotions(e),this.transactionDocument.type===m&&(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 r=o(t.products),a=r.next();!a.done;a=r.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=r.return)&&n.call(r)}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!==l&&this.transactionDocument.type!==m&&this.transactionDocument.type!==d||(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 b=function(){function t(t){this.productQuantity=0,this.itemCount=0,this.largestNumber=0,this.rjObject={},this.paymentTypes=[{paymentType:"Card",type:"SEPAY",tenderType:"5",tenderSubType:"8"},{paymentType:"Cash",type:"TMC_CASH",tenderType:"1",tenderSubType:"0"},{paymentType:"PDQ",type:"Unintegrated",tenderType:"2",tenderSubType:"8"},{paymentType:"Gift Card",type:"TMC_GIFTCARD",tenderType:"5",tenderSubType:"8"}],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()}return t.prototype.getPosbasketInfo=function(){return this.rjObject.Keyword=this.generateKeyword(),this.rjObject.ID=this.generateId(this.transactionDocument.createdAt),this.rjObject.XMLSchemaVersion="2",this.rjObject.LastUpdated=this.transactionDocument.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.transactionDocument.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.transactionDocument.storeId,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},t.prototype.rjMapper=function(){var t=this;if(this.transactionDocument.type===u)this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(e){var n=[];if(t.transactionDocument.basket.lineDiscount&&t.transactionDocument.basket.lineDiscount.length>0&&(n=t.transactionDocument.basket.lineDiscount.filter((function(t){return t.itemLineId===e.itemLineId}))).length>0){var i=t.transactionDocument.basket.lineDiscount.indexOf(n[0]);i>-1&&t.transactionDocument.basket.lineDiscount.splice(i,1)}var o=t.addProduct(e,n.length>0?n[0]:null);t.rjObject.ProductSale.push(o),t.getModifierItem(n.length>0?n[0]:null,e.itemLineId)}));else if(this.transactionDocument.type===l)this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(e){var n=t.returnProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductReturn.push(n),t.getModifierItem(e.lineDiscount,e.itemLineId)}));else if(this.transactionDocument.type===m){this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],(new y).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(e){var n=t.returnProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductReturn.push(n),t.getModifierItem(e.lineDiscount,e.itemLineId)}))}else if(this.transactionDocument.type===d){this.rjObject.ProductReturn=[],this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],(new y).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(e){if(e.refundedQuantity>0){var n=t.returnProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductReturn.push(n)}else{var i=t.addProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductSale.push(i)}t.getModifierItem(e.lineDiscount,e.itemLineId)}))}return(this)},t.prototype.getBasketDiscount=function(){var t=this;return this.rjObject.BasketDiscount=[],this.transactionDocument.basket.transactionDiscount?(this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={XMLSchemaVersion:1};n.NetValue=e.discountAmount<0?e.discountAmount:-e.discountAmount,n.EffectiveNetValue=e.discountAmount<0?e.discountAmount:-e.discountAmount,n.Description=e.reasonCode,n.UserID=t.transactionDocument.basket.userId,n.ReasonCodeID=e.reasonCode,n.DiscountType=e.discountType.toUpperCase()==p.PERCENT.toUpperCase()?0:1,n.RoundingRule=2,n["ModifiedLineNumber "]=[],e.itemLineIds.forEach((function(t){n.ModifiedLineNumber.push(t)})),n.LineNumber=t.generateLineNumber(),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.userId,n.DateTimeCreated=this.transactionDocument.updatedAt,n.AuthorisingUserID=this.userId,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.transactionDocument.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.transactionDocument.storeId,this.rjObject.Trailer.CompletedBy.TerminalNumber=this.transactionDocument.terminalId,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.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=e.VAT,n.TaxableTotal=t.convertToString(e.taxableAmount),n.TaxTotal=t.convertToString(e.taxLineTotal),n.TaxDescription=t.convertToString(e.VATCode),n.TaxIncluded="1",n.TaxPercentage=e.VAT,t.rjObject.Trailer.TaxItem.push(n)})),this.rjObject.Trailer.PromotionItem=[],this.transactionDocument.basket.linePromotion.forEach((function(e){var n={};n.PromotionID=e.promotionId,n.PromotionSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionQuantity="",n.PromotionDescription=e.displayText,n.PromotionHit.XMLSchemaVersion=t.transactionDocument.storeId,n.PromotionHit.HitNumber="",n.PromotionHit.HitQuantity="",n.PromotionHit.HitSaving="",n.PromotionHit.PromotionTrigger=[],e.trigger.forEach((function(i){var o={},r=t.transactionDocument.basket.products.find((function(t){return t.lineItemId==i.itemLineId}));o.XMLSchemaVersion=t.xmlSchemaVersion,o.ProductID=t.transactionDocument.basket.products.find((function(t){return t.itemLineId===i.itemLineId})).SKU,o.UnitValue=t.convertToString(e.promotionLinePrice/r.quantity),o.LineNumber=t.convertToString(i.itemLineId),o.Quantity=t.convertToString(i.quantity.toFixed(1)),o.TaxCode=t.transactionDocument.basket.taxBreakdown.taxLines.find((function(t){return t.itemLineId==e.itemLineId})).VATCode,n.PromotionHit.PromotionTrigger.push(o)})),t.rjObject.Trailer.PromotionItem.push(n)})),this},t.prototype.getTenderInfo=function(){var t=this;return this.rjObject.CashTender=[],this.transactionDocument.paymentDetails&&this.transactionDocument.paymentDetails.length>0&&this.transactionDocument.paymentDetails.forEach((function(e){var n=t.paymentTypes.filter((function(t){return t.paymentType.toUpperCase()===e.paymentType.toUpperCase()}));if("GIFT CARD"===e.paymentType.toUpperCase()){var i={XMLSchemaVersion:t.xmlSchemaVersion,LineNumber:t.generateLineNumber(),NetValue:t.convertToString(-1*Math.round(e.amount)),EffectiveNetValue:t.convertToString(-1*Math.round(e.amount)),Description:t.getDescription(n[0].paymentType,e),DeviceID:t.deviceId,UserID:t.userId,DateTimeCreated:t.transactionDocument.updatedAt,TenderType:n[0].tenderType,TenderSubType:n[0].tenderSubType,TenderAmount:t.convertToString(-1*Math.round(e.amount)),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,GiftVoucherSalesAllowed:"",AllowRechargeableVoucherSales:"",GiftVoucherID:""};t.rjObject.CashTender.push(i)}else{var o={XMLSchemaVersion:"1",LineNumber:t.generateLineNumber(),NetValue:JSON.stringify(-1*Math.round(e.amount)),EffectiveNetValue:JSON.stringify(-1*Math.round(e.amount)),Description:t.getDescription(n[0].paymentType,e),DeviceID:t.deviceId,UserID:t.userId,DateTimeCreated:t.transactionDocument.updatedAt,TenderType:n[0].tenderType,TenderSubType:n[0].tenderSubType,TenderAmount:JSON.stringify(-1*Math.round(e.amount)),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,IncludeInTransactionTotalCheck:"1",AllowRechargeableVoucherSales:"1",OpenDrawerAtEnd:"1"};t.rjObject.CashTender.push(o)}})),this},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,e){return"CARD"===t.toUpperCase()?e.cardType:t},t.prototype.setDeviceInfo=function(t){return this.deviceId=t,this},t.prototype.setUserInfo=function(t){return this.userId=t,this},t.prototype.removeDecimal=function(t){return 100*t},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(t){return this.cashierId=t,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.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){var n={};n.LineNumber=t.itemLineId,n.NetValue=this.removeDecimal(t.refundedTotal),n.EffectiveNetValue=this.removeDecimal(t.refundedTotal),n.Description=t.description,n.DeviceID=this.transactionDocument.terminalId,n.UserID=this.userId,n.DateTimeCreated=this.transactionDocument.createdAt,n.ExtendedValue=this.removeDecimal(t.totalLinePrice),n.UnitPrice=this.removeDecimal(t.price),n.Quantity=t.refundedQuantity<0?t.refundedQuantity.toFixed(1):-t.refundedQuantity.toFixed(1),n.OriginalTaxAmountSet=1,n.ProductID=t.SKU,n.HandKeyed=1,n.LongDescription=t.description,n.Return={},n.Return.ReturnReasonID=t.refundedReason,n.Return.ReturnDescription=t.refundedReasonDescription,n.Return.ReturnToStock=t.refundedQuantity>0?t.refundedQuantity:-1*t.refundedQuantity,n.TaxCode=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})).VATCode,n.DisplayTaxCode="",n.ProductAttributes="",n.Perishable=this.getAttributes(),n.MMGroupID=this.getAttributes(),n.CustomerDetails="",n.TotalPromotionSaving=t.promotionAmount||-1;var i=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId}));return n.OriginalTaxAmount=i.taxLineTotal<0?this.removeDecimal(i.taxLineTotal):this.removeDecimal(-i.taxLineTotal),n.taxAmount=i.taxLineTotal<0?this.removeDecimal(i.taxLineTotal):this.removeDecimal(-i.taxLineTotal),e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(n.Discount={},n.Discount.ModifierValue=-1*this.removeDecimal(e.unitPrice),n.Discount.ModifierDateTime=n.DateTimeCreated,n.Discount.ModifierReasonID=e.percentageDiscountReasonCode,n.Discount.ModifierDescription=e.percentageDiscountReasonName,n.Discount.AuthorisingUserID=this.userId,n.Discount.DiscountType=e.discountType,n.Discount.XMLSchemaVersion=1,n.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),n.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),n.Discount.DiscountPercentage=e.percentageDiscountValue,n.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(n.PriceOverride={},n.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),n.PriceOverride.ModifierDateTime=n.DateTimeCreated,n.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,n.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,n.PriceOverride.AuthorisingUserID=this.userId,n.PriceOverride.XMLSchemaVersion=1,n.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),n.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),n.NetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),n.EffectiveNetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),n.ExtendedValue=-1*((e.discountedLinePrice||0)+e.discountAmount),n.UnitPrice=-1*((e.discountedLinePrice||0)+e.discountAmount)),n},t.prototype.addProduct=function(t,e){var n={XMLSchemaVersion:this.xmlSchemaVersion,LineNumber:t.itemLineId,NetValue:this.removeDecimal(t.totalLinePrice),EffectiveNetValue:this.removeDecimal(t.totalLinePrice),Description:t.description,DeviceID:this.deviceId,UserID:this.userId,DateTimeCreated:this.transactionDocument.createdAt,ExtendedValue:this.removeDecimal(t.price),UnitPrice:this.removeDecimal(t.price),MMGroupID:this.getAttributes(),Quantity:t.quantity.toFixed(1),SalespersonID:this.transactionDocument.userId,SalespersonName:this.transactionDocument.userName,TaxCode:0,TaxModifiable:1,TaxAmount:0,OriginalTaxAmount:0,OriginalTaxAmountSet:1,ProductID:t.SKU,HandKeyed:1,CustomerDetails:"",Perishable:this.getAttributes()};return e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(n.Discount={},n.Discount.ModifierValue=-1*this.removeDecimal(e.unitPrice),n.Discount.ModifierDateTime=n.DateTimeCreated,n.Discount.ModifierReasonID=e.percentageDiscountReasonCode,n.Discount.ModifierDescription=e.percentageDiscountReasonName,n.Discount.AuthorisingUserID=this.userId,n.Discount.DiscountType=e.discountType,n.Discount.XMLSchemaVersion=1,n.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),n.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),n.Discount.DiscountPercentage=e.percentageDiscountValue,n.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(n.PriceOverride={},n.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),n.PriceOverride.ModifierDateTime=n.DateTimeCreated,n.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,n.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,n.PriceOverride.AuthorisingUserID=this.userId,n.PriceOverride.XMLSchemaVersion=1,n.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),n.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),n.NetValue=(e.discountedLinePrice||0)+e.discountAmount,n.EffectiveNetValue=(e.discountedLinePrice||0)+e.discountAmount,n.ExtendedValue=(e.discountedLinePrice||0)+e.discountAmount,n.UnitPrice=(e.discountedLinePrice||0)+e.discountAmount),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.getAttributes=function(){var t=[];return this.transactionDocument.basket.products.forEach((function(e){e.attributes&&e.attributes.length>0&&(t=e.attributes.filter((function(t){return t.name.toUpperCase()===e.name.toUpperCase()})))})),t.length>0?t[0].value:""},t}();t.MapperLibraryComponent=s,t.MapperLibraryModule=c,t.RJMapperBuilderClass=b,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */function o(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 r(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 a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}var s=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}(),c=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[s],imports:[],exports:[s]}]}],t}(),u="SALE",l="REFUND",m="SALE_REFUND",d="SALE_EXCHANGE";var h={DELIVERY:1,DROP_SHIP:2,COLLECT_FROM_STORE:3};h[h.DELIVERY]="DELIVERY",h[h.DROP_SHIP]="DROP_SHIP",h[h.COLLECT_FROM_STORE]="COLLECT_FROM_STORE";var p={PERCENT:"Percent",AMOUNT:"AMOUNT"},D=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 r=o(t.products),a=r.next();!a.done;a=r.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=r.return)&&i.call(r)}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,r,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=o(e.products),c=s.next();!c.done;c=s.next()){var u=c.value;try{for(var l=(r=void 0,o(t.result.linePromotions)),m=l.next();!m.done;m=l.next()){var d=m.value;u.itemLineId.toString()===d.itemLineId.toString()&&(u.linePromotions=d)}}catch(t){r={error:t}}finally{try{m&&!m.done&&(a=l.return)&&a.call(l)}finally{if(r)throw r.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=o(t.products),r=i.next();!r.done;r=i.next()){var a=r.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{r&&!r.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=o(t.products),r=i.next();!r.done;r=i.next()){var a=r.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{r&&!r.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===h.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 y=function(){function t(t,e,n){this.currencyPipe=e,this.basketService=n,this.numberUtilService=new f(e),this.basketService=new D(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,a(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===d)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?a(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 s=i.exchange.newItems[r],c={lineItemId:s.itemLineId,Quantity:s.quantity};o.push(c)}i.exchange.newItems=a(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?a(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||h.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===l?o.total=n.refundedTotal:(t.transactionDocument.type===m||d)&&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===l&&o.total>0&&(o.total*=-1),e.products.push(o)})),(e=this.getTransactionDiscountAndTransactionPromotionPortion(e)).total=(e.basketTotal||0)+this.getTotalDiscountWithTransactionDiscountsAndPromotions(e),this.transactionDocument.type===m&&(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 r=o(t.products),a=r.next();!a.done;a=r.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=r.return)&&n.call(r)}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!==l&&this.transactionDocument.type!==m&&this.transactionDocument.type!==d||(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 b=function(){function t(t){this.productQuantity=0,this.itemCount=0,this.largestNumber=0,this.rjObject={},this.paymentTypes=[{paymentType:"Card",type:"SEPAY",tenderType:"5",tenderSubType:"8"},{paymentType:"Cash",type:"TMC_CASH",tenderType:"1",tenderSubType:"0"},{paymentType:"PDQ",type:"Unintegrated",tenderType:"2",tenderSubType:"8"},{paymentType:"Gift Card",type:"TMC_GIFTCARD",tenderType:"5",tenderSubType:"8"}],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()}return t.prototype.getPosbasketInfo=function(){return this.rjObject.Keyword=this.generateKeyword(),this.rjObject.ID=this.generateId(this.transactionDocument.createdAt),this.rjObject.XMLSchemaVersion="2",this.rjObject.LastUpdated=this.transactionDocument.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.transactionDocument.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.transactionDocument.storeId,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},t.prototype.rjMapper=function(){var t=this;if(this.transactionDocument.type===u)this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(e){var n=[];if(t.transactionDocument.basket.lineDiscount&&t.transactionDocument.basket.lineDiscount.length>0&&(n=t.transactionDocument.basket.lineDiscount.filter((function(t){return t.itemLineId===e.itemLineId}))).length>0){var i=t.transactionDocument.basket.lineDiscount.indexOf(n[0]);i>-1&&t.transactionDocument.basket.lineDiscount.splice(i,1)}var o=t.addProduct(e,n.length>0?n[0]:null);t.rjObject.ProductSale.push(o),t.getModifierItem(n.length>0?n[0]:null,e.itemLineId)}));else if(this.transactionDocument.type===l)this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],this.transactionDocument.basket.products.forEach((function(e){var n=t.returnProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductReturn.push(n),t.getModifierItem(e.lineDiscount,e.itemLineId)}));else if(this.transactionDocument.type===m){this.rjObject.ProductReturn=[],this.rjObject.ModifierItem=[],(new y).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(e){var n=t.returnProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductReturn.push(n),t.getModifierItem(e.lineDiscount,e.itemLineId)}))}else if(this.transactionDocument.type===d){this.rjObject.ProductReturn=[],this.rjObject.ProductSale=[],this.rjObject.ModifierItem=[],(new y).basket(this.transactionDocument.currentTransactionDetails).build().basket.products.forEach((function(e){if(e.refundedQuantity>0){var n=t.returnProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductReturn.push(n)}else{var i=t.addProduct(e,e.hasOwnProperty("lineDiscount")?e.lineDiscount:null);t.rjObject.ProductSale.push(i)}t.getModifierItem(e.lineDiscount,e.itemLineId)}))}return(this)},t.prototype.getBasketDiscount=function(){var t=this;return this.rjObject.BasketDiscount=[],this.transactionDocument.basket.transactionDiscount?(this.transactionDocument.basket.transactionDiscount.forEach((function(e){var n={XMLSchemaVersion:1};n.NetValue=e.discountAmount<0?e.discountAmount:-e.discountAmount,n.EffectiveNetValue=e.discountAmount<0?e.discountAmount:-e.discountAmount,n.Description=e.reasonCode,n.UserID=t.transactionDocument.basket.userId,n.ReasonCodeID=e.reasonCode,n.DiscountType=e.discountType.toUpperCase()==p.PERCENT.toUpperCase()?0:1,n.RoundingRule=2,n["ModifiedLineNumber "]=[],e.itemLineIds.forEach((function(t){n.ModifiedLineNumber.push(t)})),n.LineNumber=t.generateLineNumber(),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.userId,n.DateTimeCreated=this.transactionDocument.updatedAt,n.AuthorisingUserID=this.userId,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.transactionDocument.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.transactionDocument.storeId,this.rjObject.Trailer.CompletedBy.TerminalNumber=this.transactionDocument.terminalId,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.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=e.VAT,n.TaxableTotal=t.convertToString(e.taxableAmount),n.TaxTotal=t.convertToString(e.taxLineTotal),n.TaxDescription=t.convertToString(e.VATCode),n.TaxIncluded="1",n.TaxPercentage=e.VAT.toFixed(2),t.rjObject.Trailer.TaxItem.push(n)})),this.rjObject.Trailer.PromotionItem=[],this.transactionDocument.basket.linePromotion.forEach((function(e){var n={};n.PromotionID=e.promotionId,n.PromotionSaving=e.promotionAmount<0?e.promotionAmount:-e.promotionAmount,n.PromotionQuantity="",n.PromotionDescription=e.displayText,n.PromotionHit.XMLSchemaVersion=t.transactionDocument.storeId,n.PromotionHit.HitNumber="",n.PromotionHit.HitQuantity="",n.PromotionHit.HitSaving="",n.PromotionHit.PromotionTrigger=[],e.trigger.forEach((function(i){var o={},r=t.transactionDocument.basket.products.find((function(t){return t.lineItemId==i.itemLineId}));o.XMLSchemaVersion=t.xmlSchemaVersion,o.ProductID=t.transactionDocument.basket.products.find((function(t){return t.itemLineId===i.itemLineId})).SKU,o.UnitValue=t.convertToString(e.promotionLinePrice/r.quantity),o.LineNumber=t.convertToString(i.itemLineId),o.Quantity=t.convertToString(i.quantity.toFixed(1)),o.TaxCode=t.transactionDocument.basket.taxBreakdown.taxLines.find((function(t){return t.itemLineId==e.itemLineId})).VATCode,n.PromotionHit.PromotionTrigger.push(o)})),t.rjObject.Trailer.PromotionItem.push(n)})),this},t.prototype.getTenderInfo=function(){var t=this;return this.rjObject.CashTender=[],this.transactionDocument.paymentDetails&&this.transactionDocument.paymentDetails.length>0&&this.transactionDocument.paymentDetails.forEach((function(e){var n=t.paymentTypes.filter((function(t){return t.paymentType.toUpperCase()===e.paymentType.toUpperCase()}));if("GIFT CARD"===e.paymentType.toUpperCase()){var i={XMLSchemaVersion:t.xmlSchemaVersion,LineNumber:t.generateLineNumber(),NetValue:t.convertToString(-1*Math.round(e.amount)),EffectiveNetValue:t.convertToString(-1*Math.round(e.amount)),Description:t.getDescription(n[0].paymentType,e),DeviceID:t.deviceId,UserID:t.userId,DateTimeCreated:t.transactionDocument.updatedAt,TenderType:n[0].tenderType,TenderSubType:n[0].tenderSubType,TenderAmount:t.convertToString(-1*Math.round(e.amount)),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,GiftVoucherSalesAllowed:"",AllowRechargeableVoucherSales:"",GiftVoucherID:""};t.rjObject.CashTender.push(i)}else{var o={XMLSchemaVersion:"1",LineNumber:t.generateLineNumber(),NetValue:JSON.stringify(-1*Math.round(e.amount)),EffectiveNetValue:JSON.stringify(-1*Math.round(e.amount)),Description:t.getDescription(n[0].paymentType,e),DeviceID:t.deviceId,UserID:t.userId,DateTimeCreated:t.transactionDocument.updatedAt,TenderType:n[0].tenderType,TenderSubType:n[0].tenderSubType,TenderAmount:JSON.stringify(-1*Math.round(e.amount)),CurrencyID:t.transactionDocument.baseCurrency,CurrencyDescription:t.transactionDocument.baseCurrency,IncludeInTransactionTotalCheck:"1",AllowRechargeableVoucherSales:"1",OpenDrawerAtEnd:"1"};t.rjObject.CashTender.push(o)}})),this},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,e){return"CARD"===t.toUpperCase()?e.cardType:t},t.prototype.setDeviceInfo=function(t){return this.deviceId=t,this},t.prototype.setUserInfo=function(t){return this.userId=t,this},t.prototype.removeDecimal=function(t){return 100*t},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(t){return this.cashierId=t,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.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){var n={};n.XMLSchemaVersion=this.xmlSchemaVersion,n.LineNumber=t.itemLineId,n.NetValue=this.removeDecimal(t.refundedTotal),n.EffectiveNetValue=this.removeDecimal(t.refundedTotal),n.Description=t.description,n.DeviceID=this.transactionDocument.terminalId,n.UserID=this.userId,n.DateTimeCreated=this.transactionDocument.createdAt,n.ExtendedValue=this.removeDecimal(-1*t.totalLinePrice),n.UnitPrice=this.removeDecimal(t.price),n.Quantity=t.refundedQuantity<0?t.refundedQuantity.toFixed(1):-t.refundedQuantity.toFixed(1),n.OriginalTaxAmountSet=1,n.ProductID=t.SKU,n.HandKeyed=1,n.LongDescription=t.description,n.Return={},n.Return.ReturnReasonID=t.refundedReason,n.Return.ReturnDescription=t.refundedReasonDescription,n.Return.ReturnToStock=t.refundedQuantity>0?t.refundedQuantity.toFixed(1):-1*t.refundedQuantity.toFixed(1),n.TaxCode=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId})).VATCode,n.DisplayTaxCode="",n.ProductAttributes="",n.Perishable=this.getAttributes(),n.MMGroupID=this.getAttributes(),n.CustomerDetails="",n.TotalPromotionSaving=t.promotionAmount||-1;var i=this.transactionDocument.basket.taxBreakdown.taxLines.find((function(e){return e.itemLineId==t.itemLineId}));return n.OriginalTaxAmount=i.taxLineTotal<0?this.removeDecimal(i.taxLineTotal):this.removeDecimal(-i.taxLineTotal),n.taxAmount=i.taxLineTotal<0?this.removeDecimal(i.taxLineTotal):this.removeDecimal(-i.taxLineTotal),e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(n.Discount={},n.Discount.ModifierValue=-1*this.removeDecimal(e.unitPrice),n.Discount.ModifierDateTime=n.DateTimeCreated,n.Discount.ModifierReasonID=e.percentageDiscountReasonCode,n.Discount.ModifierDescription=e.percentageDiscountReasonName,n.Discount.AuthorisingUserID=this.userId,n.Discount.DiscountType=e.discountType,n.Discount.XMLSchemaVersion=1,n.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),n.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),n.Discount.DiscountPercentage=e.percentageDiscountValue,n.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(n.PriceOverride={},n.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),n.PriceOverride.ModifierDateTime=n.DateTimeCreated,n.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,n.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,n.PriceOverride.AuthorisingUserID=this.userId,n.PriceOverride.XMLSchemaVersion=1,n.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),n.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),n.NetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),n.EffectiveNetValue=-1*((e.discountedLinePrice||0)+e.discountAmount),n.ExtendedValue=-1*((e.discountedLinePrice||0)+e.discountAmount),n.UnitPrice=-1*((e.discountedLinePrice||0)+e.discountAmount)),n},t.prototype.addProduct=function(t,e){var n={XMLSchemaVersion:this.xmlSchemaVersion,LineNumber:t.itemLineId,NetValue:this.removeDecimal(t.totalLinePrice),EffectiveNetValue:this.removeDecimal(t.totalLinePrice),Description:t.description,DeviceID:this.deviceId,UserID:this.userId,DateTimeCreated:this.transactionDocument.createdAt,ExtendedValue:this.removeDecimal(t.price),UnitPrice:this.removeDecimal(t.price),MMGroupID:this.getAttributes(),Quantity:t.quantity.toFixed(1),SalespersonID:this.transactionDocument.userId,SalespersonName:this.transactionDocument.userName,TaxCode:0,TaxModifiable:1,TaxAmount:0,OriginalTaxAmount:0,OriginalTaxAmountSet:1,ProductID:t.SKU,HandKeyed:1,CustomerDetails:"",Perishable:this.getAttributes()};return e&&(e.percentageDiscountReasonName&&e.percentageDiscountReasonCode&&(n.Discount={},n.Discount.ModifierValue=-1*this.removeDecimal(e.unitPrice),n.Discount.ModifierDateTime=n.DateTimeCreated,n.Discount.ModifierReasonID=e.percentageDiscountReasonCode,n.Discount.ModifierDescription=e.percentageDiscountReasonName,n.Discount.AuthorisingUserID=this.userId,n.Discount.DiscountType=e.discountType,n.Discount.XMLSchemaVersion=1,n.Discount.OriginalPrice=this.removeDecimal(e.discountAmount+(e.discountedLinePrice||0)),n.Discount.DiscountedValue=this.removeDecimal(e.unitPrice),n.Discount.DiscountPercentage=e.percentageDiscountValue,n.Discount.RoundingRule=2),e.priceOverrideReasonCode&&e.priceOverrideReasonName&&(n.PriceOverride={},n.PriceOverride.ModifierValue=-1*this.removeDecimal(e.discountAmount),n.PriceOverride.ModifierDateTime=n.DateTimeCreated,n.PriceOverride.ModifierReasonID=e.priceOverrideReasonCode,n.PriceOverride.ModifierReasonDescription=e.priceOverrideReasonName,n.PriceOverride.AuthorisingUserID=this.userId,n.PriceOverride.XMLSchemaVersion=1,n.PriceOverride.NewPrice=this.removeDecimal(e.unitPrice),n.PriceOverride.OriginalPrice=this.removeDecimal(e.discountedLinePrice||0+e.discountAmount)),n.NetValue=(e.discountedLinePrice||0)+e.discountAmount,n.EffectiveNetValue=(e.discountedLinePrice||0)+e.discountAmount,n.ExtendedValue=(e.discountedLinePrice||0)+e.discountAmount,n.UnitPrice=(e.discountedLinePrice||0)+e.discountAmount),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.getAttributes=function(){var t=[];return this.transactionDocument.basket.products.forEach((function(e){e.attributes&&e.attributes.length>0&&(t=e.attributes.filter((function(t){return t.name.toUpperCase()===e.name.toUpperCase()})))})),t.length>0?t[0].value:""},t}();t.MapperLibraryComponent=s,t.MapperLibraryModule=c,t.RJMapperBuilderClass=b,Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
16
16
|
//# sourceMappingURL=pmcretail-mapper-library.umd.min.js.map
|