diff --git a/apps/server/package.json b/apps/server/package.json index 8d734e02..b57086a4 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -1,6 +1,6 @@ { "name": "@erp/factuges-server", - "version": "0.7.6", + "version": "0.7.8", "private": true, "scripts": { "build": "tsup src/index.ts --config tsup.config.ts", @@ -39,6 +39,7 @@ "@erp/catalogs": "workspace:*", "@erp/customer-invoices": "workspace:*", "@erp/customers": "workspace:*", + "@erp/identity": "workspace:*", "@erp/factuges": "workspace:*", "@repo/rdx-logger": "workspace:*", "@repo/rdx-utils": "workspace:*", diff --git a/apps/server/src/register-modules.ts b/apps/server/src/register-modules.ts index b66b77b4..df47f97f 100644 --- a/apps/server/src/register-modules.ts +++ b/apps/server/src/register-modules.ts @@ -2,6 +2,7 @@ import catalogsAPIModule from "@erp/catalogs/api"; import customerInvoicesAPIModule from "@erp/customer-invoices/api"; import customersAPIModule from "@erp/customers/api"; import factuGESAPIModule from "@erp/factuges/api"; +import identityAPIModule from "@erp/identity/api"; //import suppliersAPIModule from "@erp/suppliers/api"; @@ -13,7 +14,7 @@ import { registerModule } from "./lib"; // las rutas, los modelos y los servicios // públicos de ese módulo. export const registerModules = () => { - //registerModule(authAPIModule); + registerModule(identityAPIModule); registerModule(catalogsAPIModule); registerModule(customersAPIModule); registerModule(customerInvoicesAPIModule); diff --git a/apps/web/package.json b/apps/web/package.json index d4dcc716..f2f8626d 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,7 +1,7 @@ { "name": "@erp/factuges-web", "private": true, - "version": "0.7.6", + "version": "0.7.8", "type": "module", "scripts": { "typecheck": "tsc -p tsconfig.json --noEmit", diff --git a/modules/auth/package.json b/modules/auth/package.json index 60f027fa..e280de97 100644 --- a/modules/auth/package.json +++ b/modules/auth/package.json @@ -1,6 +1,6 @@ { "name": "@erp/auth", - "version": "0.7.6", + "version": "0.7.8", "private": true, "type": "module", "sideEffects": false, diff --git a/modules/catalogs/package.json b/modules/catalogs/package.json index 1193561d..18accab3 100644 --- a/modules/catalogs/package.json +++ b/modules/catalogs/package.json @@ -1,7 +1,7 @@ { "name": "@erp/catalogs", "description": "Catalogs module", - "version": "0.7.6", + "version": "0.7.8", "private": true, "type": "module", "sideEffects": false, diff --git a/modules/core/package.json b/modules/core/package.json index 5acf47ad..ee7a9af3 100644 --- a/modules/core/package.json +++ b/modules/core/package.json @@ -1,6 +1,6 @@ { "name": "@erp/core", - "version": "0.7.6", + "version": "0.7.8", "private": true, "type": "module", "sideEffects": false, diff --git a/modules/core/src/common/types/index.ts b/modules/core/src/common/types/index.ts index f36c9945..d28bb26d 100644 --- a/modules/core/src/common/types/index.ts +++ b/modules/core/src/common/types/index.ts @@ -1,2 +1,3 @@ export * from "./dto.d"; export * from "./module-metadata.d"; +export * from "./permissions"; diff --git a/modules/core/src/common/types/permissions.ts b/modules/core/src/common/types/permissions.ts new file mode 100644 index 00000000..e43b4a28 --- /dev/null +++ b/modules/core/src/common/types/permissions.ts @@ -0,0 +1,7 @@ +export type PermissionCode = string; + +export type PermissionDefinition = { + code: PermissionCode; + module: string; + description: string; +}; diff --git a/modules/customer-invoices/package.json b/modules/customer-invoices/package.json index 4e417bf3..b1f14cae 100644 --- a/modules/customer-invoices/package.json +++ b/modules/customer-invoices/package.json @@ -1,6 +1,6 @@ { "name": "@erp/customer-invoices", - "version": "0.7.6", + "version": "0.7.8", "private": true, "type": "module", "sideEffects": false, diff --git a/modules/customer-invoices/src/api/domain/common/value-objects/index.ts b/modules/customer-invoices/src/api/domain/common/value-objects/index.ts index d69995a8..3c80d4b5 100644 --- a/modules/customer-invoices/src/api/domain/common/value-objects/index.ts +++ b/modules/customer-invoices/src/api/domain/common/value-objects/index.ts @@ -1,9 +1,6 @@ -export * from "../entities/invoice-tax-regime.entity"; - export * from "./invoice-address-type.vo"; export * from "./invoice-amount.vo"; export * from "./invoice-number.vo"; -export * from "./invoice-recipient/invoice-recipient.vo"; export * from "./invoice-serie.vo"; export * from "./invoice-status.vo"; export * from "./item-amount.vo"; diff --git a/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/index.ts b/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/index.ts deleted file mode 100644 index d7a9b283..00000000 --- a/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./invoice-recipient.vo"; diff --git a/modules/customer-invoices/src/api/domain/issued-invoices/aggregates/issued-invoice.aggregate.ts b/modules/customer-invoices/src/api/domain/issued-invoices/aggregates/issued-invoice.aggregate.ts index f23856ba..5f97614d 100644 --- a/modules/customer-invoices/src/api/domain/issued-invoices/aggregates/issued-invoice.aggregate.ts +++ b/modules/customer-invoices/src/api/domain/issued-invoices/aggregates/issued-invoice.aggregate.ts @@ -15,7 +15,6 @@ import type { InvoiceAmount, InvoiceNumber, InvoicePaymentMethod, - InvoiceRecipient, InvoiceSerie, InvoiceStatus, } from "../../common"; @@ -27,6 +26,7 @@ import { type VerifactuRecord, } from "../entities"; import { IssuedInvoiceItemMismatch } from "../errors"; +import type { IssuedInvoiceRecipient } from "../value-objects"; export interface IIssuedInvoiceCreateProps { companyId: UniqueID; @@ -41,7 +41,7 @@ export interface IIssuedInvoiceCreateProps { operationDate: Maybe; customerId: UniqueID; - recipient: InvoiceRecipient; + recipient: IssuedInvoiceRecipient; reference: Maybe; description: string; @@ -214,7 +214,7 @@ export class IssuedInvoice return this.props.notes; } - public get recipient(): InvoiceRecipient { + public get recipient(): IssuedInvoiceRecipient { return this.props.recipient; } diff --git a/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/index.ts b/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/index.ts index 9b42f37f..4e79622a 100644 --- a/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/index.ts +++ b/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/index.ts @@ -1,2 +1,3 @@ +export * from "./issued-invoice-recipient.vo"; export * from "./issued-invoice-tax-group.vo"; export * from "./verifactu-status.vo"; diff --git a/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/issued-invoice-recipient.vo.ts b/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/issued-invoice-recipient.vo.ts new file mode 100644 index 00000000..7d70a030 --- /dev/null +++ b/modules/customer-invoices/src/api/domain/issued-invoices/value-objects/issued-invoice-recipient.vo.ts @@ -0,0 +1,103 @@ +import { + type City, + type Country, + type Name, + type PostalCode, + type Province, + type Street, + type TINNumber, + ValueObject, + maybeToNullable, +} from "@repo/rdx-ddd"; +import { type Maybe, Result } from "@repo/rdx-utils"; + +export type IssuedInvoiceRecipientProps = { + name: Name; + tin: TINNumber; + street: Maybe; + street2: Maybe; + city: Maybe; + postalCode: Maybe; + province: Maybe; + country: Maybe; +}; + +export class IssuedInvoiceRecipient extends ValueObject { + protected static validate(values: IssuedInvoiceRecipientProps) { + return Result.ok(values); + } + + static create(values: IssuedInvoiceRecipientProps): Result { + const valueIsValid = IssuedInvoiceRecipient.validate(values); + + if (valueIsValid.isFailure) { + return Result.fail(valueIsValid.error); + } + + return Result.ok(new IssuedInvoiceRecipient(values)); + } + + public update( + partial: Partial + ): Result { + const updatedProps = { + ...this.props, + ...partial, + } as IssuedInvoiceRecipientProps; + + return IssuedInvoiceRecipient.create(updatedProps); + } + + public get name(): Name { + return this.props.name; + } + + public get tin(): TINNumber { + return this.props.tin; + } + + get street(): Maybe { + return this.props.street; + } + + get street2(): Maybe { + return this.props.street2; + } + + get city(): Maybe { + return this.props.city; + } + + get postalCode(): Maybe { + return this.props.postalCode; + } + + get province(): Maybe { + return this.props.province; + } + + get country(): Maybe { + return this.props.country; + } + + getProps(): IssuedInvoiceRecipientProps { + return this.props; + } + + toPrimitive() { + return this.getProps(); + } + + toObjectString() { + return { + tin: this.tin.toString(), + name: this.name.toString(), + street: maybeToNullable(this.street, (value) => value.toString()), + street2: maybeToNullable(this.street2, (value) => value.toString()), + city: maybeToNullable(this.city, (value) => value.toString()), + postal_code: maybeToNullable(this.postalCode, (value) => value.toString()), + province: maybeToNullable(this.province, (value) => value.toString()), + country: maybeToNullable(this.country, (value) => value.toString()), + }; + } +} diff --git a/modules/customer-invoices/src/api/domain/proformas/aggregates/proforma.aggregate.ts b/modules/customer-invoices/src/api/domain/proformas/aggregates/proforma.aggregate.ts index dc96198f..fac4a7c4 100644 --- a/modules/customer-invoices/src/api/domain/proformas/aggregates/proforma.aggregate.ts +++ b/modules/customer-invoices/src/api/domain/proformas/aggregates/proforma.aggregate.ts @@ -15,7 +15,6 @@ import { INVOICE_STATUS, InvoiceAmount, type InvoiceNumber, - type InvoiceRecipient, type InvoiceSerie, InvoiceStatus, type ItemAmount, @@ -30,7 +29,7 @@ import { import { InvalidProformaTransitionError, ProformaItemMismatch } from "../errors"; import type { IProformaTaxTotals, ProformaCalculationContext } from "../services"; import { canManuallyTransitionProformaStatus } from "../services"; -import { ProformaItemTaxes } from "../value-objects"; +import { ProformaItemTaxes, type ProformaRecipient } from "../value-objects"; export interface IProformaCreateProps { companyId: UniqueID; @@ -43,7 +42,7 @@ export interface IProformaCreateProps { operationDate: Maybe; customerId: UniqueID; - recipient: Maybe; + recipient: Maybe; reference: Maybe; description: Maybe; @@ -93,7 +92,7 @@ export interface IProforma { operationDate: Maybe; customerId: UniqueID; - recipient: Maybe; + recipient: Maybe; reference: Maybe; description: Maybe; @@ -258,7 +257,7 @@ export class Proforma extends AggregateRoot implements IP return this.props.notes; } - public get recipient(): Maybe { + public get recipient(): Maybe { return this.props.recipient; } diff --git a/modules/customer-invoices/src/api/domain/proformas/value-objects/index.ts b/modules/customer-invoices/src/api/domain/proformas/value-objects/index.ts index d3a820d4..3dabc5d4 100644 --- a/modules/customer-invoices/src/api/domain/proformas/value-objects/index.ts +++ b/modules/customer-invoices/src/api/domain/proformas/value-objects/index.ts @@ -1 +1,2 @@ export * from "./proforma-item-taxes.vo"; +export * from "./proforma-recipient.vo"; diff --git a/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts b/modules/customer-invoices/src/api/domain/proformas/value-objects/proforma-recipient.vo.ts similarity index 75% rename from modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts rename to modules/customer-invoices/src/api/domain/proformas/value-objects/proforma-recipient.vo.ts index e41054d0..34726cbb 100644 --- a/modules/customer-invoices/src/api/domain/common/value-objects/invoice-recipient/invoice-recipient.vo.ts +++ b/modules/customer-invoices/src/api/domain/proformas/value-objects/proforma-recipient.vo.ts @@ -11,7 +11,7 @@ import { } from "@repo/rdx-ddd"; import { type Maybe, Result } from "@repo/rdx-utils"; -export type InvoiceRecipientProps = { +export type ProformaRecipientProps = { name: Name; tin: Maybe; street: Maybe; @@ -22,28 +22,28 @@ export type InvoiceRecipientProps = { country: Maybe; }; -export class InvoiceRecipient extends ValueObject { - protected static validate(values: InvoiceRecipientProps) { +export class ProformaRecipient extends ValueObject { + protected static validate(values: ProformaRecipientProps) { return Result.ok(values); } - static create(values: InvoiceRecipientProps): Result { - const valueIsValid = InvoiceRecipient.validate(values); + static create(values: ProformaRecipientProps): Result { + const valueIsValid = ProformaRecipient.validate(values); if (valueIsValid.isFailure) { return Result.fail(valueIsValid.error); } - return Result.ok(new InvoiceRecipient(values)); + return Result.ok(new ProformaRecipient(values)); } - public update(partial: Partial): Result { + public update(partial: Partial): Result { const updatedProps = { ...this.props, ...partial, - } as InvoiceRecipientProps; + } as ProformaRecipientProps; - return InvoiceRecipient.create(updatedProps); + return ProformaRecipient.create(updatedProps); } public get name(): Name { @@ -78,7 +78,7 @@ export class InvoiceRecipient extends ValueObject { return this.props.country; } - getProps(): InvoiceRecipientProps { + getProps(): ProformaRecipientProps { return this.props; } diff --git a/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts b/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts index 9b461410..d64d815d 100644 --- a/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/domain/sequelize-issued-invoice-recipient-domain.mapper.ts @@ -15,14 +15,14 @@ import { } from "@repo/rdx-ddd"; import { Result } from "@repo/rdx-utils"; -import { type IIssuedInvoiceCreateProps, InvoiceRecipient } from "../../../../../../domain"; +import { type IIssuedInvoiceCreateProps, IssuedInvoiceRecipient } from "../../../../../../domain"; import type { CustomerInvoiceModel } from "../../../../../common"; export class SequelizeIssuedInvoiceRecipientDomainMapper { public mapToDomain( source: CustomerInvoiceModel, params?: MapperParamsType - ): Result { + ): Result { /** * - Issued invoice -> snapshot de los datos (campos customer_*) */ @@ -45,11 +45,7 @@ export class SequelizeIssuedInvoiceRecipientDomainMapper { const customerName = extractOrPushError(Name.create(_name!), "customer_name", errors); //const customerTin = extractOrPushError(TINNumber.create(_tin!), "customer_tin", errors); - const customerTin = extractOrPushError( - maybeFromNullableResult(_tin, (value) => TINNumber.create(value)), - "customer_tin", - errors - ); + const customerTin = extractOrPushError(TINNumber.create(_tin), "customer_tin", errors); const customerStreet = extractOrPushError( maybeFromNullableResult(_street, (value) => Street.create(value)), @@ -87,7 +83,7 @@ export class SequelizeIssuedInvoiceRecipientDomainMapper { errors ); - const createResult = InvoiceRecipient.create({ + const createResult = IssuedInvoiceRecipient.create({ name: customerName!, tin: customerTin!, street: customerStreet!, @@ -118,7 +114,7 @@ export class SequelizeIssuedInvoiceRecipientDomainMapper { * - Si la factura no es proforma (`isProforma === false`), debe existir `recipient`. * En caso contrario, se agrega un error de validación. */ - mapToPersistence(source: InvoiceRecipient, params?: MapperParamsType) { + mapToPersistence(source: IssuedInvoiceRecipient, params?: MapperParamsType) { /*const { errors, parent } = params as { parent: IssuedInvoice; errors: ValidationErrorDetail[]; @@ -127,7 +123,7 @@ export class SequelizeIssuedInvoiceRecipientDomainMapper { const recipient = source; return { - customer_tin: maybeToNullable(recipient.tin, (value) => value.toString()), + customer_tin: recipient.tin.toString(), customer_name: recipient.name.toPrimitive(), customer_street: maybeToNullable(recipient.street, (v) => v.toPrimitive()), customer_street2: maybeToNullable(recipient.street2, (v) => v.toPrimitive()), diff --git a/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/summary/sequelize-issued-invoice-recipient-summary.mapper.ts b/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/summary/sequelize-issued-invoice-recipient-summary.mapper.ts index 07f3b567..effd2116 100644 --- a/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/summary/sequelize-issued-invoice-recipient-summary.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/issued-invoices/persistence/sequelize/mappers/summary/sequelize-issued-invoice-recipient-summary.mapper.ts @@ -15,17 +15,17 @@ import { import { Result } from "@repo/rdx-utils"; import type { IssuedInvoiceSummary } from "../../../../../../application"; -import { InvoiceRecipient } from "../../../../../../domain"; +import { IssuedInvoiceRecipient } from "../../../../../../domain"; import type { CustomerInvoiceModel } from "../../../../../common"; export class SequelizeIssuedInvoiceRecipientListMapper extends SequelizeQueryMapper< CustomerInvoiceModel, - InvoiceRecipient + IssuedInvoiceRecipient > { public mapToReadModel( raw: CustomerInvoiceModel, params?: MapperParamsType - ): Result { + ): Result { /** * - Issued invoice => snapshot de los datos (campos customer_*) */ @@ -94,7 +94,7 @@ export class SequelizeIssuedInvoiceRecipientListMapper extends SequelizeQueryMap errors ); - const createResult = InvoiceRecipient.create({ + const createResult = IssuedInvoiceRecipient.create({ name: customerName!, tin: customerTin!, street: customerStreet!, diff --git a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts index e7f68d9f..53dc08e7 100644 --- a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/domain/sequelize-proforma-recipient-domain.mapper.ts @@ -14,14 +14,14 @@ import { } from "@repo/rdx-ddd"; import { Maybe, Result } from "@repo/rdx-utils"; -import { type IProformaCreateProps, InvoiceRecipient } from "../../../../../../domain"; +import { type IProformaCreateProps, ProformaRecipient } from "../../../../../../domain"; import type { CustomerInvoiceModel } from "../../../../../common"; export class SequelizeProformaRecipientDomainMapper { public mapToDomain( source: CustomerInvoiceModel, params?: MapperParamsType - ): Result, Error> { + ): Result, Error> { /** * En proforma -> datos de "current_customer" */ @@ -85,7 +85,7 @@ export class SequelizeProformaRecipientDomainMapper { errors ); - const createResult = InvoiceRecipient.create({ + const createResult = ProformaRecipient.create({ name: customerName!, tin: customerTin!, street: customerStreet!, @@ -110,7 +110,7 @@ export class SequelizeProformaRecipientDomainMapper { /** * Para una proforma, el recipient no se persiste (todos los campos son null). */ - mapToPersistence(source: Maybe, params?: MapperParamsType) { + mapToPersistence(source: Maybe, params?: MapperParamsType) { return { customer_tin: null, customer_name: null, diff --git a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts index 5568ea18..96c49792 100644 --- a/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts +++ b/modules/customer-invoices/src/api/infrastructure/proformas/persistence/sequelize/mappers/summary/sequelize-proforma-recipient-summary.mapper.ts @@ -15,17 +15,17 @@ import { import { Result } from "@repo/rdx-utils"; import type { ProformaSummary } from "../../../../../../application"; -import { InvoiceRecipient } from "../../../../../../domain"; +import { ProformaRecipient } from "../../../../../../domain"; import type { CustomerInvoiceModel } from "../../../../../common"; export class SequelizeInvoiceRecipientSummaryMapper extends SequelizeQueryMapper< CustomerInvoiceModel, - InvoiceRecipient + ProformaRecipient > { public mapToReadModel( raw: CustomerInvoiceModel, params?: MapperParamsType - ): Result { + ): Result { /** * En proforma -> datos de "current_customer" */ @@ -43,6 +43,7 @@ export class SequelizeInvoiceRecipientSummaryMapper extends SequelizeQueryMapper message: "Current customer not included in query (SequelizeInvoiceRecipientListMapper)", }); } + const _name = raw.current_customer!.name; const _tin = raw.current_customer!.tin; const _street = raw.current_customer!.street; @@ -98,7 +99,7 @@ export class SequelizeInvoiceRecipientSummaryMapper extends SequelizeQueryMapper errors ); - const createResult = InvoiceRecipient.create({ + const createResult = ProformaRecipient.create({ name: customerName!, tin: customerTin!, street: customerStreet!, diff --git a/modules/customer-invoices/src/web/issued-invoices/list/ui/pages/list-issued-invoices-page.tsx b/modules/customer-invoices/src/web/issued-invoices/list/ui/pages/list-issued-invoices-page.tsx index cde08e4b..7d64c4dd 100644 --- a/modules/customer-invoices/src/web/issued-invoices/list/ui/pages/list-issued-invoices-page.tsx +++ b/modules/customer-invoices/src/web/issued-invoices/list/ui/pages/list-issued-invoices-page.tsx @@ -1,5 +1,5 @@ import { ErrorAlert, PageHeader, SimpleSearchInput } from "@erp/core/components"; -import { AppContent, AppHeader, BackHistoryButton, LogoVerifactu } from "@repo/rdx-ui/components"; +import { AppContent, BackHistoryButton, LogoVerifactu } from "@repo/rdx-ui/components"; import { Alert, AlertDescription, @@ -57,25 +57,23 @@ export const ListIssuedInvoicesPage = () => { } return ( -
- - navigate("/issued-invoices/create")} - > - - {t("pages.issued_invoices.create.title")} - - } - title={t("pages.issued_invoices.list.title")} - /> - +
+ navigate("/issued-invoices/create")} + > + + {t("pages.issued_invoices.create.title")} + + } + title={t("pages.issued_invoices.list.title")} + /> - +
¡Atención! @@ -154,7 +152,7 @@ export const ListIssuedInvoicesPage = () => {
)} - -
+ + ); }; diff --git a/modules/customer-invoices/src/web/proformas/pages/index.ts b/modules/customer-invoices/src/web/proformas/pages/index.ts deleted file mode 100644 index 491ccf0c..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./list"; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/context/index.ts b/modules/customer-invoices/src/web/proformas/pages/update/context/index.ts deleted file mode 100644 index 1608c32d..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/context/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./proforma-context"; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/context/proforma-context.tsx b/modules/customer-invoices/src/web/proformas/pages/update/context/proforma-context.tsx deleted file mode 100644 index c02dea28..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/context/proforma-context.tsx +++ /dev/null @@ -1,118 +0,0 @@ -import type { TaxCatalogProvider } from "@erp/core"; -import type { ModuleTFunction } from "@repo/rdx-ui/locales/i18n.js"; -import { - type PropsWithChildren, - createContext, - useCallback, - useContext, - useMemo, - useState, -} from "react"; - -import { useTranslation } from "../../../../i18n"; - -export type ProformaContextValue = { - company_id: string; - proforma_id: string; - status: string; - currency_code: string; - language_code: string; - is_proforma: boolean; - - readOnly: boolean; - taxCatalog: TaxCatalogProvider; - - t: ModuleTFunction; - - changeLanguage: (lang: string) => void; - changeCurrency: (currency: string) => void; - changeIsProforma: (value: boolean) => void; -}; - -const ProformaContext = createContext(null); - -export interface ProformaProviderParams { - taxCatalog: TaxCatalogProvider; - proforma_id: string; - company_id: string; - status: string; // default "draft" - language_code?: string; // default "es" - currency_code?: string; // default "EUR" - is_proforma?: boolean; // default 'true' - readOnly?: boolean; // default 'false' - - children: React.ReactNode; -} - -export const ProformaProvider = ({ - taxCatalog: initialTaxCatalog, - proforma_id, - company_id, - status: initialStatus = "draft", - language_code: initialLang = "es", - currency_code: initialCurrency = "EUR", - readOnly: initialReadOnly = false, - is_proforma: initialProforma = true, - children, -}: PropsWithChildren) => { - const { t } = useTranslation(); - - // Estado interno local para campos dinámicos - const [language_code, setLanguage] = useState(initialLang); - const [currency_code, setCurrency] = useState(initialCurrency); - const [is_proforma, setIsProforma] = useState(initialProforma); - const [readOnly, setReadOnly] = useState(initialReadOnly); - const [status] = useState(initialStatus); - const [taxCatalog] = useState(initialTaxCatalog); - - // Callbacks memoizados - const setLanguageMemo = useCallback((language_code: string) => setLanguage(language_code), []); - const setCurrencyMemo = useCallback((currency_code: string) => setCurrency(currency_code), []); - const setIsProformaMemo = useCallback((is_proforma: boolean) => setIsProforma(is_proforma), []); - const setReadOnlyMemo = useCallback((readOnly: boolean) => setReadOnly(readOnly), []); - - const value = useMemo(() => { - return { - t, - - proforma_id, - company_id, - status, - language_code, - currency_code, - is_proforma, - - taxCatalog, - readOnly, - - changeLanguage: setLanguageMemo, - changeCurrency: setCurrencyMemo, - changeIsProforma: setIsProformaMemo, - setReadOnly: setReadOnlyMemo, - }; - }, [ - t, - readOnly, - company_id, - proforma_id, - status, - language_code, - currency_code, - is_proforma, - taxCatalog, - setLanguageMemo, - setCurrencyMemo, - setIsProformaMemo, - setReadOnlyMemo, - ]); - - return {children}; -}; - -export function useProformaContext(): ProformaContextValue { - const context = useContext(ProformaContext); - if (!context) { - throw new Error("useProformaContext must be used within "); - } - return context; -} diff --git a/modules/customer-invoices/src/web/proformas/pages/update/index.ts b/modules/customer-invoices/src/web/proformas/pages/update/index.ts deleted file mode 100644 index ff0a0125..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./proforma-update-page"; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/index.ts b/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/index.ts deleted file mode 100644 index b4cd11db..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./proforma-basic-info-fields"; -export * from "./proforma-totals"; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/proforma-basic-info-fields.tsx b/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/proforma-basic-info-fields.tsx deleted file mode 100644 index 8c623f50..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/proforma-basic-info-fields.tsx +++ /dev/null @@ -1,75 +0,0 @@ -import { DatePickerInputField, TextField } from "@repo/rdx-ui/components"; -import { FieldDescription, FieldGroup, FieldLegend, FieldSet } from "@repo/shadcn-ui/components"; -import type { ComponentProps } from "react"; -import { useFormContext } from "react-hook-form"; - -import { useTranslation } from "../../../../../i18n"; -import type { ProformaFormData } from "../../../../types"; - -export const ProformaBasicInfoFields = (props: ComponentProps<"fieldset">) => { - const { t } = useTranslation(); - const { control } = useFormContext(); - - return ( -
- - {t("form_groups.basic_info.title")} - - - {t("form_groups.basic_info.description")} - - - - - - - - - - - - - -
- ); -}; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/proforma-totals.tsx b/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/proforma-totals.tsx deleted file mode 100644 index b3b6f5f3..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/ui/blocks/proforma-totals.tsx +++ /dev/null @@ -1,153 +0,0 @@ -import { - FieldDescription, - FieldGroup, - FieldLegend, - FieldSet, - Separator, -} from "@repo/shadcn-ui/components"; -import { cn } from "@repo/shadcn-ui/lib/utils"; -import { ReceiptIcon } from "lucide-react"; -import type { ComponentProps } from "react"; -import { useFormContext, useWatch } from "react-hook-form"; - -import { useTranslation } from "../../../../../i18n"; -import { useProformaContext } from "../../context"; -import { PercentageInputField } from "../components"; - -export const ProformaTotals = (props: ComponentProps<"fieldset">) => { - const { t } = useTranslation(); - const { control } = useFormContext(); - const { currency_code, language_code, readOnly, taxCatalog } = useProformaContext(); - - const displayTaxes = useWatch({ control, name: "taxes", defaultValue: [] }); - const subtotal_amount = useWatch({ control, name: "subtotal_amount", defaultValue: 0 }); - const items_discount_amount = useWatch({ - control, - name: "items_discount_amount", - defaultValue: 0, - }); - const discount_amount = useWatch({ control, name: "discount_amount", defaultValue: 0 }); - const taxable_amount = useWatch({ control, name: "taxable_amount", defaultValue: 0 }); - const taxes_amount = useWatch({ control, name: "taxes_amount", defaultValue: 0 }); - const total_amount = useWatch({ control, name: "total_amount", defaultValue: 0 }); - - return ( -
- - - {t("form_groups.totals.title")} - - - {t("form_groups.totals.description")} - -
- {/* Sección: Subtotal y Descuentos */} -
- Subtotal sin descuentos - - {formatCurrency(subtotal_amount, 2, currency_code, language_code)} - -
- -
-
- Descuento en líneas -
- - -{formatCurrency(items_discount_amount, 2, currency_code, language_code)} - -
- -
-
- Descuento global - -
- - -{formatCurrency(discount_amount, 2, currency_code, language_code)} - -
- - {/* Sección: Base Imponible */} -
- Base imponible - - {formatCurrency(taxable_amount, 2, currency_code, language_code)} - -
-
- - - - {/* Sección: Impuestos */} -
-

- Impuestos y retenciones -

- - {taxCatalog.groups().map((group) => { - // Filtra impuestos de ese grupo - const taxesInGroup = displayTaxes?.filter((item) => { - const tax = taxCatalog.findByCode(item.tax_code).match( - (t) => t, - () => undefined - ); - return tax?.group === group; - }); - - // Si el grupo no tiene impuestos, no renderiza nada - if (taxesInGroup?.length === 0) return null; - - return ( -
- {taxesInGroup?.map((item) => { - const tax = taxCatalog.findByCode(item.tax_code).match( - (t) => t, - () => undefined - ); - return ( -
- {tax?.name} - - {formatCurrency(item.taxes_amount, 2, currency_code, language_code)} - -
- ); - })} -
- ); - })} - -
- Total de impuestos - - {formatCurrency(taxes_amount, 2, currency_code, language_code)} - -
-
- - - -
- Total de la factura - - {formatCurrency(total_amount, 2, currency_code, language_code)} - -
-
-
- ); -}; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/ui/components/index.ts b/modules/customer-invoices/src/web/proformas/pages/update/ui/components/index.ts deleted file mode 100644 index 6dd28b1a..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/ui/components/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./items-editor"; -export * from "./proforma-editor-skeleton"; diff --git a/modules/customer-invoices/src/web/proformas/pages/update/ui/components/proforma-editor-skeleton.tsx b/modules/customer-invoices/src/web/proformas/pages/update/ui/components/proforma-editor-skeleton.tsx deleted file mode 100644 index 660afc63..00000000 --- a/modules/customer-invoices/src/web/proformas/pages/update/ui/components/proforma-editor-skeleton.tsx +++ /dev/null @@ -1,31 +0,0 @@ -// components/CustomerSkeleton.tsx -import { AppContent, BackHistoryButton } from "@repo/rdx-ui/components"; -import { Button } from "@repo/shadcn-ui/components"; - -import { useTranslation } from "../../../../../i18n"; - -export const ProformaEditorSkeleton = () => { - const { t } = useTranslation(); - return ( - -
-