b23-lib 3.2.2 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Classes/Invoice.ts"],"names":["InvoiceModel","BaseModel","data","date","AddressModel","Utils_default","PriceModel","key","value","breakdown","systemKey","systemValue","subKey","subValue","totals"],"mappings":"8RAoGA,IAAqBA,EAArB,cAA0CC,CAAU,CACxC,aACA,CAAA,WAAA,CACA,UACA,OACA,CAAA,QAAA,CACA,MACA,CAAA,UAAA,CACA,cACA,cACA,CAAA,eAAA,CACA,WACA,QACA,CAAA,SAAA,CACA,QACA,KAEV,CAAA,WAAA,CAAYC,CAAyBC,CAAAA,CAAAA,CAAa,IAAI,IAAQ,CAAA,CAC5D,MAAMD,CAAMC,CAAAA,CAAI,EAChB,IAAK,CAAA,aAAA,CAAgBD,CAAK,CAAA,aAAA,CAC1B,KAAK,WAAcA,CAAAA,CAAAA,CAAK,YACxB,IAAK,CAAA,SAAA,CAAYA,EAAK,SACtB,CAAA,IAAA,CAAK,OAAUA,CAAAA,CAAAA,CAAK,QACpB,IAAK,CAAA,QAAA,CAAWA,EAAK,QACrB,CAAA,IAAA,CAAK,OAASA,CAAK,CAAA,MAAA,CACnB,IAAK,CAAA,UAAA,CAAaA,EAAK,UACvB,CAAA,IAAA,CAAK,cAAgBA,CAAK,CAAA,aAAA,CAC1B,KAAK,cAAiB,CAAA,IAAIE,GAAaF,CAAAA,CAAAA,CAAK,cAAc,CAC1D,CAAA,IAAA,CAAK,gBAAkB,IAAIE,GAAAA,CAAaF,EAAK,eAAe,CAAA,CAC5D,KAAK,UAAaA,CAAAA,CAAAA,CAAK,WACvB,IAAK,CAAA,QAAA,CAAW,CACd,YAAcA,CAAAA,CAAAA,CAAK,SAAS,YAC5B,CAAA,aAAA,CAAeA,CAAK,CAAA,QAAA,CAAS,cAC7B,KAAOA,CAAAA,CAAAA,CAAK,SAAS,KACrB,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UAAA,EACxC,CAAA,kBAAA,CAAoBA,EAAO,kBAAmB,CAAA,UAAA,GAC9C,uBAAyBA,CAAAA,CAAAA,CAAO,wBAAwB,UAAW,EAAA,CACnE,2BAA6B,CAAA,IAAA,CAAK,sBAAsBA,CAAO,CAAA,2BAA2B,EAE1F,iBAAmBA,CAAAA,CAAAA,CAAO,kBAAkB,UAAW,EAAA,CAEvD,gBAAiBA,CAAO,CAAA,eAAA,CAAgB,YACxC,CAAA,kBAAA,CAAoBA,EAAO,kBAAmB,CAAA,UAAA,GAG9C,aAAeA,CAAAA,CAAAA,CAAO,aAAc,CAAA,UAAA,GACpC,iBAAmB,CAAA,MAAA,CAAO,YACxB,MAAO,CAAA,OAAA,CAAQA,EAAO,iBAAiB,CAAA,CAAE,GAAI,CAAA,CAAC,CAACP,CAAKC,CAAAA,CAAK,IAAM,CAACD,CAAAA,CAAKC,EAAM,UAAW,EAAC,CAAC,CAC1F,EACA,QAAUM,CAAAA,CAAAA,CAAO,SAAS,UAAW,EAAA,CACrC,aAAc,IAAK,CAAA,qBAAA,CAAsBA,EAAO,YAAY,CAAA,CAC5D,WAAYA,CAAO,CAAA,UAAA,CAAW,YAChC,CACF,CACF,CACF","file":"Invoice.mjs","sourcesContent":["import { ChargeImpact, ChargeType, TaxSystem } from \"./Enum\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { CountryCode, CurrencyCode, LocaleCode, Prettify } from \"./Common\";\r\nimport AddressModel, { AddressData } from \"./Address\";\r\nimport { ShoppingContainerTotal, ShoppingContainerTotalModel, TaxSystemBreakdown, TaxSystemBreakdownModel } from \"./ShoppingContainer\";\r\nimport BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport Utils from \"../Utils\";\r\n\r\nexport type InvoiceTaxBreakdown = {\r\n rate: number;\r\n taxableAmount: PriceData;\r\n taxAmount: PriceData;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type InvoiceTaxBreakdownModel = {\r\n rate: number;\r\n taxableAmount: PriceModel;\r\n taxAmount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type InvoiceLineItemData = {\r\n id: string;\r\n productKey: string;\r\n name: string;\r\n variantLabel: string;\r\n quantity: number;\r\n netUnitPrice: PriceData;\r\n netSubtotal: PriceData;\r\n taxTotal: PriceData;\r\n grandTotal: PriceData;\r\n taxBreakdown: Record<string, InvoiceTaxBreakdown>;\r\n taxCode: string;\r\n taxCodeType: string;\r\n}\r\n\r\nexport type InvoiceChargeData = {\r\n id: string;\r\n type: ChargeType;\r\n category: string;\r\n impact: ChargeImpact;\r\n name: string;\r\n taxableValue: PriceData;\r\n taxTotal: PriceData;\r\n grandTotal: PriceData;\r\n taxBreakdown: Record<string, InvoiceTaxBreakdown>;\r\n taxCode: string;\r\n taxCodeType: string;\r\n}\r\n\r\n\r\nexport type InvoiceTaxContextData = {\r\n recipientTaxIdentifier: string;\r\n recipientTaxIdentifierType: string;\r\n supplyRegion: string;\r\n supplyRegionCode: string;\r\n}\r\n\r\nexport type MerchantData = {\r\n merchantName: string;\r\n taxIdentifier: string;\r\n email: string;\r\n phone: string;\r\n address: AddressData;\r\n};\r\n\r\nexport type MerchantModel = {\r\n merchantName: string;\r\n taxIdentifier: string;\r\n email: string;\r\n phone: string;\r\n address: AddressModel;\r\n};\r\n\r\nexport type InvoiceTotal = ShoppingContainerTotal;\r\nexport type InvoiceTotalModel = ShoppingContainerTotalModel;\r\n\r\nexport type InvoiceAttributes = Prettify<BaseAttributes & {\r\n invoiceNumber: string;\r\n orderNumber: string;\r\n issueDate: string;\r\n country: CountryCode;\r\n currency: CurrencyCode;\r\n locale: LocaleCode;\r\n customerId: string;\r\n customerEmail: string;\r\n billingAddress: AddressData;\r\n shippingAddress: AddressData;\r\n taxContext: InvoiceTaxContextData;\r\n merchant: MerchantData;\r\n lineItems: InvoiceLineItemData[];\r\n charges: InvoiceChargeData[];\r\n total: InvoiceTotal;\r\n}>;\r\n\r\nexport type InvoiceData = Prettify<BaseData & InvoiceAttributes>;\r\n\r\nexport default class InvoiceModel extends BaseModel {\r\n protected invoiceNumber: string;\r\n protected orderNumber: string;\r\n protected issueDate: string;\r\n protected country: CountryCode;\r\n protected currency: CurrencyCode;\r\n protected locale: LocaleCode;\r\n protected customerId: string;\r\n protected customerEmail: string;\r\n protected billingAddress: AddressModel;\r\n protected shippingAddress: AddressModel;\r\n protected taxContext: InvoiceTaxContextData;\r\n protected merchant: MerchantModel;\r\n protected lineItems: InvoiceLineItemData[];\r\n protected charges: InvoiceChargeData[];\r\n protected total: InvoiceTotalModel;\r\n\r\n constructor(data: InvoiceAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.invoiceNumber = data.invoiceNumber;\r\n this.orderNumber = data.orderNumber;\r\n this.issueDate = data.issueDate;\r\n this.country = data.country;\r\n this.currency = data.currency;\r\n this.locale = data.locale;\r\n this.customerId = data.customerId;\r\n this.customerEmail = data.customerEmail;\r\n this.billingAddress = new AddressModel(data.billingAddress);\r\n this.shippingAddress = new AddressModel(data.shippingAddress);\r\n this.taxContext = data.taxContext;\r\n this.merchant = {\r\n merchantName: data.merchant.merchantName,\r\n taxIdentifier: data.merchant.taxIdentifier,\r\n email: data.merchant.email,\r\n phone: data.merchant.phone,\r\n address: new AddressModel(data.merchant.address)\r\n };\r\n this.lineItems = Utils.deepClone(data.lineItems);\r\n this.charges = Utils.deepClone(data.charges);\r\n this.total = {\r\n lineItemSubtotal: new PriceModel(data.total.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.netLineItemSubtotal),\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown),\r\n\r\n additiveCharges: new PriceModel(data.total.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.netAdditiveCharges),\r\n additiveChargesTaxTotal: new PriceModel(data.total.additiveChargesTaxTotal),\r\n\r\n additiveChargesTaxBreakdown: this.mapTaxBreakdown(data.total.additiveChargesTaxBreakdown),\r\n adjustmentCharges: new PriceModel(data.total.adjustmentCharges),\r\n shippingCharges: new PriceModel(data.total.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.netShippingCharges),\r\n\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n 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 getInvoiceNumber(): string {\r\n return this.invoiceNumber;\r\n }\r\n\r\n getOrderNumber(): string {\r\n return this.orderNumber;\r\n }\r\n\r\n getIssueDate(): string {\r\n return this.issueDate;\r\n }\r\n\r\n getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n getLocale(): LocaleCode {\r\n return this.locale;\r\n }\r\n\r\n getCustomerId(): string {\r\n return this.customerId;\r\n }\r\n\r\n getCustomerEmail(): string {\r\n return this.customerEmail;\r\n }\r\n\r\n getTaxContext(): InvoiceTaxContextData {\r\n return { ...this.taxContext };\r\n }\r\n\r\n getTaxRegistrationNumber(): string {\r\n return this.taxContext.recipientTaxIdentifier;\r\n }\r\n\r\n getRecipientTaxIdentifier(): string {\r\n return this.taxContext.recipientTaxIdentifier;\r\n }\r\n\r\n getRecipientTaxIdentifierType(): string {\r\n return this.taxContext.recipientTaxIdentifierType;\r\n }\r\n\r\n getBillingAddress(): AddressModel {\r\n return this.billingAddress;\r\n }\r\n\r\n getShippingAddress(): AddressModel {\r\n return this.shippingAddress;\r\n }\r\n\r\n getPlaceOfSupplyState(): string {\r\n return this.taxContext.supplyRegion;\r\n }\r\n\r\n getPlaceOfSupplyCode(): string {\r\n return this.taxContext.supplyRegionCode;\r\n }\r\n\r\n getSupplyRegion(): string {\r\n return this.taxContext.supplyRegion;\r\n }\r\n\r\n getSupplyRegionCode(): string {\r\n return this.taxContext.supplyRegionCode;\r\n }\r\n\r\n getMerchant(): MerchantModel {\r\n return {\r\n merchantName: this.merchant.merchantName,\r\n taxIdentifier: this.merchant.taxIdentifier,\r\n email: this.merchant.email,\r\n phone: this.merchant.phone,\r\n address: this.merchant.address\r\n };\r\n }\r\n\r\n getLineItems(): InvoiceLineItemData[] {\r\n return this.lineItems;\r\n }\r\n\r\n getCharges(): InvoiceChargeData[] {\r\n return this.charges;\r\n }\r\n\r\n getTotal(): InvoiceTotalModel {\r\n return this.total;\r\n }\r\n\r\n getDetails(): InvoiceData {\r\n const totals = this.getTotal();\r\n return {\r\n ...super.getDetails(),\r\n invoiceNumber: this.invoiceNumber,\r\n orderNumber: this.orderNumber,\r\n issueDate: this.issueDate,\r\n country: this.country,\r\n currency: this.currency,\r\n locale: this.locale,\r\n customerId: this.customerId,\r\n customerEmail: this.customerEmail,\r\n billingAddress: this.billingAddress.getDetails(),\r\n shippingAddress: this.shippingAddress.getDetails(),\r\n taxContext: this.taxContext,\r\n merchant: {\r\n merchantName: this.merchant.merchantName,\r\n taxIdentifier: this.merchant.taxIdentifier,\r\n email: this.merchant.email,\r\n phone: this.merchant.phone,\r\n address: this.merchant.address.getDetails()\r\n },\r\n lineItems: this.lineItems,\r\n charges: this.charges,\r\n total: {\r\n // Item Totals\r\n lineItemSubtotal: totals.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.netLineItemSubtotal.getDetails(),\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n additiveCharges: totals.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.netAdditiveCharges.getDetails(),\r\n additiveChargesTaxTotal: totals.additiveChargesTaxTotal.getDetails(),\r\n additiveChargesTaxBreakdown: this.serializeTaxBreakdown(totals.additiveChargesTaxBreakdown),\r\n\r\n adjustmentCharges: totals.adjustmentCharges.getDetails(),\r\n\r\n shippingCharges: totals.shippingCharges.getDetails(),\r\n netShippingCharges: totals.netShippingCharges.getDetails(),\r\n\r\n // Aggregate Totals\r\n discountTotal: totals.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(totals.discountBreakdown).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n grandTotal: totals.grandTotal.getDetails(),\r\n },\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"sources":["../../src/Classes/Invoice.ts"],"names":["InvoiceModel","BaseModel","data","date","AddressModel","item","PriceModel","systemKey","systemValue","charge","key","value","breakdown","subKey","subValue","totals"],"mappings":"qLAgIqBA,IAAAA,CAAAA,C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qBA,CAAAA,CAAAA,CAAO,mBAAoB,CAAA,UAAA,EAChD,CAAA,gBAAA,CAAkBA,CAAO,CAAA,gBAAA,CAAiB,YAC1C,CAAA,oBAAA,CAAsB,IAAK,CAAA,qBAAA,CAAsBA,CAAO,CAAA,oBAAoB,CAG5E,CAAA,eAAA,CAAiBA,CAAO,CAAA,eAAA,CAAgB,UAAW,EAAA,CACnD,kBAAoBA,CAAAA,CAAAA,CAAO,mBAAmB,UAAW,EAAA,CACzD,uBAAyBA,CAAAA,CAAAA,CAAO,uBAAwB,CAAA,UAAA,EACxD,CAAA,2BAAA,CAA6B,IAAK,CAAA,qBAAA,CAAsBA,CAAO,CAAA,2BAA2B,CAE1F,CAAA,iBAAA,CAAmBA,EAAO,iBAAkB,CAAA,UAAA,EAE5C,CAAA,eAAA,CAAiBA,CAAO,CAAA,eAAA,CAAgB,UAAW,EAAA,CACnD,kBAAoBA,CAAAA,CAAAA,CAAO,kBAAmB,CAAA,UAAA,EAG9C,CAAA,aAAA,CAAeA,EAAO,aAAc,CAAA,UAAA,EACpC,CAAA,iBAAA,CAAmB,MAAO,CAAA,WAAA,CACxB,MAAO,CAAA,OAAA,CAAQA,CAAO,CAAA,iBAAiB,CAAE,CAAA,GAAA,CAAI,CAAC,CAACL,EAAKC,CAAK,CAAA,GAAM,CAACD,CAAAA,CAAKC,CAAM,CAAA,UAAA,EAAY,CAAC,CAC1F,CAAA,CACA,QAAUI,CAAAA,CAAAA,CAAO,QAAS,CAAA,UAAA,EAC1B,CAAA,YAAA,CAAc,IAAK,CAAA,qBAAA,CAAsBA,CAAO,CAAA,YAAY,CAC5D,CAAA,UAAA,CAAYA,CAAO,CAAA,UAAA,CAAW,UAAW,EAC3C,CACF,CACF,CACF","file":"Invoice.mjs","sourcesContent":["import { ChargeImpact, ChargeType, TaxSystem } from \"./Enum\";\r\nimport PriceModel, { PriceData } from \"./Price\";\r\nimport { CountryCode, CurrencyCode, LocaleCode, Prettify } from \"./Common\";\r\nimport AddressModel, { AddressData } from \"./Address\";\r\nimport { ShoppingContainerTotal, ShoppingContainerTotalModel, TaxSystemBreakdown, TaxSystemBreakdownModel } from \"./ShoppingContainer\";\r\nimport BaseModel, { BaseAttributes, BaseData } from \"./Base\";\r\nimport Utils from \"../Utils\";\r\n\r\nexport type InvoiceTaxBreakdown = {\r\n rate: number;\r\n taxableAmount: PriceData;\r\n taxAmount: PriceData;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type InvoiceTaxBreakdownModel = {\r\n rate: number;\r\n taxableAmount: PriceModel;\r\n taxAmount: PriceModel;\r\n system: TaxSystem;\r\n subSystem: string;\r\n};\r\n\r\nexport type InvoiceLineItemData = {\r\n id: string;\r\n productKey: string;\r\n name: string;\r\n variantLabel: string;\r\n quantity: number;\r\n netUnitPrice: PriceData;\r\n netSubtotal: PriceData;\r\n taxTotal: PriceData;\r\n grandTotal: PriceData;\r\n taxBreakdown: Record<string, InvoiceTaxBreakdown>;\r\n taxCode: string;\r\n taxCodeType: string;\r\n}\r\n\r\nexport type InvoiceLineItemModel = {\r\n id: string;\r\n productKey: string;\r\n name: string;\r\n variantLabel: string;\r\n quantity: number;\r\n netUnitPrice: PriceModel;\r\n netSubtotal: PriceModel;\r\n taxTotal: PriceModel;\r\n grandTotal: PriceModel;\r\n taxBreakdown: Record<string, InvoiceTaxBreakdownModel>;\r\n taxCode: string;\r\n taxCodeType: string;\r\n}\r\n\r\nexport type InvoiceChargeData = {\r\n id: string;\r\n type: ChargeType;\r\n category: string;\r\n impact: ChargeImpact;\r\n name: string;\r\n taxableValue: PriceData;\r\n taxTotal: PriceData;\r\n grandTotal: PriceData;\r\n taxBreakdown: Record<string, InvoiceTaxBreakdown>;\r\n taxCode: string;\r\n taxCodeType: string;\r\n}\r\n\r\nexport type InvoiceChargeModel = {\r\n id: string;\r\n type: ChargeType;\r\n category: string;\r\n impact: ChargeImpact;\r\n name: string;\r\n taxableValue: PriceModel;\r\n taxTotal: PriceModel;\r\n grandTotal: PriceModel;\r\n taxBreakdown: Record<string, InvoiceTaxBreakdownModel>;\r\n taxCode: string;\r\n taxCodeType: string;\r\n}\r\n\r\nexport type InvoiceTaxContextData = {\r\n recipientTaxIdentifier: string;\r\n recipientTaxIdentifierType: string;\r\n supplyRegion: string;\r\n supplyRegionCode: string;\r\n}\r\n\r\nexport type MerchantData = {\r\n merchantName: string;\r\n taxIdentifier: string;\r\n email: string;\r\n phone: string;\r\n address: AddressData;\r\n};\r\n\r\nexport type MerchantModel = {\r\n merchantName: string;\r\n taxIdentifier: string;\r\n email: string;\r\n phone: string;\r\n address: AddressModel;\r\n};\r\n\r\nexport type InvoiceTotal = ShoppingContainerTotal;\r\nexport type InvoiceTotalModel = ShoppingContainerTotalModel;\r\n\r\nexport type InvoiceAttributes = Prettify<BaseAttributes & {\r\n invoiceNumber: string;\r\n orderNumber: string;\r\n issueDate: string;\r\n country: CountryCode;\r\n currency: CurrencyCode;\r\n locale: LocaleCode;\r\n customerId: string;\r\n customerEmail: string;\r\n billingAddress: AddressData;\r\n shippingAddress: AddressData;\r\n taxContext: InvoiceTaxContextData;\r\n merchant: MerchantData;\r\n lineItems: InvoiceLineItemData[];\r\n charges: InvoiceChargeData[];\r\n total: InvoiceTotal;\r\n}>;\r\n\r\nexport type InvoiceData = Prettify<BaseData & InvoiceAttributes>;\r\n\r\nexport default class InvoiceModel extends BaseModel {\r\n protected invoiceNumber: string;\r\n protected orderNumber: string;\r\n protected issueDate: string;\r\n protected country: CountryCode;\r\n protected currency: CurrencyCode;\r\n protected locale: LocaleCode;\r\n protected customerId: string;\r\n protected customerEmail: string;\r\n protected billingAddress: AddressModel;\r\n protected shippingAddress: AddressModel;\r\n protected taxContext: InvoiceTaxContextData;\r\n protected merchant: MerchantModel;\r\n protected lineItems: InvoiceLineItemModel[];\r\n protected charges: InvoiceChargeModel[];\r\n protected total: InvoiceTotalModel;\r\n\r\n constructor(data: InvoiceAttributes, date: Date = new Date()) {\r\n super(data, date);\r\n this.invoiceNumber = data.invoiceNumber;\r\n this.orderNumber = data.orderNumber;\r\n this.issueDate = data.issueDate;\r\n this.country = data.country;\r\n this.currency = data.currency;\r\n this.locale = data.locale;\r\n this.customerId = data.customerId;\r\n this.customerEmail = data.customerEmail;\r\n this.billingAddress = new AddressModel(data.billingAddress);\r\n this.shippingAddress = new AddressModel(data.shippingAddress);\r\n this.taxContext = data.taxContext;\r\n this.merchant = {\r\n merchantName: data.merchant.merchantName,\r\n taxIdentifier: data.merchant.taxIdentifier,\r\n email: data.merchant.email,\r\n phone: data.merchant.phone,\r\n address: new AddressModel(data.merchant.address)\r\n };\r\n this.lineItems = data.lineItems.map((item) => {\r\n return {\r\n ...item,\r\n netUnitPrice: new PriceModel(item.netUnitPrice),\r\n netSubtotal: new PriceModel(item.netSubtotal),\r\n taxTotal: new PriceModel(item.taxTotal),\r\n grandTotal: new PriceModel(item.grandTotal),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(item.taxBreakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n ...systemValue,\r\n taxableAmount: new PriceModel(systemValue.taxableAmount),\r\n taxAmount: new PriceModel(systemValue.taxAmount),\r\n },\r\n ])\r\n )\r\n };\r\n });\r\n this.charges = data.charges.map((charge) => {\r\n return {\r\n ...charge,\r\n taxableValue: new PriceModel(charge.taxableValue),\r\n taxTotal: new PriceModel(charge.taxTotal),\r\n grandTotal: new PriceModel(charge.grandTotal),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(charge.taxBreakdown || {}).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n ...systemValue,\r\n taxableAmount: new PriceModel(systemValue.taxableAmount),\r\n taxAmount: new PriceModel(systemValue.taxAmount),\r\n },\r\n ])\r\n )\r\n };\r\n });\r\n\r\n this.total = {\r\n lineItemSubtotal: new PriceModel(data.total.lineItemSubtotal),\r\n netLineItemSubtotal: new PriceModel(data.total.netLineItemSubtotal),\r\n lineItemTaxTotal: new PriceModel(data.total.lineItemTaxTotal),\r\n lineItemTaxBreakdown: this.mapTaxBreakdown(data.total.lineItemTaxBreakdown),\r\n\r\n additiveCharges: new PriceModel(data.total.additiveCharges),\r\n netAdditiveCharges: new PriceModel(data.total.netAdditiveCharges),\r\n additiveChargesTaxTotal: new PriceModel(data.total.additiveChargesTaxTotal),\r\n\r\n additiveChargesTaxBreakdown: this.mapTaxBreakdown(data.total.additiveChargesTaxBreakdown),\r\n adjustmentCharges: new PriceModel(data.total.adjustmentCharges),\r\n shippingCharges: new PriceModel(data.total.shippingCharges),\r\n netShippingCharges: new PriceModel(data.total.netShippingCharges),\r\n\r\n discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([key, value]) => [key, new PriceModel(value)])\r\n ),\r\n\r\n taxTotal: new PriceModel(data.total.taxTotal),\r\n taxBreakdown: this.mapTaxBreakdown(data.total.taxBreakdown),\r\n 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 getInvoiceNumber(): string {\r\n return this.invoiceNumber;\r\n }\r\n\r\n getOrderNumber(): string {\r\n return this.orderNumber;\r\n }\r\n\r\n getIssueDate(): string {\r\n return this.issueDate;\r\n }\r\n\r\n getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n getCurrency(): CurrencyCode {\r\n return this.currency;\r\n }\r\n\r\n getLocale(): LocaleCode {\r\n return this.locale;\r\n }\r\n\r\n getCustomerId(): string {\r\n return this.customerId;\r\n }\r\n\r\n getCustomerEmail(): string {\r\n return this.customerEmail;\r\n }\r\n\r\n getTaxContext(): InvoiceTaxContextData {\r\n return { ...this.taxContext };\r\n }\r\n\r\n getTaxRegistrationNumber(): string {\r\n return this.taxContext.recipientTaxIdentifier;\r\n }\r\n\r\n getRecipientTaxIdentifier(): string {\r\n return this.taxContext.recipientTaxIdentifier;\r\n }\r\n\r\n getRecipientTaxIdentifierType(): string {\r\n return this.taxContext.recipientTaxIdentifierType;\r\n }\r\n\r\n getBillingAddress(): AddressModel {\r\n return this.billingAddress;\r\n }\r\n\r\n getShippingAddress(): AddressModel {\r\n return this.shippingAddress;\r\n }\r\n\r\n getPlaceOfSupplyState(): string {\r\n return this.taxContext.supplyRegion;\r\n }\r\n\r\n getPlaceOfSupplyCode(): string {\r\n return this.taxContext.supplyRegionCode;\r\n }\r\n\r\n getSupplyRegion(): string {\r\n return this.taxContext.supplyRegion;\r\n }\r\n\r\n getSupplyRegionCode(): string {\r\n return this.taxContext.supplyRegionCode;\r\n }\r\n\r\n getMerchant(): MerchantModel {\r\n return {\r\n merchantName: this.merchant.merchantName,\r\n taxIdentifier: this.merchant.taxIdentifier,\r\n email: this.merchant.email,\r\n phone: this.merchant.phone,\r\n address: this.merchant.address\r\n };\r\n }\r\n\r\n getLineItems(): InvoiceLineItemModel[] {\r\n return [...this.lineItems];\r\n }\r\n\r\n getCharges(): InvoiceChargeModel[] {\r\n return [...this.charges];\r\n }\r\n\r\n getTotal(): InvoiceTotalModel {\r\n return this.total;\r\n }\r\n\r\n getDetails(): InvoiceData {\r\n const totals = this.getTotal();\r\n return {\r\n ...super.getDetails(),\r\n invoiceNumber: this.invoiceNumber,\r\n orderNumber: this.orderNumber,\r\n issueDate: this.issueDate,\r\n country: this.country,\r\n currency: this.currency,\r\n locale: this.locale,\r\n customerId: this.customerId,\r\n customerEmail: this.customerEmail,\r\n billingAddress: this.billingAddress.getDetails(),\r\n shippingAddress: this.shippingAddress.getDetails(),\r\n taxContext: this.taxContext,\r\n merchant: {\r\n merchantName: this.merchant.merchantName,\r\n taxIdentifier: this.merchant.taxIdentifier,\r\n email: this.merchant.email,\r\n phone: this.merchant.phone,\r\n address: this.merchant.address.getDetails()\r\n },\r\n lineItems: this.lineItems.map((item) => {\r\n return {\r\n ...item,\r\n netUnitPrice: item.netUnitPrice.getDetails(),\r\n netSubtotal: item.netSubtotal.getDetails(),\r\n taxTotal: item.taxTotal.getDetails(),\r\n grandTotal: item.grandTotal.getDetails(),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(item.taxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n ...systemValue,\r\n taxableAmount: systemValue.taxableAmount.getDetails(),\r\n taxAmount: systemValue.taxAmount.getDetails(),\r\n },\r\n ])\r\n )\r\n };\r\n }),\r\n charges: this.charges.map((charge) => {\r\n return {\r\n ...charge,\r\n taxableValue: charge.taxableValue.getDetails(),\r\n taxTotal: charge.taxTotal.getDetails(),\r\n grandTotal: charge.grandTotal.getDetails(),\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(charge.taxBreakdown).map(([systemKey, systemValue]) => [\r\n systemKey,\r\n {\r\n ...systemValue,\r\n taxableAmount: systemValue.taxableAmount.getDetails(),\r\n taxAmount: systemValue.taxAmount.getDetails(),\r\n },\r\n ])\r\n )\r\n };\r\n }),\r\n total: {\r\n // Item Totals\r\n lineItemSubtotal: totals.lineItemSubtotal.getDetails(),\r\n netLineItemSubtotal: totals.netLineItemSubtotal.getDetails(),\r\n lineItemTaxTotal: totals.lineItemTaxTotal.getDetails(),\r\n lineItemTaxBreakdown: this.serializeTaxBreakdown(totals.lineItemTaxBreakdown),\r\n\r\n // Charge Totals\r\n additiveCharges: totals.additiveCharges.getDetails(),\r\n netAdditiveCharges: totals.netAdditiveCharges.getDetails(),\r\n additiveChargesTaxTotal: totals.additiveChargesTaxTotal.getDetails(),\r\n additiveChargesTaxBreakdown: this.serializeTaxBreakdown(totals.additiveChargesTaxBreakdown),\r\n\r\n adjustmentCharges: totals.adjustmentCharges.getDetails(),\r\n\r\n shippingCharges: totals.shippingCharges.getDetails(),\r\n netShippingCharges: totals.netShippingCharges.getDetails(),\r\n\r\n // Aggregate Totals\r\n discountTotal: totals.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(totals.discountBreakdown).map(([key, value]) => [key, value.getDetails()])\r\n ),\r\n taxTotal: totals.taxTotal.getDetails(),\r\n taxBreakdown: this.serializeTaxBreakdown(totals.taxBreakdown),\r\n grandTotal: totals.grandTotal.getDetails(),\r\n },\r\n };\r\n }\r\n}\r\n"]}
@@ -1,2 +1,2 @@
1
- export{a as default}from'../chunk-5IRYC2KY.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-QGIQ3MH6.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=LineItem.mjs.map
1
+ export{a as default}from'../chunk-B2VFJRLS.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=LineItem.mjs.map
2
2
  //# sourceMappingURL=LineItem.mjs.map
