Document Numering
This commit is contained in:
parent
e93d48b930
commit
d06c4932ed
@ -25,7 +25,7 @@ export interface CustomerInvoiceProps {
|
||||
status: CustomerInvoiceStatus;
|
||||
|
||||
series: Maybe<CustomerInvoiceSerie>;
|
||||
invoiceNumber: Maybe<CustomerInvoiceNumber>;
|
||||
invoiceNumber: Maybe<DocNumber>;
|
||||
|
||||
invoiceDate: UtcDate;
|
||||
operationDate: Maybe<UtcDate>;
|
||||
|
||||
@ -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<DocNumberProps> {
|
||||
protected _formatted!: string;
|
||||
|
||||
static create(props: DocNumberProps, id?: UniqueID): Result<DocNumber, Error> {
|
||||
const docNumber = new DocNumber(props, id);
|
||||
|
||||
@ -25,6 +28,21 @@ export class DocNumber extends AggregateRoot<DocNumberProps> {
|
||||
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<DocNumberProps> {
|
||||
public get currentValue(): number {
|
||||
return this.props.currentValue;
|
||||
}
|
||||
|
||||
public get formatPattern(): string {
|
||||
return this.props.formatPattern;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@ export class DocNumberModel extends Model<
|
||||
InferCreationAttributes<DocNumberModel>
|
||||
> {
|
||||
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"],
|
||||
},
|
||||
],
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user