66 lines
1.3 KiB
TypeScript
66 lines
1.3 KiB
TypeScript
|
|
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();
|
||
|
|
}
|
||
|
|
}
|