.
This commit is contained in:
parent
dd3f53c2b1
commit
936c440cf3
@ -11,15 +11,15 @@ export type IssuedInvoiceItemsProps = {
|
||||
};
|
||||
|
||||
export class IssuedInvoiceItems extends Collection<IssuedInvoiceItem> {
|
||||
private _languageCode!: LanguageCode;
|
||||
private _currencyCode!: CurrencyCode;
|
||||
private _globalDiscountPercentage!: Percentage;
|
||||
private languageCode!: LanguageCode;
|
||||
private currencyCode!: CurrencyCode;
|
||||
private globalDiscountPercentage!: Percentage;
|
||||
|
||||
constructor(props: IssuedInvoiceItemsProps) {
|
||||
super(props.items ?? []);
|
||||
this._languageCode = props.languageCode;
|
||||
this._currencyCode = props.currencyCode;
|
||||
this._globalDiscountPercentage = props.globalDiscountPercentage;
|
||||
this.languageCode = props.languageCode;
|
||||
this.currencyCode = props.currencyCode;
|
||||
this.globalDiscountPercentage = props.globalDiscountPercentage;
|
||||
}
|
||||
|
||||
public static create(props: IssuedInvoiceItemsProps): IssuedInvoiceItems {
|
||||
@ -40,9 +40,9 @@ export class IssuedInvoiceItems extends Collection<IssuedInvoiceItem> {
|
||||
// tiene el mismo "currencyCode" y "languageCode" que la colección de items.
|
||||
if (
|
||||
!(
|
||||
this._languageCode.equals(item.languageCode) &&
|
||||
this._currencyCode.equals(item.currencyCode) &&
|
||||
this._globalDiscountPercentage.equals(item.globalDiscountPercentage)
|
||||
this.languageCode.equals(item.languageCode) &&
|
||||
this.currencyCode.equals(item.currencyCode) &&
|
||||
this.globalDiscountPercentage.equals(item.globalDiscountPercentage)
|
||||
)
|
||||
)
|
||||
return false;
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import type { CurrencyCode, LanguageCode } from "@repo/rdx-ddd";
|
||||
import { Collection } from "@repo/rdx-utils";
|
||||
|
||||
import { InvoiceAmount } from "../../../common";
|
||||
|
||||
import type { IssuedInvoiceTax } from "./issued-invoice-tax.entity";
|
||||
|
||||
export type IssuedInvoiceTaxesProps = {
|
||||
@ -10,16 +12,59 @@ export type IssuedInvoiceTaxesProps = {
|
||||
};
|
||||
|
||||
export class IssuedInvoiceTaxes extends Collection<IssuedInvoiceTax> {
|
||||
private _languageCode!: LanguageCode;
|
||||
private _currencyCode!: CurrencyCode;
|
||||
private languageCode!: LanguageCode;
|
||||
private currencyCode!: CurrencyCode;
|
||||
|
||||
constructor(props: IssuedInvoiceTaxesProps) {
|
||||
super(props.taxes ?? []);
|
||||
this._languageCode = props.languageCode;
|
||||
this._currencyCode = props.currencyCode;
|
||||
this.languageCode = props.languageCode;
|
||||
this.currencyCode = props.currencyCode;
|
||||
}
|
||||
|
||||
public static create(props: IssuedInvoiceTaxesProps): IssuedInvoiceTaxes {
|
||||
return new IssuedInvoiceTaxes(props);
|
||||
}
|
||||
|
||||
public getTaxableAmount(): InvoiceAmount {
|
||||
return this.items.reduce(
|
||||
(acc, tax) => acc.add(tax.taxableAmount),
|
||||
InvoiceAmount.zero(this.currencyCode.toString())
|
||||
);
|
||||
}
|
||||
|
||||
public getIvaAmount(): InvoiceAmount {
|
||||
return this.items.reduce(
|
||||
(acc, tax) => acc.add(tax.ivaAmount),
|
||||
InvoiceAmount.zero(this.currencyCode.toString())
|
||||
);
|
||||
}
|
||||
|
||||
public getRecAmount(): InvoiceAmount {
|
||||
return this.items.reduce(
|
||||
(acc, tax) => acc.add(tax.recAmount),
|
||||
InvoiceAmount.zero(this.currencyCode.toString())
|
||||
);
|
||||
}
|
||||
|
||||
public getRetentionAmount(): InvoiceAmount {
|
||||
return this.items.reduce(
|
||||
(acc, tax) => acc.add(tax.retentionAmount),
|
||||
InvoiceAmount.zero(this.currencyCode.toString())
|
||||
);
|
||||
}
|
||||
|
||||
public getTaxesAmount(): InvoiceAmount {
|
||||
return this.items.reduce(
|
||||
(acc, tax) => acc.add(tax.taxesAmount),
|
||||
InvoiceAmount.zero(this.currencyCode.toString())
|
||||
);
|
||||
}
|
||||
|
||||
public getTransferredTaxesAmount(): InvoiceAmount {
|
||||
return this.getIvaAmount().add(this.getRecAmount());
|
||||
}
|
||||
|
||||
public getNetTaxesAmount(): InvoiceAmount {
|
||||
return this.getTransferredTaxesAmount().subtract(this.getRetentionAmount());
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,15 +247,17 @@ export class Proforma extends AggregateRoot<InternalProformaProps> implements IP
|
||||
}
|
||||
|
||||
// Mutabilidad
|
||||
public update(
|
||||
partialProforma: Partial<Omit<IProformaCreateProps, "companyId">>
|
||||
): Result<Proforma, Error> {
|
||||
const updatedProps = {
|
||||
public update(patch: ProformaPatchProps): Result<Proforma, Error> {
|
||||
const candidateProps: InternalProformaProps = {
|
||||
...this.props,
|
||||
...partialProforma,
|
||||
} as IProformaCreateProps;
|
||||
...patch,
|
||||
};
|
||||
|
||||
return Proforma.create(updatedProps, this.id);
|
||||
// Validacciones
|
||||
|
||||
Object.assign(this.props, candidateProps);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
public issue(): Result<void, Error> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user