b23-lib 3.0.8 → 3.0.9
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/Auth/index.js +1 -1
- package/dist/Auth/index.js.map +1 -1
- package/dist/Auth/index.mjs +1 -1
- package/dist/Classes/Cart.js +1 -1
- package/dist/Classes/Cart.js.map +1 -1
- package/dist/Classes/Cart.mjs +1 -1
- package/dist/Classes/Charge.d.mts +18 -2
- package/dist/Classes/Charge.d.ts +18 -2
- package/dist/Classes/Charge.js +1 -1
- package/dist/Classes/Charge.js.map +1 -1
- package/dist/Classes/Charge.mjs +1 -1
- package/dist/Classes/Coupon.js +1 -1
- package/dist/Classes/Coupon.js.map +1 -1
- package/dist/Classes/Coupon.mjs +1 -1
- package/dist/Classes/Enum.d.mts +9 -1
- package/dist/Classes/Enum.d.ts +9 -1
- package/dist/Classes/Enum.js +1 -1
- package/dist/Classes/Enum.js.map +1 -1
- package/dist/Classes/Enum.mjs +1 -1
- package/dist/Classes/Inventory.js +1 -1
- package/dist/Classes/Inventory.js.map +1 -1
- package/dist/Classes/Inventory.mjs +1 -1
- package/dist/Classes/LineItem.js +1 -1
- package/dist/Classes/LineItem.js.map +1 -1
- package/dist/Classes/LineItem.mjs +1 -1
- package/dist/Classes/Order.js +1 -1
- package/dist/Classes/Order.js.map +1 -1
- package/dist/Classes/Order.mjs +1 -1
- package/dist/Classes/Price.js +1 -1
- package/dist/Classes/Price.js.map +1 -1
- package/dist/Classes/Price.mjs +1 -1
- package/dist/Classes/Product.js +1 -1
- package/dist/Classes/Product.js.map +1 -1
- package/dist/Classes/Product.mjs +1 -1
- package/dist/Classes/ShoppingContainer.d.mts +4 -0
- package/dist/Classes/ShoppingContainer.d.ts +4 -0
- package/dist/Classes/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Classes/TaxRule.js.map +1 -1
- package/dist/Classes/TaxRule.mjs +1 -1
- package/dist/Classes/TieredPrice.js +1 -1
- package/dist/Classes/TieredPrice.js.map +1 -1
- package/dist/Classes/TieredPrice.mjs +1 -1
- package/dist/chunk-2QHUEAZR.mjs +2 -0
- package/dist/chunk-2QHUEAZR.mjs.map +1 -0
- package/dist/{chunk-XHGUVYQO.mjs → chunk-3HKY6ZOF.mjs} +2 -2
- package/dist/{chunk-XHGUVYQO.mjs.map → chunk-3HKY6ZOF.mjs.map} +1 -1
- package/dist/chunk-4ZFZXWD7.mjs +2 -0
- package/dist/chunk-4ZFZXWD7.mjs.map +1 -0
- package/dist/chunk-GFMGTV5E.mjs +2 -0
- package/dist/chunk-GFMGTV5E.mjs.map +1 -0
- package/dist/{chunk-L3CNGDFJ.mjs → chunk-JCUHTCOC.mjs} +2 -2
- package/dist/{chunk-L3CNGDFJ.mjs.map → chunk-JCUHTCOC.mjs.map} +1 -1
- package/dist/{chunk-EB5IQLSA.mjs → chunk-OAE2FJFJ.mjs} +2 -2
- package/dist/{chunk-EB5IQLSA.mjs.map → chunk-OAE2FJFJ.mjs.map} +1 -1
- package/dist/{chunk-XBFSNBKL.mjs → chunk-QLYPJDDV.mjs} +2 -2
- package/dist/{chunk-XBFSNBKL.mjs.map → chunk-QLYPJDDV.mjs.map} +1 -1
- package/dist/{chunk-NNMLXCUS.mjs → chunk-Z3CF4K5C.mjs} +2 -2
- package/dist/{chunk-NNMLXCUS.mjs.map → chunk-Z3CF4K5C.mjs.map} +1 -1
- package/dist/{chunk-3RTEHBPX.mjs → chunk-ZZ3B7OGM.mjs} +2 -2
- package/dist/{chunk-3RTEHBPX.mjs.map → chunk-ZZ3B7OGM.mjs.map} +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-FC4P26U3.mjs +0 -2
- package/dist/chunk-FC4P26U3.mjs.map +0 -1
- package/dist/chunk-FSAVZRS6.mjs +0 -2
- package/dist/chunk-FSAVZRS6.mjs.map +0 -1
- package/dist/chunk-UMVN5K5M.mjs +0 -2
- package/dist/chunk-UMVN5K5M.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Classes/ShoppingContainer.ts"],"names":["BaseShoppingContainerModel","BaseModel","data","date","item","LineItemModel","charge","ChargeModel","AddressModel","coupon","CouponModel","Utils_default","PriceModel","key","value","breakdown","systemKey","systemValue","subKey","subValue","totals","zero","filteredLineItems","lineitem","subTotal","total","lineItem","netSubtotal","shippingCharge","totalDiscount","discounts","nonShippingCouponTotal","couponValue","shippingCoupon","additiveChargesTotal","deductiveChargesTotal","chargesTotal","chargeAdjustmentsTotal","netShippingCharge","taxTotal","lineItemTaxTotal","chargeTaxTotal","taxBreakdown","lineItemTaxBreakdown","chargeTaxBreakdown","mergeTax","sourceBreakdown","targetBreakdown","ruleId","system","subsystem","lineItemTaxes","chargeTaxes","grandTotal","shippingDetails","applicableCoupons","shippingCoupons","otherCoupons","couponTotal","couponDiscounts","couponDiscount","itemDiscounts","li","code","validItems","a","b","distributed","index","amount","shippingCharges","chargeDiscounts","c","validCharges","coupons","subTotalWithCouponDiscount","maxValuedCoupon","maxCoupon","currentCoupon","currentCouponValue","maxCouponValue"],"mappings":"+RA4HA,IAA8BA,CAA9B,CAAA,cAAiEC,CAAU,CAC/D,EACA,CAAA,UAAA,CACA,aACA,CAAA,WAAA,CACA,SACA,CAAA,OAAA,CACA,eACA,CAAA,eAAA,CACA,cAGA,CAAA,OAAA,CAGA,KAEA,CAAA,OAAA,CACA,QACA,CAAA,MAAA,CAQV,WAAYC,CAAAA,CAAAA,CAAuCC,GAAa,CAAA,IAAI,IAAQ,CAAA,CAC1E,KAAMD,CAAAA,CAAAA,CAAMC,GAAI,CAAA,CAChB,IAAK,CAAA,EAAA,CAAKD,CAAK,CAAA,EAAA,CACf,IAAK,CAAA,UAAA,CAAaA,CAAK,CAAA,UAAA,CACvB,IAAK,CAAA,aAAA,CAAgBA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AAM,cAAc,CAAA,CAEpL,OAAII,CAAAA,GAAuBC,CAClBF,CAAAA,CAAAA,CAAc,OAAQ,EAAA,GAAM,QAAWA,CAAAA,CAAAA,CAAgBD,CAEzDE,CAAAA,CAAAA,CAAmB,SAAUC,CAAAA,CAAc,CAAI,CAAA,CAAA,CAAIF,CAAgBD,CAAAA,CAC5E,CAAC,CAAA,CAEK7C,CAAc4C,CAAAA,CAAAA,CAAgB,iCAAkCD,CAAAA,CAAAA,CAA4B,IAAK,CAAA,KAAA,CAAM,cAAgB,CAAA,IAAA,CAAK,OAAS,CAAA,IAAA,CAAK,QAAQ,CAAA,CAAE,GAAI,CAAA,IAAA,CAAK,KAAM,CAAA,cAAc,CACnL3C,CAAAA,CAAAA,CAAY,SAAU,EAAA,CAAI,CAC5B,GAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,CAAK4C,CAAe,CAAA,CACjC,IAAK,CAAA,KAAA,CAAM,SAAUA,CAAAA,CAAAA,CAAgB,OAAQ,EAAC,CAAI5C,CAAAA,CAAAA,CAClD,IAAK,CAAA,KAAA,CAAM,aAAgB,CAAA,IAAA,CAAK,KAAM,CAAA,aAAA,CAAc,GAAIA,CAAAA,CAAW,CACnE,CAAA,IAAA,CAAK,KAAM,CAAA,iBAAA,CAAoB,IAAK,CAAA,KAAA,CAAM,cAAe,CAAA,QAAA,CAASA,CAAW,CAAA,EAEjF,CACF,CACF","file":"chunk-2QHUEAZR.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 { FixedTaxRuleModel, TaxRuleModel } from \"./TaxRule\";\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 /** Sum of all line item prices before any discounts or taxes */\r\n subtotal: PriceData;\r\n /** Total item subtotal after item-level discounts have been applied (taxable base for items) */\r\n netSubtotal: PriceData;\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 /** Sum of all extra charges (shipping, processing, etc.) before tax */\r\n chargesTotal: PriceData;\r\n /** Sum of subtractive adjustment charges (non-taxed) */\r\n chargeAdjustmentsTotal: PriceData;\r\n /** Specifically the shipping portion of charges */\r\n shippingCharge: PriceData;\r\n /** Shipping cost after any shipping-specific discounts */\r\n netShippingCharge: PriceData;\r\n /** Total tax collected specifically from charges */\r\n chargeTaxTotal: PriceData;\r\n /** Granular tax breakdown for all charges */\r\n chargeTaxBreakdown: Record<string, TaxSystemBreakdown>;\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 /** Map of applied coupon codes to their calculated discount amounts */\r\n discounts: Record<string, PriceData>;\r\n /** Sum of all coupon discounts applied to the container */\r\n totalDiscount: PriceData;\r\n /** Final total amount to be paid (NetSubtotal + ChargesTotal + TaxTotal - (any remaining discounts)) */\r\n grandTotal: PriceData;\r\n};\r\n\r\n/**\r\n * Internal model version of ShoppingContainerTotal using PriceModel instances.\r\n */\r\nexport type ShoppingContainerTotalModel = {\r\n subtotal: PriceModel;\r\n netSubtotal: PriceModel;\r\n lineItemTaxTotal: PriceModel;\r\n lineItemTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n chargesTotal: PriceModel;\r\n chargeAdjustmentsTotal: PriceModel;\r\n shippingCharge: PriceModel;\r\n netShippingCharge: PriceModel;\r\n chargeTaxTotal: PriceModel;\r\n chargeTaxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, TaxSystemBreakdownModel>;\r\n discounts: Record<string, PriceModel>;\r\n totalDiscount: PriceModel;\r\n grandTotal: PriceModel;\r\n};\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\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()) {\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 subtotal: new PriceModel(data.total.subtotal),\r\n netSubtotal: new PriceModel(data.total.netSubtotal),\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal || { amount: 0, currency: data.currency }),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown || {}),\r\n\r\n chargesTotal: new PriceModel(data.total.chargesTotal || { amount: 0, currency: data.currency }),\r\n chargeAdjustmentsTotal: new PriceModel(data.total.chargeAdjustmentsTotal),\r\n shippingCharge: new PriceModel(data.total.shippingCharge),\r\n netShippingCharge: new PriceModel(data.total.netShippingCharge),\r\n chargeTaxTotal: new PriceModel(data.total.chargeTaxTotal || { amount: 0, currency: data.currency }),\r\n chargeTaxBreakdown: this.mapTaxBreakdown(data.total.chargeTaxBreakdown || {}),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n discounts: Object.fromEntries(\r\n Object.entries(data.total.discounts).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n totalDiscount: new PriceModel(data.total.totalDiscount),\r\n grandTotal: new PriceModel(data.total.grandTotal),\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 subtotal: this.total.subtotal,\r\n netSubtotal: this.total.netSubtotal,\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 chargesTotal: this.total.chargesTotal,\r\n chargeAdjustmentsTotal: this.total.chargeAdjustmentsTotal,\r\n shippingCharge: this.total.shippingCharge,\r\n netShippingCharge: this.total.netShippingCharge,\r\n chargeTaxTotal: this.total.chargeTaxTotal,\r\n chargeTaxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.chargeTaxBreakdown).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 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 discounts: { ...this.total.discounts },\r\n totalDiscount: this.total.totalDiscount,\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 subtotal: totals.subtotal.getDetails(),\r\n netSubtotal: totals.netSubtotal.getDetails(),\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n chargesTotal: totals.chargesTotal.getDetails(),\r\n chargeAdjustmentsTotal: totals.chargeAdjustmentsTotal.getDetails(),\r\n shippingCharge: totals.shippingCharge.getDetails(),\r\n netShippingCharge: totals.netShippingCharge.getDetails(),\r\n chargeTaxTotal: totals.chargeTaxTotal.getDetails(),\r\n chargeTaxBreakdown: this.serializeTaxBreakdown(totals.chargeTaxBreakdown),\r\n\r\n // Aggregate Totals\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n discounts: Object.fromEntries(\r\n Object.entries(totals.discounts).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n totalDiscount: totals.totalDiscount.getDetails(),\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 includes summing line items, calculating shipping, applying coupons, and computing taxes.\r\n */\r\n public calculateTotals(): void {\r\n const zero = new PriceModel({ amount: 0, currency: this.currency });\r\n \r\n // 1. Calculate LineItem subtotals\r\n const filteredLineItems = this.lineItems.filter(lineitem => lineitem.getState() !== LineItemState.CANCELLED);\r\n const subTotal = filteredLineItems.reduce((total, lineItem) => total.add(lineItem.getTotal().subtotal), zero);\r\n const netSubtotal = filteredLineItems.reduce((total, lineItem) => total.add(lineItem.getTotal().netSubtotal), zero);\r\n\r\n // 2. Calculate Shipping Cost\r\n const shippingCharge = this.charges\r\n .filter(charge => charge.getChargeType() === ChargeType.SHIPPING)\r\n .reduce((total, charge) => total.add(charge.getTotal().price), zero);\r\n\r\n // 3. Calculate coupon values based on gross subtotal & shipping\r\n let totalDiscount = zero;\r\n let discounts: Record<string, PriceModel> = {};\r\n let nonShippingCouponTotal: Record<string, PriceModel> = {};\r\n this.coupons.forEach(coupon => {\r\n const couponValue = coupon.calculateApplicableCouponDiscount(subTotal, shippingCharge, this.country, this.currency);\r\n totalDiscount = totalDiscount.add(couponValue);\r\n discounts[coupon.getCode()] = couponValue;\r\n if (coupon.getCategory() !== CouponCategory.SHIPPING) {\r\n nonShippingCouponTotal[coupon.getCode()] = couponValue;\r\n }\r\n })\r\n\r\n // 4. Apply discounts at lineitem and shipping charges\r\n this.applyDiscountsInLineItem(nonShippingCouponTotal);\r\n\r\n const shippingCoupon = this.coupons.find(coupon => coupon.getCategory() === CouponCategory.SHIPPING);\r\n if(shippingCoupon) {\r\n this.applyDiscuountsInShippingCharges({[shippingCoupon.getCode()] : discounts[shippingCoupon.getCode()] || zero});\r\n } else {\r\n // If no shipping coupon, ensure any previous discounts on shipping charges are cleared\r\n this.applyDiscuountsInShippingCharges({});\r\n }\r\n\r\n // 5. Calculate charges and net shipping after discount\r\n const additiveChargesTotal = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.ADD)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n const deductiveChargesTotal = this.charges\r\n .filter(charge => charge.getImpact() === ChargeImpact.SUBTRACT)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n\r\n const chargesTotal = additiveChargesTotal;\r\n const chargeAdjustmentsTotal = deductiveChargesTotal;\r\n\r\n const netShippingCharge = this.charges\r\n .filter(charge => charge.getChargeType() === ChargeType.SHIPPING)\r\n .reduce((total, charge) => total.add(charge.getTotal().grandTotal), zero);\r\n\r\n // 6. Aggregate Taxes & Grand Total from all items and charges\r\n let taxTotal = zero;\r\n let lineItemTaxTotal = zero;\r\n let chargeTaxTotal = zero;\r\n\r\n const taxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const lineItemTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n const chargeTaxBreakdown: ShoppingContainerTaxBreakdownModel = {};\r\n\r\n // Helper to merge tax breakdowns into hierarchical structure\r\n const mergeTax = (\r\n sourceBreakdown: Record<string, LineItemTaxBreakdownModel | ChargeTaxBreakdownModel>,\r\n targetBreakdown: ShoppingContainerTaxBreakdownModel\r\n ) => {\r\n Object.entries(sourceBreakdown).forEach(([ruleId, breakdown]) => {\r\n const system = breakdown.system;\r\n const subsystem = breakdown.subSystem;\r\n\r\n // Populate Target Breakdown\r\n if (!targetBreakdown[system]) {\r\n targetBreakdown[system] = { system, totalAmount: zero, subSystems: {} };\r\n }\r\n if (!targetBreakdown[system].subSystems[subsystem]) {\r\n targetBreakdown[system].subSystems[subsystem] = breakdown.amount;\r\n } else {\r\n targetBreakdown[system].subSystems[subsystem] = targetBreakdown[system].subSystems[subsystem].add(breakdown.amount);\r\n }\r\n targetBreakdown[system].totalAmount = targetBreakdown[system].totalAmount.add(breakdown.amount);\r\n\r\n // Populate Combined taxBreakdown\r\n if (!taxBreakdown[system]) {\r\n taxBreakdown[system] = { system, totalAmount: zero, subSystems: {} };\r\n }\r\n if (!taxBreakdown[system].subSystems[subsystem]) {\r\n taxBreakdown[system].subSystems[subsystem] = breakdown.amount;\r\n } else {\r\n taxBreakdown[system].subSystems[subsystem] = taxBreakdown[system].subSystems[subsystem].add(breakdown.amount);\r\n }\r\n taxBreakdown[system].totalAmount = taxBreakdown[system].totalAmount.add(breakdown.amount);\r\n });\r\n };\r\n\r\n // 6.1 Merge line item taxes\r\n filteredLineItems.forEach(lineItem => {\r\n const lineItemTaxes = lineItem.getTotal().taxBreakdown;\r\n if (lineItemTaxes) {\r\n mergeTax(lineItemTaxes, lineItemTaxBreakdown);\r\n mergeTax(lineItemTaxes, taxBreakdown);\r\n lineItemTaxTotal = lineItemTaxTotal.add(lineItem.getTotal().taxTotal);\r\n }\r\n });\r\n\r\n // 6.2 Merge charge taxes\r\n this.charges.forEach(charge => {\r\n const chargeTaxes = charge.getTotal().taxBreakdown;\r\n if (chargeTaxes) {\r\n mergeTax(chargeTaxes, chargeTaxBreakdown);\r\n mergeTax(chargeTaxes, taxBreakdown);\r\n chargeTaxTotal = chargeTaxTotal.add(charge.getTotal().taxTotal);\r\n }\r\n });\r\n\r\n // 6.3 Calculate total tax\r\n taxTotal = lineItemTaxTotal.add(chargeTaxTotal);\r\n\r\n // 7. Final Grand Total: netSubtotal + netShippingCharge + taxTotal\r\n const grandTotal = netSubtotal.add(lineItemTaxTotal).add(chargesTotal).subtract(chargeAdjustmentsTotal);\r\n\r\n this.total = {\r\n subtotal: subTotal,\r\n netSubtotal: netSubtotal,\r\n lineItemTaxTotal: lineItemTaxTotal,\r\n lineItemTaxBreakdown: lineItemTaxBreakdown,\r\n\r\n chargesTotal: chargesTotal,\r\n chargeAdjustmentsTotal: chargeAdjustmentsTotal,\r\n shippingCharge: shippingCharge,\r\n netShippingCharge: netShippingCharge,\r\n chargeTaxTotal: chargeTaxTotal,\r\n chargeTaxBreakdown: chargeTaxBreakdown,\r\n\r\n taxTotal: taxTotal,\r\n taxBreakdown: taxBreakdown,\r\n discounts: discounts,\r\n totalDiscount: totalDiscount,\r\n grandTotal: 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 this.calculateTotals();\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.totalDiscount = this.total.subtotal.zero();\r\n this.total.discounts = {};\r\n // Apply non shipping coupons\r\n otherCoupons.length && this.applyNonShippingCoupons(otherCoupons);\r\n this.applyDiscountsInLineItem(this.total.discounts);\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, totalDiscount]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || totalDiscount.isZero()) return;\r\n\r\n const validItems = this.lineItems\r\n .filter(li => li.getState() !== LineItemState.CANCELLED && !li.getTotal().subtotal.isZero())\r\n .sort((a, b) => a.getTotal().subtotal.compareTo(b.getTotal().subtotal));\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 if (index === validItems.length - 1) {\r\n amount = totalDiscount.subtract(distributed);\r\n } else {\r\n amount = totalDiscount.multiply(item.getTotal().subtotal).divide(this.total.subtotal).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 if (lineItem.getState() === LineItemState.CANCELLED || this.total.subtotal.isZero()) {\r\n lineItem.updateDiscounts([]);\r\n } else {\r\n lineItem.updateDiscounts(itemDiscounts.get(lineItem.getId()) || []);\r\n }\r\n });\r\n }\r\n\r\n private applyDiscuountsInShippingCharges(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.getChargeType() === 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, totalDiscount]) => {\r\n const coupon = this.coupons.find(c => c.getCode() === code);\r\n if (!coupon || totalDiscount.isZero()) return;\r\n\r\n const validCharges = shippingCharges\r\n .sort((a, b) => a.getTotal().grandTotal.compareTo(b.getTotal().grandTotal));\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 if (index === validCharges.length - 1) {\r\n amount = totalDiscount.subtract(distributed);\r\n } else {\r\n amount = totalDiscount.multiply(charge.getTotal().grandTotal).divide(this.total.subtotal).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 * 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 couponValue = coupons[0].calculateApplicableCouponDiscount(this.total.subtotal, this.total.shippingCharge, this.country, this.currency);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(coupons[0]);\r\n this.total.discounts[coupons[0].getCode()] = couponValue;\r\n this.total.totalDiscount = 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 if (this.total.shippingCharge.getAmount() > 0 && applicableCoupons.length > 0) {\r\n const subTotalWithCouponDiscount = this.total.subtotal.subtract(this.total.totalDiscount);\r\n\r\n const maxValuedCoupon = applicableCoupons.reduce((maxCoupon, currentCoupon) => {\r\n if (!maxCoupon) return currentCoupon;\r\n\r\n const currentCouponValue = currentCoupon.calculateApplicableCouponDiscount(subTotalWithCouponDiscount, this.total.shippingCharge, this.country, this.currency).min(this.total.shippingCharge);\r\n const maxCouponValue = maxCoupon.calculateApplicableCouponDiscount(subTotalWithCouponDiscount, this.total.shippingCharge, this.country, this.currency).min(this.total.shippingCharge);\r\n\r\n if (currentCouponValue === maxCouponValue) {\r\n return currentCoupon.getType() === 'coupon' ? currentCoupon : maxCoupon;\r\n }\r\n return currentCouponValue.compareTo(maxCouponValue) > 0 ? currentCoupon : maxCoupon;\r\n });\r\n\r\n const couponValue = maxValuedCoupon.calculateApplicableCouponDiscount(subTotalWithCouponDiscount, this.total.shippingCharge, this.country, this.currency).min(this.total.shippingCharge);\r\n if (couponValue.getAmount() > 0) {\r\n this.coupons.push(maxValuedCoupon);\r\n this.total.discounts[maxValuedCoupon.getCode()] = couponValue;\r\n this.total.totalDiscount = this.total.totalDiscount.add(couponValue);\r\n this.total.netShippingCharge = this.total.shippingCharge.subtract(couponValue);\r\n }\r\n }\r\n }\r\n}\r\n\r\n\r\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {i,h}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {i,h}from'./chunk-GFMGTV5E.mjs';import {q,r,s,t}from'./chunk-XPKK6DFA.mjs';var d=class t$1{#e;amount;currency;constructor(e){if(this.#e="PriceModel",e.amount<0)throw new q("Amount cannot be negative.");if(!e.currency)throw new r("Currency code is required.");this.amount=e.amount,this.currency=e.currency;}get kind(){return this.#e}static isPriceModel(e){return typeof e=="object"&&e!==null&&e.kind==="PriceModel"}getCurrency(){return this.currency}getAmount(){return this.amount}getDetails(){return {amount:this.amount,currency:this.currency}}compareTo(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return this.amount-e.getAmount()}add(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot add prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return new t$1({amount:this.amount+e.getAmount(),currency:this.currency})}subtract(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot subtract prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return new t$1({amount:this.amount-e.getAmount(),currency:this.currency})}multiply(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot multiply prices in different currencies.");return new t$1({amount:this.amount*e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>=0)return new t$1({amount:this.amount*e,currency:this.currency});throw new t("Must be a non-negative number.")}divide(e){if(t$1.isPriceModel(e)){if(this.currency!==e.getCurrency())throw new s("Cannot divide prices in different currencies.");return new t$1({amount:this.amount/e.getAmount(),currency:this.currency})}else if(typeof e=="number"&&e>0)return new t$1({amount:this.amount/e,currency:this.currency});throw new t("Must be a positive number.")}min(...e){if(e.length===0)throw new t("Must provide at least one PriceModel.");return e.reduce((r,n)=>{if(t$1.isPriceModel(n)){if(r.getCurrency()!==n.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return r.compareTo(n)<0?r:n},this)}max(...e){if(e.length===0)throw new t("Must provide at least one PriceModel.");return e.reduce((r,n)=>{if(t$1.isPriceModel(n)){if(r.getCurrency()!==n.getCurrency())throw new s("Cannot compare prices in different currencies.")}else throw new t("Must be a PriceModel instance.");return r.compareTo(n)>0?r:n},this)}zero(){return new t$1({currency:this.currency,amount:0})}isZero(){return this.amount===0}round(){return new t$1({currency:this.currency,amount:this.getRoundedAmount()})}getRoundedAmount(){return t$1.getRoundedAmount(this.amount,this.currency)}getFormattedString(){return t$1.getFormattedString(this.amount,this.currency)}toString(){return this.getFormattedString()}static getFormattedString(e,r$1,n={displayAsInteger:!1,style:"currency",currencyDisplay:"symbol"}){let c=i[r$1];if(!r$1||!c)throw new r("Invalid currency code for formatting.");let o=e,a=n.displayAsInteger?0:t$1.getDecimalPlaces(r$1),h$1={style:n.style??"currency",currency:r$1,signDisplay:"never",currencyDisplay:n.currencyDisplay,minimumFractionDigits:a,maximumFractionDigits:a};n.displayAsInteger&&(o=Math.ceil(o));try{return new Intl.NumberFormat(c,h$1).format(o)}catch(g){return console.error(`Error formatting price for currency "${r$1}" and locale "${c}":`,g),`${h[r$1]??r$1} ${t$1.addThousandSeparators(o.toFixed(a))}`}}static getDecimalPlaces(e){switch(e){case"INR":default:return 2}}static addThousandSeparators(e){let r=e.split("."),n=r[0],c=r.length>1?"."+r[1]:"";return n.replace(/\B(?=(\d{3})+(?!\d))/g,",")+c}static getRoundedAmount(e,r$1){if(e<0)throw new q("Amount cannot be negative for rounding.");if(r$1===void 0)throw new r("Invalid currency code for rounding.");let n=t$1.getDecimalPlaces(r$1),c=Math.pow(10,n);return Math.round(e*c)/c}};export{d as a};//# sourceMappingURL=chunk-3HKY6ZOF.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-3HKY6ZOF.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Classes/Price.ts"],"names":["PriceModel","_PriceModel","#kind","data","InvalidPriceAmountError","InvalidCurrencyCodeError","obj","priceModel","CurrencyMismatchError","InvalidArgumentError","factor","divisor","priceModels","minPrice","currentPrice","maxPrice","amount","currency","options","locale","CurrencyLocaleMap","valueToFormat","fractionDigits","formattingOptions","error","CurrencySymbolMap","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"kFAgBA,IAAqBA,EAArB,MAAqBC,GAAW,CAC9BC,EAAAA,CACU,OACA,QAQV,CAAA,WAAA,CAAYC,CAAuB,CAAA,CAEjC,GADA,IAAKD,CAAAA,EAAAA,CAAQ,aACTC,CAAK,CAAA,MAAA,CAAS,EAChB,MAAM,IAAIC,CAAwB,CAAA,4BAA4B,EAGhE,GAAI,CAACD,CAAK,CAAA,QAAA,CACR,MAAM,IAAIE,CAAAA,CAAyB,4BAA4B,CAAA,CAGjE,KAAK,MAASF,CAAAA,CAAAA,CAAK,OACnB,IAAK,CAAA,QAAA,CAAWA,EAAK,SACvB,CAEA,IAAI,IAAA,EAAO,CACT,OAAO,IAAA,CAAKD,EACd,CAEA,OAAO,YAAaI,CAAAA,CAAAA,CAAiC,CACnD,OAAO,OAAOA,CAAQ,EAAA,QAAA,EACpBA,IAAQ,IACPA,EAAAA,CAAAA,CAAY,OAAS,YAC1B,CAMO,WAA4B,EAAA,CACjC,OAAO,IAAK,CAAA,QACd,CAKO,SAAoB,EAAA,CACzB,OAAO,IAAK,CAAA,MACd,CAMO,UAAA,EAAwB,CAC7B,OAAO,CACL,OAAQ,IAAK,CAAA,MAAA,CACb,SAAU,IAAK,CAAA,QACjB,CACF,CAoCO,UAAUC,CAAgC,CAAA,CAC/C,GAAKN,GAAAA,CAAW,aAAaM,CAAU,CAAA,CAAA,CAEhC,GAAI,IAAA,CAAK,WAAaA,CAAW,CAAA,WAAA,GACtC,MAAM,IAAIC,EAAsB,gDAAgD,CAAA,CAAA,KAF1E,MAAA,IAAIC,EAAqB,gCAAgC,CAAA,CAKjE,OAAO,IAAA,CAAK,OAASF,CAAW,CAAA,SAAA,EAClC,CAEO,IAAIA,CAAoC,CAAA,CAC7C,GAAKN,GAAW,CAAA,YAAA,C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CAAgBC,CAAAA,GAAAA,CAAgC,CACtE,GAAID,EAAS,CACX,CAAA,MAAM,IAAIZ,CAAAA,CAAwB,yCAAyC,CAG7E,CAAA,GAAIa,MAAa,KACf,CAAA,CAAA,MAAM,IAAIZ,CAAyB,CAAA,qCAAqC,CAG1E,CAAA,IAAMyB,EAAgB7B,GAAW,CAAA,gBAAA,CAAiBgB,GAAQ,CACpDc,CAAAA,CAAAA,CAAa,KAAK,GAAI,CAAA,EAAA,CAAID,CAAa,CAAA,CAG7C,OAFqB,IAAK,CAAA,KAAA,CAAMd,EAASe,CAAU,CAAA,CAAIA,CAGzD,CACF","file":"chunk-XHGUVYQO.mjs","sourcesContent":["import { CurrencyCode } from \"./Common\";\r\nimport { CurrencyLocaleMap, CurrencySymbolMap, OperationalCountryCurrency } from \"./Enum\";\r\nimport {\r\n InvalidPriceAmountError,\r\n InvalidCurrencyCodeError,\r\n CurrencyMismatchError,\r\n InvalidArgumentError\r\n} from \"./Error\";\r\n\r\nexport type PriceAttributes = {\r\n amount: number;\r\n currency: CurrencyCode;\r\n}\r\n\r\nexport type PriceData = PriceAttributes;\r\n\r\nexport default class PriceModel {\r\n #kind: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param amount - The initial price value.\r\n * @param currency - The currency code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(data: PriceAttributes) {\r\n this.#kind = \"PriceModel\";\r\n if (data.amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative.\");\r\n }\r\n\r\n if (!data.currency) {\r\n throw new InvalidCurrencyCodeError(\"Currency code is required.\");\r\n }\r\n\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n }\r\n\r\n get kind() {\r\n return this.#kind;\r\n }\r\n\r\n static isPriceModel(obj: unknown): obj is PriceModel {\r\n return typeof obj === \"object\" &&\r\n obj !== null &&\r\n (obj as any).kind === \"PriceModel\";\r\n }\r\n\r\n /**\r\n * Gets the currency associated with this price instance.\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 * Returns the raw numeric price value.\r\n */\r\n public getAmount(): number {\r\n return this.amount;\r\n }\r\n\r\n /**\r\n *\r\n * @returns PriceData\r\n */\r\n public getDetails(): PriceData {\r\n return {\r\n amount: this.amount,\r\n currency: this.currency\r\n }\r\n }\r\n\r\n /**\r\n * Compares this price with another {@link PriceModel} instance.\r\n *\r\n * The comparison is performed using the numeric price value and is only valid\r\n * when both prices are expressed in the same currency.\r\n *\r\n * ### Comparison result:\r\n * - Returns a **negative number** if this price is **less than** `priceModel`\r\n * - Returns **zero** if both prices are **equal**\r\n * - Returns a **positive number** if this price is **greater than** `priceModel`\r\n *\r\n * @param priceModel - The {@link PriceModel} instance to compare against.\r\n *\r\n * @returns\r\n * A signed number representing the comparison result:\r\n * - `< 0` → this price is lower\r\n * - `0` → prices are equal\r\n * - `> 0` → this price is higher\r\n *\r\n * @throws {Error}\r\n * Throws an error if:\r\n * - `priceModel` is not an instance of {@link PriceModel}\r\n * - The currencies of the two prices do not match\r\n *\r\n * @example\r\n * ```ts\r\n * const a = new PriceModel(\"USD\", 100);\r\n * const b = new PriceModel(\"USD\", 150);\r\n *\r\n * a.compareTo(b); // -50\r\n * b.compareTo(a); // 50\r\n * a.compareTo(a); // 0\r\n * ```\r\n */\r\n public compareTo(priceModel: PriceModel): number {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return this.amount - priceModel.getAmount();\r\n }\r\n\r\n public add(priceModel: PriceModel): PriceModel {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot add prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount + priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public subtract(priceModel: PriceModel): PriceModel {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot subtract prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount - priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public multiply(factor: number | PriceModel): PriceModel {\r\n if (PriceModel.isPriceModel(factor)) {\r\n if (this.currency !== factor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot multiply prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount * factor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof factor === \"number\" && factor >= 0) {\r\n return new PriceModel({\r\n amount: this.amount * factor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a non-negative number.\");\r\n }\r\n\r\n public divide(divisor: number | PriceModel): PriceModel {\r\n if (PriceModel.isPriceModel(divisor)) {\r\n if (this.currency !== divisor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot divide prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount / divisor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof divisor === \"number\" && divisor > 0) {\r\n return new PriceModel({\r\n amount: this.amount / divisor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a positive number.\");\r\n }\r\n\r\n public min(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((minPrice, currentPrice) => {\r\n if (!PriceModel.isPriceModel(currentPrice)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (minPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return minPrice.compareTo(currentPrice) < 0 ? minPrice : currentPrice;\r\n }, this);\r\n }\r\n\r\n public max(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((maxPrice, currentPrice) => {\r\n if (!PriceModel.isPriceModel(currentPrice)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (maxPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return maxPrice.compareTo(currentPrice) > 0 ? maxPrice : currentPrice;\r\n }, this);\r\n }\r\n\r\n /**\r\n * Gets a zero value PriceModel for the same currency.\r\n * @returns A PriceModel instance representing zero in the same currency.\r\n */\r\n public zero(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: 0\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the price is zero.\r\n * @returns True if the price is zero, false otherwise.\r\n */\r\n public isZero(): boolean {\r\n return this.amount === 0;\r\n }\r\n\r\n\r\n public round(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: this.getRoundedAmount()\r\n });\r\n }\r\n\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedAmount(): number {\r\n return PriceModel.getRoundedAmount(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price stored in this instance.\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n public getFormattedString() {\r\n return PriceModel.getFormattedString(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n toString() {\r\n return this.getFormattedString();\r\n }\r\n\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the amount.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param amount - The initial amount value.\r\n * @param currency - The currency code for formatting.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the amount rounded to the next nearest integer (no decimals). Defaults to false.\r\n * @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.\r\n * @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.\r\n * @returns The formatted price string according to locale rules.\r\n * @throws {Error} If currency code is invalid.\r\n */\r\n static getFormattedString(amount: number, currency: CurrencyCode, options: {\r\n displayAsInteger?: boolean,\r\n style?: 'currency' | 'decimal',\r\n currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name'\r\n } = {\r\n displayAsInteger: false,\r\n style: 'currency',\r\n currencyDisplay: 'symbol'\r\n }): string {\r\n\r\n const locale = CurrencyLocaleMap[currency];\r\n if (!currency || !locale) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for formatting.');\r\n }\r\n\r\n let valueToFormat = amount;\r\n const fractionDigits = options.displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: options.style ?? 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (options.displayAsInteger) {\r\n valueToFormat = Math.ceil(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for currency \"${currency}\" and locale \"${locale}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case OperationalCountryCurrency.INR:\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param currency - The currency code to determine the rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the price is negative or currency is invalid.\r\n */\r\n static getRoundedAmount(amount: number, currency: CurrencyCode): number {\r\n if (amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative for rounding.\");\r\n }\r\n\r\n if (currency === undefined) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for rounding.');\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(amount * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"sources":["../src/Classes/Price.ts"],"names":["PriceModel","_PriceModel","#kind","data","InvalidPriceAmountError","InvalidCurrencyCodeError","obj","priceModel","CurrencyMismatchError","InvalidArgumentError","factor","divisor","priceModels","minPrice","currentPrice","maxPrice","amount","currency","options","locale","CurrencyLocaleMap","valueToFormat","fractionDigits","formattingOptions","error","CurrencySymbolMap","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"kFAgBA,IAAqBA,EAArB,MAAqBC,GAAW,CAC9BC,EAAAA,CACU,OACA,QAQV,CAAA,WAAA,CAAYC,CAAuB,CAAA,CAEjC,GADA,IAAKD,CAAAA,EAAAA,CAAQ,aACTC,CAAK,CAAA,MAAA,CAAS,EAChB,MAAM,IAAIC,CAAwB,CAAA,4BAA4B,EAGhE,GAAI,CAACD,CAAK,CAAA,QAAA,CACR,MAAM,IAAIE,CAAAA,CAAyB,4BAA4B,CAAA,CAGjE,KAAK,MAASF,CAAAA,CAAAA,CAAK,OACnB,IAAK,CAAA,QAAA,CAAWA,EAAK,SACvB,CAEA,IAAI,IAAA,EAAO,CACT,OAAO,IAAA,CAAKD,EACd,CAEA,OAAO,YAAaI,CAAAA,CAAAA,CAAiC,CACnD,OAAO,OAAOA,CAAQ,EAAA,QAAA,EACpBA,IAAQ,IACPA,EAAAA,CAAAA,CAAY,OAAS,YAC1B,CAMO,WAA4B,EAAA,CACjC,OAAO,IAAK,CAAA,QACd,CAKO,SAAoB,EAAA,CACzB,OAAO,IAAK,CAAA,MACd,CAMO,UAAA,EAAwB,CAC7B,OAAO,CACL,OAAQ,IAAK,CAAA,MAAA,CACb,SAAU,IAAK,CAAA,QACjB,CACF,CAoCO,UAAUC,CAAgC,CAAA,CAC/C,GAAKN,GAAAA,CAAW,aAAaM,CAAU,CAAA,CAAA,CAEhC,GAAI,IAAA,CAAK,WAAaA,CAAW,CAAA,WAAA,GACtC,MAAM,IAAIC,EAAsB,gDAAgD,CAAA,CAAA,KAF1E,MAAA,IAAIC,EAAqB,g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CAAM,CAAA,CAAC,EAAI,EAGxD,CAAA,OADyBC,EAAY,OAAQ,CAAA,uBAAA,CAAyB,GAAG,CAC/CC,CAAAA,CAC5B,CAWA,OAAO,iBAAiBb,CAAgBC,CAAAA,GAAAA,CAAgC,CACtE,GAAID,EAAS,CACX,CAAA,MAAM,IAAIZ,CAAAA,CAAwB,yCAAyC,CAG7E,CAAA,GAAIa,MAAa,KACf,CAAA,CAAA,MAAM,IAAIZ,CAAyB,CAAA,qCAAqC,CAG1E,CAAA,IAAMyB,EAAgB7B,GAAW,CAAA,gBAAA,CAAiBgB,GAAQ,CACpDc,CAAAA,CAAAA,CAAa,KAAK,GAAI,CAAA,EAAA,CAAID,CAAa,CAAA,CAG7C,OAFqB,IAAK,CAAA,KAAA,CAAMd,EAASe,CAAU,CAAA,CAAIA,CAGzD,CACF","file":"chunk-3HKY6ZOF.mjs","sourcesContent":["import { CurrencyCode } from \"./Common\";\r\nimport { CurrencyLocaleMap, CurrencySymbolMap, OperationalCountryCurrency } from \"./Enum\";\r\nimport {\r\n InvalidPriceAmountError,\r\n InvalidCurrencyCodeError,\r\n CurrencyMismatchError,\r\n InvalidArgumentError\r\n} from \"./Error\";\r\n\r\nexport type PriceAttributes = {\r\n amount: number;\r\n currency: CurrencyCode;\r\n}\r\n\r\nexport type PriceData = PriceAttributes;\r\n\r\nexport default class PriceModel {\r\n #kind: string;\r\n protected amount: number;\r\n protected currency: CurrencyCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param amount - The initial price value.\r\n * @param currency - The currency code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(data: PriceAttributes) {\r\n this.#kind = \"PriceModel\";\r\n if (data.amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative.\");\r\n }\r\n\r\n if (!data.currency) {\r\n throw new InvalidCurrencyCodeError(\"Currency code is required.\");\r\n }\r\n\r\n this.amount = data.amount;\r\n this.currency = data.currency;\r\n }\r\n\r\n get kind() {\r\n return this.#kind;\r\n }\r\n\r\n static isPriceModel(obj: unknown): obj is PriceModel {\r\n return typeof obj === \"object\" &&\r\n obj !== null &&\r\n (obj as any).kind === \"PriceModel\";\r\n }\r\n\r\n /**\r\n * Gets the currency associated with this price instance.\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 * Returns the raw numeric price value.\r\n */\r\n public getAmount(): number {\r\n return this.amount;\r\n }\r\n\r\n /**\r\n *\r\n * @returns PriceData\r\n */\r\n public getDetails(): PriceData {\r\n return {\r\n amount: this.amount,\r\n currency: this.currency\r\n }\r\n }\r\n\r\n /**\r\n * Compares this price with another {@link PriceModel} instance.\r\n *\r\n * The comparison is performed using the numeric price value and is only valid\r\n * when both prices are expressed in the same currency.\r\n *\r\n * ### Comparison result:\r\n * - Returns a **negative number** if this price is **less than** `priceModel`\r\n * - Returns **zero** if both prices are **equal**\r\n * - Returns a **positive number** if this price is **greater than** `priceModel`\r\n *\r\n * @param priceModel - The {@link PriceModel} instance to compare against.\r\n *\r\n * @returns\r\n * A signed number representing the comparison result:\r\n * - `< 0` → this price is lower\r\n * - `0` → prices are equal\r\n * - `> 0` → this price is higher\r\n *\r\n * @throws {Error}\r\n * Throws an error if:\r\n * - `priceModel` is not an instance of {@link PriceModel}\r\n * - The currencies of the two prices do not match\r\n *\r\n * @example\r\n * ```ts\r\n * const a = new PriceModel(\"USD\", 100);\r\n * const b = new PriceModel(\"USD\", 150);\r\n *\r\n * a.compareTo(b); // -50\r\n * b.compareTo(a); // 50\r\n * a.compareTo(a); // 0\r\n * ```\r\n */\r\n public compareTo(priceModel: PriceModel): number {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return this.amount - priceModel.getAmount();\r\n }\r\n\r\n public add(priceModel: PriceModel): PriceModel {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot add prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount + priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public subtract(priceModel: PriceModel): PriceModel {\r\n if (!PriceModel.isPriceModel(priceModel)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (this.currency !== priceModel.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot subtract prices in different currencies.\");\r\n }\r\n\r\n return new PriceModel({\r\n amount: this.amount - priceModel.getAmount(),\r\n currency: this.currency\r\n });\r\n }\r\n\r\n public multiply(factor: number | PriceModel): PriceModel {\r\n if (PriceModel.isPriceModel(factor)) {\r\n if (this.currency !== factor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot multiply prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount * factor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof factor === \"number\" && factor >= 0) {\r\n return new PriceModel({\r\n amount: this.amount * factor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a non-negative number.\");\r\n }\r\n\r\n public divide(divisor: number | PriceModel): PriceModel {\r\n if (PriceModel.isPriceModel(divisor)) {\r\n if (this.currency !== divisor.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot divide prices in different currencies.\");\r\n }\r\n return new PriceModel({\r\n amount: this.amount / divisor.getAmount(),\r\n currency: this.currency\r\n });\r\n } else if (typeof divisor === \"number\" && divisor > 0) {\r\n return new PriceModel({\r\n amount: this.amount / divisor,\r\n currency: this.currency\r\n });\r\n }\r\n\r\n throw new InvalidArgumentError(\"Must be a positive number.\");\r\n }\r\n\r\n public min(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((minPrice, currentPrice) => {\r\n if (!PriceModel.isPriceModel(currentPrice)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (minPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return minPrice.compareTo(currentPrice) < 0 ? minPrice : currentPrice;\r\n }, this);\r\n }\r\n\r\n public max(...priceModels: PriceModel[]): PriceModel {\r\n if (priceModels.length === 0) {\r\n throw new InvalidArgumentError(\"Must provide at least one PriceModel.\");\r\n }\r\n\r\n return priceModels.reduce((maxPrice, currentPrice) => {\r\n if (!PriceModel.isPriceModel(currentPrice)) {\r\n throw new InvalidArgumentError(\"Must be a PriceModel instance.\");\r\n } else if (maxPrice.getCurrency() !== currentPrice.getCurrency()) {\r\n throw new CurrencyMismatchError(\"Cannot compare prices in different currencies.\");\r\n }\r\n\r\n return maxPrice.compareTo(currentPrice) > 0 ? maxPrice : currentPrice;\r\n }, this);\r\n }\r\n\r\n /**\r\n * Gets a zero value PriceModel for the same currency.\r\n * @returns A PriceModel instance representing zero in the same currency.\r\n */\r\n public zero(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: 0\r\n });\r\n }\r\n\r\n /**\r\n * Checks if the price is zero.\r\n * @returns True if the price is zero, false otherwise.\r\n */\r\n public isZero(): boolean {\r\n return this.amount === 0;\r\n }\r\n\r\n\r\n public round(): PriceModel {\r\n return new PriceModel({\r\n currency: this.currency,\r\n amount: this.getRoundedAmount()\r\n });\r\n }\r\n\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedAmount(): number {\r\n return PriceModel.getRoundedAmount(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price stored in this instance.\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n public getFormattedString() {\r\n return PriceModel.getFormattedString(this.amount, this.currency);\r\n }\r\n\r\n /**\r\n * Uses the static `PriceModel.getFormattedString` method for the actual formatting.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n toString() {\r\n return this.getFormattedString();\r\n }\r\n\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the amount.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param amount - The initial amount value.\r\n * @param currency - The currency code for formatting.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the amount rounded to the next nearest integer (no decimals). Defaults to false.\r\n * @param options.style - The style of formatting, either 'currency' or 'decimal'. Defaults to 'currency'.\r\n * @param options.currencyDisplay - The display format for the currency symbol. Options are 'symbol', 'narrowSymbol', 'code', or 'name'. Defaults to 'symbol'.\r\n * @returns The formatted price string according to locale rules.\r\n * @throws {Error} If currency code is invalid.\r\n */\r\n static getFormattedString(amount: number, currency: CurrencyCode, options: {\r\n displayAsInteger?: boolean,\r\n style?: 'currency' | 'decimal',\r\n currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name'\r\n } = {\r\n displayAsInteger: false,\r\n style: 'currency',\r\n currencyDisplay: 'symbol'\r\n }): string {\r\n\r\n const locale = CurrencyLocaleMap[currency];\r\n if (!currency || !locale) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for formatting.');\r\n }\r\n\r\n let valueToFormat = amount;\r\n const fractionDigits = options.displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: options.style ?? 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (options.displayAsInteger) {\r\n valueToFormat = Math.ceil(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for currency \"${currency}\" and locale \"${locale}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case OperationalCountryCurrency.INR:\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param currency - The currency code to determine the rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the price is negative or currency is invalid.\r\n */\r\n static getRoundedAmount(amount: number, currency: CurrencyCode): number {\r\n if (amount < 0) {\r\n throw new InvalidPriceAmountError(\"Amount cannot be negative for rounding.\");\r\n }\r\n\r\n if (currency === undefined) {\r\n throw new InvalidCurrencyCodeError('Invalid currency code for rounding.');\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(amount * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n}"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {c}from'./chunk-JCUHTCOC.mjs';import {a as a$2}from'./chunk-OAE2FJFJ.mjs';import {a as a$1}from'./chunk-3HKY6ZOF.mjs';import {e}from'./chunk-GFMGTV5E.mjs';import {v,j}from'./chunk-XPKK6DFA.mjs';import {a}from'./chunk-UXZBULDS.mjs';var h=class extends a{id;name;category;lineItemId;chargeType;impact;taxTreatment;pricing;total;constructor(t){if(super(t),this.id=t.id,this.name=t.name,this.category=t.category,this.lineItemId=t.lineItemId,this.chargeType=t.chargeType,this.impact=t.impact??"ADD",this.taxTreatment=t.taxTreatment??"APPLY",this.pricing={price:new a$1(t.pricing.price),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(e=>new c(e))},this.chargeType!=="ADJUSTMENT"){if(this.impact!=="ADD")throw new v("Only adjustment charges can be subtractive.");if(this.taxTreatment!=="APPLY")throw new v("Non-adjustment charges must apply tax.")}else {if(this.taxTreatment!=="EXEMPT")throw new v("Adjustment charges must be tax exempt.");if(this.pricing.applicableTaxRule.length>0)throw new v("Adjustment charges cannot have tax rules.")}this.total={price:new a$1(t.total.price),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([e,a])=>[e,new a$1(a)])),totalDiscount:new a$1(t.total.totalDiscount),netPrice:new a$1(t.total.netPrice),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([e,a])=>[e,{rate:a.rate,taxablePrice:new a$1(a.taxablePrice),amount:new a$1(a.amount),system:a.system,subSystem:a.subSystem}])),taxTotal:new a$1(t.total.taxTotal),grandTotal:new a$1(t.total.grandTotal)};}getId(){return this.id}getName(t){return t?a$2.deepClone(this.name[t]??this.name[e[t]]??this.name.en):a$2.deepClone(this.name)}getCategory(){return this.category}getChargeType(){return this.chargeType}getImpact(){return this.impact}getTaxTreatment(){return this.taxTreatment}getLineItemId(){return this.lineItemId}getPricing(){return {price:this.pricing.price,taxCategory:this.pricing.taxCategory,applicableTaxRule:[...this.pricing.applicableTaxRule]}}getTotal(){return {price:this.total.price,discounts:{...this.total.discounts},netPrice:this.total.netPrice,totalDiscount:this.total.totalDiscount,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{rate:e.rate,taxablePrice:e.taxablePrice,amount:e.amount,system:e.system,subSystem:e.subSystem}])),taxTotal:this.total.taxTotal,grandTotal:this.total.grandTotal}}getApplicableTaxRules(){return [...this.pricing.applicableTaxRule]}updateTax(t){if(this.chargeType==="ADJUSTMENT")throw new v("Adjustment charges cannot apply tax rules.");t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getTaxCountry()))throw new j}),this.pricing.applicableTaxRule=t,this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(a=>{e[a.coupon.getCode()]=a.amount;}),this.total.discounts=e,this.calculateTotals();}calculateTotals(){let t=this.pricing.price.zero(),e=this.pricing.price,a=Object.values(this.total.discounts).reduce((i,o)=>i.add(o),t),c=e.subtract(a);if(this.taxTreatment==="EXEMPT"){this.total={price:e,discounts:this.total.discounts,netPrice:c,totalDiscount:a,taxBreakdown:{},taxTotal:t,grandTotal:c};return}let m={},n=this.pricing.applicableTaxRule.reduce((i,o)=>i+o.getApplicableTaxRate(),0),l=c.divide(1+n).round(),u=n>0?c.subtract(l):t,d=t,p=this.pricing.applicableTaxRule.reduce((i,o)=>o.getApplicableTaxRate()>i.getApplicableTaxRate()?o:i),T=p.getTaxRuleId();this.pricing.applicableTaxRule.forEach(i=>{if(i.getTaxRuleId()===T)return;let o=i.getApplicableTaxRate(),x=n>0?u.multiply(o).divide(n).round():t;m[i.getTaxRuleId()]={rate:o,taxablePrice:l,amount:x,system:i.getTaxSystem(),subSystem:i.getTaxSubSystem()},d=d.add(x);});let D=u.subtract(d);m[T]={rate:p.getApplicableTaxRate(),taxablePrice:l,amount:D,system:p.getTaxSystem(),subSystem:p.getTaxSubSystem()};let R=l,w=c;this.total={price:e,discounts:this.total.discounts,netPrice:R,totalDiscount:a,taxBreakdown:m,taxTotal:u,grandTotal:w};}getDetails(){return {id:this.id,name:a$2.deepClone(this.name),category:this.category,lineItemId:this.lineItemId,chargeType:this.chargeType,impact:this.impact,taxTreatment:this.taxTreatment,pricing:{price:this.pricing.price.getDetails(),taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule.map(e=>e.getDetails())},total:{price:this.total.price.getDetails(),discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([e,a])=>[e,a.getDetails()])),totalDiscount:this.total.totalDiscount.getDetails(),netPrice:this.total.netPrice.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([e,a])=>[e,{rate:a.rate,taxablePrice:a.taxablePrice.getDetails(),amount:a.amount.getDetails(),system:a.system,subSystem:a.subSystem}])),taxTotal:this.total.taxTotal.getDetails(),grandTotal:this.total.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}};export{h as a};//# sourceMappingURL=chunk-4ZFZXWD7.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-4ZFZXWD7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Classes/Charge.ts"],"names":["ChargeModel","CustomFieldModel","data","PriceModel","r","FixedTaxRuleModel","InvalidChargeError","discountId","discount","taxRuleId","taxBreakdown","locale","Utils_default","LocaleLanguageMap","key","value","taxRules","taxRule","InvalidTaxRuleError","appliedDiscounts","chargeDiscounts","zero","price","totalDiscount","sum","s","grossAmount","totalRate","taxableBase","totalTaxAmount","distributedTax","maxRateRule","prev","current","maxRateRuleId","rate","taxAmount","maxRateTaxAmount","netPrice","grandTotal","k","v"],"mappings":"8OAyEqBA,IAAAA,CAAAA,CAArB,cAAyCC,CAAiB,CAC5C,GACA,IACA,CAAA,QAAA,C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AAK,KAAM,CAAA,SAAS,EAAE,GAAI,CAAA,CAAC,CAACoC,CAAAA,CAAGC,CAAC,CAAA,GAAM,CAACD,CAAGC,CAAAA,CAAAA,CAAE,YAAY,CAAC,CAAC,CACvG,CAAA,aAAA,CAAe,IAAK,CAAA,KAAA,CAAM,aAAc,CAAA,UAAA,GACxC,QAAU,CAAA,IAAA,CAAK,KAAM,CAAA,QAAA,CAAS,UAAW,EAAA,CACzC,aAAc,MAAO,CAAA,WAAA,CAAY,MAAO,CAAA,OAAA,CAAQ,IAAK,CAAA,KAAA,CAAM,YAAY,CAAE,CAAA,GAAA,CAAI,CAAC,CAACD,CAAAA,CAAGC,CAAC,CAAM,GAAA,CAACD,CAAG,CAAA,CACzF,IAAMC,CAAAA,CAAAA,CAAE,KACR,YAAcA,CAAAA,CAAAA,CAAE,YAAa,CAAA,UAAA,EAC7B,CAAA,MAAA,CAAQA,EAAE,MAAO,CAAA,UAAA,EACjB,CAAA,MAAA,CAAQA,CAAE,CAAA,MAAA,CACV,UAAWA,CAAE,CAAA,SACjB,CAAC,CAAC,CAAC,EACH,QAAU,CAAA,IAAA,CAAK,KAAM,CAAA,QAAA,CAAS,UAAW,EAAA,CACzC,WAAY,IAAK,CAAA,KAAA,CAAM,UAAW,CAAA,UAAA,EACtC,CAAA,CACA,aAAc,IAAK,CAAA,kBAAA,EACvB,CAEJ,CACJ","file":"chunk-4ZFZXWD7.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData, CustomFieldAttributes, CustomFieldModel } from \"./Base\";\r\nimport Utils from \"../Utils\";\r\nimport { LocaleCode, LocalizedString } from \"./Common\";\r\nimport { ChargeImpact, ChargeTaxTreatment, ChargeType, LocaleLanguageMap, TaxSystem } from \"./Enum\";\r\nimport { InvalidChargeError, InvalidTaxRuleError } from \"./Error\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { FixedTaxRuleData, FixedTaxRuleModel } from \"./TaxRule\";\r\nimport CouponModel from \"./Coupon\";\r\n\r\nexport type ChargePricing = {\r\n price: PriceData;\r\n taxCategory: string;\r\n applicableTaxRule: FixedTaxRuleData[];\r\n};\r\n\r\nexport type ChargeTaxBreakdown = {\r\n rate: number;\r\n taxablePrice: PriceData;\r\n amount: PriceData;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type ChargeTaxBreakdownModel = {\r\n rate: number;\r\n taxablePrice: PriceModel;\r\n amount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type ChargeTotals = {\r\n price: PriceData;\r\n discounts: Record<string, PriceData>;\r\n totalDiscount: PriceData;\r\n netPrice: PriceData;\r\n taxBreakdown: Record<string, ChargeTaxBreakdown>;\r\n taxTotal: PriceData;\r\n grandTotal: PriceData;\r\n};\r\n\r\nexport type ChargeTotalsModel = {\r\n price: PriceModel;\r\n discounts: Record<string, PriceModel>;\r\n totalDiscount: PriceModel;\r\n netPrice: PriceModel;\r\n taxBreakdown: Record<string, ChargeTaxBreakdownModel>;\r\n taxTotal: PriceModel;\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type ChargeAttributes = CustomFieldAttributes & {\r\n id: string;\r\n name: LocalizedString;\r\n category: string;\r\n lineItemId?: string;\r\n chargeType: ChargeType;\r\n impact?: ChargeImpact;\r\n taxTreatment?: ChargeTaxTreatment;\r\n pricing: ChargePricing;\r\n total: ChargeTotals;\r\n};\r\n\r\nexport type ChargeData = Omit<Required<ChargeAttributes>, 'lineItemId' | 'impact' | 'taxTreatment'> & {\r\n lineItemId?: string;\r\n impact?: ChargeImpact;\r\n taxTreatment?: ChargeTaxTreatment;\r\n};\r\n\r\n/**\r\n * Represents an additional charge (or discount if amount is negative) in a shopping container.\r\n * Supports its own tax rules.\r\n */\r\nexport default class ChargeModel extends CustomFieldModel {\r\n protected id: string;\r\n protected name: LocalizedString;\r\n protected category: string;\r\n protected lineItemId?: string;\r\n protected chargeType: ChargeType;\r\n protected impact: ChargeImpact;\r\n protected taxTreatment: ChargeTaxTreatment;\r\n protected pricing: {\r\n price: PriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: FixedTaxRuleModel[];\r\n };\r\n protected total: ChargeTotalsModel;\r\n\r\n constructor(data: ChargeAttributes) {\r\n super(data);\r\n this.id = data.id;\r\n this.name = data.name;\r\n this.category = data.category;\r\n this.lineItemId = data.lineItemId;\r\n this.chargeType = data.chargeType;\r\n this.impact = data.impact ?? ChargeImpact.ADD;\r\n this.taxTreatment = data.taxTreatment ?? ChargeTaxTreatment.APPLY;\r\n this.pricing = {\r\n price: new PriceModel(data.pricing.price),\r\n taxCategory: data.pricing.taxCategory,\r\n applicableTaxRule: data.pricing.applicableTaxRule.map(r => new FixedTaxRuleModel(r))\r\n };\r\n\r\n if (this.chargeType !== ChargeType.ADJUSTMENT) {\r\n if (this.impact !== ChargeImpact.ADD) {\r\n throw new InvalidChargeError(\"Only adjustment charges can be subtractive.\");\r\n }\r\n if (this.taxTreatment !== ChargeTaxTreatment.APPLY) {\r\n throw new InvalidChargeError(\"Non-adjustment charges must apply tax.\");\r\n }\r\n } else {\r\n if (this.taxTreatment !== ChargeTaxTreatment.EXEMPT) {\r\n throw new InvalidChargeError(\"Adjustment charges must be tax exempt.\");\r\n }\r\n if (this.pricing.applicableTaxRule.length > 0) {\r\n throw new InvalidChargeError(\"Adjustment charges cannot have tax rules.\");\r\n }\r\n }\r\n\r\n this.total = {\r\n price: new PriceModel(data.total.price),\r\n discounts: Object.fromEntries(\r\n Object.entries(data.total.discounts).map(([discountId, discount]) => [\r\n discountId,\r\n new PriceModel(discount)\r\n ])\r\n ),\r\n totalDiscount: new PriceModel(data.total.totalDiscount),\r\n netPrice: new PriceModel(data.total.netPrice),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(data.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxablePrice: new PriceModel(taxBreakdown.taxablePrice),\r\n amount: new PriceModel(taxBreakdown.amount),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n grandTotal: new PriceModel(data.total.grandTotal),\r\n };\r\n }\r\n\r\n /**\r\n * Gets the unique identifier of the charge.\r\n * @returns \r\n */\r\n public getId(): string { return this.id; }\r\n\r\n\r\n /**\r\n * Gets the full localized product name object.\r\n * @returns A copy of the LocalizedString object for the name.\r\n */\r\n getName(): LocalizedString\r\n /**\r\n * Gets the product name for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The name string for the specified locale.\r\n */\r\n getName(locale: LocaleCode): string\r\n getName(locale?: LocaleCode): LocalizedString | string {\r\n if (locale) {\r\n return Utils.deepClone(this.name[locale] ?? this.name[LocaleLanguageMap[locale]] ?? this.name.en);\r\n } else {\r\n return Utils.deepClone(this.name);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the charge category.\r\n * @returns The category string.\r\n */\r\n public getCategory(): string { return this.category; }\r\n\r\n /**\r\n * Gets the charge type.\r\n * @returns The charge type enum value.\r\n */\r\n public getChargeType(): ChargeType { return this.chargeType; }\r\n /**\r\n * Gets the charge impact (add or subtract).\r\n * @returns The charge impact.\r\n */\r\n public getImpact(): ChargeImpact { return this.impact; }\r\n /**\r\n * Gets how tax is treated for this charge.\r\n * @returns The tax treatment for this charge.\r\n */\r\n public getTaxTreatment(): ChargeTaxTreatment { return this.taxTreatment; }\r\n\r\n /**\r\n * Gets the related line item id, if any.\r\n * @returns The line item id or undefined.\r\n */\r\n public getLineItemId(): string | undefined { return this.lineItemId; }\r\n\r\n /**\r\n * Gets the pricing details (models) for this charge.\r\n * @returns Pricing details including price, tax category, and tax rules.\r\n */\r\n public getPricing() {\r\n return {\r\n price: this.pricing.price,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: [...this.pricing.applicableTaxRule]\r\n };\r\n }\r\n \r\n /**\r\n * Gets the computed totals for this charge.\r\n * @returns Totals including discounts, taxes, and grand total.\r\n */\r\n public getTotal(): ChargeTotalsModel {\r\n return {\r\n price: this.total.price,\r\n discounts: { ...this.total.discounts },\r\n netPrice: this.total.netPrice,\r\n totalDiscount: this.total.totalDiscount,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([key, value]) => [\r\n key,\r\n {\r\n rate: value.rate,\r\n taxablePrice: value.taxablePrice,\r\n amount: value.amount,\r\n system: value.system,\r\n subSystem: value.subSystem\r\n }\r\n ])\r\n ),\r\n taxTotal: this.total.taxTotal,\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the applicable tax rules for this charge.\r\n * @returns A list of tax rules.\r\n */\r\n public getApplicableTaxRules(): FixedTaxRuleModel[] {\r\n return [...this.pricing.applicableTaxRule];\r\n }\r\n\r\n /**\r\n * Updates the tax rule for this line item and recalculates totals.\r\n * @param taxRule - The new tax rule to apply.\r\n * @throws {Error} If the tax rule category does not match the item's tax category.\r\n */\r\n public updateTax(taxRules: FixedTaxRuleModel[]): void {\r\n if (this.chargeType === ChargeType.ADJUSTMENT) {\r\n throw new InvalidChargeError(\"Adjustment charges cannot apply tax rules.\");\r\n }\r\n taxRules.forEach(taxRule => {\r\n if (!taxRule.appliesTo(this.pricing.taxCategory, taxRule.getTaxCountry())) {\r\n throw new InvalidTaxRuleError();\r\n }\r\n });\r\n\r\n // Remove the old taxableUnitPrice calculation - no longer needed\r\n this.pricing.applicableTaxRule = taxRules;\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the discounts applied to this line item and recalculates totals.\r\n * @param appliedDiscounts - List of coupons and their allocated discount amounts.\r\n */\r\n public updateDiscounts(appliedDiscounts: { coupon: CouponModel, amount: PriceModel }[]): void {\r\n let chargeDiscounts = {} as Record<string, PriceModel>;\r\n appliedDiscounts.forEach(discount => {\r\n chargeDiscounts[discount.coupon.getCode()] = discount.amount;\r\n });\r\n\r\n this.total.discounts = chargeDiscounts;\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Recalculates totals for this charge based on pricing and discounts.\r\n */\r\n public calculateTotals(): void {\r\n const zero = this.pricing.price.zero();\r\n const price = this.pricing.price;\r\n\r\n const totalDiscount = Object.values(this.total.discounts).reduce((sum, s) => sum.add(s), zero);\r\n const grossAmount = price.subtract(totalDiscount);\r\n\r\n if (this.taxTreatment === ChargeTaxTreatment.EXEMPT) {\r\n this.total = {\r\n price: price,\r\n discounts: this.total.discounts,\r\n netPrice: grossAmount,\r\n totalDiscount: totalDiscount,\r\n taxBreakdown: {},\r\n taxTotal: zero,\r\n grandTotal: grossAmount\r\n };\r\n return;\r\n }\r\n\r\n const taxBreakdown: Record<string, ChargeTaxBreakdownModel> = {};\r\n\r\n // 1. Calculate total rate for inclusive back-calculation\r\n const totalRate = this.pricing.applicableTaxRule.reduce((sum, r) => sum + r.getApplicableTaxRate(), 0);\r\n\r\n // 2. Calculate BASE and TOTAL TAX using balancing logic\r\n // We round the base first, then define tax as the residual (Gross - Base)\r\n // This guarantees Base + Tax === GrandTotal (inclusive price)\r\n const taxableBase = grossAmount.divide(1 + totalRate).round();\r\n const totalTaxAmount = totalRate > 0 ? grossAmount.subtract(taxableBase) : zero;\r\n\r\n // 3. Distribute total tax among rules\r\n // We find the rule with the largest rate to absorb the rounding residual\r\n let distributedTax = zero;\r\n const maxRateRule = this.pricing.applicableTaxRule.reduce((prev, current) =>\r\n (current.getApplicableTaxRate() > prev.getApplicableTaxRate()) ? current : prev\r\n );\r\n const maxRateRuleId = maxRateRule.getTaxRuleId();\r\n\r\n // Calculate all other rules first\r\n this.pricing.applicableTaxRule.forEach((taxRule) => {\r\n if (taxRule.getTaxRuleId() === maxRateRuleId) return;\r\n\r\n const rate = taxRule.getApplicableTaxRate();\r\n const taxAmount = totalRate > 0 ? totalTaxAmount.multiply(rate).divide(totalRate).round() : zero;\r\n\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxablePrice: taxableBase,\r\n amount: taxAmount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n distributedTax = distributedTax.add(taxAmount);\r\n });\r\n\r\n // Assign residual to the largest rate rule\r\n const maxRateTaxAmount = totalTaxAmount.subtract(distributedTax);\r\n taxBreakdown[maxRateRuleId] = {\r\n rate: maxRateRule.getApplicableTaxRate(),\r\n taxablePrice: taxableBase,\r\n amount: maxRateTaxAmount,\r\n system: maxRateRule.getTaxSystem(),\r\n subSystem: maxRateRule.getTaxSubSystem()\r\n };\r\n\r\n const netPrice = taxableBase;\r\n const grandTotal = grossAmount;\r\n\r\n this.total = {\r\n price: price,\r\n discounts: this.total.discounts,\r\n netPrice: netPrice,\r\n totalDiscount: totalDiscount,\r\n taxBreakdown: taxBreakdown,\r\n taxTotal: totalTaxAmount,\r\n grandTotal: grandTotal\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing this charge.\r\n * @returns ChargeData for serialization.\r\n */\r\n public getDetails(): ChargeData {\r\n const details: ChargeData = {\r\n id: this.id,\r\n name: Utils.deepClone(this.name),\r\n category: this.category,\r\n lineItemId: this.lineItemId,\r\n chargeType: this.chargeType,\r\n impact: this.impact,\r\n taxTreatment: this.taxTreatment,\r\n pricing: {\r\n price: this.pricing.price.getDetails(),\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: this.pricing.applicableTaxRule.map(r => r.getDetails())\r\n },\r\n total: {\r\n price: this.total.price.getDetails(),\r\n discounts: Object.fromEntries(Object.entries(this.total.discounts).map(([k, v]) => [k, v.getDetails()])),\r\n totalDiscount: this.total.totalDiscount.getDetails(),\r\n netPrice: this.total.netPrice.getDetails(),\r\n taxBreakdown: Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([k, v]) => [k, {\r\n rate: v.rate,\r\n taxablePrice: v.taxablePrice.getDetails(),\r\n amount: v.amount.getDetails(),\r\n system: v.system,\r\n subSystem: v.subSystem\r\n }])),\r\n taxTotal: this.total.taxTotal.getDetails(),\r\n grandTotal: this.total.grandTotal.getDetails()\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n return details;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var I=(n=>(n.IN="IN",n))(I||{}),D=(n=>(n.INR="INR",n))(D||{}),p=(R=>(R["en-IN"]="en-IN",R["kn-IN"]="kn-IN",R))(p||{}),u=(E=>(E.en="en",E.kn="kn",E))(u||{}),x={"en-IN":"en","kn-IN":"kn"},M={"en-IN":"IN","kn-IN":"IN"},a={IN:"INR"},S={INR:"\u20B9"},k={INR:"en-IN"},l=(o=>(o.MALE="Male",o.FEMALE="Female",o.UNISEX="Unisex",o.KIDS="Kids",o.BOY="Boy",o.GIRL="Girl",o.GENERAL="General",o))(l||{}),r=(E=>(E.PRIMARY="PRIMARY",E.GALLERY="GALLERY",E))(r||{}),A=(E=>(E.SHIPPING="SHIPPING",E.ADJUSTMENT="ADJUSTMENT",E))(A||{}),L=(E=>(E.ADD="ADD",E.SUBTRACT="SUBTRACT",E))(L||{}),c=(E=>(E.APPLY="APPLY",E.EXEMPT="EXEMPT",E))(c||{}),O=(n=>(n.GST="GST",n))(O||{}),P=(N=>(N.INITIAL="INITIAL",N.PROCESSING="PROCESSING",N.SHIPPED="SHIPPED",N.DELIVERED="DELIVERED",N.CANCELLED="CANCELLED",N.RETURN_REQUESTED="RETURN_REQUESTED",N.RETURNED="RETURNED",N.REFUND_INITIATED="REFUND_INITIATED",N.REFUNDED="REFUNDED",N.ON_HOLD="ON_HOLD",N))(P||{});export{I as a,D as b,p as c,u as d,x as e,M as f,a as g,S as h,k as i,l as j,r as k,A as l,L as m,c as n,O as o,P as p};//# sourceMappingURL=chunk-GFMGTV5E.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-GFMGTV5E.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Classes/Enum.ts"],"names":["OperationalCountry","OperationalCountryCurrency","OperationalLocale","OperationalLanguage","LocaleLanguageMap","LocaleCountryMap","CountryCurrencyMap","CurrencySymbolMap","CurrencyLocaleMap","GenderCategory","ImageCategory","ChargeType","ChargeImpact","ChargeTaxTreatment","TaxSystem","LineItemState"],"mappings":"AAGO,IAAKA,OACGA,CAAA,CAAA,EAAA,CAAK,IADRA,CAAAA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,IAIAC,CACGA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,GAAM,CAAA,KAAA,CADTA,OAAA,EAIAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACGA,CAAA,CAAA,OAAA,CAAA,CAAU,QACCA,CAAA,CAAA,OAAA,CAAA,CAAU,OAFxBA,CAAAA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,IAKAC,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,EAAK,CAAA,IAAA,CACLA,EAAA,EAAK,CAAA,IAAA,CAFKA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAKCC,EAAoE,CAC9E,OAAA,CAA6B,IAC7B,CAAA,OAAA,CAA6B,IAChC,CAEaC,CAAAA,CAAAA,CAAkE,CAC5E,OAAA,CAA6B,KAC7B,OAA6B,CAAA,IAChC,CAKaC,CAAAA,CAAAA,CAAqB,CACnB,EAAwB,CAAA,KACvC,CAEaC,CAAAA,CAAAA,CAAoB,CAC9B,GAAiC,CAAA,QACpC,CAEaC,CAAAA,CAAAA,CAAoB,CAC9B,GAAiC,CAAA,OACpC,CAKYC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,EAAA,IAAO,CAAA,MAAA,CACPA,CAAA,CAAA,MAAA,CAAS,SACTA,CAAA,CAAA,MAAA,CAAS,QACTA,CAAAA,CAAAA,CAAA,KAAO,MACPA,CAAAA,CAAAA,CAAA,GAAM,CAAA,KAAA,CACNA,EAAA,IAAO,CAAA,MAAA,CACPA,CAAA,CAAA,OAAA,CAAU,UAPAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAUAC,CACVA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,QAAU,SACVA,CAAAA,CAAAA,CAAA,OAAU,CAAA,SAAA,CAFAA,OAAA,EAKAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAA,CAAA,QAAA,CAAW,WACXA,CAAA,CAAA,UAAA,CAAa,YAFHA,CAAAA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,IAKAC,CACRA,CAAAA,CAAAA,CAAAA,GAAAA,CAAAA,CAAA,GAAM,CAAA,KAAA,CACNA,EAAA,QAAW,CAAA,UAAA,CAFHA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAKAC,OACRA,CAAA,CAAA,KAAA,CAAQ,OACRA,CAAAA,CAAAA,CAAA,OAAS,QAFDA,CAAAA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAKAC,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,EAAA,GAAM,CAAA,KAAA,CADIA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA,CAAA,CAkBAC,OACVA,CAAA,CAAA,OAAA,CAAU,SACVA,CAAAA,CAAAA,CAAA,WAAa,YACbA,CAAAA,CAAAA,CAAA,OAAU,CAAA,SAAA,CACVA,EAAA,SAAY,CAAA,WAAA,CACZA,CAAA,CAAA,SAAA,CAAY,YACZA,CAAA,CAAA,gBAAA,CAAmB,kBACnBA,CAAAA,CAAAA,CAAA,SAAW,UACXA,CAAAA,CAAAA,CAAA,gBAAmB,CAAA,kBAAA,CACnBA,EAAA,QAAW,CAAA,UAAA,CACXA,CAAA,CAAA,OAAA,CAAU,UAVAA,CAAA,CAAA,EAAA,CAAA,EAAA,EAAA","file":"chunk-GFMGTV5E.mjs","sourcesContent":["/**\r\n * Represents the countries where the application operates or products are available.\r\n */\r\nexport enum OperationalCountry {\r\n /** India */ IN = 'IN',\r\n}\r\n\r\nexport enum OperationalCountryCurrency {\r\n /** India */ INR = 'INR',\r\n}\r\n\r\nexport enum OperationalLocale {\r\n /** India */ 'en-IN' = 'en-IN',\r\n /** India ( Kannada) */ 'kn-IN' = 'kn-IN'\r\n}\r\n\r\nexport enum OperationalLanguage {\r\n en = 'en',\r\n kn = 'kn'\r\n}\r\n\r\nexport const LocaleLanguageMap: Record<OperationalLocale, OperationalLanguage> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalLanguage.en,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalLanguage.kn,\r\n}\r\n\r\nexport const LocaleCountryMap: Record<OperationalLocale, OperationalCountry> = {\r\n [OperationalLocale[\"en-IN\"]]: OperationalCountry.IN,\r\n [OperationalLocale[\"kn-IN\"]]: OperationalCountry.IN,\r\n}\r\n\r\n/**\r\n * Defines the supported ISO 4217 currency codes as an enumeration.\r\n */\r\nexport const CountryCurrencyMap = {\r\n /** India */[OperationalCountry.IN]: OperationalCountryCurrency.INR,\r\n};\r\n\r\nexport const CurrencySymbolMap = {\r\n [OperationalCountryCurrency.INR]: '₹',\r\n}\r\n\r\nexport const CurrencyLocaleMap = {\r\n [OperationalCountryCurrency.INR]: OperationalLocale[\"en-IN\"],\r\n}\r\n\r\n/**\r\n * Defines standard gender categories for product targeting.\r\n */\r\nexport enum GenderCategory {\r\n MALE = 'Male',\r\n FEMALE = 'Female',\r\n UNISEX = 'Unisex',\r\n KIDS = 'Kids',\r\n BOY = 'Boy',\r\n GIRL = 'Girl',\r\n GENERAL = 'General',\r\n}\r\n\r\nexport enum ImageCategory {\r\n PRIMARY = 'PRIMARY',\r\n GALLERY = 'GALLERY'\r\n}\r\n\r\nexport enum ChargeType {\r\n SHIPPING = 'SHIPPING',\r\n ADJUSTMENT = 'ADJUSTMENT'\r\n}\r\n\r\nexport enum ChargeImpact {\r\n ADD = \"ADD\",\r\n SUBTRACT = \"SUBTRACT\",\r\n}\r\n\r\nexport enum ChargeTaxTreatment {\r\n APPLY = \"APPLY\",\r\n EXEMPT = \"EXEMPT\",\r\n}\r\n\r\nexport enum TaxSystem {\r\n GST = 'GST',\r\n}\r\n\r\n/**\r\n * LineItemState\r\n * \r\n * INITIAL: Item added to order, not yet processed.\r\n * PROCESSING: Item is being prepared for shipment.\r\n * SHIPPED: Item dispatched to customer.\r\n * DELIVERED: Item delivered to customer.\r\n * CANCELLED: Item cancelled before shipment or delivery.\r\n * RETURN_REQUESTED: Customer requests to return item.\r\n * RETURNED: Item received back from customer.\r\n * REFUND_INITIATED: Refund initiated for item.\r\n * REFUNDED: Refund processed for item.\r\n * ON_HOLD: Item is paused due to payment, inventory, or other issues.\r\n */\r\nexport enum LineItemState {\r\n INITIAL = \"INITIAL\",\r\n PROCESSING = \"PROCESSING\",\r\n SHIPPED = \"SHIPPED\",\r\n DELIVERED = \"DELIVERED\",\r\n CANCELLED = \"CANCELLED\",\r\n RETURN_REQUESTED = \"RETURN_REQUESTED\",\r\n RETURNED = \"RETURNED\",\r\n REFUND_INITIATED = \"REFUND_INITIATED\",\r\n REFUNDED = \"REFUNDED\",\r\n ON_HOLD = \"ON_HOLD\",\r\n}"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a}from'./chunk-3HKY6ZOF.mjs';import {p}from'./chunk-XPKK6DFA.mjs';var i=class{taxRuleId;taxCategory;taxSystem;taxSubSystem;taxCountry;effectiveFrom;effectiveTo;constructor(e){this.taxRuleId=e.taxRuleId,this.taxSystem=e.taxSystem,this.taxSubSystem=e.taxSubSystem,this.taxCategory=e.taxCategory,this.taxCountry=e.taxCountry,this.effectiveFrom=new Date(e.effectiveFrom).toISOString(),this.effectiveTo=e.effectiveTo?new Date(e.effectiveTo).toISOString():void 0;}getTaxRuleId(){return this.taxRuleId}getTaxSystem(){return this.taxSystem}getTaxSubSystem(){return this.taxSubSystem}getTaxCategory(){return this.taxCategory}getTaxCountry(){return this.taxCountry}getEffectiveFrom(){return this.effectiveFrom}getEffectiveTo(){return this.effectiveTo}getDetails(){return {taxRuleId:this.getTaxRuleId(),taxSystem:this.getTaxSystem(),taxSubSystem:this.getTaxSubSystem(),taxCategory:this.getTaxCategory(),taxCountry:this.getTaxCountry(),effectiveFrom:this.effectiveFrom,effectiveTo:this.effectiveTo?this.effectiveTo:void 0}}appliesTo(e,t,a=new Date){return this.taxCategory===e&&this.taxCountry===t&&Date.parse(this.effectiveFrom)<=a.getTime()&&(this.effectiveTo?Date.parse(this.effectiveTo)>=a.getTime():!0)}static getTaxRateDisplayString(e,t,a){let r=t*100,n=r%1===0?r.toString():r.toFixed(2).replace(/\.?0+$/,"");return a?.percentageOnly?`${n}%`:e.getTaxSystem()==="GST"?`${e.getTaxSubSystem()} ${n}%`:`${e.getTaxSystem()} ${n}%`}},u=class s extends i{slabs;constructor(e){super(e),this.slabs=e.slabs.map(t=>({rate:t.rate,minUnitPrice:new a(t.minUnitPrice),maxUnitPrice:t.maxUnitPrice?new a(t.maxUnitPrice):void 0}));}getSlabs(){return this.slabs.map(e=>({rate:e.rate,minUnitPrice:e.minUnitPrice,maxUnitPrice:e.maxUnitPrice}))}getDetails(){return {...super.getDetails(),slabs:this.getSlabs().map(e=>({rate:e.rate,minUnitPrice:e.minUnitPrice.getDetails(),maxUnitPrice:e.maxUnitPrice?e.maxUnitPrice.getDetails():void 0}))}}getApplicableTaxRate(e){return s.getApplicableTaxRate(e,this.slabs)}calculateTax(e){let t=this.getApplicableTaxRate(e);return e.multiply(t)}static getApplicableTaxRate(e,t){let a=t.filter(r=>(r.minUnitPrice===void 0||e.compareTo(r.minUnitPrice)>=0)&&(r.maxUnitPrice===void 0||e.compareTo(r.maxUnitPrice)<0));if(a.length!==1)throw new p;return a[0].rate}},c=class extends i{rate;constructor(e){super(e),this.rate=e.rate;}getApplicableTaxRate(){return this.rate}calculateTax(e){let t=this.getApplicableTaxRate();return e.multiply(t)}getDetails(){return {...super.getDetails(),rate:this.getApplicableTaxRate()}}};export{i as a,u as b,c};//# sourceMappingURL=chunk-JCUHTCOC.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-JCUHTCOC.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Classes/TaxRule.ts"],"names":["TaxRuleBaseModel","data","taxCategory","taxCountry","at","taxRule","rate","formateOption","percentage","rateStr","TaxRuleModel","_TaxRuleModel","s","PriceModel","unitPrice","taxSlabs","slabs","TaxSlabNotFoundError","FixedTaxRuleModel"],"mappings":"0EAmBaA,IAAAA,CAAAA,CAAN,KAAuB,CAClB,SAAA,CACA,YACA,SACA,CAAA,YAAA,CACA,UACA,CAAA,aAAA,CACA,WAEV,CAAA,WAAA,CAAYC,EAA6B,CACvC,IAAA,CAAK,SAAYA,CAAAA,CAAAA,CAAK,SACtB,CAAA,IAAA,CAAK,UAAYA,CAAK,CAAA,SAAA,CACtB,IAAK,CAAA,YAAA,CAAeA,CAAK,CAAA,YAAA,CACzB,KAAK,WAAcA,CAAAA,CAAAA,CAAK,YACxB,IAAK,CAAA,UAAA,CAAaA,EAAK,UACvB,CAAA,IAAA,CAAK,aAAgB,CAAA,IAAI,IAAKA,CAAAA,CAAAA,CAAK,aAAa,CAAE,CAAA,WAAA,EAClD,CAAA,IAAA,CAAK,WAAcA,CAAAA,CAAAA,CAAK,YAAc,IAAI,IAAA,CAAKA,CAAK,CAAA,WAAW,CAAE,CAAA,WAAA,GAAgB,KACnF,EAAA,CAEA,cAAuB,CACrB,OAAO,KAAK,SACd,CAEA,YAA0B,EAAA,CACxB,OAAO,IAAA,CAAK,SACd,CAEA,eAAA,EAA0B,CACxB,OAAO,IAAK,CAAA,YACd,CAEA,cAAyB,EAAA,CACvB,OAAO,IAAA,CAAK,WACd,CAEA,eAA6B,CAC3B,OAAO,KAAK,UACd,CAEA,kBAA2B,CACzB,OAAO,IAAK,CAAA,aACd,CAEA,cAAA,EAAqC,CACnC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I,CAChC,CAQA,OAAO,oBAAqBQ,CAAAA,CAAAA,CAAuBC,CAAkC,CAAA,CACnF,IAAMC,CAAQD,CAAAA,CAAAA,CAAS,MAAOH,CAAAA,CAAAA,EAAAA,CAC3BA,CAAE,CAAA,YAAA,GAAiB,QAAaE,CAAU,CAAA,SAAA,CAAUF,EAAE,YAAY,CAAA,EAAK,KACvEA,CAAE,CAAA,YAAA,GAAiB,KAAaE,CAAAA,EAAAA,CAAAA,CAAU,SAAUF,CAAAA,CAAAA,CAAE,YAAY,CAAI,CAAA,CAAA,CACzE,CAEA,CAAA,GAAII,CAAM,CAAA,MAAA,GAAW,EACnB,MAAM,IAAIC,CAGZ,CAAA,OAAOD,CAAM,CAAA,CAAC,EAAE,IAClB,CACF,EAaaE,CAAN,CAAA,cAAgClB,CAAiB,CAC5C,IAAA,CAEV,WAAYC,CAAAA,CAAAA,CAA8B,CACxC,KAAA,CAAMA,CAAI,CACV,CAAA,IAAA,CAAK,IAAOA,CAAAA,CAAAA,CAAK,KACnB,CAEO,sBAA+B,CACpC,OAAO,IAAK,CAAA,IACd,CAMA,YAAA,CAAaa,EAAmC,CAC9C,IAAMR,CAAO,CAAA,IAAA,CAAK,oBAAqB,EAAA,CACvC,OAAOQ,CAAU,CAAA,QAAA,CAASR,CAAI,CAChC,CAEO,UAAA,EAA+B,CACpC,OAAO,CACL,GAAG,KAAA,CAAM,UAAW,EAAA,CACpB,KAAM,IAAK,CAAA,oBAAA,EACb,CACF,CACF","file":"chunk-L3CNGDFJ.mjs","sourcesContent":["import Utils from \"../Utils\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { CountryCode, ISODateTimeUTC } from \"./Common\";\r\nimport { TaxSystem } from \"./Enum\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { TaxSlabNotFoundError } from \"./Error\";\r\n\r\nexport type TaxRuleBaseAttributes = {\r\n taxRuleId: string;\r\n taxCategory: string;\r\n taxSystem: TaxSystem;\r\n taxSubSystem: string;\r\n taxCountry: CountryCode;\r\n effectiveFrom: ISODateTimeUTC;\r\n effectiveTo?: ISODateTimeUTC;\r\n}\r\n\r\nexport type TaxRuleBaseData = TaxRuleBaseAttributes;\r\n\r\nexport class TaxRuleBaseModel {\r\n protected taxRuleId: string;\r\n protected taxCategory: string;\r\n protected taxSystem: TaxSystem;\r\n protected taxSubSystem: string;\r\n protected taxCountry: CountryCode;\r\n protected effectiveFrom: ISODateTimeUTC;\r\n protected effectiveTo?: ISODateTimeUTC;\r\n\r\n constructor(data: TaxRuleBaseAttributes) {\r\n this.taxRuleId = data.taxRuleId;\r\n this.taxSystem = data.taxSystem;\r\n this.taxSubSystem = data.taxSubSystem;\r\n this.taxCategory = data.taxCategory;\r\n this.taxCountry = data.taxCountry;\r\n this.effectiveFrom = new Date(data.effectiveFrom).toISOString();\r\n this.effectiveTo = data.effectiveTo ? new Date(data.effectiveTo).toISOString() : undefined;\r\n }\r\n\r\n getTaxRuleId(): string {\r\n return this.taxRuleId;\r\n }\r\n\r\n getTaxSystem(): TaxSystem {\r\n return this.taxSystem;\r\n }\r\n\r\n getTaxSubSystem(): string {\r\n return this.taxSubSystem;\r\n }\r\n\r\n getTaxCategory(): string {\r\n return this.taxCategory;\r\n }\r\n\r\n getTaxCountry(): CountryCode {\r\n return this.taxCountry;\r\n }\r\n\r\n getEffectiveFrom(): string {\r\n return this.effectiveFrom;\r\n }\r\n\r\n getEffectiveTo(): string | undefined {\r\n return this.effectiveTo;\r\n }\r\n\r\n getDetails(): TaxRuleBaseData {\r\n return {\r\n taxRuleId: this.getTaxRuleId(),\r\n taxSystem: this.getTaxSystem(),\r\n taxSubSystem: this.getTaxSubSystem(),\r\n taxCategory: this.getTaxCategory(),\r\n taxCountry: this.getTaxCountry(),\r\n effectiveFrom: this.effectiveFrom,\r\n effectiveTo: this.effectiveTo ? this.effectiveTo : undefined\r\n };\r\n }\r\n\r\n /**\r\n * Checks whether this tax rule is applicable for the given category and taxCountry at a specific time.\r\n * @param taxCategory - The tax category to check.\r\n * @param taxCountry - The taxCountry code to check.\r\n * @param at - The date to check effectiveness against (defaults to now).\r\n * @returns True if the rule is applicable, false otherwise.\r\n */\r\n appliesTo(taxCategory: string, taxCountry: CountryCode, at: Date = new Date()): boolean {\r\n return (\r\n this.taxCategory === taxCategory &&\r\n this.taxCountry === taxCountry &&\r\n Date.parse(this.effectiveFrom) <= at.getTime() &&\r\n (this.effectiveTo ? Date.parse(this.effectiveTo) >= at.getTime() : true)\r\n );\r\n }\r\n\r\n static getTaxRateDisplayString(taxRule: TaxRuleBaseModel, rate: number, formateOption?: {\r\n percentageOnly?: boolean;\r\n }): string {\r\n const percentage = rate * 100;\r\n // Format to remove trailing zeros if it's an integer, otherwise keep up to 2 decimal places\r\n const rateStr = percentage % 1 === 0 ? percentage.toString() : percentage.toFixed(2).replace(/\\.?0+$/, '');\r\n\r\n if (formateOption?.percentageOnly) {\r\n return `${rateStr}%`;\r\n }\r\n\r\n if (taxRule.getTaxSystem() === TaxSystem.GST) {\r\n return `${taxRule.getTaxSubSystem()} ${rateStr}%`;\r\n }\r\n return `${taxRule.getTaxSystem()} ${rateStr}%`;\r\n }\r\n}\r\n\r\nexport type TaxSlabData = {\r\n minUnitPrice: PriceData; // inclusive\r\n maxUnitPrice?: PriceData; // exclusive\r\n rate: number; // e.g. 0.05 = 5%\r\n};\r\n\r\nexport type TaxSlabModel = {\r\n minUnitPrice: PriceModel; // inclusive\r\n maxUnitPrice?: PriceModel; // exclusive\r\n rate: number; // e.g. 0.05 = 5%\r\n};\r\n\r\nexport type TaxSlabs = TaxSlabData[];\r\n\r\nexport type TaxRuleAttributes = TaxRuleBaseAttributes & {\r\n slabs: TaxSlabs;\r\n};\r\n\r\nexport type TaxRuleData = TaxRuleAttributes;\r\n\r\nexport class TaxRuleModel extends TaxRuleBaseModel {\r\n protected slabs: TaxSlabModel[];\r\n\r\n /**\r\n * Creates an instance of TaxRuleModel.\r\n * @param data - The initial tax rule attributes.\r\n */\r\n constructor(data: TaxRuleAttributes) {\r\n super(data)\r\n this.slabs = data.slabs.map(s => ({\r\n rate: s.rate,\r\n minUnitPrice: new PriceModel(s.minUnitPrice),\r\n maxUnitPrice: s.maxUnitPrice ? new PriceModel(s.maxUnitPrice) : undefined,\r\n }));\r\n }\r\n\r\n getSlabs(): TaxSlabModel[] {\n return this.slabs.map(s => ({\n rate: s.rate,\n minUnitPrice: s.minUnitPrice,\n maxUnitPrice: s.maxUnitPrice,\n }));\n }\n\r\n getDetails(): TaxRuleData {\r\n return {\r\n ...super.getDetails(),\r\n slabs: this.getSlabs().map(s => ({\r\n rate: s.rate,\r\n minUnitPrice: s.minUnitPrice.getDetails(),\r\n maxUnitPrice: s.maxUnitPrice ? s.maxUnitPrice.getDetails() : undefined,\r\n })),\r\n };\r\n }\r\n\r\n /**\r\n * Gets the applicable tax rate for the given unit price based on the slabs.\r\n * @param unitPrice - The unit price to match against slabs.\r\n * @returns The applicable tax rate as a decimal (e.g., 0.18 for 18%).\r\n */\r\n getApplicableTaxRate(unitPrice: PriceModel): number {\r\n return TaxRuleModel.getApplicableTaxRate(unitPrice, this.slabs);\r\n }\r\n\r\n /**\r\n * Calculates the tax amount for a given taxable amount.\r\n * @param unitPrice - The unit price used to determine which tax slab applies.\r\n * @returns The calculated tax amount as a PriceModel.\r\n */\r\n calculateTax(unitPrice: PriceModel): PriceModel {\r\n const rate = this.getApplicableTaxRate(unitPrice);\r\n return unitPrice.multiply(rate);\r\n }\r\n\r\n /**\r\n * Calculates the applicable tax rate for a given unit price.\r\n * @param unitPrice - The unit price to find the matching tax slab for.\r\n * @returns The tax rate as a decimal (e.g., 0.05 for 5%).\r\n * @throws {TaxSlabNotFoundError} If no applicable slab or multiple slabs are found.\r\n */\r\n static getApplicableTaxRate(unitPrice: PriceModel, taxSlabs: TaxSlabModel[]): number {\r\n const slabs = taxSlabs.filter(s =>\r\n (s.minUnitPrice === undefined || unitPrice.compareTo(s.minUnitPrice) >= 0) &&\r\n (s.maxUnitPrice === undefined || unitPrice.compareTo(s.maxUnitPrice) < 0)\r\n );\r\n\r\n if (slabs.length !== 1) {\r\n throw new TaxSlabNotFoundError();\r\n }\r\n\r\n return slabs[0].rate;\r\n }\r\n}\r\n\r\n\r\nexport type FixedTaxRuleAttributes = TaxRuleBaseAttributes & {\r\n rate: number;\r\n}\r\n\r\nexport type FixedTaxRuleData = FixedTaxRuleAttributes;\r\n\r\n/**\r\n * A specialized version of TaxRuleModel for fixed-rate taxes (single slab).\r\n * Ideal for components like Charges where slab-based logic is not required.\r\n */\r\nexport class FixedTaxRuleModel extends TaxRuleBaseModel {\r\n protected rate: number;\r\n\r\n constructor(data: FixedTaxRuleAttributes) {\r\n super(data);\r\n this.rate = data.rate;\r\n }\r\n\r\n public getApplicableTaxRate(): number {\r\n return this.rate;\r\n }\r\n\r\n /**\r\n * Calculates the tax amount for a given taxable amount.\r\n * @returns The calculated tax amount as a PriceModel.\r\n */\r\n calculateTax(unitPrice: PriceModel): PriceModel {\r\n const rate = this.getApplicableTaxRate();\r\n return unitPrice.multiply(rate);\r\n }\r\n\r\n public getDetails(): FixedTaxRuleData {\r\n return {\r\n ...super.getDetails(),\r\n rate: this.getApplicableTaxRate(),\r\n };\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/Classes/TaxRule.ts"],"names":["TaxRuleBaseModel","data","taxCategory","taxCountry","at","taxRule","rate","formateOption","percentage","rateStr","TaxRuleModel","_TaxRuleModel","s","PriceModel","unitPrice","taxSlabs","slabs","TaxSlabNotFoundError","FixedTaxRuleModel"],"mappings":"0EAmBaA,IAAAA,CAAAA,CAAN,KAAuB,CAClB,SAAA,CACA,YACA,SACA,CAAA,YAAA,CACA,UACA,CAAA,aAAA,CACA,WAEV,CAAA,WAAA,CAAYC,EAA6B,CACvC,IAAA,CAAK,SAAYA,CAAAA,CAAAA,CAAK,SACtB,CAAA,IAAA,CAAK,UAAYA,CAAK,CAAA,SAAA,CACtB,IAAK,CAAA,YAAA,CAAeA,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AK,KACnB,CAEO,sBAA+B,CACpC,OAAO,IAAK,CAAA,IACd,CAMA,YAAA,CAAaa,EAAmC,CAC9C,IAAMR,CAAO,CAAA,IAAA,CAAK,oBAAqB,EAAA,CACvC,OAAOQ,CAAU,CAAA,QAAA,CAASR,CAAI,CAChC,CAEO,UAAA,EAA+B,CACpC,OAAO,CACL,GAAG,KAAA,CAAM,UAAW,EAAA,CACpB,KAAM,IAAK,CAAA,oBAAA,EACb,CACF,CACF","file":"chunk-JCUHTCOC.mjs","sourcesContent":["import Utils from \"../Utils\";\r\nimport BaseModel, { BaseAttributes } from \"./Base\";\r\nimport { CountryCode, ISODateTimeUTC } from \"./Common\";\r\nimport { TaxSystem } from \"./Enum\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { TaxSlabNotFoundError } from \"./Error\";\r\n\r\nexport type TaxRuleBaseAttributes = {\r\n taxRuleId: string;\r\n taxCategory: string;\r\n taxSystem: TaxSystem;\r\n taxSubSystem: string;\r\n taxCountry: CountryCode;\r\n effectiveFrom: ISODateTimeUTC;\r\n effectiveTo?: ISODateTimeUTC;\r\n}\r\n\r\nexport type TaxRuleBaseData = TaxRuleBaseAttributes;\r\n\r\nexport class TaxRuleBaseModel {\r\n protected taxRuleId: string;\r\n protected taxCategory: string;\r\n protected taxSystem: TaxSystem;\r\n protected taxSubSystem: string;\r\n protected taxCountry: CountryCode;\r\n protected effectiveFrom: ISODateTimeUTC;\r\n protected effectiveTo?: ISODateTimeUTC;\r\n\r\n constructor(data: TaxRuleBaseAttributes) {\r\n this.taxRuleId = data.taxRuleId;\r\n this.taxSystem = data.taxSystem;\r\n this.taxSubSystem = data.taxSubSystem;\r\n this.taxCategory = data.taxCategory;\r\n this.taxCountry = data.taxCountry;\r\n this.effectiveFrom = new Date(data.effectiveFrom).toISOString();\r\n this.effectiveTo = data.effectiveTo ? new Date(data.effectiveTo).toISOString() : undefined;\r\n }\r\n\r\n getTaxRuleId(): string {\r\n return this.taxRuleId;\r\n }\r\n\r\n getTaxSystem(): TaxSystem {\r\n return this.taxSystem;\r\n }\r\n\r\n getTaxSubSystem(): string {\r\n return this.taxSubSystem;\r\n }\r\n\r\n getTaxCategory(): string {\r\n return this.taxCategory;\r\n }\r\n\r\n getTaxCountry(): CountryCode {\r\n return this.taxCountry;\r\n }\r\n\r\n getEffectiveFrom(): string {\r\n return this.effectiveFrom;\r\n }\r\n\r\n getEffectiveTo(): string | undefined {\r\n return this.effectiveTo;\r\n }\r\n\r\n getDetails(): TaxRuleBaseData {\r\n return {\r\n taxRuleId: this.getTaxRuleId(),\r\n taxSystem: this.getTaxSystem(),\r\n taxSubSystem: this.getTaxSubSystem(),\r\n taxCategory: this.getTaxCategory(),\r\n taxCountry: this.getTaxCountry(),\r\n effectiveFrom: this.effectiveFrom,\r\n effectiveTo: this.effectiveTo ? this.effectiveTo : undefined\r\n };\r\n }\r\n\r\n /**\r\n * Checks whether this tax rule is applicable for the given category and taxCountry at a specific time.\r\n * @param taxCategory - The tax category to check.\r\n * @param taxCountry - The taxCountry code to check.\r\n * @param at - The date to check effectiveness against (defaults to now).\r\n * @returns True if the rule is applicable, false otherwise.\r\n */\r\n appliesTo(taxCategory: string, taxCountry: CountryCode, at: Date = new Date()): boolean {\r\n return (\r\n this.taxCategory === taxCategory &&\r\n this.taxCountry === taxCountry &&\r\n Date.parse(this.effectiveFrom) <= at.getTime() &&\r\n (this.effectiveTo ? Date.parse(this.effectiveTo) >= at.getTime() : true)\r\n );\r\n }\r\n\r\n static getTaxRateDisplayString(taxRule: TaxRuleBaseModel, rate: number, formateOption?: {\r\n percentageOnly?: boolean;\r\n }): string {\r\n const percentage = rate * 100;\r\n // Format to remove trailing zeros if it's an integer, otherwise keep up to 2 decimal places\r\n const rateStr = percentage % 1 === 0 ? percentage.toString() : percentage.toFixed(2).replace(/\\.?0+$/, '');\r\n\r\n if (formateOption?.percentageOnly) {\r\n return `${rateStr}%`;\r\n }\r\n\r\n if (taxRule.getTaxSystem() === TaxSystem.GST) {\r\n return `${taxRule.getTaxSubSystem()} ${rateStr}%`;\r\n }\r\n return `${taxRule.getTaxSystem()} ${rateStr}%`;\r\n }\r\n}\r\n\r\nexport type TaxSlabData = {\r\n minUnitPrice: PriceData; // inclusive\r\n maxUnitPrice?: PriceData; // exclusive\r\n rate: number; // e.g. 0.05 = 5%\r\n};\r\n\r\nexport type TaxSlabModel = {\r\n minUnitPrice: PriceModel; // inclusive\r\n maxUnitPrice?: PriceModel; // exclusive\r\n rate: number; // e.g. 0.05 = 5%\r\n};\r\n\r\nexport type TaxSlabs = TaxSlabData[];\r\n\r\nexport type TaxRuleAttributes = TaxRuleBaseAttributes & {\r\n slabs: TaxSlabs;\r\n};\r\n\r\nexport type TaxRuleData = TaxRuleAttributes;\r\n\r\nexport class TaxRuleModel extends TaxRuleBaseModel {\r\n protected slabs: TaxSlabModel[];\r\n\r\n /**\r\n * Creates an instance of TaxRuleModel.\r\n * @param data - The initial tax rule attributes.\r\n */\r\n constructor(data: TaxRuleAttributes) {\r\n super(data)\r\n this.slabs = data.slabs.map(s => ({\r\n rate: s.rate,\r\n minUnitPrice: new PriceModel(s.minUnitPrice),\r\n maxUnitPrice: s.maxUnitPrice ? new PriceModel(s.maxUnitPrice) : undefined,\r\n }));\r\n }\r\n\r\n getSlabs(): TaxSlabModel[] {\n return this.slabs.map(s => ({\n rate: s.rate,\n minUnitPrice: s.minUnitPrice,\n maxUnitPrice: s.maxUnitPrice,\n }));\n }\n\r\n getDetails(): TaxRuleData {\r\n return {\r\n ...super.getDetails(),\r\n slabs: this.getSlabs().map(s => ({\r\n rate: s.rate,\r\n minUnitPrice: s.minUnitPrice.getDetails(),\r\n maxUnitPrice: s.maxUnitPrice ? s.maxUnitPrice.getDetails() : undefined,\r\n })),\r\n };\r\n }\r\n\r\n /**\r\n * Gets the applicable tax rate for the given unit price based on the slabs.\r\n * @param unitPrice - The unit price to match against slabs.\r\n * @returns The applicable tax rate as a decimal (e.g., 0.18 for 18%).\r\n */\r\n getApplicableTaxRate(unitPrice: PriceModel): number {\r\n return TaxRuleModel.getApplicableTaxRate(unitPrice, this.slabs);\r\n }\r\n\r\n /**\r\n * Calculates the tax amount for a given taxable amount.\r\n * @param unitPrice - The unit price used to determine which tax slab applies.\r\n * @returns The calculated tax amount as a PriceModel.\r\n */\r\n calculateTax(unitPrice: PriceModel): PriceModel {\r\n const rate = this.getApplicableTaxRate(unitPrice);\r\n return unitPrice.multiply(rate);\r\n }\r\n\r\n /**\r\n * Calculates the applicable tax rate for a given unit price.\r\n * @param unitPrice - The unit price to find the matching tax slab for.\r\n * @returns The tax rate as a decimal (e.g., 0.05 for 5%).\r\n * @throws {TaxSlabNotFoundError} If no applicable slab or multiple slabs are found.\r\n */\r\n static getApplicableTaxRate(unitPrice: PriceModel, taxSlabs: TaxSlabModel[]): number {\r\n const slabs = taxSlabs.filter(s =>\r\n (s.minUnitPrice === undefined || unitPrice.compareTo(s.minUnitPrice) >= 0) &&\r\n (s.maxUnitPrice === undefined || unitPrice.compareTo(s.maxUnitPrice) < 0)\r\n );\r\n\r\n if (slabs.length !== 1) {\r\n throw new TaxSlabNotFoundError();\r\n }\r\n\r\n return slabs[0].rate;\r\n }\r\n}\r\n\r\n\r\nexport type FixedTaxRuleAttributes = TaxRuleBaseAttributes & {\r\n rate: number;\r\n}\r\n\r\nexport type FixedTaxRuleData = FixedTaxRuleAttributes;\r\n\r\n/**\r\n * A specialized version of TaxRuleModel for fixed-rate taxes (single slab).\r\n * Ideal for components like Charges where slab-based logic is not required.\r\n */\r\nexport class FixedTaxRuleModel extends TaxRuleBaseModel {\r\n protected rate: number;\r\n\r\n constructor(data: FixedTaxRuleAttributes) {\r\n super(data);\r\n this.rate = data.rate;\r\n }\r\n\r\n public getApplicableTaxRate(): number {\r\n return this.rate;\r\n }\r\n\r\n /**\r\n * Calculates the tax amount for a given taxable amount.\r\n * @returns The calculated tax amount as a PriceModel.\r\n */\r\n calculateTax(unitPrice: PriceModel): PriceModel {\r\n const rate = this.getApplicableTaxRate();\r\n return unitPrice.multiply(rate);\r\n }\r\n\r\n public getDetails(): FixedTaxRuleData {\r\n return {\r\n ...super.getDetails(),\r\n rate: this.getApplicableTaxRate(),\r\n };\r\n }\r\n}\r\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a as a$1}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import {a as a$1}from'./chunk-QLYPJDDV.mjs';import {e}from'./chunk-GFMGTV5E.mjs';import {b as b$2}from'./chunk-RSTZJZSQ.mjs';import {g,d}from'./chunk-XPKK6DFA.mjs';import {b as b$1}from'./chunk-UXZBULDS.mjs';import K from'crypto';var y=new Uint8Array(256),h=y.length;function I(){return h>y.length-16&&(K.randomFillSync(y),h=0),y.slice(h,h+=16)}var z=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function $(t){return typeof t=="string"&&z.test(t)}var U=$;var n=[];for(let t=0;t<256;++t)n.push((t+256).toString(16).slice(1));function b(t,e=0){return n[t[e+0]]+n[t[e+1]]+n[t[e+2]]+n[t[e+3]]+"-"+n[t[e+4]]+n[t[e+5]]+"-"+n[t[e+6]]+n[t[e+7]]+"-"+n[t[e+8]]+n[t[e+9]]+"-"+n[t[e+10]]+n[t[e+11]]+n[t[e+12]]+n[t[e+13]]+n[t[e+14]]+n[t[e+15]]}function k(t){if(!U(t))throw TypeError("Invalid UUID");let e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=e&255,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=e&255,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=e&255,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=e&255,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=e&255,r}var M=k;function V(t){t=unescape(encodeURIComponent(t));let e=[];for(let r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}var G="6ba7b810-9dad-11d1-80b4-00c04fd430c8",B="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function x(t,e,r){function i(o,s,u,S){var A;if(typeof o=="string"&&(o=V(o)),typeof s=="string"&&(s=M(s)),((A=s)===null||A===void 0?void 0:A.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let g=new Uint8Array(16+o.length);if(g.set(s),g.set(o,s.length),g=r(g),g[6]=g[6]&15|e,g[8]=g[8]&63|128,u){S=S||0;for(let m=0;m<16;++m)u[S+m]=g[m];return u}return b(g)}try{i.name=t;}catch{}return i.DNS=G,i.URL=B,i}var L={randomUUID:K.randomUUID};function j(t,e,r){if(L.randomUUID&&!e&&!t)return L.randomUUID();t=t||{};let i=t.random||(t.rng||I)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){r=r||0;for(let o=0;o<16;++o)e[r+o]=i[o];return e}return b(i)}var D=j;function Z(t){return Array.isArray(t)?t=Buffer.from(t):typeof t=="string"&&(t=Buffer.from(t,"utf8")),K.createHash("sha1").update(t).digest()}var R=Z;var q=x("v5",80,R),P=q;var O={isUUID:t=>/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(t),isEmail:t=>/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(t),isURL:t=>/^(http|https):\/\/[^ "]+$/.test(t),generateUUID:(t,e)=>e&&t?P(t,e):D(),generateSearchId:(t,e)=>`${t}#${f.generateSelectionAttributesKey(e)}`,getKeyfromSearchId:t=>{let[e,r]=t.split("#");return {key:e,selectionAttributes:f.parseSelectionAttributesKey(r)}},deepClone(t){return structuredClone(t)}},a=O;var f=class t extends b$1{id;key;name;description;slug;brand;pricing;variants;targetGender;attributes;specifications;categories;isActive;searchTags;static productKeyRegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static productSKURegex=/^(?!\s)(?!.*\s$)[A-Z0-9-]{4,16}$/;static generateSelectionAttributesKey(e){if(typeof e!="object")throw new g("Selection attributes must be an object");return Object.keys(e).filter(i=>e[i]!==void 0&&i.toLowerCase()!=="size").sort().map(i=>e[i].name?`${i}:c+${e[i].name}`:`${i}:${e[i]}`).join("|").toLowerCase()}static parseSelectionAttributesKey(e){try{let r={},i=e.split("|");for(let o of i){let[s,u]=o.split(":");u.startsWith("c+")?r[s]={name:u.slice(2)}:r[s]=u;}return r}catch(r){throw new g(r?.message)}}constructor(e,r=new Date){super(e,r),this.id=e.id,this.key=e.key,this.name={...e.name},this.description={...e.description},this.slug={...e.slug},this.brand=e.brand,this.pricing=Object.keys(e.pricing).reduce((o,s)=>(e.pricing[s]&&(o[s]=new a$1(e.pricing[s])),o),{}),this.targetGender=e.targetGender,this.attributes=a.deepClone(e.attributes),this.specifications=a.deepClone(e.specifications),this.categories=a.deepClone(e.categories);let i=new Set;this.variants=(e.variants||[]).map(o=>{if(!o.selectionAttributes||typeof o.selectionAttributes!="object")throw new g("Selection attributes are required");this.checkSelectionAttributes(o.selectionAttributes);let s=t.generateSelectionAttributesKey(o.selectionAttributes);if(i.has(s))throw new d(s);return i.add(s),{sku:o.sku,selectionAttributes:o.selectionAttributes,images:{primary:new b$2(o.images.primary),gallery:(o.images.gallery||[]).map(u=>new b$2(u))}}}),this.isActive=e.isActive,this.searchTags=e.searchTags?a.deepClone(e.searchTags):{en:[]};}getId(){return this.id}getKey(){return this.key}getName(e$1){return e$1?this.name[e$1]??this.name[e[e$1]]??this.name.en:a.deepClone(this.name)}getDescription(e$1){return e$1?this.description[e$1]??this.description[e[e$1]]??this.description.en:a.deepClone(this.description)}getSlug(e$1){return e$1?this.slug[e$1]??this.slug[e[e$1]]??this.slug.en:a.deepClone(this.slug)}getBrand(){return this.brand}getPriceDetails(e){return e?this.pricing[e]??null:{...this.pricing}}getAttributes(){return a.deepClone(this.attributes)}getVariants(){return this.variants.map(e=>({sku:e.sku,selectionAttributes:a.deepClone(e.selectionAttributes),images:{primary:e.images.primary,gallery:[...e.images.gallery]}}))}getImagesBySelectionAttributes(e){let r=t.generateSelectionAttributesKey(e),i=this.variants.find(o=>t.generateSelectionAttributesKey(o.selectionAttributes)===r);return i?{primary:i.images.primary,gallery:[...i.images.gallery]}:null}getImages(e,r){switch(r){case"PRIMARY":return this.getImagesBySelectionAttributes(e)?.primary??this.variants[0]?.images?.primary;case"GALLERY":return this.getImagesBySelectionAttributes(e)?.gallery??[];default:return this.getImagesBySelectionAttributes(e)??{primary:this.variants[0]?.images?.primary,gallery:[]}}}getIsActive(){return this.isActive}getTargetGender(){return this.targetGender}getCategories(){return a.deepClone(this.categories)}getSpecifications(e$1){return e$1?a.deepClone(this.specifications[e$1]??this.specifications[e[e$1]]??this.specifications.en):a.deepClone(this.specifications)}getSearchTags(e$1){return e$1?a.deepClone(this.searchTags[e$1]??this.searchTags[e[e$1]]??this.searchTags.en):a.deepClone(this.searchTags)}getDetails(){let e=super.getDetails();return {id:this.getId(),key:this.getKey(),name:this.getName(),description:this.getDescription(),slug:this.getSlug(),brand:this.getBrand(),pricing:Object.keys(this.pricing).reduce((r,i)=>(this.pricing[i]&&(r[i]=this.pricing[i]?.getDetails()),r),{}),attributes:this.getAttributes(),variants:this.variants.map(r=>({sku:r.sku,selectionAttributes:a.deepClone(r.selectionAttributes),images:{primary:r.images.primary.getDetails(),gallery:r.images.gallery.map(i=>i.getDetails())}})),isActive:this.getIsActive(),targetGender:this.getTargetGender(),categories:this.getCategories(),specifications:this.getSpecifications(),searchTags:this.getSearchTags(),...e}}checkSelectionAttributes(e){if(!e||typeof e!="object")throw new g("Selection attributes are required");Object.keys(this.attributes).forEach(r=>{if(r.toLowerCase()==="size")return;let i=this.attributes[r],o=e[r];if(o===void 0)throw new g(`Selection attribute '${r}' is missing`);if(typeof i=="string"){if(typeof o!="string"||i!==o)throw new g(`Selection attribute '${r}' is invalid`)}else if(Array.isArray(i)){if(i.length>0&&typeof i[0]=="string"){if(typeof o!="string"||!i.includes(o))throw new g(`Selection attribute '${r}' is invalid`)}else if(typeof o!="object"||!("name"in o)||i.findIndex(s=>s.name===o.name)<0)throw new g(`Selection attribute '${r}' is invalid`)}});}validateSelectionAttribute(e){let r=t.generateSelectionAttributesKey(e);return this.variants.some(i=>t.generateSelectionAttributesKey(i.selectionAttributes)===r)}validateSize(e){return this.attributes.size.includes(e)}};export{a,f as b};//# sourceMappingURL=chunk-OAE2FJFJ.mjs.map
|
|
2
|
+
//# sourceMappingURL=chunk-OAE2FJFJ.mjs.map
|