feat(report): update proforma report snapshots to include additional fields and improve data handling

This commit is contained in:
David Arranz 2026-09-09 13:01:57 +02:00
parent dd6d33366e
commit 4bb5f8dd82
6 changed files with 112 additions and 68 deletions

View File

@ -2,6 +2,7 @@ import { MoneyDTOHelper, PercentageDTOHelper, QuantityDTOHelper } from "@erp/cor
import type { ISnapshotBuilder, ISnapshotBuilderParams } from "@erp/core/api"; import type { ISnapshotBuilder, ISnapshotBuilderParams } from "@erp/core/api";
import type { ProformaFullSnapshot } from "../full"; import type { ProformaFullSnapshot } from "../full";
import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface"; import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface";
type ProformaItemReportSnapshotBuilderParams = ISnapshotBuilderParams & { type ProformaItemReportSnapshotBuilderParams = ISnapshotBuilderParams & {
@ -23,22 +24,40 @@ export class ProformaItemReportSnapshotBuilder implements IProformaItemReportSna
minimumFractionDigits: 2, minimumFractionDigits: 2,
}; };
return items.map((item) => ({ return items.map((item) => {
description: item.description ?? "", return {
quantity: item.quantity position: item.position,
? QuantityDTOHelper.format(item.quantity, locale, { minimumFractionDigits: 0 }) description: item.description ?? "",
: "", quantity:
unit_amount: item.unit_amount ? MoneyDTOHelper.format(item.unit_amount, locale, moneyOptions) : "", item.is_valued && item.quantity
subtotal_amount: MoneyDTOHelper.format(item.subtotal_amount, locale, moneyOptions), ? QuantityDTOHelper.format(item.quantity, locale, { minimumFractionDigits: 0 })
discount_percentage: item.item_discount_percentage : "",
? PercentageDTOHelper.format(item.item_discount_percentage, locale, { unit_amount:
minimumFractionDigits: 0, item.is_valued && item.unit_amount
}) ? MoneyDTOHelper.format(item.unit_amount, locale, moneyOptions)
: "", : "",
discount_amount: MoneyDTOHelper.format(item.item_discount_amount, locale, moneyOptions), subtotal_amount: item.is_valued
taxable_amount: MoneyDTOHelper.format(item.taxable_amount, locale, moneyOptions), ? MoneyDTOHelper.format(item.subtotal_amount, locale, moneyOptions)
taxes_amount: MoneyDTOHelper.format(item.taxes_amount, locale, moneyOptions), : "",
total_amount: MoneyDTOHelper.format(item.total_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)
: "",
};
});
} }
} }

View File

