From 1919a54dc2a29d2426a5429c8d611b57dd46f715 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 18 Sep 2025 13:17:18 +0200 Subject: [PATCH] Facturas de cliente --- .../application/create-account.use-case.ts | 2 +- .../application/update-account.use-case.ts | 4 +- .../account-service.integration.test.ts | 4 +- .../domain/services/account-service.test.ts | 2 +- .../infraestructure/mappers/account.mapper.ts | 4 +- .../sequelize/account.model.ts | 4 +- .../create-account.presenter.ts | 2 +- .../get-account/get-account.presenter.ts | 2 +- .../list-accounts/list-accounts.presenter.ts | 2 +- .../update-account.presenter.ts | 2 +- .../presentation/dto/accounts.request.dto.ts | 4 +- .../presentation/dto/accounts.response.dto.ts | 8 ++-- .../presentation/dto/accounts.schemas.ts | 4 +- .../infraestructure/mappers/contact.mapper.ts | 4 +- .../sequelize/contact.model.ts | 4 +- .../list/list-contacts.presenter.ts | 2 +- .../presentation/dto/contacts.response.dto.ts | 2 +- apps/web/src/locales/i18n.ts | 2 +- apps/web/src/routes/app-routes.tsx | 2 - .../auth/src/common/dto/get-profile.dto.ts | 4 +- modules/auth/src/common/dto/login.dto.ts | 2 +- .../presenters/presenter.interface.ts | 4 +- .../api/application/presenters/presenter.ts | 8 +--- .../helpers/format-quantity-dto.ts | 11 +++++ .../src/api/application/helpers/index.ts | 1 + .../api/application/helpers/quantity-dto.ts | 12 ------ .../customer-invoice-items.full.presenter.ts | 4 +- ...customer-invoice-items.report.presenter.ts | 41 +++++++++++++++++++ .../customer-invoice.report.presenter.ts | 12 +++++- .../application/presenters/queries/index.ts | 1 + .../src/api/infrastructure/dependencies.ts | 9 ++++ modules/customers/src/common/locales/en.json | 2 +- modules/customers/src/common/locales/es.json | 2 +- .../web/pages/create/customer-edit-form.tsx | 20 ++++----- .../update/customer-basic-info-fields.tsx | 4 +- 35 files changed, 127 insertions(+), 70 deletions(-) create mode 100644 modules/customer-invoices/src/api/application/helpers/format-quantity-dto.ts delete mode 100644 modules/customer-invoices/src/api/application/helpers/quantity-dto.ts create mode 100644 modules/customer-invoices/src/api/application/presenters/queries/customer-invoice-items.report.presenter.ts diff --git a/apps/server/archive/contexts/accounts/application/create-account.use-case.ts b/apps/server/archive/contexts/accounts/application/create-account.use-case.ts index 4c01fdf7..d0409f5f 100644 --- a/apps/server/archive/contexts/accounts/application/create-account.use-case.ts +++ b/apps/server/archive/contexts/accounts/application/create-account.use-case.ts @@ -85,7 +85,7 @@ export class CreateAccountUseCase { website: dto.website ? Maybe.some(dto.website) : Maybe.none(), legalRecord: dto.legal_record, defaultTax: dto.default_tax, - langCode: dto.lang_code, + langCode: dto.language_code, currencyCode: dto.currency_code, logo: dto.logo ? Maybe.some(dto.logo) : Maybe.none(), }; diff --git a/apps/server/archive/contexts/accounts/application/update-account.use-case.ts b/apps/server/archive/contexts/accounts/application/update-account.use-case.ts index 067fe5e8..753adf83 100644 --- a/apps/server/archive/contexts/accounts/application/update-account.use-case.ts +++ b/apps/server/archive/contexts/accounts/application/update-account.use-case.ts @@ -106,8 +106,8 @@ export class UpdateAccountUseCase { validatedData.defaultTax = dto.default_tax; } - if (dto.lang_code) { - validatedData.langCode = dto.lang_code; + if (dto.language_code) { + validatedData.langCode = dto.language_code; } if (dto.currency_code) { diff --git a/apps/server/archive/contexts/accounts/domain/services/account-service.integration.test.ts b/apps/server/archive/contexts/accounts/domain/services/account-service.integration.test.ts index 773949e6..74cd91c4 100644 --- a/apps/server/archive/contexts/accounts/domain/services/account-service.integration.test.ts +++ b/apps/server/archive/contexts/accounts/domain/services/account-service.integration.test.ts @@ -38,7 +38,7 @@ const sampleAccountPrimitives = { legal_record: "Registro Mercantil XYZ", default_tax: 21, status: "active", - lang_code: "es", + language_code: "es", currency_code: "EUR", logo: "https://xyz.com/logo.png", }; @@ -87,7 +87,7 @@ const accountBuilder = (accountData: any) => { : Maybe.none(), legalRecord: sampleAccountPrimitives.legal_record, defaultTax: sampleAccountPrimitives.default_tax, - langCode: sampleAccountPrimitives.lang_code, + langCode: sampleAccountPrimitives.language_code, currencyCode: sampleAccountPrimitives.currency_code, logo: sampleAccountPrimitives.logo ? Maybe.some(sampleAccountPrimitives.logo) : Maybe.none(), }; diff --git a/apps/server/archive/contexts/accounts/domain/services/account-service.test.ts b/apps/server/archive/contexts/accounts/domain/services/account-service.test.ts index c7d28b66..26cf6f14 100644 --- a/apps/server/archive/contexts/accounts/domain/services/account-service.test.ts +++ b/apps/server/archive/contexts/accounts/domain/services/account-service.test.ts @@ -30,7 +30,7 @@ const sampleAccount = { legal_record: "Registro Mercantil XYZ", default_tax: 21, status: "active", - lang_code: "es", + language_code: "es", currency_code: "EUR", logo: "https://xyz.com/logo.png", }; diff --git a/apps/server/archive/contexts/accounts/infraestructure/mappers/account.mapper.ts b/apps/server/archive/contexts/accounts/infraestructure/mappers/account.mapper.ts index 2d7bcf28..115f4932 100644 --- a/apps/server/archive/contexts/accounts/infraestructure/mappers/account.mapper.ts +++ b/apps/server/archive/contexts/accounts/infraestructure/mappers/account.mapper.ts @@ -64,7 +64,7 @@ export class AccountMapper website: source.website ? Maybe.some(source.website) : Maybe.none(), legalRecord: source.legal_record, defaultTax: source.default_tax, - langCode: source.lang_code, + langCode: source.language_code, currencyCode: source.currency_code, logo: source.logo ? Maybe.some(source.logo) : Maybe.none(), }, @@ -94,7 +94,7 @@ export class AccountMapper legal_record: source.legalRecord, default_tax: source.defaultTax, status: source.isActive ? "active" : "inactive", - lang_code: source.langCode, + language_code: source.langCode, currency_code: source.currencyCode, logo: source.logo.getOrUndefined(), }; diff --git a/apps/server/archive/contexts/accounts/infraestructure/sequelize/account.model.ts b/apps/server/archive/contexts/accounts/infraestructure/sequelize/account.model.ts index a0ad589b..9b4e8099 100644 --- a/apps/server/archive/contexts/accounts/infraestructure/sequelize/account.model.ts +++ b/apps/server/archive/contexts/accounts/infraestructure/sequelize/account.model.ts @@ -37,7 +37,7 @@ export class AccountModel extends Model, AccountCr declare default_tax: number; declare status: string; - declare lang_code: string; + declare language_code: string; declare currency_code: string; declare logo: CreationOptional; } @@ -129,7 +129,7 @@ export default (sequelize: Sequelize) => { defaultValue: null, }, - lang_code: { + language_code: { type: DataTypes.STRING(2), allowNull: false, defaultValue: "es", diff --git a/apps/server/archive/contexts/accounts/presentation/controllers/create-account/create-account.presenter.ts b/apps/server/archive/contexts/accounts/presentation/controllers/create-account/create-account.presenter.ts index 3b30b366..ac82a1c0 100644 --- a/apps/server/archive/contexts/accounts/presentation/controllers/create-account/create-account.presenter.ts +++ b/apps/server/archive/contexts/accounts/presentation/controllers/create-account/create-account.presenter.ts @@ -30,7 +30,7 @@ export const createAccountPresenter: ICreateAccountPresenter = { default_tax: ensureNumber(account.defaultTax), status: ensureString(account.isActive ? "active" : "inactive"), - lang_code: ensureString(account.langCode), + language_code: ensureString(account.langCode), currency_code: ensureString(account.currencyCode), logo: ensureString(account.logo.getOrUndefined()), }), diff --git a/apps/server/archive/contexts/accounts/presentation/controllers/get-account/get-account.presenter.ts b/apps/server/archive/contexts/accounts/presentation/controllers/get-account/get-account.presenter.ts index 56941529..7c3fef8f 100644 --- a/apps/server/archive/contexts/accounts/presentation/controllers/get-account/get-account.presenter.ts +++ b/apps/server/archive/contexts/accounts/presentation/controllers/get-account/get-account.presenter.ts @@ -30,7 +30,7 @@ export const getAccountPresenter: IGetAccountPresenter = { default_tax: ensureNumber(account.defaultTax), status: ensureString(account.isActive ? "active" : "inactive"), - lang_code: ensureString(account.langCode), + language_code: ensureString(account.langCode), currency_code: ensureString(account.currencyCode), logo: ensureString(account.logo.getOrUndefined()), }), diff --git a/apps/server/archive/contexts/accounts/presentation/controllers/list-accounts/list-accounts.presenter.ts b/apps/server/archive/contexts/accounts/presentation/controllers/list-accounts/list-accounts.presenter.ts index b7f887be..91afbf1f 100644 --- a/apps/server/archive/contexts/accounts/presentation/controllers/list-accounts/list-accounts.presenter.ts +++ b/apps/server/archive/contexts/accounts/presentation/controllers/list-accounts/list-accounts.presenter.ts @@ -31,7 +31,7 @@ export const listAccountsPresenter: IListAccountsPresenter = { default_tax: ensureNumber(account.defaultTax), status: ensureString(account.isActive ? "active" : "inactive"), - lang_code: ensureString(account.langCode), + language_code: ensureString(account.langCode), currency_code: ensureString(account.currencyCode), logo: ensureString(account.logo.getOrUndefined()), })), diff --git a/apps/server/archive/contexts/accounts/presentation/controllers/update-account/update-account.presenter.ts b/apps/server/archive/contexts/accounts/presentation/controllers/update-account/update-account.presenter.ts index 201d98d2..293f8251 100644 --- a/apps/server/archive/contexts/accounts/presentation/controllers/update-account/update-account.presenter.ts +++ b/apps/server/archive/contexts/accounts/presentation/controllers/update-account/update-account.presenter.ts @@ -30,7 +30,7 @@ export const updateAccountPresenter: IUpdateAccountPresenter = { default_tax: ensureNumber(account.defaultTax), status: ensureString(account.isActive ? "active" : "inactive"), - lang_code: ensureString(account.langCode), + language_code: ensureString(account.langCode), currency_code: ensureString(account.currencyCode), logo: ensureString(account.logo.getOrUndefined()), }), diff --git a/apps/server/archive/contexts/accounts/presentation/dto/accounts.request.dto.ts b/apps/server/archive/contexts/accounts/presentation/dto/accounts.request.dto.ts index 9047b996..73904fec 100644 --- a/apps/server/archive/contexts/accounts/presentation/dto/accounts.request.dto.ts +++ b/apps/server/archive/contexts/accounts/presentation/dto/accounts.request.dto.ts @@ -21,7 +21,7 @@ export interface ICreateAccountRequestDTO { legal_record: string; default_tax: number; - lang_code: string; + language_code: string; currency_code: string; logo: string; } @@ -46,7 +46,7 @@ export interface IUpdateAccountRequestDTO { legal_record: string; default_tax: number; - lang_code: string; + language_code: string; currency_code: string; logo: string; } diff --git a/apps/server/archive/contexts/accounts/presentation/dto/accounts.response.dto.ts b/apps/server/archive/contexts/accounts/presentation/dto/accounts.response.dto.ts index 129d90a9..684ba86d 100644 --- a/apps/server/archive/contexts/accounts/presentation/dto/accounts.response.dto.ts +++ b/apps/server/archive/contexts/accounts/presentation/dto/accounts.response.dto.ts @@ -21,7 +21,7 @@ export interface IListAccountsResponseDTO { default_tax: number; status: string; - lang_code: string; + language_code: string; currency_code: string; logo: string; } @@ -49,7 +49,7 @@ export interface IGetAccountResponseDTO { default_tax: number; status: string; - lang_code: string; + language_code: string; currency_code: string; logo: string; } @@ -77,7 +77,7 @@ export interface ICreateAccountResponseDTO { default_tax: number; status: string; - lang_code: string; + language_code: string; currency_code: string; logo: string; } @@ -108,7 +108,7 @@ export interface IUpdateAccountResponseDTO { default_tax: number; status: string; - lang_code: string; + language_code: string; currency_code: string; logo: string; } diff --git a/apps/server/archive/contexts/accounts/presentation/dto/accounts.schemas.ts b/apps/server/archive/contexts/accounts/presentation/dto/accounts.schemas.ts index e85ec8e2..0818e233 100644 --- a/apps/server/archive/contexts/accounts/presentation/dto/accounts.schemas.ts +++ b/apps/server/archive/contexts/accounts/presentation/dto/accounts.schemas.ts @@ -27,7 +27,7 @@ export const ICreateAccountRequestSchema = z.object({ default_tax: z.number(), status: z.string(), - lang_code: z.string(), + language_code: z.string(), currency_code: z.string(), logo: z.string(), }); @@ -55,7 +55,7 @@ export const IUpdateAccountRequestSchema = z.object({ default_tax: z.number(), status: z.string(), - lang_code: z.string(), + language_code: z.string(), currency_code: z.string(), logo: z.string(), }); diff --git a/apps/server/archive/contexts/contacts/infraestructure/mappers/contact.mapper.ts b/apps/server/archive/contexts/contacts/infraestructure/mappers/contact.mapper.ts index 683f793e..6403fc7d 100644 --- a/apps/server/archive/contexts/contacts/infraestructure/mappers/contact.mapper.ts +++ b/apps/server/archive/contexts/contacts/infraestructure/mappers/contact.mapper.ts @@ -63,7 +63,7 @@ export class ContactMapper legalRecord: source.legal_record, defaultTax: source.default_tax, status: source.status, - langCode: source.lang_code, + langCode: source.language_code, currencyCode: source.currency_code, }, idOrError.data @@ -96,7 +96,7 @@ export class ContactMapper legal_record: source.legalRecord, default_tax: source.defaultTax, status: source.isActive ? "active" : "inactive", - lang_code: source.langCode, + language_code: source.langCode, currency_code: source.currencyCode, }); } diff --git a/apps/server/archive/contexts/contacts/infraestructure/sequelize/contact.model.ts b/apps/server/archive/contexts/contacts/infraestructure/sequelize/contact.model.ts index b45d656a..aa2a7583 100644 --- a/apps/server/archive/contexts/contacts/infraestructure/sequelize/contact.model.ts +++ b/apps/server/archive/contexts/contacts/infraestructure/sequelize/contact.model.ts @@ -41,7 +41,7 @@ export class ContactModel extends Model< declare default_tax: number; declare status: string; - declare lang_code: string; + declare language_code: string; declare currency_code: string; } @@ -130,7 +130,7 @@ export default (sequelize: Sequelize) => { defaultValue: 2100, }, - lang_code: { + language_code: { type: DataTypes.STRING(2), allowNull: false, defaultValue: "es", diff --git a/apps/server/archive/contexts/contacts/presentation/controllers/list/list-contacts.presenter.ts b/apps/server/archive/contexts/contacts/presentation/controllers/list/list-contacts.presenter.ts index d5aeef70..a5b12647 100644 --- a/apps/server/archive/contexts/contacts/presentation/controllers/list/list-contacts.presenter.ts +++ b/apps/server/archive/contexts/contacts/presentation/controllers/list/list-contacts.presenter.ts @@ -32,7 +32,7 @@ export const listContactsPresenter: IListContactsPresenter = { default_tax: ensureNumber(contact.defaultTax), status: ensureString(contact.isActive ? "active" : "inactive"), - lang_code: ensureString(contact.langCode), + language_code: ensureString(contact.langCode), currency_code: ensureString(contact.currencyCode), })), }; diff --git a/apps/server/archive/contexts/contacts/presentation/dto/contacts.response.dto.ts b/apps/server/archive/contexts/contacts/presentation/dto/contacts.response.dto.ts index dc134533..597763db 100644 --- a/apps/server/archive/contexts/contacts/presentation/dto/contacts.response.dto.ts +++ b/apps/server/archive/contexts/contacts/presentation/dto/contacts.response.dto.ts @@ -22,6 +22,6 @@ export interface IListContactsResponseDTO { default_tax: number; status: string; - lang_code: string; + language_code: string; currency_code: string; } diff --git a/apps/web/src/locales/i18n.ts b/apps/web/src/locales/i18n.ts index 495ce9a8..729461a3 100644 --- a/apps/web/src/locales/i18n.ts +++ b/apps/web/src/locales/i18n.ts @@ -20,7 +20,7 @@ i18n detection: { order: ["navigator"], }, - debug: import.meta.env.DEV, + debug: false, //import.meta.env.DEV, fallbackLng: "es", interpolation: { escapeValue: false, diff --git a/apps/web/src/routes/app-routes.tsx b/apps/web/src/routes/app-routes.tsx index 46891565..745c612a 100644 --- a/apps/web/src/routes/app-routes.tsx +++ b/apps/web/src/routes/app-routes.tsx @@ -31,8 +31,6 @@ export const getAppRouter = () => { const grouped = groupModulesByLayout(modules); - console.debug(grouped); - return createBrowserRouter( createRoutesFromElements( diff --git a/modules/auth/src/common/dto/get-profile.dto.ts b/modules/auth/src/common/dto/get-profile.dto.ts index 1a6e9e61..8d5cb37b 100644 --- a/modules/auth/src/common/dto/get-profile.dto.ts +++ b/modules/auth/src/common/dto/get-profile.dto.ts @@ -4,7 +4,7 @@ export interface IGetProfileResponseDTO { id: string; name: string; email: string; - lang_code: string; + language_code: string; roles: string[]; dealer: { id: string; @@ -16,7 +16,7 @@ export interface IGetProfileResponseDTO { default_quote_validity: string; default_tax: IPercentageDTO; status: string; - lang_code: string; + language_code: string; currency_code: string; logo: string; }; diff --git a/modules/auth/src/common/dto/login.dto.ts b/modules/auth/src/common/dto/login.dto.ts index eaaa7920..f13f7fe2 100644 --- a/modules/auth/src/common/dto/login.dto.ts +++ b/modules/auth/src/common/dto/login.dto.ts @@ -7,7 +7,7 @@ export interface ILoginResponseDTO { id: string; name: string; email: string; - lang_code: string; + language_code: string; roles: string[]; token: string; refresh_token: string; diff --git a/modules/core/src/api/application/presenters/presenter.interface.ts b/modules/core/src/api/application/presenters/presenter.interface.ts index 0713058e..25029d76 100644 --- a/modules/core/src/api/application/presenters/presenter.interface.ts +++ b/modules/core/src/api/application/presenters/presenter.interface.ts @@ -1,6 +1,8 @@ export type DTO = T; export type BinaryOutput = Buffer; // Puedes ampliar a Readable si usas streams +export type IPresenterOutputParams = Record; + export interface IPresenter { - toOutput(source: TSource): TOutput | Promise; + toOutput(source: TSource, params?: IPresenterOutputParams): TOutput | Promise; } diff --git a/modules/core/src/api/application/presenters/presenter.ts b/modules/core/src/api/application/presenters/presenter.ts index d48228b5..de570619 100644 --- a/modules/core/src/api/application/presenters/presenter.ts +++ b/modules/core/src/api/application/presenters/presenter.ts @@ -1,13 +1,9 @@ import { IPresenterRegistry } from "./presenter-registry.interface"; -import { IPresenter } from "./presenter.interface"; - -export type IPresenterParams = { - presenterRegistry: IPresenterRegistry; -} & Record; +import { IPresenter, IPresenterOutputParams } from "./presenter.interface"; export abstract class Presenter implements IPresenter { constructor(protected presenterRegistry: IPresenterRegistry) {} - abstract toOutput(source: TSource): TOutput; + abstract toOutput(source: TSource, params?: IPresenterOutputParams): TOutput; } 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 new file mode 100644 index 00000000..5ca23026 --- /dev/null +++ b/modules/customer-invoices/src/api/application/helpers/format-quantity-dto.ts @@ -0,0 +1,11 @@ +import { QuantityDTO } from "@erp/core"; +import { Quantity } from "@repo/rdx-ddd"; + +export function formatQuantityDTO(quantity_value: QuantityDTO) { + const value = Quantity.create({ + value: Number(quantity_value.value), + scale: Number(quantity_value.scale), + }).data; + + return value.toNumber; +} diff --git a/modules/customer-invoices/src/api/application/helpers/index.ts b/modules/customer-invoices/src/api/application/helpers/index.ts index 20a90177..a8286fff 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-money-dto"; export * from "./format-percentage-dto"; +export * from "./format-quantity-dto"; export * from "./map-dto-to-customer-invoice-props"; diff --git a/modules/customer-invoices/src/api/application/helpers/quantity-dto.ts b/modules/customer-invoices/src/api/application/helpers/quantity-dto.ts deleted file mode 100644 index ce5d39a8..00000000 --- a/modules/customer-invoices/src/api/application/helpers/quantity-dto.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { MoneyDTO } from "@erp/core"; -import { MoneyValue } from "@repo/rdx-ddd"; - -export function formatMoneyDTO(amount: MoneyDTO, locale: string) { - const money = MoneyValue.create({ - value: Number(amount.value), - currency_code: amount.currency_code, - scale: Number(amount.scale), - }).data; - - return money.format(locale); -} 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 d9bcdd23..e3573bd5 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 @@ -9,7 +9,7 @@ type GetCustomerInvoiceItemByInvoiceIdResponseDTO = ArrayElement< >; export class CustomerInvoiceItemsFullPresenter extends Presenter { - protected _map( + private _mapItem( invoiceItem: CustomerInvoiceItem, index: number ): GetCustomerInvoiceItemByInvoiceIdResponseDTO { @@ -48,6 +48,6 @@ export class CustomerInvoiceItemsFullPresenter extends Presenter { } toOutput(invoiceItems: CustomerInvoiceItems): GetCustomerInvoiceByIdResponseDTO["items"] { - return invoiceItems.map(this._map); + return invoiceItems.map(this._mapItem); } } 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 new file mode 100644 index 00000000..bb4a417a --- /dev/null +++ b/modules/customer-invoices/src/api/application/presenters/queries/customer-invoice-items.report.presenter.ts @@ -0,0 +1,41 @@ +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"; + +type CustomerInvoiceItemsDTO = GetCustomerInvoiceByIdResponseDTO["items"]; +type CustomerInvoiceItemDTO = ArrayElement; + +export class CustomerInvoiceItemsReportPersenter extends Presenter< + CustomerInvoiceItemsDTO, + unknown +> { + private _locale!: string; + + private _mapItem(invoiceItem: CustomerInvoiceItemDTO, index: number) { + return { + ...invoiceItem, + + quantity: formatQuantityDTO(invoiceItem.quantity), + unit_amount: formatMoneyDTO(invoiceItem.unit_amount, this._locale), + + subtotal_amount: formatMoneyDTO(invoiceItem.subtotal_amount, this._locale), + discount_percetage: formatPercentageDTO(invoiceItem.discount_percentage), + discount_amount: formatMoneyDTO(invoiceItem.discount_amount, this._locale), + taxes_amount: formatMoneyDTO(invoiceItem.taxes_amount, this._locale), + total_amount: formatMoneyDTO(invoiceItem.total_amount, this._locale), + }; + } + + toOutput(invoiceItems: CustomerInvoiceItemsDTO, params: IPresenterOutputParams): unknown { + const { locale } = params as { + locale: string; + }; + + this._locale = locale; + + return invoiceItems.map((item, index) => { + return this._mapItem(item, index); + }); + } +} 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 8ee49ed8..3f91607c 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 @@ -7,12 +7,22 @@ export class CustomerInvoiceReportPresenter extends Presenter< unknown > { toOutput(invoiceDTO: GetCustomerInvoiceByIdResponseDTO) { + const itemsPresenter = this.presenterRegistry.getPresenter({ + resource: "customer-invoice-items", + projection: "REPORT", + format: "JSON", + }); + const locale = invoiceDTO.language_code; + const itemsDTO = itemsPresenter.toOutput(invoiceDTO.items, { + locale, + }); return { ...invoiceDTO, + items: itemsDTO, subtotal_amount: formatMoneyDTO(invoiceDTO.subtotal_amount, locale), - percentage: formatPercentageDTO(invoiceDTO.discount_percentage), + discount_percetage: formatPercentageDTO(invoiceDTO.discount_percentage), discount_amount: formatMoneyDTO(invoiceDTO.discount_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/presenters/queries/index.ts b/modules/customer-invoices/src/api/application/presenters/queries/index.ts index 8813c089..c1960355 100644 --- a/modules/customer-invoices/src/api/application/presenters/queries/index.ts +++ b/modules/customer-invoices/src/api/application/presenters/queries/index.ts @@ -1,2 +1,3 @@ +export * from "./customer-invoice-items.report.presenter"; export * from "./customer-invoice.report.presenter"; export * from "./list-customer-invoices.presenter"; diff --git a/modules/customer-invoices/src/api/infrastructure/dependencies.ts b/modules/customer-invoices/src/api/infrastructure/dependencies.ts index 60408dee..0be3461e 100644 --- a/modules/customer-invoices/src/api/infrastructure/dependencies.ts +++ b/modules/customer-invoices/src/api/infrastructure/dependencies.ts @@ -23,6 +23,7 @@ import { } from "../application"; import { JsonTaxCatalogProvider, spainTaxCatalogProvider } from "@erp/core"; +import { CustomerInvoiceItemsReportPersenter } from "../application/presenters/queries/customer-invoice-items.report.presenter"; import { CustomerInvoiceService } from "../domain"; import { CustomerInvoiceDomainMapper, CustomerInvoiceListMapper } from "./mappers"; import { CustomerInvoiceRepository } from "./sequelize"; @@ -108,6 +109,14 @@ export function buildCustomerInvoiceDependencies(params: ModuleParams): Customer }, presenter: new CustomerInvoiceReportPresenter(presenterRegistry), }, + { + key: { + resource: "customer-invoice-items", + projection: "REPORT", + format: "JSON", + }, + presenter: new CustomerInvoiceItemsReportPersenter(presenterRegistry), + }, { key: { resource: "customer-invoice", diff --git a/modules/customers/src/common/locales/en.json b/modules/customers/src/common/locales/en.json index 57acba91..3ce0a224 100644 --- a/modules/customers/src/common/locales/en.json +++ b/modules/customers/src/common/locales/en.json @@ -122,7 +122,7 @@ "placeholder": "Select default tax", "description": "The default tax rate for the customer" }, - "lang_code": { + "language_code": { "label": "Language", "placeholder": "Select language", "description": "The preferred language of the customer" diff --git a/modules/customers/src/common/locales/es.json b/modules/customers/src/common/locales/es.json index 88cb2ad9..70a8a0e4 100644 --- a/modules/customers/src/common/locales/es.json +++ b/modules/customers/src/common/locales/es.json @@ -124,7 +124,7 @@ "placeholder": "Seleccione el impuesto por defecto", "description": "La tasa de impuesto por defecto para el cliente" }, - "lang_code": { + "language_code": { "label": "Idioma", "placeholder": "Seleccione el idioma", "description": "El idioma preferido del cliente" diff --git a/modules/customers/src/web/pages/create/customer-edit-form.tsx b/modules/customers/src/web/pages/create/customer-edit-form.tsx index e39cc24a..945db6a9 100644 --- a/modules/customers/src/web/pages/create/customer-edit-form.tsx +++ b/modules/customers/src/web/pages/create/customer-edit-form.tsx @@ -40,10 +40,10 @@ const defaultCustomerData = { country: "ES", postal_code: "28080", province: "Madrid", - lang_code: "es", + language_code: "es", currency_code: "EUR", legal_record: "Registro Mercantil de Madrid, Tomo 12345, Folio 67, Hoja M-123456", - default_tax: ["iva_21", "rec_5_2"], + default_taxes: ["iva_21", "rec_5_2"], }; interface CustomerFormProps { @@ -290,20 +290,20 @@ export const CustomerEditForm = ({ {t("form_fields.customer_type.label")} field.onChange(val === "1")} + onValueChange={field.onChange} + defaultValue={field.value ? "1" : "0"} className='flex gap-6' >