118 lines
2.3 KiB
Plaintext
118 lines
2.3 KiB
Plaintext
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<string>;
|
|
recPercentage: Maybe<Percentage>;
|
|
recAmount: InvoiceAmount;
|
|
|
|
retentionCode: Maybe<string>;
|
|
retentionPercentage: Maybe<Percentage>;
|
|
retentionAmount: InvoiceAmount;
|
|
|
|
taxableAmount: InvoiceAmount;
|
|
totalAmount: InvoiceAmount;
|
|
};
|
|
|
|
export class IssuedInvoiceTaxGroup extends ValueObject<IssuedInvoiceTaxGroupProps> {
|
|
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<string> {
|
|
return this.props.recCode;
|
|
}
|
|
get recPercentage(): Maybe<Percentage> {
|
|
return this.props.recPercentage;
|
|
}
|
|
|
|
get recAmount(): Maybe<InvoiceAmount> {
|
|
return this.props.recAmount;
|
|
}
|
|
|
|
// Retención (ret)
|
|
|
|
get retentionCode(): Maybe<string> {
|
|
return this.props.retentionCode;
|
|
}
|
|
|
|
get retentionPercentage(): Maybe<Percentage> {
|
|
return this.props.retentionPercentage;
|
|
}
|
|
|
|
get retentionAmount(): Maybe<InvoiceAmount> {
|
|
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();
|
|
}
|
|
}
|