From 4bb5f8dd8263d3069d686acd9368932ea6c15b2f Mon Sep 17 00:00:00 2001 From: David Date: Wed, 9 Sep 2026 13:01:57 +0200 Subject: [PATCH] feat(report): update proforma report snapshots to include additional fields and improve data handling --- .../proforma-items-report-snapshot-builder.ts | 53 +++++++++++++------ ...proforma-report-item-snapshot.interface.ts | 5 ++ .../proforma-report-snapshot-builder.ts | 37 +++++++------ .../proforma-report-snapshot.interface.ts | 40 ++++++++------ .../proforma-report-tax-snapshot.interface.ts | 18 +++---- .../proforma-tax-report-snapshot-builder.ts | 27 ++++++---- 6 files changed, 112 insertions(+), 68 deletions(-) diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-items-report-snapshot-builder.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-items-report-snapshot-builder.ts index 4f21c08c..f4ae9b0a 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-items-report-snapshot-builder.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-items-report-snapshot-builder.ts @@ -2,6 +2,7 @@ import { MoneyDTOHelper, PercentageDTOHelper, QuantityDTOHelper } from "@erp/cor import type { ISnapshotBuilder, ISnapshotBuilderParams } from "@erp/core/api"; import type { ProformaFullSnapshot } from "../full"; + import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface"; type ProformaItemReportSnapshotBuilderParams = ISnapshotBuilderParams & { @@ -23,22 +24,40 @@ export class ProformaItemReportSnapshotBuilder implements IProformaItemReportSna minimumFractionDigits: 2, }; - return items.map((item) => ({ - description: item.description ?? "", - quantity: item.quantity - ? QuantityDTOHelper.format(item.quantity, locale, { minimumFractionDigits: 0 }) - : "", - unit_amount: item.unit_amount ? MoneyDTOHelper.format(item.unit_amount, locale, moneyOptions) : "", - subtotal_amount: MoneyDTOHelper.format(item.subtotal_amount, locale, moneyOptions), - discount_percentage: item.item_discount_percentage - ? PercentageDTOHelper.format(item.item_discount_percentage, locale, { - minimumFractionDigits: 0, - }) - : "", - discount_amount: MoneyDTOHelper.format(item.item_discount_amount, locale, moneyOptions), - taxable_amount: MoneyDTOHelper.format(item.taxable_amount, locale, moneyOptions), - taxes_amount: MoneyDTOHelper.format(item.taxes_amount, locale, moneyOptions), - total_amount: MoneyDTOHelper.format(item.total_amount, locale, moneyOptions), - })); + return items.map((item) => { + return { + position: item.position, + description: item.description ?? "", + quantity: + item.is_valued && item.quantity + ? QuantityDTOHelper.format(item.quantity, locale, { minimumFractionDigits: 0 }) + : "", + unit_amount: + item.is_valued && item.unit_amount + ? MoneyDTOHelper.format(item.unit_amount, locale, moneyOptions) + : "", + subtotal_amount: item.is_valued + ? MoneyDTOHelper.format(item.subtotal_amount, locale, moneyOptions) + : "", + discount_percentage: + item.is_valued && item.item_discount_percentage + ? PercentageDTOHelper.format(item.item_discount_percentage, locale, { + minimumFractionDigits: 0, + }) + : "", + discount_amount: item.is_valued + ? MoneyDTOHelper.format(item.item_discount_amount, locale, moneyOptions) + : "", + taxable_amount: item.is_valued + ? MoneyDTOHelper.format(item.taxable_amount, locale, moneyOptions) + : "", + taxes_amount: item.is_valued + ? MoneyDTOHelper.format(item.taxes_amount, locale, moneyOptions) + : "", + total_amount: item.is_valued + ? MoneyDTOHelper.format(item.total_amount, locale, moneyOptions) + : "", + }; + }); } } diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-item-snapshot.interface.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-item-snapshot.interface.ts index ac9bac5c..9ffb33fa 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-item-snapshot.interface.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-item-snapshot.interface.ts @@ -1,4 +1,9 @@ +/** + * Para los campos que no tengan valor, poner cadena vacĂ­a, no null + */ + export interface ProformaReportItemSnapshot { + position: number; description: string; quantity: string; unit_amount: string; diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot-builder.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot-builder.ts index cf080192..e13edf10 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot-builder.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot-builder.ts @@ -4,6 +4,7 @@ import { DateHelper } from "@repo/rdx-utils"; import type { CompanyReportProfile, ReportLocalization } from "../../models"; import type { ProformaFullSnapshot } from "../full"; + import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface"; import type { ProformaReportSnapshot } from "./proforma-report-snapshot.interface"; import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface"; @@ -54,27 +55,30 @@ export class ProformaReportSnapshotBuilder implements IProformaReportSnapshotBui id: snapshot.id, company_id: snapshot.company_id, proforma_reference: snapshot.proforma_reference, - invoice_number: snapshot.invoice_number, - series: snapshot.series, status: snapshot.status, + reference: snapshot.reference, - localization, - company, - - language_code: snapshot.language_code, - currency_code: snapshot.currency_code, - - invoice_date: DateHelper.format(snapshot.invoice_date, locale), - - payment_method: snapshot.payment_method?.description ?? snapshot.payment_method?.name ?? "", + description: snapshot.description, notes: snapshot.notes, + proforma_date: DateHelper.format(snapshot.proforma_date, locale), + operation_date: snapshot.operation_date + ? DateHelper.format(snapshot.operation_date, locale) + : null, + + payment_method: snapshot.payment_method?.name ?? "", + payment_term: snapshot.payment_term?.name ?? null, + recipient: { name: snapshot.recipient.name ?? "", - tin: snapshot.recipient.tin, + tin: snapshot.recipient.tin ?? null, format_address: this.formatAddress(snapshot.recipient), }, + tax_config: { + tax_mode: snapshot.tax_config.tax_mode, + }, + items: this.itemsBuilder.toOutput(snapshot.items, { locale }), taxes: this.taxesBuilder.toOutput(snapshot.taxes, { locale }), @@ -85,19 +89,20 @@ export class ProformaReportSnapshotBuilder implements IProformaReportSnapshotBui locale, moneyOptions ), + global_discount_percentage: PercentageDTOHelper.format( snapshot.global_discount_percentage, locale, - { - hideZeros: true, - } + moneyOptions ), + global_discount_amount: MoneyDTOHelper.format( snapshot.global_discount_amount, locale, moneyOptions ), - total_discount_amount: MoneyDTOHelper.format( + + global_total_discount_amount: MoneyDTOHelper.format( snapshot.total_discount_amount, locale, moneyOptions diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot.interface.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot.interface.ts index dd1c3767..7c1d27dc 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot.interface.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-snapshot.interface.ts @@ -1,43 +1,49 @@ -import type { CompanyReportProfile, ReportLocalization } from "../../models"; import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface"; import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface"; export interface ProformaReportSnapshot { id: string; company_id: string; + proforma_reference: string; - invoice_number: string; - series: string | null; status: string; + + proforma_date: string; + operation_date: string | null; + reference: string | null; - - localization: ReportLocalization; - company: CompanyReportProfile; - - language_code: string; - currency_code: string; - - invoice_date: string; - payment_method: string; + description: string | null; notes: string | null; + //localization: ReportLocalization; + //company: CompanyReportProfile; + + //language_code: string; + //currency_code: string; + + payment_method: string | null; + payment_term: string | null; + recipient: { name: string; tin: string | null; format_address: string; }; + tax_config: { + tax_mode: "single" | "per_line"; + }; + items: ProformaReportItemSnapshot[]; taxes: ProformaReportTaxSnapshot[]; subtotal_amount: string; - items_discount_amount: string; + items_discount_amount: string | null; - global_discount_percentage: string; - global_discount_amount: string; - - total_discount_amount: string; + global_discount_percentage: string | null; + global_discount_amount: string | null; + global_total_discount_amount: string | null; taxable_amount: string; taxes_amount: string; diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-tax-snapshot.interface.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-tax-snapshot.interface.ts index ee649393..63a94910 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-tax-snapshot.interface.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-report-tax-snapshot.interface.ts @@ -1,17 +1,17 @@ export interface ProformaReportTaxSnapshot { taxable_amount: string; - iva_code: string; - iva_percentage: string; - iva_amount: string; + iva_name: string | null; + iva_percentage: string | null; + iva_amount: string | null; - rec_code: string; - rec_percentage: string; - rec_amount: string; + rec_name: string | null; + rec_percentage: string | null; + rec_amount: string | null; - retention_code: string; - retention_percentage: string; - retention_amount: string; + retention_name: string | null; + retention_percentage: string | null; + retention_amount: string | null; taxes_amount: string; } diff --git a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-tax-report-snapshot-builder.ts b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-tax-report-snapshot-builder.ts index 31faf557..0248efc0 100644 --- a/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-tax-report-snapshot-builder.ts +++ b/modules/customer-invoices/src/api/application/proformas/snapshot-builders/report/proforma-tax-report-snapshot-builder.ts @@ -2,6 +2,7 @@ import { MoneyDTOHelper, PercentageDTOHelper } from "@erp/core"; import type { ISnapshotBuilder, ISnapshotBuilderParams } from "@erp/core/api"; import type { ProformaFullSnapshot } from "../full"; + import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface"; type ProformaTaxReportSnapshotBuilderParams = ISnapshotBuilderParams & { @@ -26,21 +27,29 @@ export class ProformaTaxReportSnapshotBuilder implements IProformaTaxReportSnaps return taxes.map((tax) => ({ taxable_amount: MoneyDTOHelper.format(tax.taxable_amount, locale, moneyOptions), - iva_code: tax.iva_code ?? "", + iva_name: tax.iva_code ?? null, iva_percentage: tax.iva_percentage ? PercentageDTOHelper.format(tax.iva_percentage, locale) - : "", - iva_amount: MoneyDTOHelper.format(tax.iva_amount, locale, moneyOptions), + : null, + iva_amount: tax.iva_amount + ? MoneyDTOHelper.format(tax.iva_amount, locale, moneyOptions) + : null, - rec_code: tax.rec_code ?? "", - rec_percentage: tax.rec_percentage ? PercentageDTOHelper.format(tax.rec_percentage, locale) : "", - rec_amount: MoneyDTOHelper.format(tax.rec_amount, locale, moneyOptions), + rec_name: tax.rec_code ?? null, + rec_percentage: tax.rec_percentage + ? PercentageDTOHelper.format(tax.rec_percentage, locale) + : null, + rec_amount: tax.rec_amount + ? MoneyDTOHelper.format(tax.rec_amount, locale, moneyOptions) + : null, - retention_code: tax.retention_code ?? "", + retention_name: tax.retention_code ?? null, retention_percentage: tax.retention_percentage ? PercentageDTOHelper.format(tax.retention_percentage, locale) - : "", - retention_amount: MoneyDTOHelper.format(tax.retention_amount, locale, moneyOptions), + : null, + retention_amount: tax.retention_amount + ? MoneyDTOHelper.format(tax.retention_amount, locale, moneyOptions) + : null, taxes_amount: MoneyDTOHelper.format(tax.taxes_amount, locale, moneyOptions), }));