@@ -1,2 +1,2 @@
1
- import {a as a$1}from'../chunk-MJGCYQ53.mjs';import'../chunk-5IRYC2KY.mjs';import {b}from'../chunk-HX32EJ3F.mjs';import'../chunk-XJPFHEW3.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-PWWKQNF7.mjs';import'../chunk-QGIQ3MH6.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-2B2XI6FG.mjs';import {a as a$2}from'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';var a=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(a||{}),i=class extends a$1{orderNumber;cartId;paymentStatus;holdReason;state;shippingAddress;billingAddress;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state,this.shippingAddress=new b(t.shippingAddress,e),this.billingAddress=new b(t.billingAddress,e);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let e=this.getLineItems().find(o=>o.getId()===t);if(!e)throw new a$2(t);return e.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{a as OrderState,i as default};//# sourceMappingURL=Order.mjs.map
1
+ import {a as a$1}from'../chunk-B5JKMVLT.mjs';import'../chunk-B2VFJRLS.mjs';import {b}from'../chunk-HX32EJ3F.mjs';import'../chunk-BSDPFVRK.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-RQ2FFWUW.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import {a as a$2}from'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';var a=(s=>(s.PLACED="PLACED",s.PENDING_PAYMENT="PENDING_PAYMENT",s.PROCESSING="PROCESSING",s.CANCELLED="CANCELLED",s.COMPLETED="COMPLETED",s))(a||{}),i=class extends a$1{orderNumber;cartId;paymentStatus;holdReason;state;shippingAddress;billingAddress;constructor(t,e=new Date){super(t,e),this.orderNumber=t.orderNumber,this.cartId=t.cartId,this.paymentStatus=t.paymentStatus,this.holdReason=t.holdReason||"",this.state=t.state,this.shippingAddress=new b(t.shippingAddress,e),this.billingAddress=new b(t.billingAddress,e);}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getShippingAddress(){return this.shippingAddress}getBillingAddress(){return this.billingAddress}getOrderNumber(){return this.orderNumber}getCartId(){return this.cartId}getPaymentStatus(){return this.paymentStatus}getHoldReason(){return this.holdReason}getState(){return this.state}getLineItemState(t){let e=this.getLineItems().find(o=>o.getId()===t);if(!e)throw new a$2(t);return e.getState()}getDetails(){return {...super.getDetails(),orderNumber:this.getOrderNumber(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),shippingAddress:this.getShippingAddress().getDetails(),billingAddress:this.getBillingAddress().getDetails(),cartId:this.getCartId(),paymentStatus:this.getPaymentStatus(),holdReason:this.getHoldReason(),state:this.getState()}}};export{a as OrderState,i as default};//# sourceMappingURL=Order.mjs.map
2
2
  //# sourceMappingURL=Order.mjs.map
@@ -1,2 +1,2 @@
1
- export{b as default}from'../chunk-QGIQ3MH6.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=Product.mjs.map
1
+ export{b as default}from'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=Product.mjs.map
2
2
  //# sourceMappingURL=Product.mjs.map
@@ -1,2 +1,2 @@
1
- export{a as default}from'../chunk-MJGCYQ53.mjs';import'../chunk-5IRYC2KY.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-XJPFHEW3.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-PWWKQNF7.mjs';import'../chunk-QGIQ3MH6.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=ShoppingContainer.mjs.map
1
+ export{a as default}from'../chunk-B5JKMVLT.mjs';import'../chunk-B2VFJRLS.mjs';import'../chunk-HX32EJ3F.mjs';import'../chunk-BSDPFVRK.mjs';import'../chunk-SOZHGHMY.mjs';import'../chunk-RQ2FFWUW.mjs';import'../chunk-MHLRJ4IJ.mjs';import'../chunk-FCRJAAPY.mjs';import'../chunk-2B2XI6FG.mjs';import'../chunk-LI5JQ6UC.mjs';import'../chunk-QK4XJ3GB.mjs';import'../chunk-R5DM7WCD.mjs';import'../chunk-UXZBULDS.mjs';//# sourceMappingURL=ShoppingContainer.mjs.map
2
2
  //# sourceMappingURL=ShoppingContainer.mjs.map
@@ -1,2 +1,2 @@
1
- import {a as a$4}from'./chunk-SOZHGHMY.mjs';import {a as a$1}from'./chunk-QGIQ3MH6.mjs';import {a as a$3}from'./chunk-FCRJAAPY.mjs';import {a as a$2}from'./chunk-LI5JQ6UC.mjs';import {e,o}from'./chunk-QK4XJ3GB.mjs';import {b as b$1}from'./chunk-2B2XI6FG.mjs';import {d,c,f,g,i,j,k,b as b$2}from'./chunk-R5DM7WCD.mjs';import {a}from'./chunk-UXZBULDS.mjs';var b=class extends a{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.selectionAttributes=a$1.deepClone(t.selectionAttributes),this.name=a$1.deepClone(t.name),this.specifications=a$1.deepClone(t.specifications),this.primaryImage=new b$1(t.primaryImage),this.subItems=a$1.deepClone(t.subItems);let e=new Set;this.subItems.forEach(i=>{if(e.has(i.size))throw new d(i.size);e.add(i.size);}),this.pricing={unitPrice:new a$2(t.pricing.unitPrice),tierPricing:new a$3(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(i=>new a$4(i))},this.validateTaxRules(this.pricing.applicableTaxRule),this.state=t.state??"INITIAL",this.total={quantity:t.total.quantity,unitPrice:new a$2(t.total.unitPrice),subtotal:new a$2(t.total.subtotal),discountTotal:new a$2(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$2(a)])),netUnitPrice:new a$2(t.total.netUnitPrice),netSubtotal:new a$2(t.total.netSubtotal),taxTotal:new a$2(t.total.taxTotal),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:new a$2(a.taxableUnitPrice),taxPerUnit:new a$2(a.taxPerUnit),taxAmount:new a$2(a.taxAmount),system:a.system,subSystem:a.subSystem}])),grandTotal:new a$2(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return a$1.deepClone(this.selectionAttributes)}getName(t){return t?a$1.deepClone(this.name[t]??this.name[e[t]]??this.name.en):a$1.deepClone(this.name)}getSpecifications(t){return t?a$1.deepClone(this.specifications[t]??this.specifications[e[t]]??this.specifications.en):a$1.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return a$1.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[...this.pricing.applicableTaxRule]}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discountTotal:this.total.discountTotal,discountBreakdown:Object.fromEntries(Object.entries(this.total.discountBreakdown).map(([t,e])=>[t,e])),netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{rate:e.rate,taxableUnitPrice:e.taxableUnitPrice,taxPerUnit:e.taxPerUnit,taxAmount:e.taxAmount,system:e.system,subSystem:e.subSystem}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getPricing(),e=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:t.unitPrice.getDetails(),tierPricing:t.tierPricing.getDetails(),taxCategory:t.taxCategory,applicableTaxRule:t.applicableTaxRule.map(i=>i.getDetails())},state:this.getState(),total:{quantity:e.quantity,unitPrice:e.unitPrice.getDetails(),subtotal:e.subtotal.getDetails(),discountTotal:e.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(e.discountBreakdown).map(([i,a])=>[i,a.getDetails()])),netUnitPrice:e.netUnitPrice.getDetails(),netSubtotal:e.netSubtotal.getDetails(),taxTotal:e.taxTotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(e.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:a.taxableUnitPrice.getDetails(),taxPerUnit:a.taxPerUnit.getDetails(),taxAmount:a.taxAmount.getDetails(),system:a.system,subSystem:a.subSystem}])),grandTotal:e.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}validateTaxRules(t){let e=new Set;for(let i=0;i<t.length;i++){let a=t[i].getTaxRuleId();if(e.has(a))throw new c("Duplicate tax rule ID found: "+a);e.add(a);}}addSubItems(t,e){t.forEach(i=>{let a=this.subItems.find(c=>c.size===i.size);a?a.quantity=e?a.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>0),this.calculateTotals();}updateProductData(t,e,i$1){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new f;if(!t.getIsActive())throw new g;this.subItems.forEach(s=>{if(!t.validateSize(s.size))throw new i});let a=t.getPriceDetails(e);if(!a||a.getBaseUnitPrice().getCurrency()!==i$1)throw new j;this.name=t.getName(),this.specifications=t.getSpecifications(),this.primaryImage=t.getImages(this.selectionAttributes).primary;let c=this.subItems.reduce((s,d)=>s+d.quantity,0),{unitPrice:l}=a.getApplicableTier(c);this.pricing={unitPrice:l,tierPricing:a,taxCategory:a.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discountBreakdown=e,this.calculateTotals();}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getCountry()))throw new k}),this.validateTaxRules(t),this.pricing.applicableTaxRule=t,this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((o,u)=>o+u.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:t,subtotal:t,discountTotal:t,discountBreakdown:{},netUnitPrice:t,netSubtotal:t,taxTotal:t,taxBreakdown:{},grandTotal:t};return}let{unitPrice:i}=this.pricing.tierPricing.getApplicableTier(e),a=i.multiply(e),c=Object.values(this.total.discountBreakdown).reduce((o,u)=>o.add(u),t),l=a.subtract(c),s=e>0?l.divide(e):t,d={},g=t;this.pricing.applicableTaxRule.forEach(o=>{let u=o.getApplicableTaxRate(s),P=o.calculateTax(s),h=P.multiply(e).round();d[o.getTaxRuleId()]={rate:u,taxableUnitPrice:s,taxPerUnit:P,taxAmount:h,system:o.getTaxSystem(),subSystem:o.getTaxSubSystem()},g=g.add(h);});let U=l.add(g);this.total={quantity:e,unitPrice:i,subtotal:a,discountTotal:c,discountBreakdown:this.total.discountBreakdown,netUnitPrice:s,netSubtotal:l,taxTotal:g,taxBreakdown:d,grandTotal:U};}updateState(t){if(this.state in o)this.state!==t&&(this.state=t);else throw new b$2(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new b$1({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:t,subtotal:t,discountTotal:t,discountBreakdown:{},netUnitPrice:t,netSubtotal:t,taxTotal:t,taxBreakdown:{},grandTotal:t};}};export{b as a};//# sourceMappingURL=chunk-5IRYC2KY.mjs.map
2
- //# sourceMappingURL=chunk-5IRYC2KY.mjs.map
1
+ import {a as a$4}from'./chunk-SOZHGHMY.mjs';import {a as a$1}from'./chunk-MHLRJ4IJ.mjs';import {a as a$3}from'./chunk-FCRJAAPY.mjs';import {b as b$1}from'./chunk-2B2XI6FG.mjs';import {a as a$2}from'./chunk-LI5JQ6UC.mjs';import {e,o}from'./chunk-QK4XJ3GB.mjs';import {d,c,f,g,i,j,k,b as b$2}from'./chunk-R5DM7WCD.mjs';import {a}from'./chunk-UXZBULDS.mjs';var b=class extends a{id;productKey;selectionAttributes;name;specifications;primaryImage;subItems;pricing;state;total;constructor(t){super(t),this.id=t.id,this.productKey=t.productKey,this.selectionAttributes=a$1.deepClone(t.selectionAttributes),this.name=a$1.deepClone(t.name),this.specifications=a$1.deepClone(t.specifications),this.primaryImage=new b$1(t.primaryImage),this.subItems=a$1.deepClone(t.subItems);let e=new Set;this.subItems.forEach(i=>{if(e.has(i.size))throw new d(i.size);e.add(i.size);}),this.pricing={unitPrice:new a$2(t.pricing.unitPrice),tierPricing:new a$3(t.pricing.tierPricing),taxCategory:t.pricing.taxCategory,applicableTaxRule:t.pricing.applicableTaxRule.map(i=>new a$4(i))},this.validateTaxRules(this.pricing.applicableTaxRule),this.state=t.state??"INITIAL",this.total={quantity:t.total.quantity,unitPrice:new a$2(t.total.unitPrice),subtotal:new a$2(t.total.subtotal),discountTotal:new a$2(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$2(a)])),netUnitPrice:new a$2(t.total.netUnitPrice),netSubtotal:new a$2(t.total.netSubtotal),taxTotal:new a$2(t.total.taxTotal),taxBreakdown:Object.fromEntries(Object.entries(t.total.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:new a$2(a.taxableUnitPrice),taxPerUnit:new a$2(a.taxPerUnit),taxAmount:new a$2(a.taxAmount),system:a.system,subSystem:a.subSystem}])),grandTotal:new a$2(t.total.grandTotal)};}getId(){return this.id}getProductKey(){return this.productKey}getSelectionAttributes(){return a$1.deepClone(this.selectionAttributes)}getName(t){return t?a$1.deepClone(this.name[t]??this.name[e[t]]??this.name.en):a$1.deepClone(this.name)}getSpecifications(t){return t?a$1.deepClone(this.specifications[t]??this.specifications[e[t]]??this.specifications.en):a$1.deepClone(this.specifications)}getImage(){return this.primaryImage}getSubItems(){return a$1.deepClone(this.subItems)}getTotalQuantity(){return this.total.quantity}getPricing(){return {unitPrice:this.pricing.unitPrice,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[...this.pricing.applicableTaxRule]}}getState(){return this.state}getTotal(){return {quantity:this.total.quantity,unitPrice:this.total.unitPrice,subtotal:this.total.subtotal,discountTotal:this.total.discountTotal,discountBreakdown:Object.fromEntries(Object.entries(this.total.discountBreakdown).map(([t,e])=>[t,e])),netUnitPrice:this.total.netUnitPrice,netSubtotal:this.total.netSubtotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{rate:e.rate,taxableUnitPrice:e.taxableUnitPrice,taxPerUnit:e.taxPerUnit,taxAmount:e.taxAmount,system:e.system,subSystem:e.subSystem}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getPricing(),e=this.getTotal();return {id:this.getId(),productKey:this.getProductKey(),selectionAttributes:this.getSelectionAttributes(),name:this.getName(),specifications:this.getSpecifications(),primaryImage:this.getImage().getDetails(),subItems:this.getSubItems(),pricing:{unitPrice:t.unitPrice.getDetails(),tierPricing:t.tierPricing.getDetails(),taxCategory:t.taxCategory,applicableTaxRule:t.applicableTaxRule.map(i=>i.getDetails())},state:this.getState(),total:{quantity:e.quantity,unitPrice:e.unitPrice.getDetails(),subtotal:e.subtotal.getDetails(),discountTotal:e.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(e.discountBreakdown).map(([i,a])=>[i,a.getDetails()])),netUnitPrice:e.netUnitPrice.getDetails(),netSubtotal:e.netSubtotal.getDetails(),taxTotal:e.taxTotal.getDetails(),taxBreakdown:Object.fromEntries(Object.entries(e.taxBreakdown).map(([i,a])=>[i,{rate:a.rate,taxableUnitPrice:a.taxableUnitPrice.getDetails(),taxPerUnit:a.taxPerUnit.getDetails(),taxAmount:a.taxAmount.getDetails(),system:a.system,subSystem:a.subSystem}])),grandTotal:e.grandTotal.getDetails()},customFields:this.getAllCustomFields()}}validateTaxRules(t){let e=new Set;for(let i=0;i<t.length;i++){let a=t[i].getTaxRuleId();if(e.has(a))throw new c("Duplicate tax rule ID found: "+a);e.add(a);}}addSubItems(t,e){t.forEach(i=>{let a=this.subItems.find(c=>c.size===i.size);a?a.quantity=e?a.quantity+i.quantity:i.quantity:this.subItems.push(i);}),this.subItems=this.subItems.filter(i=>i.quantity>0),this.calculateTotals();}updateProductData(t,e,i$1){if(this.productKey!==t.getKey()||!t.validateSelectionAttribute(this.selectionAttributes))throw new f;if(!t.getIsActive())throw new g;this.subItems.forEach(s=>{if(!t.validateSize(s.size))throw new i});let a=t.getPriceDetails(e);if(!a||a.getBaseUnitPrice().getCurrency()!==i$1)throw new j;this.name=t.getName(),this.specifications=t.getSpecifications(),this.primaryImage=t.getImages(this.selectionAttributes).primary;let c=this.subItems.reduce((s,d)=>s+d.quantity,0),{unitPrice:l}=a.getApplicableTier(c);this.pricing={unitPrice:l,tierPricing:a,taxCategory:a.getTaxCategory(),applicableTaxRule:this.pricing.applicableTaxRule},this.calculateTotals();}updateDiscounts(t){let e={};t.forEach(i=>{e[i.coupon.getCode()]=i.amount;}),this.total.discountBreakdown=e,this.calculateTotals();}updateTax(t){t.forEach(e=>{if(!e.appliesTo(this.pricing.taxCategory,e.getCountry()))throw new k}),this.validateTaxRules(t),this.pricing.applicableTaxRule=t,this.calculateTotals();}calculateTotals(){let t=this.pricing.unitPrice.zero(),e=this.subItems.reduce((o,u)=>o+u.quantity,0);if(this.state==="CANCELLED"){this.total={quantity:0,unitPrice:t,subtotal:t,discountTotal:t,discountBreakdown:{},netUnitPrice:t,netSubtotal:t,taxTotal:t,taxBreakdown:{},grandTotal:t};return}let{unitPrice:i}=this.pricing.tierPricing.getApplicableTier(e),a=i.multiply(e),c=Object.values(this.total.discountBreakdown).reduce((o,u)=>o.add(u),t),l=a.subtract(c),s=e>0?l.divide(e):t,d={},g=t;this.pricing.applicableTaxRule.forEach(o=>{let u=o.getApplicableTaxRate(s),P=o.calculateTax(s),h=P.multiply(e).round();d[o.getTaxRuleId()]={rate:u,taxableUnitPrice:s,taxPerUnit:P,taxAmount:h,system:o.getTaxSystem(),subSystem:o.getTaxSubSystem()},g=g.add(h);});let U=l.add(g);this.total={quantity:e,unitPrice:i,subtotal:a,discountTotal:c,discountBreakdown:this.total.discountBreakdown,netUnitPrice:s,netSubtotal:l,taxTotal:g,taxBreakdown:d,grandTotal:U};}updateState(t){if(this.state in o)this.state!==t&&(this.state=t);else throw new b$2(t)}clearLineItem(){let t=this.pricing.unitPrice.zero();this.id="",this.productKey="",this.selectionAttributes={color:{name:""}},this.name={en:""},this.primaryImage=new b$1({sources:{original:""}}),this.subItems=[],this.pricing={unitPrice:t,tierPricing:this.pricing.tierPricing,taxCategory:this.pricing.taxCategory,applicableTaxRule:[]},this.total={quantity:0,unitPrice:t,subtotal:t,discountTotal:t,discountBreakdown:{},netUnitPrice:t,netSubtotal:t,taxTotal:t,taxBreakdown:{},grandTotal:t};}};export{b as a};//# sourceMappingURL=chunk-B2VFJRLS.mjs.map
2
+ //# sourceMappingURL=chunk-B2VFJRLS.mjs.map
@@ -1 +1 @@
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","taxRules","uniqueTaxRule","currentTaxRuleId","InvalidLineItemTaxRuleError","subItems","addQuantity","subItem","existingSubItem","sub","product","cartCountry","cartCurrency","ProductMismatchError","ProductInactiveError","SizeMismatchError","productPricing","PricingNotFoundError","quantity","sum","s","unitPrice","appliedDiscounts","lineItemDiscounts","taxRule","InvalidTaxRuleError","zero","totalQuantity","subTotal","totalDiscount","netSubtotal","netUnitPrice","taxTotal","rate","taxPerUnit","taxAmount","grandTotal","newState","LineItemState","InvalidLineItemStateError"],"mappings":"kWA2GA,IAAqBA,CAArB,CAAA,cAA2CC,CAAiB,CAChD,GACA,UACA,CAAA,mBAAA,CAEA,IACA,CAAA,cAAA,CACA,aACA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V,UAAWA,CACX,CAAA,QAAA,CAAUA,CACV,CAAA,aAAA,CAAeA,EACf,iBAAmB,CAAA,EACnB,CAAA,YAAA,CAAcA,EACd,WAAaA,CAAAA,CAAAA,CACb,QAAUA,CAAAA,CAAAA,CACV,aAAc,EAAC,CACf,UAAYA,CAAAA,CACd,EACF,CACF","file":"chunk-5IRYC2KY.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 } 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 InvalidLineItemTaxRuleError\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 LineItemPricingModel = {\r\n unitPrice: PriceModel;\r\n tierPricing: TieredPriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleModel[];\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 taxAmount: 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 taxAmount: 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 discountTotal: PriceData; // sum of all discounts\r\n discountBreakdown: Record<string, PriceData>; // couponCode -> discount mapping\r\n netUnitPrice: PriceData; // unit price after discounts\r\n netSubtotal: PriceData; // subtotal - totalDiscount (taxable amount)\r\n taxTotal: PriceData; // sum of all tax amounts\r\n taxBreakdown: Record<string, LineItemTaxBreakdown>; // tax breakdown by tax rule\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 discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n netUnitPrice: PriceModel;\r\n netSubtotal: PriceModel;\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, LineItemTaxBreakdownModel>;\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: LineItemPricingModel;\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 this.validateTaxRules(this.pricing.applicableTaxRule);\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 discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n new PriceModel(discount),\r\n ])\r\n ),\r\n netUnitPrice: new PriceModel(data.total.netUnitPrice),\r\n netSubtotal: new PriceModel(data.total.netSubtotal),\r\n taxTotal: new PriceModel(data.total.taxTotal),\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 taxAmount: new PriceModel(taxBreakdown.taxAmount),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\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 discountTotal: this.total.discountTotal,\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(this.total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount,\r\n ])\r\n ),\r\n netUnitPrice: this.total.netUnitPrice,\r\n netSubtotal: this.total.netSubtotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: taxBreakdown.taxableUnitPrice,\r\n taxPerUnit: taxBreakdown.taxPerUnit,\r\n taxAmount: taxBreakdown.taxAmount,\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the 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 discountTotal: total.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount.getDetails(),\r\n ])\r\n ),\r\n netUnitPrice: total.netUnitPrice.getDetails(),\r\n netSubtotal: total.netSubtotal.getDetails(),\r\n taxTotal: total.taxTotal.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 taxAmount: taxBreakdown.taxAmount.getDetails(),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: total.grandTotal.getDetails(),\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n }\r\n\r\n /**\r\n\t * Validates that there are no overlapping price brackets for any tax rules within the charge.\r\n\t * @param taxRules - The list of tax rules to validate.\r\n\t * @throws {InvalidLineItemTaxRuleError} Duplicate tax rule IDs will results in error.\r\n\t */\r\n private validateTaxRules(taxRules: TaxRuleModel[]): void {\r\n const uniqueTaxRule = new Set();\r\n for (let i = 0; i < taxRules.length; i++) {\r\n const currentTaxRuleId = taxRules[i].getTaxRuleId();\r\n if (uniqueTaxRule.has(currentTaxRuleId)) {\r\n throw new InvalidLineItemTaxRuleError(\"Duplicate tax rule ID found: \" + currentTaxRuleId);\r\n } else {\r\n uniqueTaxRule.add(currentTaxRuleId);\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.discountBreakdown = 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.getCountry())) {\r\n throw new InvalidTaxRuleError();\r\n }\r\n });\r\n\r\n this.validateTaxRules(taxRules);\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 discountTotal: zero,\r\n discountBreakdown: {},\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxTotal: zero,\r\n taxBreakdown: {},\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.discountBreakdown).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 taxAmount = taxPerUnit.multiply(totalQuantity).round();\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxableUnitPrice: netUnitPrice,\r\n taxPerUnit: taxPerUnit,\r\n taxAmount: taxAmount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n taxTotal = taxTotal.add(taxAmount);\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 discountTotal: totalDiscount,\r\n discountBreakdown: this.total.discountBreakdown,\r\n netUnitPrice: netUnitPrice,\r\n netSubtotal: netSubtotal,\r\n taxTotal: taxTotal,\r\n taxBreakdown: taxBreakdown,\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 discountTotal: zero,\r\n discountBreakdown: {},\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxTotal: zero,\r\n taxBreakdown: {},\r\n grandTotal: zero\r\n };\r\n }\r\n}\r\n"]}
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","taxRules","uniqueTaxRule","currentTaxRuleId","InvalidLineItemTaxRuleError","subItems","addQuantity","subItem","existingSubItem","sub","product","cartCountry","cartCurrency","ProductMismatchError","ProductInactiveError","SizeMismatchError","productPricing","PricingNotFoundError","quantity","sum","s","unitPrice","appliedDiscounts","lineItemDiscounts","taxRule","InvalidTaxRuleError","zero","totalQuantity","subTotal","totalDiscount","netSubtotal","netUnitPrice","taxTotal","rate","taxPerUnit","taxAmount","grandTotal","newState","LineItemState","InvalidLineItemStateError"],"mappings":"kWA2GA,IAAqBA,CAArB,CAAA,cAA2CC,CAAiB,CAChD,GACA,UACA,CAAA,mBAAA,CAEA,IACA,CAAA,cAAA,CACA,aACA,QACA,CAAA,OAAA,CAEA,KACA,CAAA,KAAA,CAMV,YAAYC,CAA0B,CAAA,CACpC,KAAMA,CAAAA,CAAI,EACV,IAAK,CAAA,EAAA,CAAKA,CAAK,CAAA,EAAA,CACf,KAAK,UAAaA,CAAAA,CAAAA,CAAK,UACvB,CAAA,IAAA,CAAK,oBAAsBC,GAAM,CAAA,SAAA,CAAUD,CAAK,CAAA,mBAAmB,EAEnE,IAAK,CAAA,IAAA,CAAOC,GAAM,CAAA,SAAA,CAAUD,CAAK,CAAA,IAAI,CACrC,CAAA,IAAA,CAAK,eAAiBC,GAAM,CAAA,SAAA,CAAUD,CAAK,CAAA,cAAc,EACzD,IAAK,CAAA,YAAA,CAAe,IAAIE,GAAAA,CAAeF,EAAK,YAAY,CAAA,CACxD,IAAK,CAAA,QAAA,CAAWC,IAAM,SAAUD,CAAAA,CAAAA,CAAK,QAAQ,CAAA,CAE7C,IAAIG,CAA4B,CAAA,IAAI,GACpC,CAAA,IAAA,CAAK,SAAS,OAAQC,CAAAA,CAAAA,EAAQ,CAC5B,GAAID,EAA0B,GAAIC,CAAAA,CAAAA,CAAK,IAAI,CAAA,CACzC,MAAM,IAAIC,CAAmBD,CAAAA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,CAAK,mBAAsB,CAAA,CAAE,MAAO,CAAE,IAAA,CAAM,EAAG,CAAE,EACjD,IAAK,CAAA,IAAA,CAAO,CAAE,EAAA,CAAI,EAAG,CACrB,CAAA,IAAA,CAAK,YAAe,CAAA,IAAIzC,IAAe,CAAE,OAAA,CAAS,CAAE,QAAA,CAAU,EAAG,CAAE,CAAC,CACpE,CAAA,IAAA,CAAK,SAAW,EAAC,CACjB,IAAK,CAAA,OAAA,CAAU,CACb,SAAWyC,CAAAA,CAAAA,CACX,WAAa,CAAA,IAAA,CAAK,QAAQ,WAC1B,CAAA,WAAA,CAAa,IAAK,CAAA,OAAA,CAAQ,YAC1B,iBAAmB,CAAA,EACrB,CAAA,CACA,KAAK,KAAQ,CAAA,CACX,QAAU,CAAA,CAAA,CACV,UAAWA,CACX,CAAA,QAAA,CAAUA,CACV,CAAA,aAAA,CAAeA,EACf,iBAAmB,CAAA,EACnB,CAAA,YAAA,CAAcA,EACd,WAAaA,CAAAA,CAAAA,CACb,QAAUA,CAAAA,CAAAA,CACV,aAAc,EAAC,CACf,UAAYA,CAAAA,CACd,EACF,CACF","file":"chunk-B2VFJRLS.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 } 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 InvalidLineItemTaxRuleError\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 LineItemPricingModel = {\r\n unitPrice: PriceModel;\r\n tierPricing: TieredPriceModel;\r\n taxCategory: string;\r\n applicableTaxRule: TaxRuleModel[];\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 taxAmount: 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 taxAmount: 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 discountTotal: PriceData; // sum of all discounts\r\n discountBreakdown: Record<string, PriceData>; // couponCode -> discount mapping\r\n netUnitPrice: PriceData; // unit price after discounts\r\n netSubtotal: PriceData; // subtotal - totalDiscount (taxable amount)\r\n taxTotal: PriceData; // sum of all tax amounts\r\n taxBreakdown: Record<string, LineItemTaxBreakdown>; // tax breakdown by tax rule\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 discountTotal: PriceModel;\r\n discountBreakdown: Record<string, PriceModel>;\r\n netUnitPrice: PriceModel;\r\n netSubtotal: PriceModel;\r\n taxTotal: PriceModel;\r\n taxBreakdown: Record<string, LineItemTaxBreakdownModel>;\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: LineItemPricingModel;\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 this.validateTaxRules(this.pricing.applicableTaxRule);\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 discountTotal: new PriceModel(data.total.discountTotal),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(data.total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n new PriceModel(discount),\r\n ])\r\n ),\r\n netUnitPrice: new PriceModel(data.total.netUnitPrice),\r\n netSubtotal: new PriceModel(data.total.netSubtotal),\r\n taxTotal: new PriceModel(data.total.taxTotal),\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 taxAmount: new PriceModel(taxBreakdown.taxAmount),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\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 discountTotal: this.total.discountTotal,\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(this.total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount,\r\n ])\r\n ),\r\n netUnitPrice: this.total.netUnitPrice,\r\n netSubtotal: this.total.netSubtotal,\r\n taxTotal: this.total.taxTotal,\r\n taxBreakdown: Object.fromEntries(\r\n Object.entries(this.total.taxBreakdown).map(([taxRuleId, taxBreakdown]) => [\r\n taxRuleId,\r\n {\r\n rate: taxBreakdown.rate,\r\n taxableUnitPrice: taxBreakdown.taxableUnitPrice,\r\n taxPerUnit: taxBreakdown.taxPerUnit,\r\n taxAmount: taxBreakdown.taxAmount,\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: this.total.grandTotal,\r\n };\r\n }\r\n\r\n /**\r\n * Gets a plain data object representing the 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 discountTotal: total.discountTotal.getDetails(),\r\n discountBreakdown: Object.fromEntries(\r\n Object.entries(total.discountBreakdown).map(([couponCode, discount]) => [\r\n couponCode,\r\n discount.getDetails(),\r\n ])\r\n ),\r\n netUnitPrice: total.netUnitPrice.getDetails(),\r\n netSubtotal: total.netSubtotal.getDetails(),\r\n taxTotal: total.taxTotal.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 taxAmount: taxBreakdown.taxAmount.getDetails(),\r\n system: taxBreakdown.system,\r\n subSystem: taxBreakdown.subSystem\r\n }\r\n ])\r\n ),\r\n grandTotal: total.grandTotal.getDetails(),\r\n },\r\n customFields: this.getAllCustomFields()\r\n };\r\n }\r\n\r\n /**\r\n\t * Validates that there are no overlapping price brackets for any tax rules within the charge.\r\n\t * @param taxRules - The list of tax rules to validate.\r\n\t * @throws {InvalidLineItemTaxRuleError} Duplicate tax rule IDs will results in error.\r\n\t */\r\n private validateTaxRules(taxRules: TaxRuleModel[]): void {\r\n const uniqueTaxRule = new Set();\r\n for (let i = 0; i < taxRules.length; i++) {\r\n const currentTaxRuleId = taxRules[i].getTaxRuleId();\r\n if (uniqueTaxRule.has(currentTaxRuleId)) {\r\n throw new InvalidLineItemTaxRuleError(\"Duplicate tax rule ID found: \" + currentTaxRuleId);\r\n } else {\r\n uniqueTaxRule.add(currentTaxRuleId);\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.discountBreakdown = 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.getCountry())) {\r\n throw new InvalidTaxRuleError();\r\n }\r\n });\r\n\r\n this.validateTaxRules(taxRules);\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 discountTotal: zero,\r\n discountBreakdown: {},\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxTotal: zero,\r\n taxBreakdown: {},\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.discountBreakdown).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 taxAmount = taxPerUnit.multiply(totalQuantity).round();\r\n taxBreakdown[taxRule.getTaxRuleId()] = {\r\n rate: rate,\r\n taxableUnitPrice: netUnitPrice,\r\n taxPerUnit: taxPerUnit,\r\n taxAmount: taxAmount,\r\n system: taxRule.getTaxSystem(),\r\n subSystem: taxRule.getTaxSubSystem()\r\n };\r\n taxTotal = taxTotal.add(taxAmount);\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 discountTotal: totalDiscount,\r\n discountBreakdown: this.total.discountBreakdown,\r\n netUnitPrice: netUnitPrice,\r\n netSubtotal: netSubtotal,\r\n taxTotal: taxTotal,\r\n taxBreakdown: taxBreakdown,\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 discountTotal: zero,\r\n discountBreakdown: {},\r\n netUnitPrice: zero,\r\n netSubtotal: zero,\r\n taxTotal: zero,\r\n taxBreakdown: {},\r\n grandTotal: zero\r\n };\r\n }\r\n}\r\n"]}
@@ -1,2 +1,2 @@
1
- import {a}from'./chunk-5IRYC2KY.mjs';import {b as b$1}from'./chunk-HX32EJ3F.mjs';import {a as a$1}from'./chunk-XJPFHEW3.mjs';import {e}from'./chunk-PWWKQNF7.mjs';import {a as a$2}from'./chunk-QGIQ3MH6.mjs';import {a as a$3}from'./chunk-LI5JQ6UC.mjs';import {b}from'./chunk-UXZBULDS.mjs';var B=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e$1=new Date){super(t,e$1),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new a(i)),this.charges=(t.charges??[]).map(i=>new a$1(i)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,e$1):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,e$1):null,this.coupons=(t.coupons??[]).map(i=>new e(i)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={lineItemSubtotal:new a$3(t.total.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.netLineItemSubtotal),lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown),additiveCharges:new a$3(t.total.additiveCharges),netAdditiveCharges:new a$3(t.total.netAdditiveCharges),additiveChargesTaxTotal:new a$3(t.total.additiveChargesTaxTotal),additiveChargesTaxBreakdown:this.mapTaxBreakdown(t.total.additiveChargesTaxBreakdown),adjustmentCharges:new a$3(t.total.adjustmentCharges),shippingCharges:new a$3(t.total.shippingCharges),netShippingCharges:new a$3(t.total.netShippingCharges),discountTotal:new a$3(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$3(a)])),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),grandTotal:new a$3(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:new a$3(i.totalAmount),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,new a$3(n)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:i.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,n.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?a$2.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {lineItemSubtotal:this.total.lineItemSubtotal,netLineItemSubtotal:this.total.netLineItemSubtotal,lineItemTaxTotal:this.total.lineItemTaxTotal,lineItemTaxBreakdown:Object.fromEntries(Object.entries(this.total.lineItemTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),additiveCharges:this.total.additiveCharges,netAdditiveCharges:this.total.netAdditiveCharges,additiveChargesTaxTotal:this.total.additiveChargesTaxTotal,additiveChargesTaxBreakdown:Object.fromEntries(Object.entries(this.total.additiveChargesTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),adjustmentCharges:this.total.adjustmentCharges,shippingCharges:this.total.shippingCharges,netShippingCharges:this.total.netShippingCharges,discountBreakdown:{...this.total.discountBreakdown},discountTotal:this.total.discountTotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(e=>e.getDetails()),charges:this.getCharges().map(e=>e.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(e=>e.getDetails()),total:{lineItemSubtotal:t.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.netLineItemSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),additiveCharges:t.additiveCharges.getDetails(),netAdditiveCharges:t.netAdditiveCharges.getDetails(),additiveChargesTaxTotal:t.additiveChargesTaxTotal.getDetails(),additiveChargesTaxBreakdown:this.serializeTaxBreakdown(t.additiveChargesTaxBreakdown),adjustmentCharges:t.adjustmentCharges.getDetails(),shippingCharges:t.shippingCharges.getDetails(),netShippingCharges:t.netShippingCharges.getDetails(),discountTotal:t.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(t.discountBreakdown).map(([e,i])=>[e,i.getDetails()])),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency}),e=this.lineItems.filter(s=>s.getState()!=="CANCELLED"),i=e.reduce((s,o)=>s.add(o.getTotal().subtotal),t),a=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t);this.total.lineItemSubtotal=i,this.total.shippingCharges=a;let n=t,d={},u={};this.coupons.forEach(s=>{let o=s.calculateApplicableCouponDiscount(i,a,this.country,this.currency);n=n.add(o),d[s.getCode()]=o,s.getCategory()!=="SHIPPING"&&(u[s.getCode()]=o);}),this.total.discountTotal=n,this.total.discountBreakdown=d,this.applyDiscountsInLineItem(u);let h=this.coupons.find(s=>s.getCategory()==="SHIPPING");h?this.applyDiscountsInShippingCharges({[h.getCode()]:d[h.getCode()]||t}):this.applyDiscountsInShippingCharges({});let g=this.lineItems.reduce((s,o)=>s.add(o.getTotal().netSubtotal),t),c=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().grandTotal),t);this.total.netLineItemSubtotal=g,this.total.netShippingCharges=c;let m=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t),y=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),f=this.charges.filter(s=>s.getImpact()==="SUBTRACT").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),M=t,I=t,b=t,p={},k={},P={},x=(s,o)=>{Object.entries(s).forEach(([O,C])=>{let l=C.system,T=C.subSystem;o[l]||(o[l]={system:l,totalAmount:t,subSystems:{}}),o[l].subSystems[T]?o[l].subSystems[T]=o[l].subSystems[T].add(C.taxAmount):o[l].subSystems[T]=C.taxAmount,o[l].totalAmount=o[l].totalAmount.add(C.taxAmount),p[l]||(p[l]={system:l,totalAmount:t,subSystems:{}}),p[l].subSystems[T]?p[l].subSystems[T]=p[l].subSystems[T].add(C.taxAmount):p[l].subSystems[T]=C.taxAmount,p[l].totalAmount=p[l].totalAmount.add(C.taxAmount);});};e.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,k),x(o,p),I=I.add(s.getTotal().taxTotal));}),this.charges.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,P),x(o,p),b=b.add(s.getTotal().taxTotal));}),M=I.add(b);let E=g.add(I).add(y).subtract(f);this.total={lineItemSubtotal:i,netLineItemSubtotal:g,lineItemTaxTotal:I,lineItemTaxBreakdown:k,additiveCharges:m,netAdditiveCharges:y,additiveChargesTaxTotal:b,additiveChargesTaxBreakdown:P,adjustmentCharges:f,shippingCharges:a,netShippingCharges:c,discountTotal:n,discountBreakdown:d,taxTotal:M,taxBreakdown:p,grandTotal:E};}updateShippingDetails(t){this.shippingDetails=t;}applyCoupons(t){let e=t.filter(a=>a.getCategory()==="SHIPPING"),i=t.filter(a=>a.getCategory()!=="SHIPPING");this.coupons=[],this.total.discountTotal=this.total.lineItemSubtotal.zero(),this.total.discountBreakdown={},i.length&&this.applyNonShippingCoupons(i),this.applyDiscountsInLineItem(this.total.discountBreakdown),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(a=>!a[1].isZero()),i=new Map;this.lineItems.forEach(a=>i.set(a.getId(),[])),e.forEach(([a,n])=>{let d=this.coupons.find(g=>g.getCode()===a);if(!d||n.isZero())return;let u=this.lineItems.filter(g=>g.getState()!=="CANCELLED"&&!g.getTotal().subtotal.isZero()).sort((g,c)=>g.getTotal().subtotal.compareTo(c.getTotal().subtotal)),h=new a$3({amount:0,currency:this.currency});u.forEach((g,c)=>{let m;c===u.length-1?m=n.subtract(h):m=n.multiply(g.getTotal().subtotal).divide(this.total.lineItemSubtotal).round(),h=h.add(m),i.get(g.getId())?.push({coupon:d,amount:m});});}),this.lineItems.forEach(a=>{a.getState()==="CANCELLED"||this.total.lineItemSubtotal.isZero()?a.updateDiscounts([]):a.updateDiscounts(i.get(a.getId())||[]);});}applyDiscountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(n=>!n[1].isZero()),i=this.charges.filter(n=>n.getType()==="SHIPPING"),a=new Map;i.forEach(n=>a.set(n.getId(),[])),e.forEach(([n,d])=>{let u=this.coupons.find(c=>c.getCode()===n);if(!u||d.isZero())return;let h=i.sort((c,m)=>c.getTotal().grandTotal.compareTo(m.getTotal().grandTotal)),g=new a$3({amount:0,currency:this.currency});h.forEach((c,m)=>{let y;m===h.length-1?y=d.subtract(g):y=d.multiply(c.getTotal().chargeAmount).divide(this.total.shippingCharges).round(),g=g.add(y),a.get(c.getId())?.push({coupon:u,amount:y});});}),i.forEach(n=>{n.updateDiscounts(a.get(n.getId())||[]);});}applyNonShippingCoupons(t){let e=t.filter(i=>i.getType()==="coupon");if(e.length===1){let i=e[0].calculateApplicableCouponDiscount(this.total.lineItemSubtotal,this.total.shippingCharges,this.country,this.currency);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discountTotal=i,this.total.discountBreakdown[e[0].getCode()]=i);}}applyShippingCoupons(t){if(this.total.shippingCharges.getAmount()>0&&t.length>0){let e=this.total.lineItemSubtotal.subtract(this.total.discountTotal),i=t.reduce((n,d)=>{if(!n)return d;let u=d.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges),h=n.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);return u.compareTo(h)===0?d.getType()==="coupon"?d:n:u.compareTo(h)>0?d:n}),a=i.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);a.getAmount()>0&&(this.coupons.push(i),this.total.discountTotal=this.total.discountTotal.add(a),this.total.discountBreakdown[i.getCode()]=a);}}};export{B as a};//# sourceMappingURL=chunk-MJGCYQ53.mjs.map
2
- //# sourceMappingURL=chunk-MJGCYQ53.mjs.map
1
+ import {a}from'./chunk-B2VFJRLS.mjs';import {b as b$1}from'./chunk-HX32EJ3F.mjs';import {a as a$1}from'./chunk-BSDPFVRK.mjs';import {e}from'./chunk-RQ2FFWUW.mjs';import {a as a$2}from'./chunk-MHLRJ4IJ.mjs';import {a as a$3}from'./chunk-LI5JQ6UC.mjs';import {b}from'./chunk-UXZBULDS.mjs';var B=class extends b{id;customerId;customerEmail;anonymousId;lineItems;charges;shippingDetails;shippingAddress;billingAddress;coupons;total;country;currency;locale;constructor(t,e$1=new Date){super(t,e$1),this.id=t.id,this.customerId=t.customerId,this.customerEmail=t.customerEmail,this.anonymousId=t.anonymousId,this.country=t.country,this.currency=t.currency,this.locale=t.locale,this.lineItems=(t.lineItems??[]).map(i=>new a(i)),this.charges=(t.charges??[]).map(i=>new a$1(i)),this.billingAddress=t.billingAddress?new b$1(t.billingAddress,e$1):null,this.shippingAddress=t.shippingAddress?new b$1(t.shippingAddress,e$1):null,this.coupons=(t.coupons??[]).map(i=>new e(i)),this.shippingDetails=t.shippingDetails?a$2.deepClone(t.shippingDetails):null,this.total={lineItemSubtotal:new a$3(t.total.lineItemSubtotal),netLineItemSubtotal:new a$3(t.total.netLineItemSubtotal),lineItemTaxTotal:new a$3(t.total.lineItemTaxTotal),lineItemTaxBreakdown:this.mapTaxBreakdown(t.total.lineItemTaxBreakdown),additiveCharges:new a$3(t.total.additiveCharges),netAdditiveCharges:new a$3(t.total.netAdditiveCharges),additiveChargesTaxTotal:new a$3(t.total.additiveChargesTaxTotal),additiveChargesTaxBreakdown:this.mapTaxBreakdown(t.total.additiveChargesTaxBreakdown),adjustmentCharges:new a$3(t.total.adjustmentCharges),shippingCharges:new a$3(t.total.shippingCharges),netShippingCharges:new a$3(t.total.netShippingCharges),discountTotal:new a$3(t.total.discountTotal),discountBreakdown:Object.fromEntries(Object.entries(t.total.discountBreakdown).map(([i,a])=>[i,new a$3(a)])),taxTotal:new a$3(t.total.taxTotal),taxBreakdown:this.mapTaxBreakdown(t.total.taxBreakdown),grandTotal:new a$3(t.total.grandTotal)};}mapTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:new a$3(i.totalAmount),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,new a$3(n)]))}]))}serializeTaxBreakdown(t){return Object.fromEntries(Object.entries(t||{}).map(([e,i])=>[e,{system:i.system,totalAmount:i.totalAmount.getDetails(),subSystems:Object.fromEntries(Object.entries(i.subSystems).map(([a,n])=>[a,n.getDetails()]))}]))}getId(){return this.id}getCustomerId(){return this.customerId}getCustomerEmail(){return this.customerEmail}getAnonymousId(){return this.anonymousId}getLineItems(){return this.lineItems.map(t=>new a(t.getDetails()))}getLineItemsCount(){return this.lineItems.length}getCharges(){return this.charges.map(t=>new a$1(t.getDetails()))}addCharge(t){this.charges.push(t),this.calculateTotals();}clearCharges(){this.charges=[],this.calculateTotals();}getShippingDetails(){return this.shippingDetails?a$2.deepClone(this.shippingDetails):null}getShippingAddress(){return this.shippingAddress?new b$1(this.shippingAddress.getDetails()):null}hasShippingAddress(){return !!this.shippingAddress}hasBillingAddress(){return !!this.billingAddress}getBillingAddress(){return this.billingAddress?new b$1(this.billingAddress.getDetails()):null}getCoupons(){return [...this.coupons]}getCountry(){return this.country}getCurrency(){return this.currency}getLocale(){return this.locale}getTotal(){return {lineItemSubtotal:this.total.lineItemSubtotal,netLineItemSubtotal:this.total.netLineItemSubtotal,lineItemTaxTotal:this.total.lineItemTaxTotal,lineItemTaxBreakdown:Object.fromEntries(Object.entries(this.total.lineItemTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),additiveCharges:this.total.additiveCharges,netAdditiveCharges:this.total.netAdditiveCharges,additiveChargesTaxTotal:this.total.additiveChargesTaxTotal,additiveChargesTaxBreakdown:Object.fromEntries(Object.entries(this.total.additiveChargesTaxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),adjustmentCharges:this.total.adjustmentCharges,shippingCharges:this.total.shippingCharges,netShippingCharges:this.total.netShippingCharges,discountBreakdown:{...this.total.discountBreakdown},discountTotal:this.total.discountTotal,taxTotal:this.total.taxTotal,taxBreakdown:Object.fromEntries(Object.entries(this.total.taxBreakdown).map(([t,e])=>[t,{system:e.system,totalAmount:e.totalAmount,subSystems:{...e.subSystems}}])),grandTotal:this.total.grandTotal}}getDetails(){let t=this.getTotal();return {...super.getDetails(),id:this.getId(),customerId:this.getCustomerId(),customerEmail:this.getCustomerEmail(),anonymousId:this.getAnonymousId(),lineItems:this.getLineItems().map(e=>e.getDetails()),charges:this.getCharges().map(e=>e.getDetails()),shippingDetails:this.getShippingDetails(),shippingAddress:this.getShippingAddress()?.getDetails()||null,billingAddress:this.getBillingAddress()?.getDetails()||null,coupons:this.getCoupons().map(e=>e.getDetails()),total:{lineItemSubtotal:t.lineItemSubtotal.getDetails(),netLineItemSubtotal:t.netLineItemSubtotal.getDetails(),lineItemTaxTotal:t.lineItemTaxTotal.getDetails(),lineItemTaxBreakdown:this.serializeTaxBreakdown(t.lineItemTaxBreakdown),additiveCharges:t.additiveCharges.getDetails(),netAdditiveCharges:t.netAdditiveCharges.getDetails(),additiveChargesTaxTotal:t.additiveChargesTaxTotal.getDetails(),additiveChargesTaxBreakdown:this.serializeTaxBreakdown(t.additiveChargesTaxBreakdown),adjustmentCharges:t.adjustmentCharges.getDetails(),shippingCharges:t.shippingCharges.getDetails(),netShippingCharges:t.netShippingCharges.getDetails(),discountTotal:t.discountTotal.getDetails(),discountBreakdown:Object.fromEntries(Object.entries(t.discountBreakdown).map(([e,i])=>[e,i.getDetails()])),taxTotal:t.taxTotal.getDetails(),taxBreakdown:this.serializeTaxBreakdown(t.taxBreakdown),grandTotal:t.grandTotal.getDetails()},country:this.getCountry(),currency:this.getCurrency(),locale:this.getLocale()}}calculateTotals(){let t=new a$3({amount:0,currency:this.currency}),e=this.lineItems.filter(s=>s.getState()!=="CANCELLED"),i=e.reduce((s,o)=>s.add(o.getTotal().subtotal),t),a=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t);this.total.lineItemSubtotal=i,this.total.shippingCharges=a;let n=t,d={},u={};this.coupons.forEach(s=>{let o=s.calculateApplicableCouponDiscount(i,a,this.country,this.currency);n=n.add(o),d[s.getCode()]=o,s.getCategory()!=="SHIPPING"&&(u[s.getCode()]=o);}),this.total.discountTotal=n,this.total.discountBreakdown=d,this.applyDiscountsInLineItem(u);let h=this.coupons.find(s=>s.getCategory()==="SHIPPING");h?this.applyDiscountsInShippingCharges({[h.getCode()]:d[h.getCode()]||t}):this.applyDiscountsInShippingCharges({});let g=this.lineItems.reduce((s,o)=>s.add(o.getTotal().netSubtotal),t),c=this.charges.filter(s=>s.getType()==="SHIPPING").reduce((s,o)=>s.add(o.getTotal().grandTotal),t);this.total.netLineItemSubtotal=g,this.total.netShippingCharges=c;let m=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().chargeAmount),t),y=this.charges.filter(s=>s.getImpact()==="ADD").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),f=this.charges.filter(s=>s.getImpact()==="SUBTRACT").reduce((s,o)=>s.add(o.getTotal().grandTotal),t),M=t,I=t,b=t,p={},k={},P={},x=(s,o)=>{Object.entries(s).forEach(([O,C])=>{let l=C.system,T=C.subSystem;o[l]||(o[l]={system:l,totalAmount:t,subSystems:{}}),o[l].subSystems[T]?o[l].subSystems[T]=o[l].subSystems[T].add(C.taxAmount):o[l].subSystems[T]=C.taxAmount,o[l].totalAmount=o[l].totalAmount.add(C.taxAmount),p[l]||(p[l]={system:l,totalAmount:t,subSystems:{}}),p[l].subSystems[T]?p[l].subSystems[T]=p[l].subSystems[T].add(C.taxAmount):p[l].subSystems[T]=C.taxAmount,p[l].totalAmount=p[l].totalAmount.add(C.taxAmount);});};e.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,k),x(o,p),I=I.add(s.getTotal().taxTotal));}),this.charges.forEach(s=>{let o=s.getTotal().taxBreakdown;o&&(x(o,P),x(o,p),b=b.add(s.getTotal().taxTotal));}),M=I.add(b);let E=g.add(I).add(y).subtract(f);this.total={lineItemSubtotal:i,netLineItemSubtotal:g,lineItemTaxTotal:I,lineItemTaxBreakdown:k,additiveCharges:m,netAdditiveCharges:y,additiveChargesTaxTotal:b,additiveChargesTaxBreakdown:P,adjustmentCharges:f,shippingCharges:a,netShippingCharges:c,discountTotal:n,discountBreakdown:d,taxTotal:M,taxBreakdown:p,grandTotal:E};}updateShippingDetails(t){this.shippingDetails=t;}applyCoupons(t){let e=t.filter(a=>a.getCategory()==="SHIPPING"),i=t.filter(a=>a.getCategory()!=="SHIPPING");this.coupons=[],this.total.discountTotal=this.total.lineItemSubtotal.zero(),this.total.discountBreakdown={},i.length&&this.applyNonShippingCoupons(i),this.applyDiscountsInLineItem(this.total.discountBreakdown),e.length&&this.applyShippingCoupons(e),this.calculateTotals();}applyDiscountsInLineItem(t){let e=Array.from(Object.entries(t)).filter(a=>!a[1].isZero()),i=new Map;this.lineItems.forEach(a=>i.set(a.getId(),[])),e.forEach(([a,n])=>{let d=this.coupons.find(g=>g.getCode()===a);if(!d||n.isZero())return;let u=this.lineItems.filter(g=>g.getState()!=="CANCELLED"&&!g.getTotal().subtotal.isZero()).sort((g,c)=>g.getTotal().subtotal.compareTo(c.getTotal().subtotal)),h=new a$3({amount:0,currency:this.currency});u.forEach((g,c)=>{let m;c===u.length-1?m=n.subtract(h):m=n.multiply(g.getTotal().subtotal).divide(this.total.lineItemSubtotal).round(),h=h.add(m),i.get(g.getId())?.push({coupon:d,amount:m});});}),this.lineItems.forEach(a=>{a.getState()==="CANCELLED"||this.total.lineItemSubtotal.isZero()?a.updateDiscounts([]):a.updateDiscounts(i.get(a.getId())||[]);});}applyDiscountsInShippingCharges(t){let e=Array.from(Object.entries(t)).filter(n=>!n[1].isZero()),i=this.charges.filter(n=>n.getType()==="SHIPPING"),a=new Map;i.forEach(n=>a.set(n.getId(),[])),e.forEach(([n,d])=>{let u=this.coupons.find(c=>c.getCode()===n);if(!u||d.isZero())return;let h=i.sort((c,m)=>c.getTotal().grandTotal.compareTo(m.getTotal().grandTotal)),g=new a$3({amount:0,currency:this.currency});h.forEach((c,m)=>{let y;m===h.length-1?y=d.subtract(g):y=d.multiply(c.getTotal().chargeAmount).divide(this.total.shippingCharges).round(),g=g.add(y),a.get(c.getId())?.push({coupon:u,amount:y});});}),i.forEach(n=>{n.updateDiscounts(a.get(n.getId())||[]);});}applyNonShippingCoupons(t){let e=t.filter(i=>i.getType()==="coupon");if(e.length===1){let i=e[0].calculateApplicableCouponDiscount(this.total.lineItemSubtotal,this.total.shippingCharges,this.country,this.currency);i.getAmount()>0&&(this.coupons.push(e[0]),this.total.discountTotal=i,this.total.discountBreakdown[e[0].getCode()]=i);}}applyShippingCoupons(t){if(this.total.shippingCharges.getAmount()>0&&t.length>0){let e=this.total.lineItemSubtotal.subtract(this.total.discountTotal),i=t.reduce((n,d)=>{if(!n)return d;let u=d.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges),h=n.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);return u.compareTo(h)===0?d.getType()==="coupon"?d:n:u.compareTo(h)>0?d:n}),a=i.calculateApplicableCouponDiscount(e,this.total.shippingCharges,this.country,this.currency).min(this.total.shippingCharges);a.getAmount()>0&&(this.coupons.push(i),this.total.discountTotal=this.total.discountTotal.add(a),this.total.discountBreakdown[i.getCode()]=a);}}};export{B as a};//# sourceMappingURL=chunk-B5JKMVLT.mjs.map
2
+ //# sourceMappingURL=chunk-B5JKMVLT.mjs.map