Facturas de cliente

This commit is contained in:
David Arranz 2025-09-11 16:32:39 +02:00
parent e80cc572f9
commit cec3eba428
3 changed files with 75 additions and 9 deletions

View File

@ -31,11 +31,11 @@ export class ListCustomerInvoicesAssembler {
taxes: invoice.taxes,
/*subtotal_amount: allAmounts.subtotalAmount.toObjectString(),
discount_amount: allAmounts.discountAmount.toObjectString(),
taxable_amount: allAmounts.taxableAmount.toObjectString(),
taxes_amount: allAmounts.taxesAmount.toObjectString(),
total_amount: allAmounts.totalAmount.toObjectString(),*/
subtotal_amount: invoice.subtotalAmount.toObjectString(),
discount_amount: invoice.discountAmount.toObjectString(),
taxable_amount: invoice.taxableAmount.toObjectString(),
taxes_amount: invoice.taxesAmount.toObjectString(),
total_amount: invoice.totalAmount.toObjectString(),
metadata: {
entity: "customer-invoice",

View File

@ -20,6 +20,7 @@ import {
CustomerInvoiceNumber,
CustomerInvoiceSerie,
CustomerInvoiceStatus,
InvoiceAmount,
InvoiceRecipient,
} from "../../../domain";
import { CustomerInvoiceModel } from "../../sequelize";
@ -46,6 +47,12 @@ export type CustomerInvoiceListDTO = {
taxes: string;
discountPercentage: Percentage;
subtotalAmount: InvoiceAmount;
discountAmount: InvoiceAmount;
taxableAmount: InvoiceAmount;
taxesAmount: InvoiceAmount;
totalAmount: InvoiceAmount;
};
export interface ICustomerInvoiceListMapper
@ -109,9 +116,14 @@ export class CustomerInvoiceListMapper
languageCode: attributes.languageCode!,
currencyCode: attributes.currencyCode!,
discountPercentage: attributes.discountPercentage!,
taxes,
discountPercentage: attributes.discountPercentage!,
subtotalAmount: attributes.subtotalAmount!,
discountAmount: attributes.discountAmount!,
taxableAmount: attributes.taxableAmount!,
taxesAmount: attributes.taxesAmount!,
totalAmount: attributes.totalAmount!,
});
}
@ -167,13 +179,58 @@ export class CustomerInvoiceListMapper
const discountPercentage = extractOrPushError(
Percentage.create({
value: raw.discount_amount_scale,
value: raw.discount_percentage_value,
scale: raw.discount_percentage_scale,
}),
"discount_percentage_value",
errors
);
const subtotalAmount = extractOrPushError(
InvoiceAmount.create({
value: raw.subtotal_amount_value,
currency_code: currencyCode?.code,
}),
"subtotal_amount_value",
errors
);
const discountAmount = extractOrPushError(
InvoiceAmount.create({
value: raw.discount_amount_value,
currency_code: currencyCode?.code,
}),
"discount_amount_value",
errors
);
const taxableAmount = extractOrPushError(
InvoiceAmount.create({
value: raw.taxable_amount_value,
currency_code: currencyCode?.code,
}),
"taxable_amount_value",
errors
);
const taxesAmount = extractOrPushError(
InvoiceAmount.create({
value: raw.taxes_amount_value,
currency_code: currencyCode?.code,
}),
"taxes_amount_value",
errors
);
const totalAmount = extractOrPushError(
InvoiceAmount.create({
value: raw.total_amount_value,
currency_code: currencyCode?.code,
}),
"total_amount_value",
errors
);
return {
invoiceId,
companyId,
@ -187,6 +244,11 @@ export class CustomerInvoiceListMapper
languageCode,
currencyCode,
discountPercentage,
subtotalAmount,
discountAmount,
taxableAmount,
taxesAmount,
totalAmount,
};
}
}

View File

@ -75,7 +75,7 @@ export class MoneyValue extends ValueObject<MoneyValueProps> implements IMoneyVa
}
get value(): number {
return this.dinero.getAmount() / 10 ** this.dinero.getPrecision(); // ** => Math.pow
return this.dinero.getAmount();
}
get currencyCode(): string {
@ -90,6 +90,10 @@ export class MoneyValue extends ValueObject<MoneyValueProps> implements IMoneyVa
return this.props;
}
get formattedValue(): number {
return this.dinero.getAmount() / 10 ** this.dinero.getPrecision(); // ** => Math.pow
}
/** Reconstruye el VO desde la cadena persistida */
static fromPersistence(value: string): MoneyValue {
const [currencyCode, amountStr, scaleStr] = value.split(":");