From cec3eba428ae0bc65e74e4824f3e817bbcc79594 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 11 Sep 2025 16:32:39 +0200 Subject: [PATCH] Facturas de cliente --- .../assembler/list-invoices.assembler.ts | 10 +-- .../list/customer-invoice.list.mapper.ts | 68 ++++++++++++++++++- .../rdx-ddd/src/value-objects/money-value.ts | 6 +- 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/modules/customer-invoices/src/api/application/list-customer-invoices/assembler/list-invoices.assembler.ts b/modules/customer-invoices/src/api/application/list-customer-invoices/assembler/list-invoices.assembler.ts index dc985330..9742bdc3 100644 --- a/modules/customer-invoices/src/api/application/list-customer-invoices/assembler/list-invoices.assembler.ts +++ b/modules/customer-invoices/src/api/application/list-customer-invoices/assembler/list-invoices.assembler.ts @@ -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", diff --git a/modules/customer-invoices/src/api/infrastructure/mappers/list/customer-invoice.list.mapper.ts b/modules/customer-invoices/src/api/infrastructure/mappers/list/customer-invoice.list.mapper.ts index 45cda91e..0aeb98de 100644 --- a/modules/customer-invoices/src/api/infrastructure/mappers/list/customer-invoice.list.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/mappers/list/customer-invoice.list.mapper.ts @@ -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, }; } } diff --git a/packages/rdx-ddd/src/value-objects/money-value.ts b/packages/rdx-ddd/src/value-objects/money-value.ts index 19bce3ef..9f114f97 100644 --- a/packages/rdx-ddd/src/value-objects/money-value.ts +++ b/packages/rdx-ddd/src/value-objects/money-value.ts @@ -75,7 +75,7 @@ export class MoneyValue extends ValueObject 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 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(":");