b23-lib 4.0.0 → 4.0.2
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/dist/Classes/Cart.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'../chunk-
|
|
1
|
+
import {a}from'../chunk-3LVBCEMO.mjs';import'../chunk-YDSXBMNW.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-A2PC4S2X.mjs';import'../chunk-MWDQACOC.mjs';import'../chunk-EZ35IKUA.mjs';import'../chunk-3SUQYXIJ.mjs';import {f}from'../chunk-XXKEHCV5.mjs';import'../chunk-7RAIVZKB.mjs';import'../chunk-UIQH5QIR.mjs';import'../chunk-PL5HGCWN.mjs';import {a as a$1}from'../chunk-O6BLQQO7.mjs';import'../chunk-UXZBULDS.mjs';var p=(i=>(i.ACTIVE="ACTIVE",i.FROZEN="FROZEN",i.MERGED="MERGED",i.ORDERED="ORDERED",i))(p||{}),h={expiresAtInSeconds:120*24*60*60},c=class extends a{state;expireAt;config;constructor(t,e=new Date,r=h){super(t,e),this.state=t.state,this.expireAt=t.expireAt&&typeof t.expireAt=="number"?t.expireAt:Math.floor(e.getTime()/1e3)+r.expiresAtInSeconds,this.config=r;}getState(){return this.state}getExpireAt(){return this.expireAt}isActive(){let t=Math.ceil(Date.now()/1e3);return this.state==="ACTIVE"&&this.expireAt>t}clearCartItems(){this.lineItems=[],this.charges=[],this.coupons=[],this.shippingDetails=null,this.calculateTotals();}validateLineItems(t){this.lineItems=this.lineItems.map(e=>{try{e.updateProductData(t[e.getProductKey()],this.country,this.currency);}catch(r){console.error(`Error recalculating line item ${e.getId()}:`,r),e.clearLineItem();}return e}).filter(e=>e.getId()),this.calculateTotals();}addLineItem(t,e){let r=t.getProductKey(),i=t.getSelectionAttributes(),n=f.generateSelectionAttributesKey(i),s=this.lineItems.findIndex(l=>l.getProductKey()===r&&f.generateSelectionAttributesKey(l.getSelectionAttributes())===n);return s>=0?(t.addSubItems(this.lineItems[s].getSubItems(),e),this.lineItems[s]=t):this.lineItems.push(t),this.calculateTotals(),s>=0?s:this.lineItems.length-1}updateLineItem(t,e,r){let i=this.lineItems,n=i.findIndex(s=>s.getId()===t);if(n<0)throw new a$1(t);return i[n].addSubItems([{size:e,quantity:r}],!1),this.calculateTotals(),n}removeLineItem(t){let r=this.lineItems.findIndex(i=>i.getId()===t);if(r<0)throw new a$1(t);return this.lineItems.splice(r,1),this.charges=this.charges.filter(i=>i.getLineItemId()!==t),this.calculateTotals(),r}getDetails(){return {...super.getDetails(),state:this.getState(),expireAt:this.getExpireAt()}}};export{p as CartState,h as DEFAULT_CART_CONFIG,c as default};//# sourceMappingURL=Cart.mjs.map
|
|
2
2
|
//# sourceMappingURL=Cart.mjs.map
|
package/dist/Classes/Order.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a as a$1}from'../chunk-
|
|
1
|
+
import {a as a$1}from'../chunk-3LVBCEMO.mjs';import'../chunk-YDSXBMNW.mjs';import {b}from'../chunk-HX32EJ3F.mjs';import'../chunk-A2PC4S2X.mjs';import'../chunk-MWDQACOC.mjs';import'../chunk-EZ35IKUA.mjs';import'../chunk-3SUQYXIJ.mjs';import'../chunk-XXKEHCV5.mjs';import'../chunk-7RAIVZKB.mjs';import'../chunk-UIQH5QIR.mjs';import'../chunk-PL5HGCWN.mjs';import {a as a$2}from'../chunk-O6BLQQO7.mjs';import'../chunk-UXZBULDS.mjs';var a=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(a||{}),i=class extends a$1{orderNumber;cartId;paymentStatus;holdReason;state;shippingAddress;billingAddress;constructor(t,e=new Date){super(t,e,{checkCouponExpiry:!1}),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state,this.shippingAddress=new b(t.shippingAddress,e),this.billingAddress=new b(t.billingAddress,e);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let e=this.getLineItems().find(d=>d.getId()===t);if(!e)throw new a$2(t);return e.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{a as OrderState,i as default};//# sourceMappingURL=Order.mjs.map
|
|
2
2
|
//# sourceMappingURL=Order.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as default}from'../chunk-
|
|
1
|
+
export{a as default}from'../chunk-3LVBCEMO.mjs';import'../chunk-YDSXBMNW.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-A2PC4S2X.mjs';import'../chunk-MWDQACOC.mjs';import'../chunk-EZ35IKUA.mjs';import'../chunk-3SUQYXIJ.mjs';import'../chunk-XXKEHCV5.mjs';import'../chunk-7RAIVZKB.mjs';import'../chunk-UIQH5QIR.mjs';import'../chunk-PL5HGCWN.mjs';import'../chunk-O6BLQQO7.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=ShoppingContainer.mjs.map
|
|
2
2
|
//# sourceMappingURL=ShoppingContainer.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'./chunk-YDSXBMNW.mjs';import {e}from'./chunk-3SUQYXIJ.mjs';import {b as b$1}from'./chunk-HX32EJ3F.mjs';import {a as a$1}from'./chunk-A2PC4S2X.mjs';import {a as a$2}from'./chunk-XXKEHCV5.mjs';import {a as a$3}from'./chunk-UIQH5QIR.mjs';import {b}from'./chunk-UXZBULDS.mjs';var R=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;#t;constructor(t,e$1=new Date,a$4={checkCouponExpiry:!0}){super(t,e$1),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new a(i)),this.charges=(t.charges??[]).map(i=>new a$1(i)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,e$1):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,e$1):null,this.coupons=(t.coupons??[]).map(i=>new e(i)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown),additiveChargesTaxTotal:new a$3(t.total.additiveChargesTaxTotal),additiveChargesTaxBreakdown:this.mapTaxBreakdown(t.total.additiveChargesTaxBreakdown),adjustmentCharges:new a$3(t.total.adjustmentCharges),discountTotal:new a$3(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,o])=>[i,new a$3(o)])),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),taxExclusive:{lineItemSubtotal:new a$3(t.total.taxExclusive.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.taxExclusive.netLineItemSubtotal),additiveCharges:new a$3(t.total.taxExclusive.additiveCharges),netAdditiveCharges:new a$3(t.total.taxExclusive.netAdditiveCharges),shippingCharges:new a$3(t.total.taxExclusive.shippingCharges),netShippingCharges:new a$3(t.total.taxExclusive.netShippingCharges)},taxInclusive:{lineItemSubtotal:new a$3(t.total.taxInclusive.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.taxInclusive.netLineItemSubtotal),additiveCharges:new a$3(t.total.taxInclusive.additiveCharges),netAdditiveCharges:new a$3(t.total.taxInclusive.netAdditiveCharges),shippingCharges:new a$3(t.total.taxInclusive.shippingCharges),netShippingCharges:new a$3(t.total.taxInclusive.netShippingCharges)},grandTotal:new a$3(t.total.grandTotal)},this.#t={checkCouponExpiry:a$4.checkCouponExpiry};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,a])=>[e,{system:a.system,totalAmount:new a$3(a.totalAmount),subSystems:Object.fromEntries(Object.entries(a.subSystems).map(([i,o])=>[i,new a$3(o)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,a])=>[e,{system:a.system,totalAmount:a.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(a.subSystems).map(([i,o])=>[i,o.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?a$2.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {lineItemTaxTotal:this.total.lineItemTaxTotal,lineItemTaxBreakdown:Object.fromEntries(Object.entries(this.total.lineItemTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),additiveChargesTaxTotal:this.total.additiveChargesTaxTotal,additiveChargesTaxBreakdown:Object.fromEntries(Object.entries(this.total.additiveChargesTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),adjustmentCharges:this.total.adjustmentCharges,discountBreakdown:{...this.total.discountBreakdown},discountTotal:this.total.discountTotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),taxExclusive:{lineItemSubtotal:this.total.taxExclusive.lineItemSubtotal,netLineItemSubtotal:this.total.taxExclusive.netLineItemSubtotal,additiveCharges:this.total.taxExclusive.additiveCharges,netAdditiveCharges:this.total.taxExclusive.netAdditiveCharges,shippingCharges:this.total.taxExclusive.shippingCharges,netShippingCharges:this.total.taxExclusive.netShippingCharges},taxInclusive:{lineItemSubtotal:this.total.taxInclusive.lineItemSubtotal,netLineItemSubtotal:this.total.taxInclusive.netLineItemSubtotal,additiveCharges:this.total.taxInclusive.additiveCharges,netAdditiveCharges:this.total.taxInclusive.netAdditiveCharges,shippingCharges:this.total.taxInclusive.shippingCharges,netShippingCharges:this.total.taxInclusive.netShippingCharges},grandTotal:this.total.grandTotal}}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(e=>e.getDetails()),charges:this.getCharges().map(e=>e.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(e=>e.getDetails()),total:{lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),additiveChargesTaxTotal:t.additiveChargesTaxTotal.getDetails(),additiveChargesTaxBreakdown:this.serializeTaxBreakdown(t.additiveChargesTaxBreakdown),adjustmentCharges:t.adjustmentCharges.getDetails(),discountTotal:t.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(t.discountBreakdown).map(([e,a])=>[e,a.getDetails()])),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),taxExclusive:{lineItemSubtotal:t.taxExclusive.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.taxExclusive.netLineItemSubtotal.getDetails(),additiveCharges:t.taxExclusive.additiveCharges.getDetails(),netAdditiveCharges:t.taxExclusive.netAdditiveCharges.getDetails(),shippingCharges:t.taxExclusive.shippingCharges.getDetails(),netShippingCharges:t.taxExclusive.netShippingCharges.getDetails()},taxInclusive:{lineItemSubtotal:t.taxInclusive.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.taxInclusive.netLineItemSubtotal.getDetails(),additiveCharges:t.taxInclusive.additiveCharges.getDetails(),netAdditiveCharges:t.taxInclusive.netAdditiveCharges.getDetails(),shippingCharges:t.taxInclusive.shippingCharges.getDetails(),netShippingCharges:t.taxInclusive.netShippingCharges.getDetails()},grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency});this.lineItems.forEach(c=>{c.getState()!=="CANCELLED"&&c.updateDiscounts([]);}),this.charges.forEach(c=>c.updateDiscounts([]));let e=this.getCouponEvaluationBases(),a=t,i={},o={};this.coupons.filter(c=>c.getCategory()!=="SHIPPING").forEach(c=>{let s=c.calculateApplicableCouponDiscount(e.targetSubtotal,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry);a=a.add(s),i[c.getCode()]=s,o[c.getCode()]=s;}),this.applyDiscountsInLineItem(o);let g=this.getCouponEvaluationBases(),m={};this.coupons.filter(c=>c.getCategory()==="SHIPPING").forEach(c=>{let s=c.calculateApplicableCouponDiscount(g.targetNetSubtotal,g.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(g.targetShipping);a=a.add(s),i[c.getCode()]=s,m[c.getCode()]=s;}),this.applyDiscountsInShippingCharges(m);let n=t,r=t,d=t,h=t,C=t,T=t,w={},N={},z={},v=(c,s)=>{Object.entries(c).forEach(([F,V])=>{let{system:x,subSystem:y,taxAmount:P}=V;s[x]||(s[x]={system:x,totalAmount:t,subSystems:{}}),s[x].subSystems[y]?s[x].subSystems[y]=s[x].subSystems[y].add(P):s[x].subSystems[y]=P,s[x].totalAmount=s[x].totalAmount.add(P);});};this.lineItems.filter(c=>c.getState()!=="CANCELLED").forEach(c=>{let s=c.getTotal();d=d.add(s.taxExclusive.subtotal),h=h.add(s.taxExclusive.netSubtotal),C=C.add(s.taxInclusive.subtotal),T=T.add(s.taxInclusive.netSubtotal),s.taxBreakdown&&(v(s.taxBreakdown,N),v(s.taxBreakdown,w),n=n.add(s.taxTotal));});let D=t,A=t,E=t,S=t,B=t,k=t,M=t,f=t,b=t;this.charges.forEach(c=>{let s=c.getTotal();c.getImpact()==="ADD"?(D=D.add(s.taxExclusive.chargeAmount),A=A.add(s.taxExclusive.netChargeAmount),E=E.add(s.taxInclusive.chargeAmount),S=S.add(s.grandTotal),c.getType()==="SHIPPING"&&(B=B.add(s.taxExclusive.chargeAmount),k=k.add(s.taxExclusive.netChargeAmount),M=M.add(s.taxInclusive.chargeAmount),f=f.add(s.grandTotal)),s.taxBreakdown&&(v(s.taxBreakdown,z),v(s.taxBreakdown,w),r=r.add(s.taxTotal))):c.getImpact()==="SUBTRACT"&&(b=b.add(s.grandTotal));});let Z=n.add(r),U=T.add(S).subtract(b);this.total={lineItemTaxTotal:n,lineItemTaxBreakdown:N,additiveChargesTaxTotal:r,additiveChargesTaxBreakdown:z,adjustmentCharges:b,discountTotal:a,discountBreakdown:i,taxTotal:Z,taxBreakdown:w,taxExclusive:{lineItemSubtotal:d,netLineItemSubtotal:h,additiveCharges:D,netAdditiveCharges:A,shippingCharges:B,netShippingCharges:k},taxInclusive:{lineItemSubtotal:C,netLineItemSubtotal:T,additiveCharges:E,netAdditiveCharges:S,shippingCharges:M,netShippingCharges:f},grandTotal:U};}updateShippingDetails(t){this.shippingDetails=t;}applyCoupons(t){let e=t.filter(i=>i.getCategory()==="SHIPPING"),a=t.filter(i=>i.getCategory()!=="SHIPPING");this.coupons=[],this.total.discountTotal=this.total.discountTotal.zero(),this.total.discountBreakdown={},a.length&&this.applyNonShippingCoupons(a),this.applyDiscountsInLineItem(this.total.discountBreakdown),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(i=>!i[1].isZero()),a=new Map;this.lineItems.forEach(i=>a.set(i.getId(),[])),e.forEach(([i,o])=>{let p=this.coupons.find(n=>n.getCode()===i);if(!p||o.isZero())return;let g=this.lineItems.reduce((n,r)=>n.add(r.getIsTaxInclusive()?r.getTotal().taxInclusive.subtotal:r.getTotal().taxExclusive.subtotal),new a$3({amount:0,currency:this.currency})),m=this.lineItems.filter(n=>n.getState()!=="CANCELLED"&&!n.getTotal().taxExclusive.subtotal.isZero()).sort((n,r)=>{let d=n.getIsTaxInclusive()?n.getTotal().taxInclusive.subtotal:n.getTotal().taxExclusive.subtotal,h=r.getIsTaxInclusive()?r.getTotal().taxInclusive.subtotal:r.getTotal().taxExclusive.subtotal;return d.compareTo(h)}),u=new a$3({amount:0,currency:this.currency});m.forEach((n,r)=>{let d,h=n.getIsTaxInclusive()?n.getTotal().taxInclusive.subtotal:n.getTotal().taxExclusive.subtotal;r===m.length-1?d=o.subtract(u):d=o.multiply(h).divide(g).round(),u=u.add(d),a.get(n.getId())?.push({coupon:p,amount:d});});}),this.lineItems.forEach(i=>{i.updateDiscounts(a.get(i.getId()));});}applyDiscountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(o=>!o[1].isZero()),a=this.charges.filter(o=>o.getType()==="SHIPPING"),i=new Map;a.forEach(o=>i.set(o.getId(),[])),e.forEach(([o,p])=>{let g=this.coupons.find(r=>r.getCode()===o);if(!g||p.isZero())return;let m=a.reduce((r,d)=>r.add(d.getIsTaxInclusive()?d.getTotal().taxInclusive.chargeAmount:d.getTotal().taxExclusive.chargeAmount),new a$3({amount:0,currency:this.currency})),u=a.filter(r=>!r.getTotal().taxExclusive.chargeAmount.isZero()).sort((r,d)=>{let h=r.getIsTaxInclusive()?r.getTotal().taxInclusive.chargeAmount:r.getTotal().taxExclusive.chargeAmount,C=d.getIsTaxInclusive()?d.getTotal().taxInclusive.chargeAmount:d.getTotal().taxExclusive.chargeAmount;return h.compareTo(C)}),n=new a$3({amount:0,currency:this.currency});u.forEach((r,d)=>{let h,C=r.getIsTaxInclusive()?r.getTotal().taxInclusive.chargeAmount:r.getTotal().taxExclusive.chargeAmount;d===u.length-1?h=p.subtract(n):h=p.multiply(C).divide(m).round(),n=n.add(h),i.get(r.getId())?.push({coupon:g,amount:h});});}),a.forEach(o=>{o.updateDiscounts(i.get(o.getId()));});}getCouponEvaluationBases(){let t=new a$3({amount:0,currency:this.currency}),e=this.lineItems.filter(u=>u.getState()!=="CANCELLED"),a=this.charges.filter(u=>u.getType()==="SHIPPING"),i=e.some(u=>u.getIsTaxInclusive()),o=e.reduce((u,n)=>u.add(i?n.getTotal().taxInclusive.subtotal:n.getTotal().taxExclusive.subtotal),t),p=e.reduce((u,n)=>u.add(i?n.getTotal().taxInclusive.netSubtotal:n.getTotal().taxExclusive.netSubtotal),t),g=a.some(u=>u.getIsTaxInclusive()),m=a.reduce((u,n)=>u.add(g?n.getTotal().taxInclusive.chargeAmount:n.getTotal().taxExclusive.chargeAmount),t);return {targetSubtotal:o,targetShipping:m,targetNetSubtotal:p}}applyNonShippingCoupons(t){let e=t.filter(a=>a.getType()==="coupon");if(e.length===1){let a=this.getCouponEvaluationBases(),i=e[0].calculateApplicableCouponDiscount(a.targetSubtotal,a.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discountTotal=i,this.total.discountBreakdown[e[0].getCode()]=i);}}applyShippingCoupons(t){let e=this.getCouponEvaluationBases();if(e.targetShipping.getAmount()>0&&t.length>0){let a=e.targetNetSubtotal,i=t.reduce((p,g)=>{if(!p)return g;let m=g.calculateApplicableCouponDiscount(a,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(e.targetShipping),u=p.calculateApplicableCouponDiscount(a,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(e.targetShipping);return m.compareTo(u)===0?g.getType()==="coupon"?g:p:m.compareTo(u)>0?g:p}),o=i.calculateApplicableCouponDiscount(a,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(e.targetShipping);o.getAmount()>0&&(this.coupons.push(i),this.total.discountTotal=this.total.discountTotal.add(o),this.total.discountBreakdown[i.getCode()]=o);}}};export{R as a};//# sourceMappingURL=chunk-LE4HS2A6.mjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a}from'./chunk-YDSXBMNW.mjs';import {b as b$1}from'./chunk-HX32EJ3F.mjs';import {a as a$1}from'./chunk-A2PC4S2X.mjs';import {e}from'./chunk-3SUQYXIJ.mjs';import {a as a$2}from'./chunk-XXKEHCV5.mjs';import {a as a$3}from'./chunk-UIQH5QIR.mjs';import {b}from'./chunk-UXZBULDS.mjs';var R=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;#t;constructor(t,e$1=new Date,a$4={checkCouponExpiry:!0}){super(t,e$1),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new a(i)),this.charges=(t.charges??[]).map(i=>new a$1(i)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,e$1):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,e$1):null,this.coupons=(t.coupons??[]).map(i=>new e(i)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown),additiveChargesTaxTotal:new a$3(t.total.additiveChargesTaxTotal),additiveChargesTaxBreakdown:this.mapTaxBreakdown(t.total.additiveChargesTaxBreakdown),adjustmentCharges:new a$3(t.total.adjustmentCharges),discountTotal:new a$3(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,o])=>[i,new a$3(o)])),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),taxExclusive:{lineItemSubtotal:new a$3(t.total.taxExclusive.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.taxExclusive.netLineItemSubtotal),additiveCharges:new a$3(t.total.taxExclusive.additiveCharges),netAdditiveCharges:new a$3(t.total.taxExclusive.netAdditiveCharges),shippingCharges:new a$3(t.total.taxExclusive.shippingCharges),netShippingCharges:new a$3(t.total.taxExclusive.netShippingCharges)},taxInclusive:{lineItemSubtotal:new a$3(t.total.taxInclusive.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.taxInclusive.netLineItemSubtotal),additiveCharges:new a$3(t.total.taxInclusive.additiveCharges),netAdditiveCharges:new a$3(t.total.taxInclusive.netAdditiveCharges),shippingCharges:new a$3(t.total.taxInclusive.shippingCharges),netShippingCharges:new a$3(t.total.taxInclusive.netShippingCharges)},grandTotal:new a$3(t.total.grandTotal)},this.#t={checkCouponExpiry:a$4.checkCouponExpiry};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,a])=>[e,{system:a.system,totalAmount:new a$3(a.totalAmount),subSystems:Object.fromEntries(Object.entries(a.subSystems).map(([i,o])=>[i,new a$3(o)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,a])=>[e,{system:a.system,totalAmount:a.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(a.subSystems).map(([i,o])=>[i,o.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?a$2.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {lineItemTaxTotal:this.total.lineItemTaxTotal,lineItemTaxBreakdown:Object.fromEntries(Object.entries(this.total.lineItemTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),additiveChargesTaxTotal:this.total.additiveChargesTaxTotal,additiveChargesTaxBreakdown:Object.fromEntries(Object.entries(this.total.additiveChargesTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),adjustmentCharges:this.total.adjustmentCharges,discountBreakdown:{...this.total.discountBreakdown},discountTotal:this.total.discountTotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),taxExclusive:{lineItemSubtotal:this.total.taxExclusive.lineItemSubtotal,netLineItemSubtotal:this.total.taxExclusive.netLineItemSubtotal,additiveCharges:this.total.taxExclusive.additiveCharges,netAdditiveCharges:this.total.taxExclusive.netAdditiveCharges,shippingCharges:this.total.taxExclusive.shippingCharges,netShippingCharges:this.total.taxExclusive.netShippingCharges},taxInclusive:{lineItemSubtotal:this.total.taxInclusive.lineItemSubtotal,netLineItemSubtotal:this.total.taxInclusive.netLineItemSubtotal,additiveCharges:this.total.taxInclusive.additiveCharges,netAdditiveCharges:this.total.taxInclusive.netAdditiveCharges,shippingCharges:this.total.taxInclusive.shippingCharges,netShippingCharges:this.total.taxInclusive.netShippingCharges},grandTotal:this.total.grandTotal}}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(e=>e.getDetails()),charges:this.getCharges().map(e=>e.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(e=>e.getDetails()),total:{lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),additiveChargesTaxTotal:t.additiveChargesTaxTotal.getDetails(),additiveChargesTaxBreakdown:this.serializeTaxBreakdown(t.additiveChargesTaxBreakdown),adjustmentCharges:t.adjustmentCharges.getDetails(),discountTotal:t.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(t.discountBreakdown).map(([e,a])=>[e,a.getDetails()])),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),taxExclusive:{lineItemSubtotal:t.taxExclusive.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.taxExclusive.netLineItemSubtotal.getDetails(),additiveCharges:t.taxExclusive.additiveCharges.getDetails(),netAdditiveCharges:t.taxExclusive.netAdditiveCharges.getDetails(),shippingCharges:t.taxExclusive.shippingCharges.getDetails(),netShippingCharges:t.taxExclusive.netShippingCharges.getDetails()},taxInclusive:{lineItemSubtotal:t.taxInclusive.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.taxInclusive.netLineItemSubtotal.getDetails(),additiveCharges:t.taxInclusive.additiveCharges.getDetails(),netAdditiveCharges:t.taxInclusive.netAdditiveCharges.getDetails(),shippingCharges:t.taxInclusive.shippingCharges.getDetails(),netShippingCharges:t.taxInclusive.netShippingCharges.getDetails()},grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency});this.lineItems.forEach(c=>{c.getState()!=="CANCELLED"&&c.updateDiscounts([]);}),this.charges.forEach(c=>c.updateDiscounts([]));let e=this.getCouponEvaluationBases(),a=t,i={},o={};this.coupons.filter(c=>c.getCategory()!=="SHIPPING").forEach(c=>{let s=c.calculateApplicableCouponDiscount(e.targetSubtotal,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry);a=a.add(s),i[c.getCode()]=s,o[c.getCode()]=s;}),this.applyDiscountsInLineItem(o);let g=this.getCouponEvaluationBases(),m={};this.coupons.filter(c=>c.getCategory()==="SHIPPING").forEach(c=>{let s=c.calculateApplicableCouponDiscount(g.targetNetSubtotal,g.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(g.targetShipping);a=a.add(s),i[c.getCode()]=s,m[c.getCode()]=s;}),this.applyDiscountsInShippingCharges(m);let n=t,r=t,d=t,h=t,C=t,T=t,w={},N={},z={},v=(c,s)=>{Object.entries(c).forEach(([F,V])=>{let{system:x,subSystem:y,taxAmount:P}=V;s[x]||(s[x]={system:x,totalAmount:t,subSystems:{}}),s[x].subSystems[y]?s[x].subSystems[y]=s[x].subSystems[y].add(P):s[x].subSystems[y]=P,s[x].totalAmount=s[x].totalAmount.add(P);});};this.lineItems.filter(c=>c.getState()!=="CANCELLED").forEach(c=>{let s=c.getTotal();d=d.add(s.taxExclusive.subtotal),h=h.add(s.taxExclusive.netSubtotal),C=C.add(s.taxInclusive.subtotal),T=T.add(s.taxInclusive.netSubtotal),s.taxBreakdown&&(v(s.taxBreakdown,N),v(s.taxBreakdown,w),n=n.add(s.taxTotal));});let D=t,A=t,E=t,S=t,B=t,k=t,M=t,f=t,b=t;this.charges.forEach(c=>{let s=c.getTotal();c.getImpact()==="ADD"?(D=D.add(s.taxExclusive.chargeAmount),A=A.add(s.taxExclusive.netChargeAmount),E=E.add(s.taxInclusive.chargeAmount),S=S.add(s.grandTotal),c.getType()==="SHIPPING"&&(B=B.add(s.taxExclusive.chargeAmount),k=k.add(s.taxExclusive.netChargeAmount),M=M.add(s.taxInclusive.chargeAmount),f=f.add(s.grandTotal)),s.taxBreakdown&&(v(s.taxBreakdown,z),v(s.taxBreakdown,w),r=r.add(s.taxTotal))):c.getImpact()==="SUBTRACT"&&(b=b.add(s.grandTotal));});let Z=n.add(r),U=T.add(S).subtract(b);this.total={lineItemTaxTotal:n,lineItemTaxBreakdown:N,additiveChargesTaxTotal:r,additiveChargesTaxBreakdown:z,adjustmentCharges:b,discountTotal:a,discountBreakdown:i,taxTotal:Z,taxBreakdown:w,taxExclusive:{lineItemSubtotal:d,netLineItemSubtotal:h,additiveCharges:D,netAdditiveCharges:A,shippingCharges:B,netShippingCharges:k},taxInclusive:{lineItemSubtotal:C,netLineItemSubtotal:T,additiveCharges:E,netAdditiveCharges:S,shippingCharges:M,netShippingCharges:f},grandTotal:U};}updateShippingDetails(t){this.shippingDetails=t;}applyCoupons(t){let e=t.filter(i=>i.getCategory()==="SHIPPING"),a=t.filter(i=>i.getCategory()!=="SHIPPING");this.coupons=[],this.total.discountTotal=this.total.discountTotal.zero(),this.total.discountBreakdown={},a.length&&this.applyNonShippingCoupons(a),this.applyDiscountsInLineItem(this.total.discountBreakdown),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(i=>!i[1].isZero()),a=new Map;this.lineItems.forEach(i=>a.set(i.getId(),[])),e.forEach(([i,o])=>{let p=this.coupons.find(n=>n.getCode()===i);if(!p||o.isZero())return;let g=this.lineItems.reduce((n,r)=>n.add(r.getIsTaxInclusive()?r.getTotal().taxInclusive.subtotal:r.getTotal().taxExclusive.subtotal),new a$3({amount:0,currency:this.currency})),m=this.lineItems.filter(n=>n.getState()!=="CANCELLED"&&!n.getTotal().taxExclusive.subtotal.isZero()).sort((n,r)=>{let d=n.getIsTaxInclusive()?n.getTotal().taxInclusive.subtotal:n.getTotal().taxExclusive.subtotal,h=r.getIsTaxInclusive()?r.getTotal().taxInclusive.subtotal:r.getTotal().taxExclusive.subtotal;return d.compareTo(h)}),u=new a$3({amount:0,currency:this.currency});m.forEach((n,r)=>{let d,h=n.getIsTaxInclusive()?n.getTotal().taxInclusive.subtotal:n.getTotal().taxExclusive.subtotal;r===m.length-1?d=o.subtract(u):d=o.multiply(h).divide(g).round(),u=u.add(d),a.get(n.getId())?.push({coupon:p,amount:d});});}),this.lineItems.forEach(i=>{i.updateDiscounts(a.get(i.getId()));});}applyDiscountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(o=>!o[1].isZero()),a=this.charges.filter(o=>o.getType()==="SHIPPING"),i=new Map;a.forEach(o=>i.set(o.getId(),[])),e.forEach(([o,p])=>{let g=this.coupons.find(r=>r.getCode()===o);if(!g||p.isZero())return;let m=a.reduce((r,d)=>r.add(d.getIsTaxInclusive()?d.getTotal().taxInclusive.chargeAmount:d.getTotal().taxExclusive.chargeAmount),new a$3({amount:0,currency:this.currency})),u=a.filter(r=>!r.getTotal().taxExclusive.chargeAmount.isZero()).sort((r,d)=>{let h=r.getIsTaxInclusive()?r.getTotal().taxInclusive.chargeAmount:r.getTotal().taxExclusive.chargeAmount,C=d.getIsTaxInclusive()?d.getTotal().taxInclusive.chargeAmount:d.getTotal().taxExclusive.chargeAmount;return h.compareTo(C)}),n=new a$3({amount:0,currency:this.currency});u.forEach((r,d)=>{let h,C=r.getIsTaxInclusive()?r.getTotal().taxInclusive.chargeAmount:r.getTotal().taxExclusive.chargeAmount;d===u.length-1?h=p.subtract(n):h=p.multiply(C).divide(m).round(),n=n.add(h),i.get(r.getId())?.push({coupon:g,amount:h});});}),a.forEach(o=>{o.updateDiscounts(i.get(o.getId()));});}getCouponEvaluationBases(){let t=new a$3({amount:0,currency:this.currency}),e=this.lineItems.filter(u=>u.getState()!=="CANCELLED"),a=this.charges.filter(u=>u.getType()==="SHIPPING"),i=e.some(u=>u.getIsTaxInclusive()),o=e.reduce((u,n)=>u.add(i?n.getTotal().taxInclusive.subtotal:n.getTotal().taxExclusive.subtotal),t),p=e.reduce((u,n)=>u.add(i?n.getTotal().taxInclusive.netSubtotal:n.getTotal().taxExclusive.netSubtotal),t),g=a.some(u=>u.getIsTaxInclusive()),m=a.reduce((u,n)=>u.add(g?n.getTotal().taxInclusive.chargeAmount:n.getTotal().taxExclusive.chargeAmount),t);return {targetSubtotal:o,targetShipping:m,targetNetSubtotal:p}}applyNonShippingCoupons(t){let e=t.filter(a=>a.getType()==="coupon");if(e.length===1){let a=this.getCouponEvaluationBases(),i=e[0].calculateApplicableCouponDiscount(a.targetSubtotal,a.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discountTotal=i,this.total.discountBreakdown[e[0].getCode()]=i);}}applyShippingCoupons(t){let e=this.getCouponEvaluationBases();if(e.targetShipping.getAmount()>0&&t.length>0){let a=e.targetNetSubtotal,i=t.reduce((p,g)=>{if(!p)return g;let m=g.calculateApplicableCouponDiscount(a,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(e.targetShipping),u=p.calculateApplicableCouponDiscount(a,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(e.targetShipping);return m.compareTo(u)===0?g.getType()==="coupon"?g:p:m.compareTo(u)>0?g:p}),o=i.calculateApplicableCouponDiscount(a,e.targetShipping,this.country,this.currency,this.#t.checkCouponExpiry).min(e.targetShipping);o.getAmount()>0&&(this.coupons.push(i),this.total.discountTotal=this.total.discountTotal.add(o),this.total.discountBreakdown[i.getCode()]=o);}}};export{R as a};//# sourceMappingURL=chunk-3LVBCEMO.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-3LVBCEMO.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Classes/ShoppingContainer.ts"],"names":["BaseShoppingContainerModel","BaseModel","#metaData","data","date","metaData","item","LineItemModel","charge","ChargeModel","AddressModel","coupon","CouponModel","Utils_default","PriceModel","key","value","breakdown","systemKey","systemValue","subKey","subValue","totals","zero","li","bases","discountTotal","discountBreakdown","nonShippingCouponTotal","couponValue","updatedBases","shippingCouponTotal","lineItemTaxTotal","additiveChargesTaxTotal","lineItemSubtotalExcl","netLineItemSubtotalExcl","lineItemSubtotalIncl","netLineItemSubtotalIncl","taxBreakdown","lineItemTaxBreakdown","additiveChargesTaxBreakdown","mergeTax","source","target","_","system","subSystem","taxAmount","t","additiveChargesExcl","netAdditiveChargesExcl","additiveChargesIncl","netAdditiveChargesIncl","shippingChargesExcl","netShippingChargesExcl","shippingChargesIncl","netShippingChargesIncl","adjustmentChargesIncl","taxTotal","grandTotal","shippingDetails","applicableCoupons","shippingCoupons","otherCoupons","couponTotal","couponDiscounts","couponDiscount","itemDiscounts","code","c","targetSubtotal","total","lineItem","validItems","a","b","aVal","bVal","distributed","index","amount","itemVal","shippingCharges","chargeDiscounts","targetShipping","validCharges","chargeVal","activeItems","isAnyItemInclusive","targetNetSubtotal","isAnyShippingInclusive","coupons","netLineItemSubtotal","maxValuedCoupon","maxCoupon","currentCoupon","currentCouponValue","maxCouponValue"],"mappings":"+RAmJA,IAA8BA,CAA9B,CAAA,cAAiEC,CAAU,CAC/D,GACA,UACA,CAAA,aAAA,CACA,WACA,CAAA,SAAA,CACA,QACA,eACA,CAAA,eAAA,CACA,cAGA,CAAA,OAAA,CAGA,MAEA,OACA,CAAA,QAAA,CACA,MACVC,CAAAA,EAAAA,CAQA,WAAYC,CAAAA,CAAAA,CAAuCC,GAAa,CAAA,IAAI,KAAQC,GAAsC,CAAA,CAAE,iBAAmB,CAAA,CAAA,CAAK,EAAG,CAC7I,KAAA,CAAMF,CAAMC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AAAA,CAC5E,CAAC,CAAA,CAEKjE,EAAcgE,CAAgB,CAAA,iCAAA,CAAkCD,CAAqBnE,CAAAA,CAAAA,CAAM,eAAgB,IAAK,CAAA,OAAA,CAAS,IAAK,CAAA,QAAA,CAAU,IAAKvB,CAAAA,EAAAA,CAAU,iBAAiB,CAAA,CAAE,IAAIuB,CAAM,CAAA,cAAc,CACpMI,CAAAA,CAAAA,CAAY,WAAc,CAAA,CAAA,GAC5B,IAAK,CAAA,OAAA,CAAQ,KAAKgE,CAAe,CAAA,CACjC,IAAK,CAAA,KAAA,CAAM,cAAgB,IAAK,CAAA,KAAA,CAAM,aAAc,CAAA,GAAA,CAAIhE,CAAW,CACnE,CAAA,IAAA,CAAK,KAAM,CAAA,iBAAA,CAAkBgE,EAAgB,OAAQ,EAAC,CAAIhE,CAAAA,CAAAA,EAE9D,CACF,CAEF","file":"chunk-LE4HS2A6.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport AddressModel, { AddressData } from \"./Address\";\r\nimport LineItemModel, { LineItemData, LineItemTaxBreakdown, LineItemTaxBreakdownModel } from \"./LineItem\";\r\nimport { CountryCode, CurrencyCode, LocaleCode, ShippingDetails } from \"./Common\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport CouponModel, { CouponCategory, CouponData, CouponType } from \"./Coupon\";\r\nimport Utils from \"../Utils\";\r\nimport { ChargeImpact, ChargeType, LineItemState, TaxSystem } from \"./Enum\";\r\nimport ChargeModel, { ChargeData, ChargeTaxBreakdownModel } from \"./Charge\";\r\n\r\n/**\r\n * Breakdown of a specific tax system (e.g., GST, VAT) for the entire container.\r\n * Groups taxes by system and then by specific rule/subsystem.\r\n */\r\nexport type TaxSystemBreakdown = {\r\n /** Name of the tax system (e.g., GST) */\r\n system: TaxSystem;\r\n /** Total tax amount collected for this system across all line items and charges */\r\n totalAmount: PriceData;\r\n /** Detailed breakdown by rule/subsystem to total tax amount (e.g., CGST, SGST) */\r\n subSystems: Record<string, PriceData>;\r\n};\r\n\r\n/**\r\n * Internal model for tax system breakdown using PriceModel instances.\r\n */\r\nexport type TaxSystemBreakdownModel = {\r\n system: TaxSystem;\r\n totalAmount: PriceModel;\r\n subSystems: Record<string, PriceModel>;\r\n};\r\n\r\nexport type ShoppingContainerTaxBreakdownModel = Record<string, TaxSystemBreakdownModel>;\r\n\r\n/**\r\n * Comprehensive totals for a shopping container, logically grouped by source.\r\n */\r\nexport type ShoppingContainerTotal = {\r\n // --- Item Totals ---\r\n /** Total tax collected specifically from line items */\r\n lineItemTaxTotal: PriceData;\r\n /** Granular tax breakdown for all line items */\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n // --- Charge Totals ---\r\n /** Tax reverse-calculated from additive charges only */\r\n additiveChargesTaxTotal: PriceData;\r\n /** Granular tax breakdown from additive charges */\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n /** Sum of post-discount netChargeAmount for subtractive charges – absolute amount to subtract */\r\n adjustmentCharges: PriceData;\r\n\r\n // --- Aggregate Totals ---\r\n /** Combined total tax (lineItemTaxTotal + chargeTaxTotal) */\r\n taxTotal: PriceData;\r\n /** Combined granular tax breakdown for the entire container */\r\n taxBreakdown: Record<string, TaxSystemBreakdown>;\r\n /** Sum of all coupon discounts applied to the container */\r\n discountTotal: PriceData;\r\n /** Map of applied coupon codes to their calculated discount amounts */\r\n discountBreakdown: Record<string, PriceData>;\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: PriceData;\r\n netLineItemSubtotal: PriceData;\r\n additiveCharges: PriceData;\r\n netAdditiveCharges: PriceData;\r\n shippingCharges: PriceData;\r\n netShippingCharges: PriceData;\r\n };\r\n taxInclusive: {\r\n lineItemSubtotal: PriceData;\r\n netLineItemSubtotal: PriceData;\r\n additiveCharges: PriceData;\r\n netAdditiveCharges: PriceData;\r\n shippingCharges: PriceData;\r\n netShippingCharges: PriceData;\r\n };\r\n grandTotal: PriceData;\r\n};\r\n\r\n\r\n/**\r\n * Internal model version of ShoppingContainerTotal using PriceModel instances.\r\n */\r\nexport type ShoppingContainerTotalModel = {\r\n lineItemTaxTotal: PriceModel;\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n additiveChargesTaxTotal: PriceModel;\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n adjustmentCharges: PriceModel;\r\n\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: PriceModel;\r\n netLineItemSubtotal: PriceModel;\r\n additiveCharges: PriceModel;\r\n netAdditiveCharges: PriceModel;\r\n shippingCharges: PriceModel;\r\n netShippingCharges: PriceModel;\r\n };\r\n taxInclusive: {\r\n lineItemSubtotal: PriceModel;\r\n netLineItemSubtotal: PriceModel;\r\n additiveCharges: PriceModel;\r\n netAdditiveCharges: PriceModel;\r\n shippingCharges: PriceModel;\r\n netShippingCharges: PriceModel;\r\n };\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type ShoppingContainerMetaData = {\r\n checkCouponExpiry: boolean\r\n}\r\n\r\nexport type BaseShoppingContainerAttributes = BaseAttributes & {\r\n id: string;\r\n customerId?: string;\r\n customerEmail?: string;\r\n anonymousId?: string;\r\n lineItems: LineItemData[];\r\n charges: ChargeData[];\r\n shippingDetails: ShippingDetails | null;\r\n shippingAddress?: AddressData | null;\r\n billingAddress?: AddressData | null;\r\n coupons: CouponData[];\r\n total: ShoppingContainerTotal;\r\n country: CountryCode;\r\n currency: CurrencyCode;\r\n locale: LocaleCode;\r\n};\r\n\r\nexport type BaseShoppingContainerData = BaseShoppingContainerAttributes & BaseData\r\n\r\n\r\n/**\r\n * Abstract base class for shopping-related containers like carts and orders.\r\n * Manages common elements such as line items, addresses, coupons, and totals.\r\n */\r\nexport default abstract class BaseShoppingContainerModel extends BaseModel {\r\n protected id: string;\r\n protected customerId?: string;\r\n protected customerEmail?: string;\r\n protected anonymousId?: string;\r\n protected lineItems: LineItemModel[];\r\n protected charges: ChargeModel[];\r\n protected shippingDetails: ShippingDetails | null;\r\n protected shippingAddress: AddressModel | null;\r\n protected billingAddress: AddressModel | null;\r\n\r\n // CouponsCodes\r\n protected coupons: CouponModel[];\r\n\r\n // Cart Totals\r\n protected total: ShoppingContainerTotalModel;\r\n\r\n protected country: CountryCode;\r\n protected currency: CurrencyCode;\r\n protected locale: LocaleCode;\r\n #metaData: ShoppingContainerMetaData;\r\n\r\n /**\r\n * Creates an instance of BaseShoppingContainerModel.\r\n * Initializes common properties and calculates initial base totals.\r\n * @param data - The initial attributes for the shopping container.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: BaseShoppingContainerAttributes, date: Date = new Date(), metaData: ShoppingContainerMetaData = { checkCouponExpiry: true }) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.customerId = data.customerId;\r\n this.customerEmail = data.customerEmail;\r\n this.anonymousId = data.anonymousId;\r\n this.country = data.country;\r\n this.currency = data.currency;\r\n this.locale = data.locale;\r\n this.lineItems = (data.lineItems ?? []).map(item => new LineItemModel(item));\r\n this.charges = (data.charges ?? []).map(charge => new ChargeModel(charge));\r\n this.billingAddress = data.billingAddress ? new AddressModel(data.billingAddress, date) : null;\r\n this.shippingAddress = data.shippingAddress ? new AddressModel(data.shippingAddress, date) : null;\r\n this.coupons = (data.coupons ?? []).map(coupon => new CouponModel(coupon));\r\n\r\n this.shippingDetails = data.shippingDetails ? Utils.deepClone(data.shippingDetails) : null;\r\n\r\n this.total = {\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown),\r\n\r\n additiveChargesTaxTotal: new PriceModel(data.total.additiveChargesTaxTotal),\r\n additiveChargesTaxBreakdown: this.mapTaxBreakdown(data.total.additiveChargesTaxBreakdown),\r\n adjustmentCharges: new PriceModel(data.total.adjustmentCharges),\r\n\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: new PriceModel(data.total.taxExclusive.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.taxExclusive.netLineItemSubtotal),\r\n additiveCharges: new PriceModel(data.total.taxExclusive.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.taxExclusive.netAdditiveCharges),\r\n shippingCharges: new PriceModel(data.total.taxExclusive.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.taxExclusive.netShippingCharges),\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: new PriceModel(data.total.taxInclusive.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.taxInclusive.netLineItemSubtotal),\r\n additiveCharges: new PriceModel(data.total.taxInclusive.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.taxInclusive.netAdditiveCharges),\r\n shippingCharges: new PriceModel(data.total.taxInclusive.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.taxInclusive.netShippingCharges),\r\n },\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n };\r\n\r\n this.#metaData = {\r\n checkCouponExpiry: metaData.checkCouponExpiry\r\n }\r\n }\r\n\r\n private mapTaxBreakdown(breakdown: Record<string, TaxSystemBreakdown>): Record<string, TaxSystemBreakdownModel> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: new PriceModel(systemValue.totalAmount),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n new PriceModel(subValue)\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n private serializeTaxBreakdown(breakdown: Record<string, TaxSystemBreakdownModel>): Record<string, TaxSystemBreakdown> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount.getDetails(),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n subValue.getDetails()\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for this shopping container (cart ID or order ID).\r\n * @returns The ID string.\r\n */\r\n public getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the customer ID associated with this container, if available.\r\n * @returns The customer ID string, or undefined.\r\n */\r\n public getCustomerId(): string | undefined {\r\n return this.customerId;\r\n }\r\n\r\n /**\r\n * Gets the customer email associated with this container, if available.\r\n * @returns The customer email string, or undefined.\r\n */\r\n public getCustomerEmail(): string | undefined {\r\n return this.customerEmail;\r\n }\r\n\r\n /**\r\n * Gets the anonymous user ID associated with this container, if available.\r\n * @returns The anonymous ID string, or undefined.\r\n */\r\n public getAnonymousId(): string | undefined {\r\n return this.anonymousId;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the line items in the container.\r\n * Each item is a new LineItemModel instance created from the original's details.\r\n * @returns An array of LineItemModel instances.\r\n */\r\n public getLineItems(): LineItemModel[] {\r\n // Return new instances to prevent modification of internal state\r\n return this.lineItems.map(item => new LineItemModel(item.getDetails()));\r\n }\r\n\r\n /**\r\n * Gets current number of line items in the container.\r\n * @returns The count of line items.\r\n */\r\n public getLineItemsCount(): number {\r\n return this.lineItems.length;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the charges in the container.\r\n * @returns An array of ChargeModel instances.\r\n */\r\n public getCharges(): ChargeModel[] {\r\n return this.charges.map(charge => new ChargeModel(charge.getDetails()));\r\n }\r\n\r\n /**\r\n * Adds a new charge to the container and recalculates totals.\r\n * @param charge - The charge to add.\r\n */\r\n public addCharge(charge: ChargeModel): void {\r\n this.charges.push(charge);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Clears all charges from the container and recalculates totals.\r\n */\r\n public clearCharges(): void {\r\n this.charges = [];\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Gets a copy of the shipping details associated with the container.\r\n * @returns A ShippingDetails object, or null if none are set.\r\n */\r\n public getShippingDetails(): ShippingDetails | null {\r\n return this.shippingDetails ? Utils.deepClone(this.shippingDetails) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the shipping address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no shipping address is set.\r\n */\r\n public getShippingAddress(): AddressModel | null {\r\n return this.shippingAddress ? new AddressModel(this.shippingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Checks if a shipping address is associated with this container.\r\n * @returns True if a shipping address is set, false otherwise.\r\n */\r\n public hasShippingAddress(): boolean {\r\n return !!this.shippingAddress;\r\n }\r\n\r\n /**\r\n * Checks if a billing address is associated with this container.\r\n * @returns True if a billing address is set, false otherwise.\r\n */\r\n public hasBillingAddress(): boolean {\r\n return !!this.billingAddress;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the billing address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no billing address is set.\r\n */\r\n public getBillingAddress(): AddressModel | null {\r\n return this.billingAddress ? new AddressModel(this.billingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the coupons applied to the container.\r\n * Each item is a new CouponModel instance created from the original's details.\r\n * @returns An array of CouponModel instances.\r\n */\r\n public getCoupons(): CouponModel[] {\r\n return [...this.coupons];\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this container.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the currency code associated with this container.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n /**\r\n * Gets the locale code associated with this container.\r\n * @returns The LocaleCode enum value.\r\n */\r\n public getLocale(): LocaleCode {\r\n return this.locale;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the calculated totals for the container.\r\n * @returns An object containing shipping, subtotal, coupon, and grand totals.\r\n */\r\n public getTotal() {\r\n return {\r\n lineItemTaxTotal: this.total.lineItemTaxTotal,\r\n lineItemTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.lineItemTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n additiveChargesTaxTotal: this.total.additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.additiveChargesTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n adjustmentCharges: this.total.adjustmentCharges,\r\n discountBreakdown: { ...this.total.discountBreakdown },\r\n discountTotal: this.total.discountTotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n taxExclusive: {\r\n lineItemSubtotal: this.total.taxExclusive.lineItemSubtotal,\r\n netLineItemSubtotal: this.total.taxExclusive.netLineItemSubtotal,\r\n additiveCharges: this.total.taxExclusive.additiveCharges,\r\n netAdditiveCharges: this.total.taxExclusive.netAdditiveCharges,\r\n shippingCharges: this.total.taxExclusive.shippingCharges,\r\n netShippingCharges: this.total.taxExclusive.netShippingCharges,\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: this.total.taxInclusive.lineItemSubtotal,\r\n netLineItemSubtotal: this.total.taxInclusive.netLineItemSubtotal,\r\n additiveCharges: this.total.taxInclusive.additiveCharges,\r\n netAdditiveCharges: this.total.taxInclusive.netAdditiveCharges,\r\n shippingCharges: this.total.taxInclusive.shippingCharges,\r\n netShippingCharges: this.total.taxInclusive.netShippingCharges,\r\n },\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the shopping container's current state.\r\n * Includes details from the base model and specific container properties.\r\n * @returns BaseShoppingContainerData object suitable for serialization or API responses.\r\n */\r\n getDetails(): BaseShoppingContainerData {\r\n const totals = this.getTotal();\r\n return {\r\n ...super.getDetails(),\r\n id: this.getId(),\r\n customerId: this.getCustomerId(),\r\n customerEmail: this.getCustomerEmail(),\r\n anonymousId: this.getAnonymousId(),\r\n lineItems: this.getLineItems().map(item => item.getDetails()),\r\n charges: this.getCharges().map(charge => charge.getDetails()),\r\n shippingDetails: this.getShippingDetails(),\r\n shippingAddress: this.getShippingAddress()?.getDetails() || null,\r\n billingAddress: this.getBillingAddress()?.getDetails() || null,\r\n coupons: this.getCoupons().map(coupon => coupon.getDetails()),\r\n total: {\r\n // Item Totals\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n additiveChargesTaxTotal: totals.additiveChargesTaxTotal.getDetails(),\r\n additiveChargesTaxBreakdown: this.serializeTaxBreakdown(totals.additiveChargesTaxBreakdown),\r\n\r\n adjustmentCharges: totals.adjustmentCharges.getDetails(),\r\n\r\n // Aggregate Totals\r\n discountTotal: totals.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(totals.discountBreakdown).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: totals.taxExclusive.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.taxExclusive.netLineItemSubtotal.getDetails(),\r\n additiveCharges: totals.taxExclusive.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.taxExclusive.netAdditiveCharges.getDetails(),\r\n shippingCharges: totals.taxExclusive.shippingCharges.getDetails(),\r\n netShippingCharges: totals.taxExclusive.netShippingCharges.getDetails(),\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: totals.taxInclusive.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.taxInclusive.netLineItemSubtotal.getDetails(),\r\n additiveCharges: totals.taxInclusive.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.taxInclusive.netAdditiveCharges.getDetails(),\r\n shippingCharges: totals.taxInclusive.shippingCharges.getDetails(),\r\n netShippingCharges: totals.taxInclusive.netShippingCharges.getDetails(),\r\n },\r\n grandTotal: totals.grandTotal.getDetails(),\r\n },\r\n country: this.getCountry(),\r\n currency: this.getCurrency(),\r\n locale: this.getLocale(),\r\n };\r\n }\r\n\r\n /**\r\n * Recalculates the total costs for the shopping container.\r\n * This orchestrates computing base totals, applying active coupons, and aggregating the final net results.\r\n */\r\n public calculateTotals(): void {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n // Step 1: Initialize baseline totals for all active items and charges.\r\n // We clear any existing discounts so we can evaluate base subtotals accurately.\r\n this.lineItems.forEach(li => {\r\n if (li.getState() !== LineItemState.CANCELLED) li.updateDiscounts([]);\r\n });\r\n this.charges.forEach(charge => charge.updateDiscounts([]));\r\n\r\n // Step 2: Evaluate Non-Shipping Coupons on gross subtotals\r\n const bases = this.getCouponEvaluationBases();\r\n let discountTotal = zero;\r\n let discountBreakdown: Record<string, PriceModel> = {};\r\n let nonShippingCouponTotal: Record<string, PriceModel> = {};\r\n\r\n const nonShippingCoupons = this.coupons.filter(c => c.getCategory() !== CouponCategory.SHIPPING);\r\n nonShippingCoupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(bases.targetSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry);\r\n discountTotal = discountTotal.add(couponValue);\r\n discountBreakdown[coupon.getCode()] = couponValue;\r\n nonShippingCouponTotal[coupon.getCode()] = couponValue;\r\n });\r\n\r\n // Step 3: Distribute Non-Shipping Coupons\r\n // This internally recalculates the net subtotals and taxes for line items.\r\n this.applyDiscountsInLineItem(nonShippingCouponTotal);\r\n\r\n // Step 4: Evaluate Shipping Coupons using dynamically updated Net Subtotals\r\n const updatedBases = this.getCouponEvaluationBases();\r\n let shippingCouponTotal: Record<string, PriceModel> = {};\r\n \r\n const shippingCoupons = this.coupons.filter(c => c.getCategory() === CouponCategory.SHIPPING);\r\n shippingCoupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(updatedBases.targetNetSubtotal, updatedBases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(updatedBases.targetShipping);\r\n discountTotal = discountTotal.add(couponValue);\r\n discountBreakdown[coupon.getCode()] = couponValue;\r\n shippingCouponTotal[coupon.getCode()] = couponValue;\r\n });\r\n\r\n // Step 5: Distribute Shipping Coupons\r\n this.applyDiscountsInShippingCharges(shippingCouponTotal);\r\n\r\n // Step 6: Aggregate everything into `this.total`\r\n let lineItemTaxTotal = zero;\r\n let additiveChargesTaxTotal = zero;\r\n\r\n let lineItemSubtotalExcl = zero;\r\n let netLineItemSubtotalExcl = zero;\r\n let lineItemSubtotalIncl = zero;\r\n let netLineItemSubtotalIncl = zero;\r\n\r\n const taxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const lineItemTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const additiveChargesTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n\r\n const mergeTax = (source: Record<string, LineItemTaxBreakdownModel | ChargeTaxBreakdownModel>, target: ShoppingContainerTaxBreakdownModel) => {\r\n Object.entries(source).forEach(([_, breakdown]) => {\r\n const { system, subSystem, taxAmount } = breakdown;\r\n if (!target[system]) target[system] = { system, totalAmount: zero, subSystems: {} };\r\n if (!target[system].subSystems[subSystem]) target[system].subSystems[subSystem] = taxAmount;\r\n else target[system].subSystems[subSystem] = target[system].subSystems[subSystem].add(taxAmount);\r\n target[system].totalAmount = target[system].totalAmount.add(taxAmount);\r\n });\r\n };\r\n\r\n const filteredLineItems = this.lineItems.filter(li => li.getState() !== LineItemState.CANCELLED);\r\n filteredLineItems.forEach(li => {\r\n const t = li.getTotal();\r\n lineItemSubtotalExcl = lineItemSubtotalExcl.add(t.taxExclusive.subtotal);\r\n netLineItemSubtotalExcl = netLineItemSubtotalExcl.add(t.taxExclusive.netSubtotal);\r\n lineItemSubtotalIncl = lineItemSubtotalIncl.add(t.taxInclusive.subtotal);\r\n netLineItemSubtotalIncl = netLineItemSubtotalIncl.add(t.taxInclusive.netSubtotal);\r\n\r\n if (t.taxBreakdown) {\r\n mergeTax(t.taxBreakdown, lineItemTaxBreakdown);\r\n mergeTax(t.taxBreakdown, taxBreakdown);\r\n lineItemTaxTotal = lineItemTaxTotal.add(t.taxTotal);\r\n }\r\n });\r\n\r\n let additiveChargesExcl = zero;\r\n let netAdditiveChargesExcl = zero;\r\n let additiveChargesIncl = zero;\r\n let netAdditiveChargesIncl = zero;\r\n\r\n let shippingChargesExcl = zero;\r\n let netShippingChargesExcl = zero;\r\n let shippingChargesIncl = zero;\r\n let netShippingChargesIncl = zero;\r\n\r\n let adjustmentChargesIncl = zero;\r\n\r\n this.charges.forEach(charge => {\r\n const t = charge.getTotal();\r\n if (charge.getImpact() === ChargeImpact.ADD) {\r\n additiveChargesExcl = additiveChargesExcl.add(t.taxExclusive.chargeAmount);\r\n netAdditiveChargesExcl = netAdditiveChargesExcl.add(t.taxExclusive.netChargeAmount);\r\n additiveChargesIncl = additiveChargesIncl.add(t.taxInclusive.chargeAmount);\r\n netAdditiveChargesIncl = netAdditiveChargesIncl.add(t.grandTotal);\r\n\r\n if (charge.getType() === ChargeType.SHIPPING) {\r\n shippingChargesExcl = shippingChargesExcl.add(t.taxExclusive.chargeAmount);\r\n netShippingChargesExcl = netShippingChargesExcl.add(t.taxExclusive.netChargeAmount);\r\n shippingChargesIncl = shippingChargesIncl.add(t.taxInclusive.chargeAmount);\r\n netShippingChargesIncl = netShippingChargesIncl.add(t.grandTotal);\r\n }\r\n\r\n if (t.taxBreakdown) {\r\n mergeTax(t.taxBreakdown, additiveChargesTaxBreakdown);\r\n mergeTax(t.taxBreakdown, taxBreakdown);\r\n additiveChargesTaxTotal = additiveChargesTaxTotal.add(t.taxTotal);\r\n }\r\n } else if (charge.getImpact() === ChargeImpact.SUBTRACT) {\r\n adjustmentChargesIncl = adjustmentChargesIncl.add(t.grandTotal);\r\n }\r\n });\r\n\r\n const taxTotal = lineItemTaxTotal.add(additiveChargesTaxTotal);\r\n const grandTotal = netLineItemSubtotalIncl.add(netAdditiveChargesIncl).subtract(adjustmentChargesIncl);\r\n\r\n this.total = {\r\n lineItemTaxTotal,\r\n lineItemTaxBreakdown,\r\n additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown,\r\n adjustmentCharges: adjustmentChargesIncl,\r\n discountTotal,\r\n discountBreakdown,\r\n taxTotal,\r\n taxBreakdown,\r\n taxExclusive: {\r\n lineItemSubtotal: lineItemSubtotalExcl,\r\n netLineItemSubtotal: netLineItemSubtotalExcl,\r\n additiveCharges: additiveChargesExcl,\r\n netAdditiveCharges: netAdditiveChargesExcl,\r\n shippingCharges: shippingChargesExcl,\r\n netShippingCharges: netShippingChargesExcl,\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: lineItemSubtotalIncl,\r\n netLineItemSubtotal: netLineItemSubtotalIncl,\r\n additiveCharges: additiveChargesIncl,\r\n netAdditiveCharges: netAdditiveChargesIncl,\r\n shippingCharges: shippingChargesIncl,\r\n netShippingCharges: netShippingChargesIncl,\r\n },\r\n grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Updates the shipping details and recalculates the totals.\r\n * @param shippingDetails - The new shipping details to apply.\r\n */\r\n public updateShippingDetails(shippingDetails: ShippingDetails): void {\r\n this.shippingDetails = shippingDetails;\r\n }\r\n\r\n /**\r\n * Applies a list of coupons to the shopping container.\r\n * Filters out invalid coupons, separates shipping and non-shipping coupons,\r\n * and distributes discounts to line items.\r\n * @param applicableCoupons - The list of coupons to attempt to apply.\r\n */\r\n public applyCoupons(applicableCoupons: CouponModel[]): void {\r\n //Apply coupons\r\n const shippingCoupons = applicableCoupons.filter(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n const otherCoupons = applicableCoupons.filter(coupon => coupon.getCategory() !== CouponCategory.SHIPPING);\r\n\r\n this.coupons = [];\r\n this.total.discountTotal = this.total.discountTotal.zero();\r\n this.total.discountBreakdown = {};\r\n // Apply non shipping coupons\r\n otherCoupons.length && this.applyNonShippingCoupons(otherCoupons);\r\n this.applyDiscountsInLineItem(this.total.discountBreakdown);\r\n\r\n // Apply shipping coupons\r\n shippingCoupons.length && this.applyShippingCoupons(shippingCoupons);\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Distributes the total discount amount among the line items.\r\n * @param couponTotal - A record of coupon codes and their calculated discount amounts.\r\n */\r\n private applyDiscountsInLineItem(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n\r\n const itemDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n this.lineItems.forEach(li => itemDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const targetSubtotal = this.lineItems.reduce(\r\n (total, lineItem) => total.add(lineItem.getIsTaxInclusive() ? lineItem.getTotal().taxInclusive.subtotal : lineItem.getTotal().taxExclusive.subtotal),\r\n new PriceModel({ amount: 0, currency: this.currency })\r\n );\r\n\r\n const validItems = this.lineItems\r\n .filter(li => li.getState() !== LineItemState.CANCELLED && !li.getTotal().taxExclusive.subtotal.isZero())\r\n .sort((a, b) => {\r\n const aVal = a.getIsTaxInclusive() ? a.getTotal().taxInclusive.subtotal : a.getTotal().taxExclusive.subtotal;\r\n const bVal = b.getIsTaxInclusive() ? b.getTotal().taxInclusive.subtotal : b.getTotal().taxExclusive.subtotal;\r\n return aVal.compareTo(bVal);\r\n });\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validItems.forEach((item, index) => {\r\n let amount: PriceModel;\r\n const itemVal = item.getIsTaxInclusive() ? item.getTotal().taxInclusive.subtotal : item.getTotal().taxExclusive.subtotal;\r\n if (index === validItems.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(itemVal).divide(targetSubtotal).round();\r\n }\r\n distributed = distributed.add(amount);\r\n itemDiscounts.get(item.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n this.lineItems.forEach(lineItem => {\r\n lineItem.updateDiscounts(itemDiscounts.get(lineItem.getId())!);\r\n });\r\n }\r\n\r\n private applyDiscountsInShippingCharges(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n const shippingCharges = this.charges.filter(charge => charge.getType() === ChargeType.SHIPPING);\r\n\r\n const chargeDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n shippingCharges.forEach(li => chargeDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const targetShipping = shippingCharges.reduce(\r\n (total, charge) => total.add(charge.getIsTaxInclusive() ? charge.getTotal().taxInclusive.chargeAmount : charge.getTotal().taxExclusive.chargeAmount),\r\n new PriceModel({ amount: 0, currency: this.currency })\r\n );\r\n\r\n const validCharges = shippingCharges\r\n .filter(charge => !charge.getTotal().taxExclusive.chargeAmount.isZero())\r\n .sort((a, b) => {\r\n const aVal = a.getIsTaxInclusive() ? a.getTotal().taxInclusive.chargeAmount : a.getTotal().taxExclusive.chargeAmount;\r\n const bVal = b.getIsTaxInclusive() ? b.getTotal().taxInclusive.chargeAmount : b.getTotal().taxExclusive.chargeAmount;\r\n return aVal.compareTo(bVal);\r\n });\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validCharges.forEach((charge, index) => {\r\n let amount: PriceModel;\r\n const chargeVal = charge.getIsTaxInclusive() ? charge.getTotal().taxInclusive.chargeAmount : charge.getTotal().taxExclusive.chargeAmount;\r\n if (index === validCharges.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(chargeVal).divide(targetShipping).round();\r\n }\r\n distributed = distributed.add(amount);\r\n chargeDiscounts.get(charge.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n shippingCharges.forEach(charge => {\r\n charge.updateDiscounts(chargeDiscounts.get(charge.getId())!);\r\n });\r\n }\r\n\r\n /**\r\n * Helper to resolve the correct evaluation basis for line items and shipping charges.\r\n * If any item in a group is tax-inclusive, the inclusive total is used for the entire group.\r\n * Otherwise, the exclusive total is used.\r\n */\r\n private getCouponEvaluationBases() {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n const activeItems = this.lineItems.filter(li => li.getState() !== LineItemState.CANCELLED);\r\n const shippingCharges = this.charges.filter(charge => charge.getType() === ChargeType.SHIPPING);\r\n\r\n const isAnyItemInclusive = activeItems.some(li => li.getIsTaxInclusive());\r\n const targetSubtotal = activeItems.reduce(\r\n (total, li) => total.add(isAnyItemInclusive ? li.getTotal().taxInclusive.subtotal : li.getTotal().taxExclusive.subtotal),\r\n zero\r\n );\r\n\r\n const targetNetSubtotal = activeItems.reduce(\r\n (total, li) => total.add(isAnyItemInclusive ? li.getTotal().taxInclusive.netSubtotal : li.getTotal().taxExclusive.netSubtotal),\r\n zero\r\n );\r\n\r\n const isAnyShippingInclusive = shippingCharges.some(c => c.getIsTaxInclusive());\r\n const targetShipping = shippingCharges.reduce(\r\n (total, c) => total.add(isAnyShippingInclusive ? c.getTotal().taxInclusive.chargeAmount : c.getTotal().taxExclusive.chargeAmount),\r\n zero\r\n );\r\n\r\n return { targetSubtotal, targetShipping, targetNetSubtotal };\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable non-shipping coupon.\r\n * Currently supports applying only a single coupon of type COUPON.\r\n * @param applicableCoupons - List of available non-shipping coupons.\r\n */\r\n private applyNonShippingCoupons(applicableCoupons: CouponModel[]) {\r\n const coupons = applicableCoupons.filter(coupon => coupon.getType() === CouponType.COUPON);\r\n if (coupons.length === 1) {\r\n const bases = this.getCouponEvaluationBases();\r\n const couponValue = coupons[0].calculateApplicableCouponDiscount(bases.targetSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(coupons[0]);\r\n this.total.discountTotal = couponValue;\r\n this.total.discountBreakdown[coupons[0].getCode()] = couponValue;\r\n }\r\n }\r\n // Todo: Add support to other type in future like promotion\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable shipping coupon.\r\n * @param applicableCoupons - List of available shipping coupons.\r\n */\r\n private applyShippingCoupons(applicableCoupons: CouponModel[]) {\r\n const bases = this.getCouponEvaluationBases();\r\n if (bases.targetShipping.getAmount() > 0 && applicableCoupons.length > 0) {\r\n const netLineItemSubtotal = bases.targetNetSubtotal;\r\n\r\n const maxValuedCoupon = applicableCoupons.reduce((maxCoupon, currentCoupon) => {\r\n if (!maxCoupon) return currentCoupon;\r\n\r\n const currentCouponValue = currentCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(bases.targetShipping);\r\n const maxCouponValue = maxCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(bases.targetShipping);\r\n\r\n if (currentCouponValue.compareTo(maxCouponValue) === 0) {\r\n return currentCoupon.getType() === CouponType.COUPON ? currentCoupon : maxCoupon;\r\n }\r\n return currentCouponValue.compareTo(maxCouponValue) > 0 ? currentCoupon : maxCoupon;\r\n });\r\n\r\n const couponValue = maxValuedCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(bases.targetShipping);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(maxValuedCoupon);\r\n this.total.discountTotal = this.total.discountTotal.add(couponValue);\r\n this.total.discountBreakdown[maxValuedCoupon.getCode()] = couponValue;\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\n\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/Classes/ShoppingContainer.ts"],"names":["BaseShoppingContainerModel","BaseModel","#metaData","data","date","metaData","item","LineItemModel","charge","ChargeModel","AddressModel","coupon","CouponModel","Utils_default","PriceModel","key","value","breakdown","systemKey","systemValue","subKey","subValue","totals","zero","li","bases","discountTotal","discountBreakdown","nonShippingCouponTotal","couponValue","updatedBases","shippingCouponTotal","lineItemTaxTotal","additiveChargesTaxTotal","lineItemSubtotalExcl","netLineItemSubtotalExcl","lineItemSubtotalIncl","netLineItemSubtotalIncl","taxBreakdown","lineItemTaxBreakdown","additiveChargesTaxBreakdown","mergeTax","source","target","_","system","subSystem","taxAmount","t","additiveChargesExcl","netAdditiveChargesExcl","additiveChargesIncl","netAdditiveChargesIncl","shippingChargesExcl","netShippingChargesExcl","shippingChargesIncl","netShippingChargesIncl","adjustmentChargesIncl","taxTotal","grandTotal","shippingDetails","applicableCoupons","shippingCoupons","otherCoupons","couponTotal","couponDiscounts","couponDiscount","itemDiscounts","code","c","targetSubtotal","total","lineItem","validItems","a","b","aVal","bVal","distributed","index","amount","itemVal","shippingCharges","chargeDiscounts","targetShipping","validCharges","chargeVal","activeItems","isAnyItemInclusive","targetNetSubtotal","isAnyShippingInclusive","coupons","netLineItemSubtotal","maxValuedCoupon","maxCoupon","currentCoupon","currentCouponValue","maxCouponValue"],"mappings":"+RAmJA,IAA8BA,CAA9B,CAAA,cAAiEC,CAAU,CAC/D,GACA,UACA,CAAA,aAAA,CACA,WACA,CAAA,SAAA,CACA,QACA,eACA,CAAA,eAAA,CACA,cAGA,CAAA,OAAA,CAGA,MAEA,OACA,CAAA,QAAA,CACA,MACVC,CAAAA,EAAAA,CAQA,WAAYC,CAAAA,CAAAA,CAAuCC,GAAa,CAAA,IAAI,KAAQC,GAAsC,CAAA,CAAE,iBAAmB,CAAA,CAAA,CAAK,EAAG,CAC7I,KAAA,CAAMF,CAAMC,CAAAA,GAAI,EAChB,IAAK,CAAA,EAAA,CAAKD,CAAK,CAAA,EAAA,CACf,IAAK,CAAA,UAAA,CAAaA,CAAK,CAAA,UAAA,CACvB,KAAK,aAAgBA,CAAAA,CAAAA,CAAK,aAC1B,CAAA,IAAA,CAAK,YAAcA,CAAK,CAAA,WAAA,CACxB,IAAK,CAAA,OAAA,CAAUA,EAAK,OACpB,CAAA,IAAA,CAAK,QAAWA,CAAAA,CAAAA,CAAK,SACrB,IAAK,CAAA,MAAA,CAASA,CAAK,CAAA,MAAA,CACnB,KAAK,SAAaA,CAAAA,CAAAA,CAAAA,CAAK,SAAa,EAAA,IAAI,GAAIG,CAAAA,CAAAA,EAAQ,IAAIC,CAAAA,CAAcD,CAAI,CAAC,CAAA,CAC3E,IAAK,CAAA,OAAA,CAAA,CAAWH,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,CAAAA,EAE9D,CACF,CAEF","file":"chunk-3LVBCEMO.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport AddressModel, { AddressData } from \"./Address\";\r\nimport LineItemModel, { LineItemData, LineItemTaxBreakdown, LineItemTaxBreakdownModel } from \"./LineItem\";\r\nimport { CountryCode, CurrencyCode, LocaleCode, ShippingDetails } from \"./Common\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport CouponModel, { CouponCategory, CouponData, CouponType } from \"./Coupon\";\r\nimport Utils from \"../Utils\";\r\nimport { ChargeImpact, ChargeType, LineItemState, TaxSystem } from \"./Enum\";\r\nimport ChargeModel, { ChargeData, ChargeTaxBreakdownModel } from \"./Charge\";\r\n\r\n/**\r\n * Breakdown of a specific tax system (e.g., GST, VAT) for the entire container.\r\n * Groups taxes by system and then by specific rule/subsystem.\r\n */\r\nexport type TaxSystemBreakdown = {\r\n /** Name of the tax system (e.g., GST) */\r\n system: TaxSystem;\r\n /** Total tax amount collected for this system across all line items and charges */\r\n totalAmount: PriceData;\r\n /** Detailed breakdown by rule/subsystem to total tax amount (e.g., CGST, SGST) */\r\n subSystems: Record<string, PriceData>;\r\n};\r\n\r\n/**\r\n * Internal model for tax system breakdown using PriceModel instances.\r\n */\r\nexport type TaxSystemBreakdownModel = {\r\n system: TaxSystem;\r\n totalAmount: PriceModel;\r\n subSystems: Record<string, PriceModel>;\r\n};\r\n\r\nexport type ShoppingContainerTaxBreakdownModel = Record<string, TaxSystemBreakdownModel>;\r\n\r\n/**\r\n * Comprehensive totals for a shopping container, logically grouped by source.\r\n */\r\nexport type ShoppingContainerTotal = {\r\n // --- Item Totals ---\r\n /** Total tax collected specifically from line items */\r\n lineItemTaxTotal: PriceData;\r\n /** Granular tax breakdown for all line items */\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n // --- Charge Totals ---\r\n /** Tax reverse-calculated from additive charges only */\r\n additiveChargesTaxTotal: PriceData;\r\n /** Granular tax breakdown from additive charges */\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdown>;\r\n\r\n /** Sum of post-discount netChargeAmount for subtractive charges – absolute amount to subtract */\r\n adjustmentCharges: PriceData;\r\n\r\n // --- Aggregate Totals ---\r\n /** Combined total tax (lineItemTaxTotal + chargeTaxTotal) */\r\n taxTotal: PriceData;\r\n /** Combined granular tax breakdown for the entire container */\r\n taxBreakdown: Record<string, TaxSystemBreakdown>;\r\n /** Sum of all coupon discounts applied to the container */\r\n discountTotal: PriceData;\r\n /** Map of applied coupon codes to their calculated discount amounts */\r\n discountBreakdown: Record<string, PriceData>;\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: PriceData;\r\n netLineItemSubtotal: PriceData;\r\n additiveCharges: PriceData;\r\n netAdditiveCharges: PriceData;\r\n shippingCharges: PriceData;\r\n netShippingCharges: PriceData;\r\n };\r\n taxInclusive: {\r\n lineItemSubtotal: PriceData;\r\n netLineItemSubtotal: PriceData;\r\n additiveCharges: PriceData;\r\n netAdditiveCharges: PriceData;\r\n shippingCharges: PriceData;\r\n netShippingCharges: PriceData;\r\n };\r\n grandTotal: PriceData;\r\n};\r\n\r\n\r\n/**\r\n * Internal model version of ShoppingContainerTotal using PriceModel instances.\r\n */\r\nexport type ShoppingContainerTotalModel = {\r\n lineItemTaxTotal: PriceModel;\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n additiveChargesTaxTotal: PriceModel;\r\n additiveChargesTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n adjustmentCharges: PriceModel;\r\n\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: PriceModel;\r\n netLineItemSubtotal: PriceModel;\r\n additiveCharges: PriceModel;\r\n netAdditiveCharges: PriceModel;\r\n shippingCharges: PriceModel;\r\n netShippingCharges: PriceModel;\r\n };\r\n taxInclusive: {\r\n lineItemSubtotal: PriceModel;\r\n netLineItemSubtotal: PriceModel;\r\n additiveCharges: PriceModel;\r\n netAdditiveCharges: PriceModel;\r\n shippingCharges: PriceModel;\r\n netShippingCharges: PriceModel;\r\n };\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type ShoppingContainerMetaData = {\r\n checkCouponExpiry: boolean\r\n}\r\n\r\nexport type BaseShoppingContainerAttributes = BaseAttributes & {\r\n id: string;\r\n customerId?: string;\r\n customerEmail?: string;\r\n anonymousId?: string;\r\n lineItems: LineItemData[];\r\n charges: ChargeData[];\r\n shippingDetails: ShippingDetails | null;\r\n shippingAddress?: AddressData | null;\r\n billingAddress?: AddressData | null;\r\n coupons: CouponData[];\r\n total: ShoppingContainerTotal;\r\n country: CountryCode;\r\n currency: CurrencyCode;\r\n locale: LocaleCode;\r\n};\r\n\r\nexport type BaseShoppingContainerData = BaseShoppingContainerAttributes & BaseData\r\n\r\n\r\n/**\r\n * Abstract base class for shopping-related containers like carts and orders.\r\n * Manages common elements such as line items, addresses, coupons, and totals.\r\n */\r\nexport default abstract class BaseShoppingContainerModel extends BaseModel {\r\n protected id: string;\r\n protected customerId?: string;\r\n protected customerEmail?: string;\r\n protected anonymousId?: string;\r\n protected lineItems: LineItemModel[];\r\n protected charges: ChargeModel[];\r\n protected shippingDetails: ShippingDetails | null;\r\n protected shippingAddress: AddressModel | null;\r\n protected billingAddress: AddressModel | null;\r\n\r\n // CouponsCodes\r\n protected coupons: CouponModel[];\r\n\r\n // Cart Totals\r\n protected total: ShoppingContainerTotalModel;\r\n\r\n protected country: CountryCode;\r\n protected currency: CurrencyCode;\r\n protected locale: LocaleCode;\r\n #metaData: ShoppingContainerMetaData;\r\n\r\n /**\r\n * Creates an instance of BaseShoppingContainerModel.\r\n * Initializes common properties and calculates initial base totals.\r\n * @param data - The initial attributes for the shopping container.\r\n * @param date - Optional date object for setting creation/modification times (defaults to now).\r\n */\r\n constructor(data: BaseShoppingContainerAttributes, date: Date = new Date(), metaData: ShoppingContainerMetaData = { checkCouponExpiry: true }) {\r\n super(data, date);\r\n this.id = data.id;\r\n this.customerId = data.customerId;\r\n this.customerEmail = data.customerEmail;\r\n this.anonymousId = data.anonymousId;\r\n this.country = data.country;\r\n this.currency = data.currency;\r\n this.locale = data.locale;\r\n this.lineItems = (data.lineItems ?? []).map(item => new LineItemModel(item));\r\n this.charges = (data.charges ?? []).map(charge => new ChargeModel(charge));\r\n this.billingAddress = data.billingAddress ? new AddressModel(data.billingAddress, date) : null;\r\n this.shippingAddress = data.shippingAddress ? new AddressModel(data.shippingAddress, date) : null;\r\n this.coupons = (data.coupons ?? []).map(coupon => new CouponModel(coupon));\r\n\r\n this.shippingDetails = data.shippingDetails ? Utils.deepClone(data.shippingDetails) : null;\r\n\r\n this.total = {\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown),\r\n\r\n additiveChargesTaxTotal: new PriceModel(data.total.additiveChargesTaxTotal),\r\n additiveChargesTaxBreakdown: this.mapTaxBreakdown(data.total.additiveChargesTaxBreakdown),\r\n adjustmentCharges: new PriceModel(data.total.adjustmentCharges),\r\n\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: new PriceModel(data.total.taxExclusive.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.taxExclusive.netLineItemSubtotal),\r\n additiveCharges: new PriceModel(data.total.taxExclusive.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.taxExclusive.netAdditiveCharges),\r\n shippingCharges: new PriceModel(data.total.taxExclusive.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.taxExclusive.netShippingCharges),\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: new PriceModel(data.total.taxInclusive.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.taxInclusive.netLineItemSubtotal),\r\n additiveCharges: new PriceModel(data.total.taxInclusive.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.taxInclusive.netAdditiveCharges),\r\n shippingCharges: new PriceModel(data.total.taxInclusive.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.taxInclusive.netShippingCharges),\r\n },\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n };\r\n\r\n this.#metaData = {\r\n checkCouponExpiry: metaData.checkCouponExpiry\r\n }\r\n }\r\n\r\n private mapTaxBreakdown(breakdown: Record<string, TaxSystemBreakdown>): Record<string, TaxSystemBreakdownModel> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: new PriceModel(systemValue.totalAmount),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n new PriceModel(subValue)\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n private serializeTaxBreakdown(breakdown: Record<string, TaxSystemBreakdownModel>): Record<string, TaxSystemBreakdown> {\r\n return Object.fromEntries(\r\n Object.entries(breakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount.getDetails(),\r\n subSystems: Object.fromEntries(\r\n Object.entries(systemValue.subSystems).map(([subKey, subValue]) => [\r\n subKey,\r\n subValue.getDetails()\r\n ])\r\n )\r\n }\r\n ])\r\n );\r\n }\r\n\r\n /**\r\n * Gets the unique identifier for this shopping container (cart ID or order ID).\r\n * @returns The ID string.\r\n */\r\n public getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the customer ID associated with this container, if available.\r\n * @returns The customer ID string, or undefined.\r\n */\r\n public getCustomerId(): string | undefined {\r\n return this.customerId;\r\n }\r\n\r\n /**\r\n * Gets the customer email associated with this container, if available.\r\n * @returns The customer email string, or undefined.\r\n */\r\n public getCustomerEmail(): string | undefined {\r\n return this.customerEmail;\r\n }\r\n\r\n /**\r\n * Gets the anonymous user ID associated with this container, if available.\r\n * @returns The anonymous ID string, or undefined.\r\n */\r\n public getAnonymousId(): string | undefined {\r\n return this.anonymousId;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the line items in the container.\r\n * Each item is a new LineItemModel instance created from the original's details.\r\n * @returns An array of LineItemModel instances.\r\n */\r\n public getLineItems(): LineItemModel[] {\r\n // Return new instances to prevent modification of internal state\r\n return this.lineItems.map(item => new LineItemModel(item.getDetails()));\r\n }\r\n\r\n /**\r\n * Gets current number of line items in the container.\r\n * @returns The count of line items.\r\n */\r\n public getLineItemsCount(): number {\r\n return this.lineItems.length;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the charges in the container.\r\n * @returns An array of ChargeModel instances.\r\n */\r\n public getCharges(): ChargeModel[] {\r\n return this.charges.map(charge => new ChargeModel(charge.getDetails()));\r\n }\r\n\r\n /**\r\n * Adds a new charge to the container and recalculates totals.\r\n * @param charge - The charge to add.\r\n */\r\n public addCharge(charge: ChargeModel): void {\r\n this.charges.push(charge);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Clears all charges from the container and recalculates totals.\r\n */\r\n public clearCharges(): void {\r\n this.charges = [];\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Gets a copy of the shipping details associated with the container.\r\n * @returns A ShippingDetails object, or null if none are set.\r\n */\r\n public getShippingDetails(): ShippingDetails | null {\r\n return this.shippingDetails ? Utils.deepClone(this.shippingDetails) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the shipping address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no shipping address is set.\r\n */\r\n public getShippingAddress(): AddressModel | null {\r\n return this.shippingAddress ? new AddressModel(this.shippingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Checks if a shipping address is associated with this container.\r\n * @returns True if a shipping address is set, false otherwise.\r\n */\r\n public hasShippingAddress(): boolean {\r\n return !!this.shippingAddress;\r\n }\r\n\r\n /**\r\n * Checks if a billing address is associated with this container.\r\n * @returns True if a billing address is set, false otherwise.\r\n */\r\n public hasBillingAddress(): boolean {\r\n return !!this.billingAddress;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the billing address associated with the container.\r\n * Returns a new AddressModel instance created from the original's details.\r\n * @returns An AddressModel instance, or null if no billing address is set.\r\n */\r\n public getBillingAddress(): AddressModel | null {\r\n return this.billingAddress ? new AddressModel(this.billingAddress.getDetails()) : null;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the coupons applied to the container.\r\n * Each item is a new CouponModel instance created from the original's details.\r\n * @returns An array of CouponModel instances.\r\n */\r\n public getCoupons(): CouponModel[] {\r\n return [...this.coupons];\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this container.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the currency code associated with this container.\r\n * @returns The CurrencyCode enum value.\r\n */\r\n public getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n /**\r\n * Gets the locale code associated with this container.\r\n * @returns The LocaleCode enum value.\r\n */\r\n public getLocale(): LocaleCode {\r\n return this.locale;\r\n }\r\n\r\n /**\r\n * Gets a defensive copy of the calculated totals for the container.\r\n * @returns An object containing shipping, subtotal, coupon, and grand totals.\r\n */\r\n public getTotal() {\r\n return {\r\n lineItemTaxTotal: this.total.lineItemTaxTotal,\r\n lineItemTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.lineItemTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n additiveChargesTaxTotal: this.total.additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.additiveChargesTaxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n adjustmentCharges: this.total.adjustmentCharges,\r\n discountBreakdown: { ...this.total.discountBreakdown },\r\n discountTotal: this.total.discountTotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n system: systemValue.system,\r\n totalAmount: systemValue.totalAmount,\r\n subSystems: { ...systemValue.subSystems }\r\n }\r\n ])\r\n ),\r\n taxExclusive: {\r\n lineItemSubtotal: this.total.taxExclusive.lineItemSubtotal,\r\n netLineItemSubtotal: this.total.taxExclusive.netLineItemSubtotal,\r\n additiveCharges: this.total.taxExclusive.additiveCharges,\r\n netAdditiveCharges: this.total.taxExclusive.netAdditiveCharges,\r\n shippingCharges: this.total.taxExclusive.shippingCharges,\r\n netShippingCharges: this.total.taxExclusive.netShippingCharges,\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: this.total.taxInclusive.lineItemSubtotal,\r\n netLineItemSubtotal: this.total.taxInclusive.netLineItemSubtotal,\r\n additiveCharges: this.total.taxInclusive.additiveCharges,\r\n netAdditiveCharges: this.total.taxInclusive.netAdditiveCharges,\r\n shippingCharges: this.total.taxInclusive.shippingCharges,\r\n netShippingCharges: this.total.taxInclusive.netShippingCharges,\r\n },\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the shopping container's current state.\r\n * Includes details from the base model and specific container properties.\r\n * @returns BaseShoppingContainerData object suitable for serialization or API responses.\r\n */\r\n getDetails(): BaseShoppingContainerData {\r\n const totals = this.getTotal();\r\n return {\r\n ...super.getDetails(),\r\n id: this.getId(),\r\n customerId: this.getCustomerId(),\r\n customerEmail: this.getCustomerEmail(),\r\n anonymousId: this.getAnonymousId(),\r\n lineItems: this.getLineItems().map(item => item.getDetails()),\r\n charges: this.getCharges().map(charge => charge.getDetails()),\r\n shippingDetails: this.getShippingDetails(),\r\n shippingAddress: this.getShippingAddress()?.getDetails() || null,\r\n billingAddress: this.getBillingAddress()?.getDetails() || null,\r\n coupons: this.getCoupons().map(coupon => coupon.getDetails()),\r\n total: {\r\n // Item Totals\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n additiveChargesTaxTotal: totals.additiveChargesTaxTotal.getDetails(),\r\n additiveChargesTaxBreakdown: this.serializeTaxBreakdown(totals.additiveChargesTaxBreakdown),\r\n\r\n adjustmentCharges: totals.adjustmentCharges.getDetails(),\r\n\r\n // Aggregate Totals\r\n discountTotal: totals.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(totals.discountBreakdown).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n\r\n taxExclusive: {\r\n lineItemSubtotal: totals.taxExclusive.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.taxExclusive.netLineItemSubtotal.getDetails(),\r\n additiveCharges: totals.taxExclusive.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.taxExclusive.netAdditiveCharges.getDetails(),\r\n shippingCharges: totals.taxExclusive.shippingCharges.getDetails(),\r\n netShippingCharges: totals.taxExclusive.netShippingCharges.getDetails(),\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: totals.taxInclusive.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.taxInclusive.netLineItemSubtotal.getDetails(),\r\n additiveCharges: totals.taxInclusive.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.taxInclusive.netAdditiveCharges.getDetails(),\r\n shippingCharges: totals.taxInclusive.shippingCharges.getDetails(),\r\n netShippingCharges: totals.taxInclusive.netShippingCharges.getDetails(),\r\n },\r\n grandTotal: totals.grandTotal.getDetails(),\r\n },\r\n country: this.getCountry(),\r\n currency: this.getCurrency(),\r\n locale: this.getLocale(),\r\n };\r\n }\r\n\r\n /**\r\n * Recalculates the total costs for the shopping container.\r\n * This orchestrates computing base totals, applying active coupons, and aggregating the final net results.\r\n */\r\n public calculateTotals(): void {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n // Step 1: Initialize baseline totals for all active items and charges.\r\n // We clear any existing discounts so we can evaluate base subtotals accurately.\r\n this.lineItems.forEach(li => {\r\n if (li.getState() !== LineItemState.CANCELLED) li.updateDiscounts([]);\r\n });\r\n this.charges.forEach(charge => charge.updateDiscounts([]));\r\n\r\n // Step 2: Evaluate Non-Shipping Coupons on gross subtotals\r\n const bases = this.getCouponEvaluationBases();\r\n let discountTotal = zero;\r\n let discountBreakdown: Record<string, PriceModel> = {};\r\n let nonShippingCouponTotal: Record<string, PriceModel> = {};\r\n\r\n const nonShippingCoupons = this.coupons.filter(c => c.getCategory() !== CouponCategory.SHIPPING);\r\n nonShippingCoupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(bases.targetSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry);\r\n discountTotal = discountTotal.add(couponValue);\r\n discountBreakdown[coupon.getCode()] = couponValue;\r\n nonShippingCouponTotal[coupon.getCode()] = couponValue;\r\n });\r\n\r\n // Step 3: Distribute Non-Shipping Coupons\r\n // This internally recalculates the net subtotals and taxes for line items.\r\n this.applyDiscountsInLineItem(nonShippingCouponTotal);\r\n\r\n // Step 4: Evaluate Shipping Coupons using dynamically updated Net Subtotals\r\n const updatedBases = this.getCouponEvaluationBases();\r\n let shippingCouponTotal: Record<string, PriceModel> = {};\r\n \r\n const shippingCoupons = this.coupons.filter(c => c.getCategory() === CouponCategory.SHIPPING);\r\n shippingCoupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(updatedBases.targetNetSubtotal, updatedBases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(updatedBases.targetShipping);\r\n discountTotal = discountTotal.add(couponValue);\r\n discountBreakdown[coupon.getCode()] = couponValue;\r\n shippingCouponTotal[coupon.getCode()] = couponValue;\r\n });\r\n\r\n // Step 5: Distribute Shipping Coupons\r\n this.applyDiscountsInShippingCharges(shippingCouponTotal);\r\n\r\n // Step 6: Aggregate everything into `this.total`\r\n let lineItemTaxTotal = zero;\r\n let additiveChargesTaxTotal = zero;\r\n\r\n let lineItemSubtotalExcl = zero;\r\n let netLineItemSubtotalExcl = zero;\r\n let lineItemSubtotalIncl = zero;\r\n let netLineItemSubtotalIncl = zero;\r\n\r\n const taxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const lineItemTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const additiveChargesTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n\r\n const mergeTax = (source: Record<string, LineItemTaxBreakdownModel | ChargeTaxBreakdownModel>, target: ShoppingContainerTaxBreakdownModel) => {\r\n Object.entries(source).forEach(([_, breakdown]) => {\r\n const { system, subSystem, taxAmount } = breakdown;\r\n if (!target[system]) target[system] = { system, totalAmount: zero, subSystems: {} };\r\n if (!target[system].subSystems[subSystem]) target[system].subSystems[subSystem] = taxAmount;\r\n else target[system].subSystems[subSystem] = target[system].subSystems[subSystem].add(taxAmount);\r\n target[system].totalAmount = target[system].totalAmount.add(taxAmount);\r\n });\r\n };\r\n\r\n const filteredLineItems = this.lineItems.filter(li => li.getState() !== LineItemState.CANCELLED);\r\n filteredLineItems.forEach(li => {\r\n const t = li.getTotal();\r\n lineItemSubtotalExcl = lineItemSubtotalExcl.add(t.taxExclusive.subtotal);\r\n netLineItemSubtotalExcl = netLineItemSubtotalExcl.add(t.taxExclusive.netSubtotal);\r\n lineItemSubtotalIncl = lineItemSubtotalIncl.add(t.taxInclusive.subtotal);\r\n netLineItemSubtotalIncl = netLineItemSubtotalIncl.add(t.taxInclusive.netSubtotal);\r\n\r\n if (t.taxBreakdown) {\r\n mergeTax(t.taxBreakdown, lineItemTaxBreakdown);\r\n mergeTax(t.taxBreakdown, taxBreakdown);\r\n lineItemTaxTotal = lineItemTaxTotal.add(t.taxTotal);\r\n }\r\n });\r\n\r\n let additiveChargesExcl = zero;\r\n let netAdditiveChargesExcl = zero;\r\n let additiveChargesIncl = zero;\r\n let netAdditiveChargesIncl = zero;\r\n\r\n let shippingChargesExcl = zero;\r\n let netShippingChargesExcl = zero;\r\n let shippingChargesIncl = zero;\r\n let netShippingChargesIncl = zero;\r\n\r\n let adjustmentChargesIncl = zero;\r\n\r\n this.charges.forEach(charge => {\r\n const t = charge.getTotal();\r\n if (charge.getImpact() === ChargeImpact.ADD) {\r\n additiveChargesExcl = additiveChargesExcl.add(t.taxExclusive.chargeAmount);\r\n netAdditiveChargesExcl = netAdditiveChargesExcl.add(t.taxExclusive.netChargeAmount);\r\n additiveChargesIncl = additiveChargesIncl.add(t.taxInclusive.chargeAmount);\r\n netAdditiveChargesIncl = netAdditiveChargesIncl.add(t.grandTotal);\r\n\r\n if (charge.getType() === ChargeType.SHIPPING) {\r\n shippingChargesExcl = shippingChargesExcl.add(t.taxExclusive.chargeAmount);\r\n netShippingChargesExcl = netShippingChargesExcl.add(t.taxExclusive.netChargeAmount);\r\n shippingChargesIncl = shippingChargesIncl.add(t.taxInclusive.chargeAmount);\r\n netShippingChargesIncl = netShippingChargesIncl.add(t.grandTotal);\r\n }\r\n\r\n if (t.taxBreakdown) {\r\n mergeTax(t.taxBreakdown, additiveChargesTaxBreakdown);\r\n mergeTax(t.taxBreakdown, taxBreakdown);\r\n additiveChargesTaxTotal = additiveChargesTaxTotal.add(t.taxTotal);\r\n }\r\n } else if (charge.getImpact() === ChargeImpact.SUBTRACT) {\r\n adjustmentChargesIncl = adjustmentChargesIncl.add(t.grandTotal);\r\n }\r\n });\r\n\r\n const taxTotal = lineItemTaxTotal.add(additiveChargesTaxTotal);\r\n const grandTotal = netLineItemSubtotalIncl.add(netAdditiveChargesIncl).subtract(adjustmentChargesIncl);\r\n\r\n this.total = {\r\n lineItemTaxTotal,\r\n lineItemTaxBreakdown,\r\n additiveChargesTaxTotal,\r\n additiveChargesTaxBreakdown,\r\n adjustmentCharges: adjustmentChargesIncl,\r\n discountTotal,\r\n discountBreakdown,\r\n taxTotal,\r\n taxBreakdown,\r\n taxExclusive: {\r\n lineItemSubtotal: lineItemSubtotalExcl,\r\n netLineItemSubtotal: netLineItemSubtotalExcl,\r\n additiveCharges: additiveChargesExcl,\r\n netAdditiveCharges: netAdditiveChargesExcl,\r\n shippingCharges: shippingChargesExcl,\r\n netShippingCharges: netShippingChargesExcl,\r\n },\r\n taxInclusive: {\r\n lineItemSubtotal: lineItemSubtotalIncl,\r\n netLineItemSubtotal: netLineItemSubtotalIncl,\r\n additiveCharges: additiveChargesIncl,\r\n netAdditiveCharges: netAdditiveChargesIncl,\r\n shippingCharges: shippingChargesIncl,\r\n netShippingCharges: netShippingChargesIncl,\r\n },\r\n grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Updates the shipping details and recalculates the totals.\r\n * @param shippingDetails - The new shipping details to apply.\r\n */\r\n public updateShippingDetails(shippingDetails: ShippingDetails): void {\r\n this.shippingDetails = shippingDetails;\r\n }\r\n\r\n /**\r\n * Applies a list of coupons to the shopping container.\r\n * Filters out invalid coupons, separates shipping and non-shipping coupons,\r\n * and distributes discounts to line items.\r\n * @param applicableCoupons - The list of coupons to attempt to apply.\r\n */\r\n public applyCoupons(applicableCoupons: CouponModel[]): void {\r\n //Apply coupons\r\n const shippingCoupons = applicableCoupons.filter(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n const otherCoupons = applicableCoupons.filter(coupon => coupon.getCategory() !== CouponCategory.SHIPPING);\r\n\r\n this.coupons = [];\r\n this.total.discountTotal = this.total.discountTotal.zero();\r\n this.total.discountBreakdown = {};\r\n // Apply non shipping coupons\r\n otherCoupons.length && this.applyNonShippingCoupons(otherCoupons);\r\n this.applyDiscountsInLineItem(this.total.discountBreakdown);\r\n\r\n // Apply shipping coupons\r\n shippingCoupons.length && this.applyShippingCoupons(shippingCoupons);\r\n\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Distributes the total discount amount among the line items.\r\n * @param couponTotal - A record of coupon codes and their calculated discount amounts.\r\n */\r\n private applyDiscountsInLineItem(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n\r\n const itemDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n this.lineItems.forEach(li => itemDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const targetSubtotal = this.lineItems.reduce(\r\n (total, lineItem) => total.add(lineItem.getIsTaxInclusive() ? lineItem.getTotal().taxInclusive.subtotal : lineItem.getTotal().taxExclusive.subtotal),\r\n new PriceModel({ amount: 0, currency: this.currency })\r\n );\r\n\r\n const validItems = this.lineItems\r\n .filter(li => li.getState() !== LineItemState.CANCELLED && !li.getTotal().taxExclusive.subtotal.isZero())\r\n .sort((a, b) => {\r\n const aVal = a.getIsTaxInclusive() ? a.getTotal().taxInclusive.subtotal : a.getTotal().taxExclusive.subtotal;\r\n const bVal = b.getIsTaxInclusive() ? b.getTotal().taxInclusive.subtotal : b.getTotal().taxExclusive.subtotal;\r\n return aVal.compareTo(bVal);\r\n });\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validItems.forEach((item, index) => {\r\n let amount: PriceModel;\r\n const itemVal = item.getIsTaxInclusive() ? item.getTotal().taxInclusive.subtotal : item.getTotal().taxExclusive.subtotal;\r\n if (index === validItems.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(itemVal).divide(targetSubtotal).round();\r\n }\r\n distributed = distributed.add(amount);\r\n itemDiscounts.get(item.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n this.lineItems.forEach(lineItem => {\r\n lineItem.updateDiscounts(itemDiscounts.get(lineItem.getId())!);\r\n });\r\n }\r\n\r\n private applyDiscountsInShippingCharges(couponTotal: Record<string, PriceModel>) {\r\n const couponDiscounts: [string, PriceModel][] = Array.from(Object.entries(couponTotal))\r\n .filter(couponDiscount => !couponDiscount[1].isZero());\r\n const shippingCharges = this.charges.filter(charge => charge.getType() === ChargeType.SHIPPING);\r\n\r\n const chargeDiscounts = new Map<string, { coupon: CouponModel, amount: PriceModel }[]>();\r\n shippingCharges.forEach(li => chargeDiscounts.set(li.getId(), []));\r\n\r\n couponDiscounts.forEach(([code, discountTotal]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || discountTotal.isZero()) return;\r\n\r\n const targetShipping = shippingCharges.reduce(\r\n (total, charge) => total.add(charge.getIsTaxInclusive() ? charge.getTotal().taxInclusive.chargeAmount : charge.getTotal().taxExclusive.chargeAmount),\r\n new PriceModel({ amount: 0, currency: this.currency })\r\n );\r\n\r\n const validCharges = shippingCharges\r\n .filter(charge => !charge.getTotal().taxExclusive.chargeAmount.isZero())\r\n .sort((a, b) => {\r\n const aVal = a.getIsTaxInclusive() ? a.getTotal().taxInclusive.chargeAmount : a.getTotal().taxExclusive.chargeAmount;\r\n const bVal = b.getIsTaxInclusive() ? b.getTotal().taxInclusive.chargeAmount : b.getTotal().taxExclusive.chargeAmount;\r\n return aVal.compareTo(bVal);\r\n });\r\n\r\n let distributed = new PriceModel({ amount: 0, currency: this.currency });\r\n\r\n validCharges.forEach((charge, index) => {\r\n let amount: PriceModel;\r\n const chargeVal = charge.getIsTaxInclusive() ? charge.getTotal().taxInclusive.chargeAmount : charge.getTotal().taxExclusive.chargeAmount;\r\n if (index === validCharges.length - 1) {\r\n amount = discountTotal.subtract(distributed);\r\n } else {\r\n amount = discountTotal.multiply(chargeVal).divide(targetShipping).round();\r\n }\r\n distributed = distributed.add(amount);\r\n chargeDiscounts.get(charge.getId())?.push({ coupon, amount });\r\n });\r\n });\r\n\r\n shippingCharges.forEach(charge => {\r\n charge.updateDiscounts(chargeDiscounts.get(charge.getId())!);\r\n });\r\n }\r\n\r\n /**\r\n * Helper to resolve the correct evaluation basis for line items and shipping charges.\r\n * If any item in a group is tax-inclusive, the inclusive total is used for the entire group.\r\n * Otherwise, the exclusive total is used.\r\n */\r\n private getCouponEvaluationBases() {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n const activeItems = this.lineItems.filter(li => li.getState() !== LineItemState.CANCELLED);\r\n const shippingCharges = this.charges.filter(charge => charge.getType() === ChargeType.SHIPPING);\r\n\r\n const isAnyItemInclusive = activeItems.some(li => li.getIsTaxInclusive());\r\n const targetSubtotal = activeItems.reduce(\r\n (total, li) => total.add(isAnyItemInclusive ? li.getTotal().taxInclusive.subtotal : li.getTotal().taxExclusive.subtotal),\r\n zero\r\n );\r\n\r\n const targetNetSubtotal = activeItems.reduce(\r\n (total, li) => total.add(isAnyItemInclusive ? li.getTotal().taxInclusive.netSubtotal : li.getTotal().taxExclusive.netSubtotal),\r\n zero\r\n );\r\n\r\n const isAnyShippingInclusive = shippingCharges.some(c => c.getIsTaxInclusive());\r\n const targetShipping = shippingCharges.reduce(\r\n (total, c) => total.add(isAnyShippingInclusive ? c.getTotal().taxInclusive.chargeAmount : c.getTotal().taxExclusive.chargeAmount),\r\n zero\r\n );\r\n\r\n return { targetSubtotal, targetShipping, targetNetSubtotal };\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable non-shipping coupon.\r\n * Currently supports applying only a single coupon of type COUPON.\r\n * @param applicableCoupons - List of available non-shipping coupons.\r\n */\r\n private applyNonShippingCoupons(applicableCoupons: CouponModel[]) {\r\n const coupons = applicableCoupons.filter(coupon => coupon.getType() === CouponType.COUPON);\r\n if (coupons.length === 1) {\r\n const bases = this.getCouponEvaluationBases();\r\n const couponValue = coupons[0].calculateApplicableCouponDiscount(bases.targetSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(coupons[0]);\r\n this.total.discountTotal = couponValue;\r\n this.total.discountBreakdown[coupons[0].getCode()] = couponValue;\r\n }\r\n }\r\n // Todo: Add support to other type in future like promotion\r\n }\r\n\r\n /**\r\n * Selects and applies the best applicable shipping coupon.\r\n * @param applicableCoupons - List of available shipping coupons.\r\n */\r\n private applyShippingCoupons(applicableCoupons: CouponModel[]) {\r\n const bases = this.getCouponEvaluationBases();\r\n if (bases.targetShipping.getAmount() > 0 && applicableCoupons.length > 0) {\r\n const netLineItemSubtotal = bases.targetNetSubtotal;\r\n\r\n const maxValuedCoupon = applicableCoupons.reduce((maxCoupon, currentCoupon) => {\r\n if (!maxCoupon) return currentCoupon;\r\n\r\n const currentCouponValue = currentCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(bases.targetShipping);\r\n const maxCouponValue = maxCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(bases.targetShipping);\r\n\r\n if (currentCouponValue.compareTo(maxCouponValue) === 0) {\r\n return currentCoupon.getType() === CouponType.COUPON ? currentCoupon : maxCoupon;\r\n }\r\n return currentCouponValue.compareTo(maxCouponValue) > 0 ? currentCoupon : maxCoupon;\r\n });\r\n\r\n const couponValue = maxValuedCoupon.calculateApplicableCouponDiscount(netLineItemSubtotal, bases.targetShipping, this.country, this.currency, this.#metaData.checkCouponExpiry).min(bases.targetShipping);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(maxValuedCoupon);\r\n this.total.discountTotal = this.total.discountTotal.add(couponValue);\r\n this.total.discountBreakdown[maxValuedCoupon.getCode()] = couponValue;\r\n }\r\n }\r\n }\r\n\r\n}\r\n\r\n\r\n"]}
|