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 { 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) => ({
return items.map((item) => {
return {
position: item.position,
description: item.description ?? "",
quantity: item.quantity
quantity:
item.is_valued && 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
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: 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),
}));
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 {
position: number;
description: string;
quantity: string;
unit_amount: string;

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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),
}));