b23-lib 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Classes/Cart.js +1 -1
- package/dist/Classes/Cart.js.map +1 -1
- package/dist/Classes/Cart.mjs +1 -1
- 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/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/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/Classes/TaxRule.d.mts +4 -8
- package/dist/Classes/TaxRule.d.ts +4 -8
- package/dist/Classes/TaxRule.js +1 -1
- package/dist/Classes/TaxRule.js.map +1 -1
- package/dist/Classes/TaxRule.mjs +1 -1
- package/dist/{chunk-GF3OGUDE.mjs → chunk-52Y5EI7O.mjs} +2 -2
- package/dist/chunk-52Y5EI7O.mjs.map +1 -0
- package/dist/chunk-6VRUVGN3.mjs +2 -0
- package/dist/chunk-6VRUVGN3.mjs.map +1 -0
- package/dist/{chunk-4KMF3LE7.mjs → chunk-DLLGHKS5.mjs} +2 -2
- package/dist/chunk-DLLGHKS5.mjs.map +1 -0
- package/dist/chunk-YKRWZ24N.mjs +2 -0
- package/dist/chunk-YKRWZ24N.mjs.map +1 -0
- package/package.json +1 -11
- package/dist/Classes/TaxCategory.d.mts +0 -42
- package/dist/Classes/TaxCategory.d.ts +0 -42
- package/dist/Classes/TaxCategory.js +0 -2
- package/dist/Classes/TaxCategory.js.map +0 -1
- package/dist/Classes/TaxCategory.mjs +0 -2
- package/dist/Classes/TaxCategory.mjs.map +0 -1
- package/dist/chunk-2HBQ3C6V.mjs +0 -2
- package/dist/chunk-2HBQ3C6V.mjs.map +0 -1
- package/dist/chunk-4KMF3LE7.mjs.map +0 -1
- package/dist/chunk-GF3OGUDE.mjs.map +0 -1
- package/dist/chunk-SNDTKUMW.mjs +0 -2
- package/dist/chunk-SNDTKUMW.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Classes/LineItem.ts"],"names":["LineItemModel","CustomFieldModel","data","Utils_default","ImageInfoModel","uniqueSelectionAttributes","item","DuplicateSizeError","PriceModel","TieredPriceModel","rule","TaxRuleModel","couponCode","discount","taxRuleId","taxBreakdown","locale","LocaleLanguageMap","pricing","total","subItems","addQuantity","subItem","existingSubItem","sub","product","cartCountry","cartCurrency","ProductMismatchError","ProductInactiveError","SizeMismatchError","productPricing","PricingNotFoundError","quantity","sum","s","unitPrice","appliedDiscounts","lineItemDiscounts","taxRules","taxRule","InvalidTaxRuleError","zero","totalQuantity","subTotal","totalDiscount","netSubtotal","netUnitPrice","taxTotal","rate","taxPerUnit","amount","grandTotal","newState","LineItemState","InvalidLineItemStateError"],"mappings":"uWAmGA,IAAqBA,CAArB,CAAA,cAA2CC,CAAiB,CAChD,GACA,UACA,CAAA,mBAAA,CAEA,IACA,CAAA,cAAA,CACA,YACA,CAAA,QAAA,CACA,OAOA,CAAA,KAAA,CACA,MAMV,WAAYC,CAAAA,CAAAA,CAA0B,CACpC,KAAA,CAAMA,CAAI,CAAA,CACV,IAAK,CAAA,EAAA,CAAKA,EAAK,EACf,CAAA,IAAA,CAAK,UAAaA,CAAAA,CAAAA,CAAK,UACvB,CAAA,IAAA,CAAK,mBAAsBC,CAAAA,GAAAA,CAAM,UAAUD,CAAK,CAAA,mBAAmB,CAEnE,CAAA,IAAA,CAAK,IAAOC,CAAAA,GAAAA,CAAM,SAAUD,CAAAA,CAAAA,CAAK,IAAI,CACrC,CAAA,IAAA,CAAK,cAAiBC,CAAAA,GAAAA,CAAM,SAAUD,CAAAA,CAAAA,C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CAAa,IAAK,CAAA,OAAA,CAAQ,WAC1B,CAAA,iBAAA,CAAmB,EACrB,CAAA,CACA,IAAK,CAAA,KAAA,CAAQ,CACX,QAAA,CAAU,CACV,CAAA,SAAA,CAAWA,EACX,QAAUA,CAAAA,CAAAA,CACV,SAAW,CAAA,EACX,CAAA,aAAA,CAAeA,CACf,CAAA,YAAA,CAAcA,EACd,WAAaA,CAAAA,CAAAA,CACb,YAAc,CAAA,GACd,QAAUA,CAAAA,CAAAA,CACV,UAAYA,CAAAA,CACd,EACF,CACF","file":"chunk-GF3OGUDE.mjs","sourcesContent":["import Utils from \"../Utils\";\r\nimport { Color, CountryCode, CurrencyCode, LocaleCode, LocalizedString, LocalizedValue } from \"./Common\";\r\nimport CouponModel from \"./Coupon\";\r\nimport { LineItemState, LocaleLanguageMap, TaxSystem } from \"./Enum\";\r\nimport ImageInfoModel, { ImageInfoData } from \"./ImageInfo\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport ProductModel, { ProductSelectionAttributes, ProductSpecification, SelectionAttributes } from \"./Product\";\r\nimport { TaxRuleData, TaxRuleModel, TaxSlabModel, TaxSlabs } from \"./TaxRule\";\r\nimport { TieredPriceData, TieredPriceModel } from \"./TieredPrice\";\r\nimport {\r\n DuplicateSizeError,\r\n ProductMismatchError,\r\n ProductInactiveError,\r\n SizeMismatchError,\r\n PricingNotFoundError,\r\n InvalidTaxRuleError,\r\n InvalidLineItemStateError\r\n} from \"./Error\";\r\nimport { CustomFieldAttributes, CustomFieldModel } from \"./Base\";\r\n\r\nexport type SubItem = {\r\n size: string | 'ONESIZE';\r\n quantity: number;\r\n};\r\n\r\nexport type LineItemPricing = {\r\n unitPrice: PriceData;\r\n tierPricing: TieredPriceData;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleData[];\r\n};\r\n\r\nexport type LineItemTaxBreakdown = {\r\n rate: number; // 0.09 for 9%\r\n taxableUnitPrice: PriceData; // effectiveUnitPrice used for calculation\r\n taxPerUnit: PriceData; // tax on single unit\r\n amount: PriceData; // taxPerUnit × quantity (total tax)\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type LineItemTaxBreakdownModel = {\r\n rate: number;\r\n taxableUnitPrice: PriceModel;\r\n taxPerUnit: PriceModel;\r\n amount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type LineItemTotals = {\r\n quantity: number;\r\n unitPrice: PriceData; // original unit price (from tier pricing)\r\n subtotal: PriceData; // unitPrice × quantity\r\n discounts: Record<string, PriceData>; // couponCode -> discount mapping\r\n totalDiscount: PriceData; // sum of all discounts\r\n netUnitPrice: PriceData; // unit price after discounts\r\n netSubtotal: PriceData; // subtotal - totalDiscount (taxable amount)\r\n taxBreakdown: Record<string, LineItemTaxBreakdown>;\r\n taxTotal: PriceData; // sum of all tax amounts\r\n grandTotal: PriceData; // effectiveSubtotal + taxTotal\r\n};\r\n\r\nexport type LineItemTotalsModel = {\r\n quantity: number;\r\n unitPrice: PriceModel;\r\n subtotal: PriceModel;\r\n discounts: Record<string, PriceModel>;\r\n totalDiscount: PriceModel;\r\n netUnitPrice: PriceModel;\r\n netSubtotal: PriceModel;\r\n taxBreakdown: Record<string, LineItemTaxBreakdownModel>;\r\n taxTotal: PriceModel;\r\n grandTotal: PriceModel;\r\n};\r\n\r\nexport type LineItemAttributes = CustomFieldAttributes & {\r\n id: string;\r\n\r\n productKey: string;\r\n selectionAttributes: SelectionAttributes;\r\n\r\n name: LocalizedString;\r\n specifications: LocalizedValue<ProductSpecification>;\r\n primaryImage: ImageInfoData;\r\n\r\n subItems: SubItem[];\r\n\r\n pricing: LineItemPricing;\r\n\r\n state?: LineItemState;\r\n total: LineItemTotals;\r\n}\r\n\r\nexport type LineItemData = Required<LineItemAttributes>;\r\n\r\n/**\r\n * Represents a line item within a shopping cart.\r\n */\r\nexport default class LineItemModel extends CustomFieldModel {\r\n protected id: string;\r\n protected productKey: string;\r\n protected selectionAttributes: SelectionAttributes;\r\n\r\n protected name: LocalizedString;\r\n protected specifications: LocalizedValue<ProductSpecification>;\r\n protected primaryImage: ImageInfoModel;\r\n protected subItems: SubItem[];\r\n protected pricing: {\r\n unitPrice: PriceModel;\r\n tierPricing: TieredPriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleModel[];\r\n };\r\n\r\n protected state: LineItemState;\r\n protected total: LineItemTotalsModel;\r\n\r\n /**\r\n * Creates an instance of LineItemModel.\r\n * @param data - The initial line item attributes.\r\n */\r\n constructor(data: LineItemAttributes) {\r\n super(data);\r\n this.id = data.id;\r\n this.productKey = data.productKey;\r\n this.selectionAttributes = Utils.deepClone(data.selectionAttributes);\r\n\r\n this.name = Utils.deepClone(data.name);\r\n this.specifications = Utils.deepClone(data.specifications);\r\n this.primaryImage = new ImageInfoModel(data.primaryImage);\r\n this.subItems = Utils.deepClone(data.subItems);\r\n\r\n let uniqueSelectionAttributes = new Set();\r\n this.subItems.forEach(item => {\r\n if (uniqueSelectionAttributes.has(item.size)) {\r\n throw new DuplicateSizeError(item.size);\r\n }\r\n uniqueSelectionAttributes.add(item.size);\r\n });\r\n\r\n this.pricing = {\r\n unitPrice: new PriceModel(data.pricing.unitPrice),\r\n tierPricing: new TieredPriceModel(data.pricing.tierPricing),\r\n taxCategory: data.pricing.taxCategory,\r\n applicableTaxRule: data.pricing.applicableTaxRule.map(rule => new TaxRuleModel(rule)),\r\n }\r\n\r\n this.state = data.state ?? LineItemState.INITIAL;\r\n\r\n this.total = {\r\n quantity: data.total.quantity,\r\n unitPrice: new PriceModel(data.total.unitPrice),\r\n subtotal: new PriceModel(data.total.subtotal),\r\n discounts: Object.fromEntries(\r\n Object.entries(data.total.discounts).map(([couponCode, discount]) => [\r\n couponCode,\r\n new PriceModel(discount),\r\n ])\r\n ),\r\n totalDiscount: new PriceModel(data.total.totalDiscount),\r\n netUnitPrice: new PriceModel(data.total.netUnitPrice),\r\n netSubtotal: new PriceModel(data.total.netSubtotal),\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 taxableUnitPrice: new PriceModel(taxBreakdown.taxableUnitPrice),\r\n taxPerUnit: new PriceModel(taxBreakdown.taxPerUnit),\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 line item.\r\n * @returns The unique ID string.\r\n */\r\n getId(): string {\r\n return this.id;\r\n }\r\n\r\n /**\r\n * Gets the product key associated with this line item.\r\n * @returns The product key string.\r\n */\r\n getProductKey(): string {\r\n return this.productKey;\r\n }\r\n\r\n /**\r\n * Gets the selection attributes (e.g., size, color) for this line item.\r\n * @returns A copy of the selection attributes object.\r\n */\r\n getSelectionAttributes(): SelectionAttributes {\r\n return Utils.deepClone(this.selectionAttributes);\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 full localized product specifications object.\r\n * @returns Product Specifications\r\n */\r\n getSpecifications(): LocalizedValue<ProductSpecification>\r\n /**\r\n * Gets the product specifications for a specific locale, falling back to English ('en').\r\n * @param locale - The desired locale code.\r\n * @returns The ProductSpecification object for the specified locale, or undefined if not found.\r\n */\r\n getSpecifications(locale: LocaleCode): ProductSpecification | undefined\r\n getSpecifications(locale?: LocaleCode): LocalizedValue<ProductSpecification> | ProductSpecification | undefined {\r\n if (locale) {\r\n return Utils.deepClone(this.specifications[locale] ?? this.specifications[LocaleLanguageMap[locale]] ?? this.specifications.en);\r\n } else {\r\n return Utils.deepClone(this.specifications);\r\n }\r\n }\r\n\r\n /**\r\n * Gets the image information model for this line item.\r\n * @returns The ImageInfoModel instance.\r\n */\r\n getImage(): ImageInfoModel {\r\n return this.primaryImage;\r\n }\r\n\r\n /**\r\n * Gets the sub-items (size/quantity breakdown).\r\n * @returns A copy of the array of SubItems.\r\n */\r\n getSubItems(): SubItem[] {\r\n return Utils.deepClone(this.subItems);\r\n }\r\n\r\n /**\r\n * Gets the total quantity for this line item across all sub-items.\r\n * @returns The total quantity as a number.\r\n */\r\n getTotalQuantity(): number {\r\n return this.total.quantity;\r\n }\r\n\r\n /**\r\n * Gets the pricing information model for this line item.\r\n * @returns An object containing unit price, tiered pricing, tax category, and tax details.\r\n */\r\n getPricing() {\r\n return {\r\n unitPrice: this.pricing.unitPrice,\r\n tierPricing: this.pricing.tierPricing,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: this.pricing.applicableTaxRule,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current state of the line item.\r\n * @returns The LineItemState enum value.\r\n */\r\n getState() {\r\n return this.state;\r\n }\r\n\r\n /**\r\n * Gets the total price for this line item (including all sub-items).\r\n * @returns An object containing line item totals including subtotal, tax, discounts, and grand total.\r\n */\r\n getTotal(): LineItemTotalsModel {\r\n return {\r\n quantity: this.total.quantity,\r\n unitPrice: this.total.unitPrice,\r\n subtotal: this.total.subtotal,\r\n discounts: Object.fromEntries(\r\n Object.entries(this.total.discounts).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount,\r\n ])\r\n ),\r\n totalDiscount: this.total.totalDiscount,\r\n netUnitPrice: this.total.netUnitPrice,\r\n netSubtotal: this.total.netSubtotal,\r\n taxBreakdown: this.total.taxBreakdown,\r\n taxTotal: this.total.taxTotal,\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the line item's details.\r\n * @returns LineItemData.\r\n */\r\n getDetails(): LineItemData {\r\n const pricing = this.getPricing();\r\n const total = this.getTotal();\r\n return {\r\n id: this.getId(),\r\n productKey: this.getProductKey(),\r\n selectionAttributes: this.getSelectionAttributes(),\r\n name: this.getName(),\r\n specifications: this.getSpecifications(),\r\n primaryImage: this.getImage().getDetails(),\r\n subItems: this.getSubItems(),\r\n pricing: {\r\n unitPrice: pricing.unitPrice.getDetails(),\r\n tierPricing: pricing.tierPricing.getDetails(),\r\n taxCategory: pricing.taxCategory,\r\n applicableTaxRule: pricing.applicableTaxRule.map(rule => rule.getDetails()),\r\n },\r\n state: this.getState(),\r\n total: {\r\n quantity: total.quantity,\r\n unitPrice: total.unitPrice.getDetails(),\r\n subtotal: total.subtotal.getDetails(),\r\n discounts: Object.fromEntries(\r\n Object.entries(total.discounts).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount.getDetails(),\r\n ])\r\n ),\r\n totalDiscount: total.totalDiscount.getDetails(),\r\n netUnitPrice: total.netUnitPrice.getDetails(),\r\n netSubtotal: total.netSubtotal.getDetails(),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: taxBreakdown.taxableUnitPrice.getDetails(),\r\n taxPerUnit: taxBreakdown.taxPerUnit.getDetails(),\r\n amount: taxBreakdown.amount.getDetails(),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n taxTotal: total.taxTotal.getDetails(),\r\n grandTotal: total.grandTotal.getDetails(),\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n }\r\n\r\n /**\r\n * Adds or updates sub-items (e.g., sizes with quantities) to the line item.\r\n * If a sub-item with the same size already exists, its quantity is either\r\n * updated by adding the new quantity or replaced entirely, based on the `addQuantity` flag.\r\n * Sub-items with a resulting quantity of 0 are removed.\r\n * @param subItems - An array of `SubItem` objects to add or update.\r\n * @param addQuantity - If true, adds the quantity from `subItem` to the existing quantity.\r\n * If false, replaces the existing quantity with the one from `subItem`.\r\n */\r\n addSubItems(subItems: SubItem[], addQuantity: boolean): void {\r\n subItems.forEach(subItem => {\r\n const existingSubItem = this.subItems.find(item => item.size === subItem.size);\r\n if (existingSubItem) {\r\n existingSubItem.quantity = addQuantity ? existingSubItem.quantity + subItem.quantity : subItem.quantity;\r\n } else {\r\n this.subItems.push(subItem);\r\n }\r\n })\r\n this.subItems = this.subItems.filter(sub => sub.quantity > 0);\r\n this.calculateTotals();\r\n }\r\n\r\n /**\r\n * Updates the line item with the latest product data (price, image, name, specifications).\r\n * Validates that the product matches the line item's selection and is active.\r\n * @param product - The product model to update from.\r\n * @param cartCountry - The country code for pricing context.\r\n * @param cartCurrency - The currency code for pricing context.\r\n * @throws {Error} If product mismatch, inactive, size mismatch, or pricing missing.\r\n */\r\n public updateProductData(product: ProductModel, cartCountry: CountryCode, cartCurrency: CurrencyCode): void {\r\n if (this.productKey !== product.getKey() || !product.validateSelectionAttribute(this.selectionAttributes)) {\r\n throw new ProductMismatchError();\r\n } else if (!product.getIsActive()) {\r\n throw new ProductInactiveError();\r\n }\r\n\r\n this.subItems.forEach(subItem => {\r\n if (!product.validateSize(subItem.size)) {\r\n throw new SizeMismatchError();\r\n }\r\n });\r\n\r\n const productPricing = product.getPriceDetails(cartCountry);\r\n if (!productPricing || productPricing.getBaseUnitPrice().getCurrency() !== cartCurrency) {\r\n throw new PricingNotFoundError();\r\n }\r\n this.name = product.getName();\r\n this.specifications = product.getSpecifications();\r\n this.primaryImage = product.getImages(this.selectionAttributes).primary;\r\n\r\n const quantity = this.subItems.reduce((sum, s) => sum + s.quantity, 0);\r\n const { unitPrice } = productPricing.getApplicableTier(quantity);\r\n\r\n this.pricing = {\r\n unitPrice: unitPrice,\r\n tierPricing: productPricing,\r\n taxCategory: productPricing.getTaxCategory(),\r\n applicableTaxRule: this.pricing.applicableTaxRule\r\n }\r\n\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 lineItemDiscounts = {} as Record<string, PriceModel>;\r\n appliedDiscounts.forEach(discount => {\r\n lineItemDiscounts[discount.coupon.getCode()] = discount.amount;\r\n });\r\n\r\n this.total.discounts = lineItemDiscounts;\r\n this.calculateTotals();\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: TaxRuleModel[]): void {\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 * Recalculates the line item totals based on current quantity, unit price, discounts, and tax rates.\r\n */\r\n public calculateTotals(): void {\r\n const zero = this.pricing.unitPrice.zero();\r\n const totalQuantity = this.subItems.reduce((sum, s) => sum + s.quantity, 0);\r\n\r\n if (this.state === LineItemState.CANCELLED) {\r\n this.total = {\r\n quantity: 0,\r\n unitPrice: zero,\r\n subtotal: zero,\r\n discounts: {},\r\n totalDiscount: zero,\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxBreakdown: {},\r\n taxTotal: zero,\r\n grandTotal: zero\r\n };\r\n return;\r\n }\r\n\r\n const { unitPrice } = this.pricing.tierPricing.getApplicableTier(totalQuantity);\r\n const subTotal = unitPrice.multiply(totalQuantity);\r\n const totalDiscount = Object.values(this.total.discounts).reduce((sum, s) => sum.add(s), zero);\r\n const netSubtotal = subTotal.subtract(totalDiscount);\r\n const netUnitPrice = totalQuantity > 0 ? netSubtotal.divide(totalQuantity) : zero;\r\n\r\n // Calculate tax for each applicable rule\r\n const taxBreakdown: Record<string, LineItemTaxBreakdownModel> = {};\r\n let taxTotal = zero;\r\n this.pricing.applicableTaxRule.forEach(taxRule => {\r\n const rate = taxRule.getApplicableTaxRate(netUnitPrice);\r\n const taxPerUnit = taxRule.calculateTax(netUnitPrice);\r\n const amount = taxPerUnit.multiply(totalQuantity);\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxableUnitPrice: netUnitPrice,\r\n taxPerUnit: taxPerUnit,\r\n amount: amount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n taxTotal = taxTotal.add(amount);\r\n });\r\n\r\n const grandTotal = netSubtotal.add(taxTotal);\r\n\r\n this.total = {\r\n quantity: totalQuantity,\r\n unitPrice: unitPrice,\r\n subtotal: subTotal,\r\n discounts: this.total.discounts,\r\n totalDiscount: totalDiscount,\r\n netUnitPrice: netUnitPrice,\r\n netSubtotal: netSubtotal,\r\n taxBreakdown: taxBreakdown,\r\n taxTotal: taxTotal,\r\n grandTotal: grandTotal\r\n };\r\n }\r\n\r\n /**\r\n * Updates the line item's state.\r\n * @param newState \r\n */\r\n public updateState(newState: LineItemState): void {\r\n if (this.state in LineItemState) {\r\n if (this.state !== newState) {\r\n this.state = newState;\r\n }\r\n } else {\r\n throw new InvalidLineItemStateError(newState);\r\n }\r\n }\r\n\r\n /**\r\n * Resets the line item's properties to their default empty or initial state.\r\n * Useful for clearing out line item data without creating a new instance.\r\n * Recalculates total quantity and price total afterwards (which will be zero).\r\n */\r\n clearLineItem(): void {\r\n const zero = this.pricing.unitPrice.zero()\r\n this.id = '';\r\n this.productKey = '';\r\n this.selectionAttributes = { color: { name: '' } };\r\n this.name = { en: '' };\r\n this.primaryImage = new ImageInfoModel({ sources: { original: '' } });\r\n this.subItems = [];\r\n this.pricing = {\r\n unitPrice: zero,\r\n tierPricing: this.pricing.tierPricing,\r\n taxCategory: this.pricing.taxCategory,\r\n applicableTaxRule: []\r\n }\r\n this.total = {\r\n quantity: 0,\r\n unitPrice: zero,\r\n subtotal: zero,\r\n discounts: {},\r\n totalDiscount: zero,\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxBreakdown: {},\r\n taxTotal: zero,\r\n grandTotal: zero\r\n };\r\n }\r\n}"]}
|
package/dist/chunk-SNDTKUMW.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {c}from'./chunk-2HBQ3C6V.mjs';import {a as a$2}from'./chunk-Y5D6RHTJ.mjs';import {a as a$1}from'./chunk-XHGUVYQO.mjs';import {j}from'./chunk-XPKK6DFA.mjs';import {a}from'./chunk-6KCJVEZD.mjs';var u=class extends a{id;name;category;lineItemId;chargeType;pricing;total;constructor(t){super(t),this.id=t.id,this.name=t.name,this.category=t.category,this.lineItemId=t.lineItemId,this.chargeType=t.chargeType,this.pricing={price:new a$1(t.pricing.price),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(a=>new c(a))},this.total={price:new a$1(t.total.price),discounts:Object.fromEntries(Object.entries(t.total.discounts).map(([a,e])=>[a,new a$1(e)])),totalDiscount:new a$1(t.total.totalDiscount),netPrice:new a$1(t.total.netPrice),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([a,e])=>[a,{rate:e.rate,taxablePrice:new a$1(e.taxablePrice),amount:new a$1(e.amount),system:e.system,subSystem:e.subSystem}])),taxTotal:new a$1(t.total.taxTotal),grandTotal:new a$1(t.total.grandTotal)};}getId(){return this.id}getName(){return this.name}getCategory(){return this.category}getChargeType(){return this.chargeType}getLineItemId(){return this.lineItemId}getPricing(){return this.pricing}getTotal(){return this.total}getApplicableTaxRules(){return this.pricing.applicableTaxRule}updateTax(t){t.forEach(a=>{if(!a.appliesTo(this.pricing.taxCategory,a.getTaxCountry()))throw new j}),this.pricing.applicableTaxRule=t,this.calculateTotals();}updateDiscounts(t){let a={};t.forEach(e=>{a[e.coupon.getCode()]=e.amount;}),this.total.discounts=a,this.calculateTotals();}calculateTotals(){let t=this.pricing.price.zero(),a=this.pricing.price,e=Object.values(this.total.discounts).reduce((i,o)=>i.add(o),t),c=a.subtract(e),n={},d=this.pricing.applicableTaxRule.reduce((i,o)=>i+o.getApplicableTaxRate(),0),s=c.divide(1+d).round(),p=c.subtract(s),g=t,l=this.pricing.applicableTaxRule.reduce((i,o)=>o.getApplicableTaxRate()>i.getApplicableTaxRate()?o:i),m=l.getTaxRuleId();this.pricing.applicableTaxRule.forEach(i=>{if(i.getTaxRuleId()===m)return;let o=i.getApplicableTaxRate(),x=p.multiply(o).divide(d).round();n[i.getTaxRuleId()]={rate:o,taxablePrice:s,amount:x,system:i.getTaxSystem(),subSystem:i.getTaxSubSystem()},g=g.add(x);});let P=p.subtract(g);n[m]={rate:l.getApplicableTaxRate(),taxablePrice:s,amount:P,system:l.getTaxSystem(),subSystem:l.getTaxSubSystem()};let C=s,D=c;this.total={price:a,discounts:this.total.discounts,netPrice:C,totalDiscount:e,taxBreakdown:n,taxTotal:p,grandTotal:D};}getDetails(){return {id:this.id,name:a$2.deepClone(this.name),category:this.category,lineItemId:this.lineItemId,chargeType:this.chargeType,pricing:{price:this.pricing.price.getDetails(),taxCategory:this.pricing.taxCategory,applicableTaxRule:this.pricing.applicableTaxRule.map(a=>a.getDetails())},total:{price:this.total.price.getDetails(),discounts:Object.fromEntries(Object.entries(this.total.discounts).map(([a,e])=>[a,e.getDetails()])),totalDiscount:this.total.totalDiscount.getDetails(),netPrice:this.total.netPrice.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([a,e])=>[a,{rate:e.rate,taxablePrice:e.taxablePrice.getDetails(),amount:e.amount.getDetails(),system:e.system,subSystem:e.subSystem}])),taxTotal:this.total.taxTotal.getDetails(),grandTotal:this.total.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}};export{u as a};//# sourceMappingURL=chunk-SNDTKUMW.mjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-SNDTKUMW.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Classes/Charge.ts"],"names":["ChargeModel","CustomFieldModel","data","PriceModel","r","FixedTaxRuleModel","discountId","discount","taxRuleId","taxBreakdown","taxRules","taxRule","InvalidTaxRuleError","appliedDiscounts","chargeDiscounts","zero","price","totalDiscount","sum","s","grossAmount","totalRate","taxableBase","totalTaxAmount","distributedTax","maxRateRule","prev","current","maxRateRuleId","rate","taxAmount","maxRateTaxAmount","netPrice","grandTotal","Utils_default","k","v"],"mappings":"uMAqEA,IAAqBA,CAArB,CAAA,cAAyCC,CAAiB,CAC5C,GACA,IACA,CAAA,QAAA,CACA,UACA,CAAA,UAAA,CACA,QAKA,KAEV,CAAA,WAAA,CAAYC,CAAwB,CAAA,CAChC,MAAMA,CAAI,CAAA,CACV,IAAK,CAAA,EAAA,CAAKA,EAAK,EACf,CAAA,IAAA,CAAK,IAAOA,CAAAA,CAAAA,CAAK,KACjB,IAAK,CAAA,QAAA,CAAWA,CAAK,CAAA,QAAA,CACrB,KAAK,UAAaA,CAAAA,CAAAA,CAAK,UACvB,CAAA,IAAA,CAAK,WAAaA,CAAK,CAAA,UAAA,CACvB,IAAK,CAAA,OAAA,CAAU,CACX,KAAA,CAAO,IAAIC,GAAAA,CAAWD,EAAK,OAAQ,CAAA,KAAK,CACxC,CAAA,WAAA,CAAaA,EAAK,OAAQ,CAAA,WAAA,CAC1B,iBAAmBA,CAAAA,CAAAA,CAAK,QAAQ,iBAAkB,CAAA,GAAA,CAAIE,CAAK,EAAA,IAAIC,EAAkBD,CAAC,CAAC,CACvF,CAAA,CAEA,KAAK,KAAQ,CAAA,CACT,KAAO,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A,YAAA,CAAc,MAAO,CAAA,WAAA,CAAY,OAAO,OAAQ,CAAA,IAAA,CAAK,KAAM,CAAA,YAAY,EAAE,GAAI,CAAA,CAAC,CAACD,CAAAA,CAAGC,CAAC,CAAM,GAAA,CAACD,CAAG,CAAA,CACzF,KAAMC,CAAE,CAAA,IAAA,CACR,YAAcA,CAAAA,CAAAA,CAAE,aAAa,UAAW,EAAA,CACxC,MAAQA,CAAAA,CAAAA,CAAE,OAAO,UAAW,EAAA,CAC5B,MAAQA,CAAAA,CAAAA,CAAE,OACV,SAAWA,CAAAA,CAAAA,CAAE,SACjB,CAAC,CAAC,CAAC,CAAA,CACH,QAAU,CAAA,IAAA,CAAK,MAAM,QAAS,CAAA,UAAA,EAC9B,CAAA,UAAA,CAAY,KAAK,KAAM,CAAA,UAAA,CAAW,UAAW,EACjD,EACA,YAAc,CAAA,IAAA,CAAK,kBAAmB,EAC1C,CAEJ,CACJ","file":"chunk-SNDTKUMW.mjs","sourcesContent":["import BaseModel, { BaseAttributes, BaseData, CustomFieldAttributes, CustomFieldModel } from \"./Base\";\r\nimport Utils from \"../Utils\";\r\nimport { LocalizedString } from \"./Common\";\r\nimport { ChargeType, TaxSystem } from \"./Enum\";\r\nimport { InvalidChargeError, InvalidTaxRuleError } from \"./Error\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { FixedTaxRuleData, FixedTaxRuleModel, TaxRuleData, TaxRuleModel } 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 pricing: ChargePricing;\r\n total: ChargeTotals;\r\n};\r\n\r\nexport type ChargeData = Omit<Required<ChargeAttributes>, 'lineItemId'> & {\r\n lineItemId?: string;\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 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.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 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 public getId(): string { return this.id; }\r\n public getName(): LocalizedString { return this.name; }\r\n public getCategory(): string { return this.category; }\r\n public getChargeType(): ChargeType { return this.chargeType; }\r\n public getLineItemId(): string | undefined { return this.lineItemId; }\r\n public getPricing() { return this.pricing; }\r\n public getTotal(): ChargeTotalsModel { return this.total; }\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 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 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 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 = grossAmount.subtract(taxableBase);\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 = totalTaxAmount.multiply(rate).divide(totalRate).round();\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 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 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"]}
|