37 lines
806 B
TypeScript
37 lines
806 B
TypeScript
import { Tax } from "@erp/core/api";
|
|
import { DomainEntity, UniqueID } from "@repo/rdx-ddd";
|
|
import { Result } from "@repo/rdx-utils";
|
|
import { ItemAmount } from "../../value-objects";
|
|
|
|
export interface ItemTaxProps {
|
|
tax: Tax;
|
|
}
|
|
|
|
export class ItemTax extends DomainEntity<ItemTaxProps> {
|
|
static create(props: ItemTaxProps, id?: UniqueID): Result<ItemTax, Error> {
|
|
const itemTax = new ItemTax(props, id);
|
|
|
|
// Reglas de negocio / validaciones
|
|
// ...
|
|
// ...
|
|
|
|
return Result.ok(itemTax);
|
|
}
|
|
|
|
public get tax(): Tax {
|
|
return this.props.tax;
|
|
}
|
|
|
|
getProps(): ItemTaxProps {
|
|
return this.props;
|
|
}
|
|
|
|
toPrimitive() {
|
|
return this.getProps();
|
|
}
|
|
|
|
public getTaxAmount(taxableAmount: ItemAmount): ItemAmount {
|
|
return taxableAmount.percentage(this.tax.percentage);
|
|
}
|
|
}
|