Uecko_ERP/modules/customer-invoices/src/api/domain/entities/invoice-taxes/invoice-taxes.ts
2025-09-12 18:23:36 +02:00

32 lines
854 B
TypeScript

import { Collection } from "@repo/rdx-utils";
import { InvoiceAmount } from "../../value-objects";
import { InvoiceTax } from "./invoice-tax";
export interface InvoiceTaxesProps {
items?: InvoiceTax[];
}
export class InvoiceTaxes extends Collection<InvoiceTax> {
constructor(props: InvoiceTaxesProps) {
const { items = [] } = props;
super(items);
}
public static create(props: InvoiceTaxesProps): InvoiceTaxes {
return new InvoiceTaxes(props);
}
public getTaxesAmount(taxableAmount: InvoiceAmount): InvoiceAmount {
return this.getAll().reduce(
(total, tax) => total.add(tax.getTaxAmount(taxableAmount)),
InvoiceAmount.zero(taxableAmount.currencyCode)
) as InvoiceAmount;
}
public getCodesToString(): string {
return this.getAll()
.map((taxItem) => taxItem.tax.code)
.join(", ");
}
}