@ -1,4 +1,9 @@
/**
* Para los campos que no tengan valor, poner cadena vacía, no null
*/
export interface ProformaReportItemSnapshot { export interface ProformaReportItemSnapshot {
position: number;
description: string; description: string;
quantity: string; quantity: string;
unit_amount: string; unit_amount: string;

View File

@ -4,6 +4,7 @@ import { DateHelper } from "@repo/rdx-utils";
import type { CompanyReportProfile, ReportLocalization } from "../../models"; import type { CompanyReportProfile, ReportLocalization } from "../../models";
import type { ProformaFullSnapshot } from "../full"; import type { ProformaFullSnapshot } from "../full";
import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface"; import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface";
import type { ProformaReportSnapshot } from "./proforma-report-snapshot.interface"; import type { ProformaReportSnapshot } from "./proforma-report-snapshot.interface";
import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface"; import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface";
@ -54,27 +55,30 @@ export class ProformaReportSnapshotBuilder implements IProformaReportSnapshotBui
id: snapshot.id, id: snapshot.id,
company_id: snapshot.company_id, company_id: snapshot.company_id,
proforma_reference: snapshot.proforma_reference, proforma_reference: snapshot.proforma_reference,
invoice_number: snapshot.invoice_number,
series: snapshot.series,
status: snapshot.status, status: snapshot.status,
reference: snapshot.reference, reference: snapshot.reference,
localization, description: snapshot.description,
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 ?? "",
notes: snapshot.notes, 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: { recipient: {
name: snapshot.recipient.name ?? "", name: snapshot.recipient.name ?? "",
tin: snapshot.recipient.tin, tin: snapshot.recipient.tin ?? null,
format_address: this.formatAddress(snapshot.recipient), format_address: this.formatAddress(snapshot.recipient),
}, },
tax_config: {
tax_mode: snapshot.tax_config.tax_mode,
},
items: this.itemsBuilder.toOutput(snapshot.items, { locale }), items: this.itemsBuilder.toOutput(snapshot.items, { locale }),
taxes: this.taxesBuilder.toOutput(snapshot.taxes, { locale }), taxes: this.taxesBuilder.toOutput(snapshot.taxes, { locale }),
@ -85,19 +89,20 @@ export class ProformaReportSnapshotBuilder implements IProformaReportSnapshotBui
locale, locale,
moneyOptions moneyOptions
), ),
global_discount_percentage: PercentageDTOHelper.format( global_discount_percentage: PercentageDTOHelper.format(
snapshot.global_discount_percentage, snapshot.global_discount_percentage,
locale, locale,
{ moneyOptions
hideZeros: true,
}
), ),
global_discount_amount: MoneyDTOHelper.format( global_discount_amount: MoneyDTOHelper.format(
snapshot.global_discount_amount, snapshot.global_discount_amount,
locale, locale,
moneyOptions moneyOptions
), ),
total_discount_amount: MoneyDTOHelper.format(
global_total_discount_amount: MoneyDTOHelper.format(
snapshot.total_discount_amount, snapshot.total_discount_amount,
locale, locale,
moneyOptions moneyOptions

View File

@ -1,43 +1,49 @@
import type { CompanyReportProfile, ReportLocalization } from "../../models";
import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface"; import type { ProformaReportItemSnapshot } from "./proforma-report-item-snapshot.interface";
import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface"; import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface";
export interface ProformaReportSnapshot { export interface ProformaReportSnapshot {
id: string; id: string;
company_id: string; company_id: string;
proforma_reference: string; proforma_reference: string;
invoice_number: string;
series: string | null;
status: string; status: string;
proforma_date: string;
operation_date: string | null;
reference: string | null; reference: string | null;
description: string | null;
localization: ReportLocalization;
company: CompanyReportProfile;
language_code: string;
currency_code: string;
invoice_date: string;
payment_method: string;
notes: string | null; notes: string | null;
//localization: ReportLocalization;
//company: CompanyReportProfile;
//language_code: string;
//currency_code: string;
payment_method: string | null;
payment_term: string | null;
recipient: { recipient: {
name: string; name: string;
tin: string | null; tin: string | null;
format_address: string; format_address: string;
}; };
tax_config: {
tax_mode: "single" | "per_line";
};
items: ProformaReportItemSnapshot[]; items: ProformaReportItemSnapshot[];
taxes: ProformaReportTaxSnapshot[]; taxes: ProformaReportTaxSnapshot[];
subtotal_amount: string; subtotal_amount: string;
items_discount_amount: string; items_discount_amount: string | null;
global_discount_percentage: string; global_discount_percentage: string | null;
global_discount_amount: string; global_discount_amount: string | null;
global_total_discount_amount: string | null;
total_discount_amount: string;
taxable_amount: string; taxable_amount: string;
taxes_amount: string; taxes_amount: string;

View File

@ -1,17 +1,17 @@
export interface ProformaReportTaxSnapshot { export interface ProformaReportTaxSnapshot {
taxable_amount: string; taxable_amount: string;
iva_code: string; iva_name: string | null;
iva_percentage: string; iva_percentage: string | null;
iva_amount: string; iva_amount: string | null;
rec_code: string; rec_name: string | null;
rec_percentage: string; rec_percentage: string | null;
rec_amount: string; rec_amount: string | null;
retention_code: string; retention_name: string | null;
retention_percentage: string; retention_percentage: string | null;
retention_amount: string; retention_amount: string | null;
taxes_amount: string; taxes_amount: string;
} }

View File

@ -2,6 +2,7 @@ import { MoneyDTOHelper, PercentageDTOHelper } from "@erp/core";
import type { ISnapshotBuilder, ISnapshotBuilderParams } from "@erp/core/api"; import type { ISnapshotBuilder, ISnapshotBuilderParams } from "@erp/core/api";
import type { ProformaFullSnapshot } from "../full"; import type { ProformaFullSnapshot } from "../full";
import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface"; import type { ProformaReportTaxSnapshot } from "./proforma-report-tax-snapshot.interface";
type ProformaTaxReportSnapshotBuilderParams = ISnapshotBuilderParams & { type ProformaTaxReportSnapshotBuilderParams = ISnapshotBuilderParams & {
@ -26,21 +27,29 @@ export class ProformaTaxReportSnapshotBuilder implements IProformaTaxReportSnaps
return taxes.map((tax) => ({ return taxes.map((tax) => ({
taxable_amount: MoneyDTOHelper.format(tax.taxable_amount, locale, moneyOptions), 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 iva_percentage: tax.iva_percentage
? PercentageDTOHelper.format(tax.iva_percentage, locale) ? PercentageDTOHelper.format(tax.iva_percentage, locale)
: "", : null,
iva_amount: MoneyDTOHelper.format(tax.iva_amount, locale, moneyOptions), iva_amount: tax.iva_amount
? MoneyDTOHelper.format(tax.iva_amount, locale, moneyOptions)
: null,
rec_code: tax.rec_code ?? "", rec_name: tax.rec_code ?? null,
rec_percentage: tax.rec_percentage ? PercentageDTOHelper.format(tax.rec_percentage, locale) : "", rec_percentage: tax.rec_percentage
rec_amount: MoneyDTOHelper.format(tax.rec_amount, locale, moneyOptions), ? 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 retention_percentage: tax.retention_percentage
? PercentageDTOHelper.format(tax.retention_percentage, locale) ? PercentageDTOHelper.format(tax.retention_percentage, locale)
: "", : null,
retention_amount: MoneyDTOHelper.format(tax.retention_amount, locale, moneyOptions), retention_amount: tax.retention_amount
? MoneyDTOHelper.format(tax.retention_amount, locale, moneyOptions)
: null,
taxes_amount: MoneyDTOHelper.format(tax.taxes_amount, locale, moneyOptions), taxes_amount: MoneyDTOHelper.format(tax.taxes_amount, locale, moneyOptions),
})); }));