diff --git a/modules/customer-invoices/src/api/domain/aggregates/customer-invoice.ts b/modules/customer-invoices/src/api/domain/aggregates/customer-invoice.ts index 5c8d5aeb..ab7b21fc 100644 --- a/modules/customer-invoices/src/api/domain/aggregates/customer-invoice.ts +++ b/modules/customer-invoices/src/api/domain/aggregates/customer-invoice.ts @@ -25,7 +25,7 @@ export interface CustomerInvoiceProps { status: CustomerInvoiceStatus; series: Maybe; - invoiceNumber: Maybe; + invoiceNumber: Maybe; invoiceDate: UtcDate; operationDate: Maybe; diff --git a/modules/doc-numbering/src/api/domain/aggregates/doc-number.ts b/modules/doc-numbering/src/api/domain/aggregates/doc-number.ts index e83dd12b..ed1655ae 100644 --- a/modules/doc-numbering/src/api/domain/aggregates/doc-number.ts +++ b/modules/doc-numbering/src/api/domain/aggregates/doc-number.ts @@ -1,16 +1,19 @@ -import { AggregateRoot, UniqueID, UtcDate } from "@repo/rdx-ddd"; +import { AggregateRoot, UniqueID } from "@repo/rdx-ddd"; import { Result } from "@repo/rdx-utils"; import { DocType } from "../value-objects"; export interface DocNumberProps { + companyId: UniqueID; + year: number; docType: DocType; // INVOICE, QUOTATION, DELIVERY_NOTE, PAYMENT... series: string; // opcional: "2025", "Sucursal-01" currentValue: number; formatPattern: string; // ej: "{year}/{number:000000}" - lastAssignedAt: UtcDate; } export class DocNumber extends AggregateRoot { + protected _formatted!: string; + static create(props: DocNumberProps, id?: UniqueID): Result { const docNumber = new DocNumber(props, id); @@ -25,6 +28,21 @@ export class DocNumber extends AggregateRoot { return Result.ok(docNumber); } + protected constructor(props: DocNumberProps, id?: UniqueID) { + super(props, id); + + this._formatted = this.applyFormat(); + } + + private applyFormat(): string { + // Sustituye {series}, {number:000000}, {year}, etc. + return ""; + } + + getFormatted(): string { + return this._formatted; + } + public get docType(): DocType { return this.props.docType; } @@ -36,8 +54,4 @@ export class DocNumber extends AggregateRoot { public get currentValue(): number { return this.props.currentValue; } - - public get formatPattern(): string { - return this.props.formatPattern; - } } diff --git a/modules/doc-numbering/src/api/infrastructure/sequelize/models/doc-number.ts b/modules/doc-numbering/src/api/infrastructure/sequelize/models/doc-number.ts index a22b9d63..0ff1baad 100644 --- a/modules/doc-numbering/src/api/infrastructure/sequelize/models/doc-number.ts +++ b/modules/doc-numbering/src/api/infrastructure/sequelize/models/doc-number.ts @@ -7,6 +7,8 @@ export class DocNumberModel extends Model< InferCreationAttributes > { declare id: string; // UUID + declare company_id: string; + declare year: number; // 2025, 2026 declare docType: string; // ej. "INVOICE" declare series: string | null; // ej. "2025", "Sucursal-01" declare currentValue: number; // último número asignado @@ -24,6 +26,14 @@ export default (database: Sequelize) => { type: DataTypes.UUID, primaryKey: true, }, + company_id: { + type: DataTypes.UUID, + allowNull: false, + }, + year: { + type: DataTypes.SMALLINT(), + allowNull: false, + }, docType: { type: DataTypes.STRING(), allowNull: false, @@ -59,7 +69,7 @@ export default (database: Sequelize) => { indexes: [ { unique: true, - fields: ["docType", "series"], + fields: ["company_id", "year", "docType", "series"], }, ],