diff --git a/modules/customer-invoices/src/api/application/helpers/format-date-dto.ts b/modules/customer-invoices/src/api/application/helpers/format-date-dto.ts new file mode 100644 index 00000000..f4d6a720 --- /dev/null +++ b/modules/customer-invoices/src/api/application/helpers/format-date-dto.ts @@ -0,0 +1,7 @@ +import { UtcDate } from "@repo/rdx-ddd"; + +export function formatDateDTO(dateString: string) { + const result = UtcDate.createFromISO(dateString).data; + + return result.toDateString(); +} diff --git a/modules/customer-invoices/src/api/application/helpers/format-money-dto.ts b/modules/customer-invoices/src/api/application/helpers/format-money-dto.ts index ce5d39a8..3a84ea1a 100644 --- a/modules/customer-invoices/src/api/application/helpers/format-money-dto.ts +++ b/modules/customer-invoices/src/api/application/helpers/format-money-dto.ts @@ -2,6 +2,10 @@ import { MoneyDTO } from "@erp/core"; import { MoneyValue } from "@repo/rdx-ddd"; export function formatMoneyDTO(amount: MoneyDTO, locale: string) { + if (amount.value === "") { + return ""; + } + const money = MoneyValue.create({ value: Number(amount.value), currency_code: amount.currency_code, diff --git a/modules/customer-invoices/src/api/application/helpers/format-percentage-dto.ts b/modules/customer-invoices/src/api/application/helpers/format-percentage-dto.ts index 4d72baad..dee79061 100644 --- a/modules/customer-invoices/src/api/application/helpers/format-percentage-dto.ts +++ b/modules/customer-invoices/src/api/application/helpers/format-percentage-dto.ts @@ -1,11 +1,11 @@ import { PercentageDTO } from "@erp/core"; import { Percentage } from "@repo/rdx-ddd"; -export function formatPercentageDTO(Percentage_value: PercentageDTO) { +export function formatPercentageDTO(Percentage_value: PercentageDTO, locale: string) { const value = Percentage.create({ value: Number(Percentage_value.value), scale: Number(Percentage_value.scale), }).data; - return value.toNumber; + return value.format(locale); } diff --git a/modules/customer-invoices/src/api/application/helpers/format-quantity-dto.ts b/modules/customer-invoices/src/api/application/helpers/format-quantity-dto.ts index 5ca23026..3a662b16 100644 --- a/modules/customer-invoices/src/api/application/helpers/format-quantity-dto.ts +++ b/modules/customer-invoices/src/api/application/helpers/format-quantity-dto.ts @@ -2,10 +2,14 @@ import { QuantityDTO } from "@erp/core"; import { Quantity } from "@repo/rdx-ddd"; export function formatQuantityDTO(quantity_value: QuantityDTO) { + if (quantity_value.value === "") { + return ""; + } + const value = Quantity.create({ value: Number(quantity_value.value), scale: Number(quantity_value.scale), }).data; - return value.toNumber; + return value.format(); } diff --git a/modules/customer-invoices/src/api/application/helpers/index.ts b/modules/customer-invoices/src/api/application/helpers/index.ts index a8286fff..789c112f 100644 --- a/modules/customer-invoices/src/api/application/helpers/index.ts +++ b/modules/customer-invoices/src/api/application/helpers/index.ts @@ -1,3 +1,4 @@ +export * from "./format-date-dto"; export * from "./format-money-dto"; export * from "./format-percentage-dto"; export * from "./format-quantity-dto"; diff --git a/modules/customer-invoices/src/api/application/presenters/domain/customer-invoice-items.full.presenter.ts b/modules/customer-invoices/src/api/application/presenters/domain/customer-invoice-items.full.presenter.ts index e3573bd5..fe9be325 100644 --- a/modules/customer-invoices/src/api/application/presenters/domain/customer-invoice-items.full.presenter.ts +++ b/modules/customer-invoices/src/api/application/presenters/domain/customer-invoice-items.full.presenter.ts @@ -17,6 +17,7 @@ export class CustomerInvoiceItemsFullPresenter extends Presenter { return { id: invoiceItem.id.toPrimitive(), + isNonValued: String(invoiceItem.isNonValued), position: String(index), description: toEmptyString(invoiceItem.description, (value) => value.toPrimitive()), diff --git a/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice-items.report.presenter.ts b/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice-items.report.presenter.ts index bb4a417a..97e53116 100644 --- a/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice-items.report.presenter.ts +++ b/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice-items.report.presenter.ts @@ -1,7 +1,7 @@ import { IPresenterOutputParams, Presenter } from "@erp/core/api"; import { GetCustomerInvoiceByIdResponseDTO } from "@erp/customer-invoices/common"; import { ArrayElement } from "@repo/rdx-utils"; -import { formatMoneyDTO, formatPercentageDTO, formatQuantityDTO } from "../../helpers"; +import { formatMoneyDTO, formatQuantityDTO } from "../../helpers"; type CustomerInvoiceItemsDTO = GetCustomerInvoiceByIdResponseDTO["items"]; type CustomerInvoiceItemDTO = ArrayElement; @@ -20,8 +20,9 @@ export class CustomerInvoiceItemsReportPersenter extends Presenter< unit_amount: formatMoneyDTO(invoiceItem.unit_amount, this._locale), subtotal_amount: formatMoneyDTO(invoiceItem.subtotal_amount, this._locale), - discount_percetage: formatPercentageDTO(invoiceItem.discount_percentage), + // discount_percetage: formatPercentageDTO(invoiceItem.discount_percentage, this._locale), discount_amount: formatMoneyDTO(invoiceItem.discount_amount, this._locale), + taxable_amount: formatMoneyDTO(invoiceItem.taxable_amount, this._locale), taxes_amount: formatMoneyDTO(invoiceItem.taxes_amount, this._locale), total_amount: formatMoneyDTO(invoiceItem.total_amount, this._locale), }; diff --git a/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice.report.presenter.ts b/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice.report.presenter.ts index 3f91607c..ae4e1967 100644 --- a/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice.report.presenter.ts +++ b/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice.report.presenter.ts @@ -1,6 +1,6 @@ import { Presenter } from "@erp/core/api"; import { GetCustomerInvoiceByIdResponseDTO } from "../../../../common/dto"; -import { formatMoneyDTO, formatPercentageDTO } from "../../helpers"; +import { formatDateDTO, formatMoneyDTO, formatPercentageDTO } from "../../helpers"; export class CustomerInvoiceReportPresenter extends Presenter< GetCustomerInvoiceByIdResponseDTO, @@ -21,9 +21,12 @@ export class CustomerInvoiceReportPresenter extends Presenter< return { ...invoiceDTO, items: itemsDTO, + + invoice_date: formatDateDTO(invoiceDTO.invoice_date), subtotal_amount: formatMoneyDTO(invoiceDTO.subtotal_amount, locale), - discount_percetage: formatPercentageDTO(invoiceDTO.discount_percentage), + discount_percetage: formatPercentageDTO(invoiceDTO.discount_percentage, locale), discount_amount: formatMoneyDTO(invoiceDTO.discount_amount, locale), + taxable_amount: formatMoneyDTO(invoiceDTO.taxable_amount, locale), taxes_amount: formatMoneyDTO(invoiceDTO.taxes_amount, locale), total_amount: formatMoneyDTO(invoiceDTO.total_amount, locale), }; diff --git a/modules/customer-invoices/src/api/application/use-cases/report/reporter/customer-invoice.report.pdf.ts b/modules/customer-invoices/src/api/application/use-cases/report/reporter/customer-invoice.report.pdf.ts index 62addfac..f6c62700 100644 --- a/modules/customer-invoices/src/api/application/use-cases/report/reporter/customer-invoice.report.pdf.ts +++ b/modules/customer-invoices/src/api/application/use-cases/report/reporter/customer-invoice.report.pdf.ts @@ -20,6 +20,8 @@ export class CustomerInvoiceReportPDFPresenter extends Presenter< const htmlData = htmlPresenter.toOutput(customerInvoice); + console.log(htmlData); + // Generar el PDF con Puppeteer const browser = await puppeteer.launch({ args: [ @@ -44,6 +46,10 @@ export class CustomerInvoiceReportPDFPresenter extends Presenter< right: "10mm", top: "10mm", }, + landscape: false, + preferCSSPageSize: true, + omitBackground: false, + printBackground: true, }); await browser.close(); diff --git a/modules/customer-invoices/src/api/application/use-cases/report/reporter/templates/customer-invoice/template.hbs b/modules/customer-invoices/src/api/application/use-cases/report/reporter/templates/customer-invoice/template.hbs index 0331e031..c28c4e7b 100644 --- a/modules/customer-invoices/src/api/application/use-cases/report/reporter/templates/customer-invoice/template.hbs +++ b/modules/customer-invoices/src/api/application/use-cases/report/reporter/templates/customer-invoice/template.hbs @@ -3,7 +3,7 @@ - Factura F26200