26 lines
666 B
TypeScript
26 lines
666 B
TypeScript
import { Collection } from "@repo/rdx-utils";
|
|
import { ItemAmount } from "../../value-objects";
|
|
import { ItemTax } from "./item-tax";
|
|
|
|
export interface ItemTaxesProps {
|
|
items?: ItemTax[];
|
|
}
|
|
|
|
export class ItemTaxes extends Collection<ItemTax> {
|
|
constructor(props: ItemTaxesProps) {
|
|
const { items = [] } = props;
|
|
super(items);
|
|
}
|
|
|
|
public static create(props: ItemTaxesProps): ItemTaxes {
|
|
return new ItemTaxes(props);
|
|
}
|
|
|
|
public getTaxesAmount(taxableAmount: ItemAmount): ItemAmount {
|
|
return this.getAll().reduce(
|
|
(total, tax) => total.add(tax.getTaxAmount(taxableAmount)),
|
|
ItemAmount.zero(taxableAmount.currencyCode)
|
|
);
|
|
}
|
|
}
|