.
This commit is contained in:
parent
4d76919e44
commit
75a0294cb1
@ -0,0 +1,47 @@
|
||||
import { type JsonTaxCatalogProvider, SpainTaxCatalogProvider } from "@erp/core";
|
||||
import { type IPresenterOutputParams, Presenter } from "@erp/core/api";
|
||||
import type { GetIssueInvoiceByIdResponseDTO } from "@erp/customer-invoices/common";
|
||||
import type { ArrayElement } from "@repo/rdx-utils";
|
||||
|
||||
import { type FormatMoneyOptions, formatMoneyDTO } from "../../helpers";
|
||||
|
||||
type CustomerInvoiceTaxesDTO = GetIssueInvoiceByIdResponseDTO["taxes"];
|
||||
type CustomerInvoiceTaxDTO = ArrayElement<CustomerInvoiceTaxesDTO>;
|
||||
|
||||
export class CustomerInvoiceTaxesReportPresenter extends Presenter<
|
||||
CustomerInvoiceTaxesDTO,
|
||||
unknown
|
||||
> {
|
||||
private _locale!: string;
|
||||
private _taxCatalog!: JsonTaxCatalogProvider;
|
||||
|
||||
private _mapTax(taxItem: CustomerInvoiceTaxDTO) {
|
||||
const moneyOptions: FormatMoneyOptions = {
|
||||
locale: this._locale,
|
||||
hideZeros: true,
|
||||
newScale: 2,
|
||||
};
|
||||
|
||||
const taxCatalogItem = this._taxCatalog.findByCode(taxItem.tax_code);
|
||||
|
||||
return {
|
||||
tax_code: taxItem.tax_code,
|
||||
tax_name: taxCatalogItem.unwrap().name,
|
||||
taxable_amount: formatMoneyDTO(taxItem.taxable_amount, moneyOptions),
|
||||
taxes_amount: formatMoneyDTO(taxItem.taxes_amount, moneyOptions),
|
||||
};
|
||||
}
|
||||
|
||||
toOutput(taxes: CustomerInvoiceTaxesDTO, params: IPresenterOutputParams): unknown {
|
||||
const { locale } = params as {
|
||||
locale: string;
|
||||
};
|
||||
|
||||
this._locale = locale;
|
||||
this._taxCatalog = SpainTaxCatalogProvider();
|
||||
|
||||
return taxes.map((item, _index) => {
|
||||
return this._mapTax(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -20,11 +20,21 @@ export class CustomerInvoiceReportPresenter extends Presenter<
|
||||
format: "JSON",
|
||||
});
|
||||
|
||||
const taxesPresenter = this.presenterRegistry.getPresenter({
|
||||
resource: "customer-invoice-taxes",
|
||||
projection: "REPORT",
|
||||
format: "JSON",
|
||||
});
|
||||
|
||||
const locale = invoiceDTO.language_code;
|
||||
const itemsDTO = itemsPresenter.toOutput(invoiceDTO.items, {
|
||||
locale,
|
||||
});
|
||||
|
||||
const taxesDTO = taxesPresenter.toOutput(invoiceDTO.taxes, {
|
||||
locale,
|
||||
});
|
||||
|
||||
const moneyOptions: FormatMoneyOptions = {
|
||||
locale,
|
||||
hideZeros: true,
|
||||
@ -33,6 +43,7 @@ export class CustomerInvoiceReportPresenter extends Presenter<
|
||||
|
||||
return {
|
||||
...invoiceDTO,
|
||||
taxes: taxesDTO,
|
||||
items: itemsDTO,
|
||||
|
||||
invoice_date: formatDateDTO(invoiceDTO.invoice_date),
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./customer-invoice-items.report.presenter";
|
||||
export * from "./customer-invoice.report.presenter";
|
||||
export * from "./customer-invoice-items.report.presenter";
|
||||
export * from "./customer-invoice-taxes.report.presenter";
|
||||
export * from "./list-customer-invoices.presenter";
|
||||
|
||||
@ -18,6 +18,7 @@ import {
|
||||
CustomerInvoiceReportHTMLPresenter,
|
||||
CustomerInvoiceReportPDFPresenter,
|
||||
CustomerInvoiceReportPresenter,
|
||||
CustomerInvoiceTaxesReportPresenter,
|
||||
GetProformaUseCase,
|
||||
IssueProformaInvoiceUseCase,
|
||||
ListCustomerInvoicesPresenter,
|
||||
@ -104,6 +105,10 @@ export function buildCustomerInvoiceDependencies(params: ModuleParams): Customer
|
||||
key: { resource: "customer-invoice", projection: "REPORT", format: "JSON" },
|
||||
presenter: new CustomerInvoiceReportPresenter(presenterRegistry),
|
||||
},
|
||||
{
|
||||
key: { resource: "customer-invoice-taxes", projection: "REPORT", format: "JSON" },
|
||||
presenter: new CustomerInvoiceTaxesReportPresenter(presenterRegistry),
|
||||
},
|
||||
{
|
||||
key: { resource: "customer-invoice-items", projection: "REPORT", format: "JSON" },
|
||||
presenter: new CustomerInvoiceItemsReportPersenter(presenterRegistry),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user