import { type Percentage, ValueObject } from "@repo/rdx-ddd"; import { type Maybe, Result } from "@repo/rdx-utils"; import type { InvoiceAmount } from "../../common"; export type IssuedInvoiceTaxGroupProps = { ivaCode: string; ivaPercentage: Percentage; ivaAmount: InvoiceAmount; recCode: Maybe; recPercentage: Maybe; recAmount: InvoiceAmount; retentionCode: Maybe; retentionPercentage: Maybe; retentionAmount: InvoiceAmount; taxableAmount: InvoiceAmount; totalAmount: InvoiceAmount; }; export class IssuedInvoiceTaxGroup extends ValueObject { static create(props: IssuedInvoiceTaxGroupProps) { return Result.ok(new IssuedInvoiceTaxGroup(props)); } // IVA get ivaCode(): string { return this.props.ivaCode; } get ivaPercentage(): Percentage { return this.props.ivaPercentage; } get ivaAmount(): InvoiceAmount { return this.props.ivaAmount; } // Recargo de equivalencia (rec) get recCode(): Maybe { return this.props.recCode; } get recPercentage(): Maybe { return this.props.recPercentage; } get recAmount(): Maybe { return this.props.recAmount; } // Retención (ret) get retentionCode(): Maybe { return this.props.retentionCode; } get retentionPercentage(): Maybe { return this.props.retentionPercentage; } get retentionAmount(): Maybe { return this.props.retentionAmount; } // get taxableAmount(): InvoiceAmount { return this.props.taxableAmount; } get totalAmount(): InvoiceAmount { return this.props.totalAmount; } /** * Devuelve únicamente los códigos existentes: ["iva_21", "rec_5_2"] */ public getCodesArray(): string[] { const codes: string[] = []; // IVA codes.push(this.props.ivaCode); this.props.rec.match( (t) => codes.push(t.code), () => { // } ); this.props.retention.match( (t) => codes.push(t.code), () => { // } ); return codes; } /** * Devuelve una cadena tipo: "iva_21, rec_5_2" */ public getCodesToString(): string { return this.getCodesArray().join(", "); } getProps() { return this.props; } toPrimitive() { return this.getProps(); } }