Uecko_ERP/modules/customers/src/api/domain/value-objects/customer-taxes.vo.ts

66 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-03-16 17:45:45 +00:00
import type { Tax } from "@erp/core/api";
import { ValueObject } from "@repo/rdx-ddd";
import { type Maybe, Result } from "@repo/rdx-utils";
export type CustomerTaxesProps = {
iva: Maybe<Tax>; // si existe
rec: Maybe<Tax>; // si existe
retention: Maybe<Tax>; // si existe
};
export interface ICustomerItemTaxes {
iva: Maybe<Tax>; // si existe
rec: Maybe<Tax>; // si existe
retention: Maybe<Tax>; // si existe
toKey(): string; // Clave para representar un trío.
}
export class CustomerTaxes
extends ValueObject<CustomerTaxesProps>
implements ICustomerItemTaxes
{
static create(props: CustomerTaxesProps) {
return Result.ok(new CustomerTaxes(props));
}
toKey(): string {
const ivaCode = this.props.iva.match(
(iva) => iva.code,
() => "#"
);
const recCode = this.props.rec.match(
(rec) => rec.code,
() => "#"
);
const retentionCode = this.props.retention.match(
(retention) => retention.code,
() => "#"
);
return `${ivaCode};${recCode};${retentionCode}`;
}
get iva(): Maybe<Tax> {
return this.props.iva;
}
get rec(): Maybe<Tax> {
return this.props.rec;
}
get retention(): Maybe<Tax> {
return this.props.retention;
}
getProps() {
return this.props;
}
toPrimitive() {
return this.getProps();
}
}