From d6883f9715b64beea7e8406056a3001801b70e36 Mon Sep 17 00:00:00 2001 From: rckrdmrd Date: Tue, 20 Jan 2026 04:37:56 -0600 Subject: [PATCH] [ERP-CONSTRUCCION-BE] chore: Update finance entities Co-Authored-By: Claude Opus 4.5 --- .../entities/account-payable.entity.ts | 78 +++++++++++++++++++ .../entities/account-receivable.entity.ts | 78 +++++++++++++++++++ .../entities/accounting-entry-line.entity.ts | 43 ++++++++++ .../entities/accounting-entry.entity.ts | 25 ++++++ .../finance/entities/ap-payment.entity.ts | 26 ++++++- .../finance/entities/ar-payment.entity.ts | 26 ++++++- .../entities/chart-of-accounts.entity.ts | 34 ++++++++ tsconfig.json | 3 +- 8 files changed, 307 insertions(+), 6 deletions(-) diff --git a/src/modules/finance/entities/account-payable.entity.ts b/src/modules/finance/entities/account-payable.entity.ts index c1a6a994..02be8cd4 100644 --- a/src/modules/finance/entities/account-payable.entity.ts +++ b/src/modules/finance/entities/account-payable.entity.ts @@ -230,4 +230,82 @@ export class AccountPayable { @Column({ name: 'deleted_at', type: 'timestamptz', nullable: true }) deletedAt?: Date; + + // Aliases for service compatibility + get documentDate(): Date { + return this.invoiceDate; + } + set documentDate(value: Date) { + this.invoiceDate = value; + } + + get netAmount(): number { + return this.totalAmount; + } + set netAmount(value: number) { + this.totalAmount = value; + } + + get originalAmount(): number { + return this.totalAmount; + } + set originalAmount(value: number) { + this.totalAmount = value; + } + + get retentionIsr(): number { + return this.retentionAmount; + } + set retentionIsr(value: number) { + this.retentionAmount = value; + } + + get retentionIva(): number { + return 0; + } + set retentionIva(_value: number) { + // No-op, mapped to retentionAmount + } + + get guaranteeFund(): number { + return 0; + } + set guaranteeFund(_value: number) { + // No-op + } + + get balanceAmount(): number { + return this.balance; + } + set balanceAmount(value: number) { + this.balance = value; + } + + get lastPaymentDate(): Date | undefined { + return this.paymentDate ?? undefined; + } + set lastPaymentDate(value: Date | undefined) { + this.paymentDate = value ?? null as any; + } + + get partnerId(): string { + return this.supplierId; + } + set partnerId(value: string) { + this.supplierId = value; + } + + get partnerName(): string { + return this.supplierName; + } + set partnerName(value: string) { + this.supplierName = value; + } + + get partnerRfc(): string | undefined { + return this.supplierRfc; + } + set partnerRfc(value: string | undefined) { + this.supplierRfc = value; + } } diff --git a/src/modules/finance/entities/account-receivable.entity.ts b/src/modules/finance/entities/account-receivable.entity.ts index a76e5faf..636cd2bf 100644 --- a/src/modules/finance/entities/account-receivable.entity.ts +++ b/src/modules/finance/entities/account-receivable.entity.ts @@ -221,4 +221,82 @@ export class AccountReceivable { @Column({ name: 'deleted_at', type: 'timestamptz', nullable: true }) deletedAt?: Date; + + // Aliases for service compatibility + get documentDate(): Date { + return this.invoiceDate; + } + set documentDate(value: Date) { + this.invoiceDate = value; + } + + get netAmount(): number { + return this.totalAmount; + } + set netAmount(value: number) { + this.totalAmount = value; + } + + get originalAmount(): number { + return this.totalAmount; + } + set originalAmount(value: number) { + this.totalAmount = value; + } + + get retentionIsr(): number { + return this.retentionAmount; + } + set retentionIsr(value: number) { + this.retentionAmount = value; + } + + get retentionIva(): number { + return 0; + } + set retentionIva(_value: number) { + // No-op, mapped to retentionAmount + } + + get guaranteeFund(): number { + return 0; + } + set guaranteeFund(_value: number) { + // No-op + } + + get balanceAmount(): number { + return this.balance; + } + set balanceAmount(value: number) { + this.balance = value; + } + + get lastCollectionDate(): Date | undefined { + return this.collectionDate ?? undefined; + } + set lastCollectionDate(value: Date | undefined) { + this.collectionDate = value ?? null as any; + } + + get partnerId(): string { + return this.customerId; + } + set partnerId(value: string) { + this.customerId = value; + } + + get partnerName(): string { + return this.customerName; + } + set partnerName(value: string) { + this.customerName = value; + } + + get partnerRfc(): string | undefined { + return this.customerRfc; + } + set partnerRfc(value: string | undefined) { + this.customerRfc = value; + } } diff --git a/src/modules/finance/entities/accounting-entry-line.entity.ts b/src/modules/finance/entities/accounting-entry-line.entity.ts index d45ca80f..98d12db9 100644 --- a/src/modules/finance/entities/accounting-entry-line.entity.ts +++ b/src/modules/finance/entities/accounting-entry-line.entity.ts @@ -74,6 +74,21 @@ export class AccountingEntryLine { }) credit!: number; + // Aliases for service compatibility + get debitAmount(): number { + return this.debit; + } + set debitAmount(value: number) { + this.debit = value; + } + + get creditAmount(): number { + return this.credit; + } + set creditAmount(value: number) { + this.credit = value; + } + // Centro de costo (opcional) @Column({ name: 'cost_center_id', type: 'uuid', nullable: true }) costCenterId?: string; @@ -115,6 +130,34 @@ export class AccountingEntryLine { }) originalAmount?: number; + @Column({ + name: 'exchange_rate', + type: 'decimal', + precision: 12, + scale: 6, + nullable: true, + }) + exchangeRate?: number; + + // Reference for the line + @Column({ name: 'reference', length: 255, nullable: true }) + reference?: string; + + // Aliases for service compatibility + get currencyCode(): string | undefined { + return this.originalCurrency; + } + set currencyCode(value: string | undefined) { + this.originalCurrency = value; + } + + get currencyAmount(): number | undefined { + return this.originalAmount; + } + set currencyAmount(value: number | undefined) { + this.originalAmount = value; + } + // Metadatos @Column({ type: 'jsonb', nullable: true }) metadata?: Record; diff --git a/src/modules/finance/entities/accounting-entry.entity.ts b/src/modules/finance/entities/accounting-entry.entity.ts index 17e43b92..2cf06588 100644 --- a/src/modules/finance/entities/accounting-entry.entity.ts +++ b/src/modules/finance/entities/accounting-entry.entity.ts @@ -89,6 +89,13 @@ export class AccountingEntry { @Column({ name: 'project_id', type: 'uuid', nullable: true }) projectId?: string; + @Column({ name: 'project_code', length: 50, nullable: true }) + projectCode?: string; + + // Centro de costo + @Column({ name: 'cost_center_id', type: 'uuid', nullable: true }) + costCenterId?: string; + // Periodo contable @Column({ name: 'fiscal_year', type: 'int' }) fiscalYear!: number; @@ -118,6 +125,9 @@ export class AccountingEntry { @Column({ name: 'is_balanced', type: 'boolean', default: false }) isBalanced!: boolean; + @Column({ name: 'line_count', type: 'int', default: 0 }) + lineCount!: number; + // Moneda @Column({ length: 3, default: 'MXN' }) currency!: string; @@ -182,4 +192,19 @@ export class AccountingEntry { @Column({ name: 'deleted_at', type: 'timestamptz', nullable: true }) deletedAt?: Date; + + // Aliases for service compatibility + get currencyCode(): string { + return this.currency; + } + set currencyCode(value: string) { + this.currency = value; + } + + get reversalEntryId(): string | undefined { + return this.reversedEntryId; + } + set reversalEntryId(value: string | undefined) { + this.reversedEntryId = value; + } } diff --git a/src/modules/finance/entities/ap-payment.entity.ts b/src/modules/finance/entities/ap-payment.entity.ts index 0c3398f9..33723bac 100644 --- a/src/modules/finance/entities/ap-payment.entity.ts +++ b/src/modules/finance/entities/ap-payment.entity.ts @@ -20,7 +20,7 @@ import { AccountPayable } from './account-payable.entity'; import { BankAccount } from './bank-account.entity'; export type PaymentMethod = 'cash' | 'check' | 'transfer' | 'card' | 'compensation' | 'other'; -export type PaymentStatus = 'pending' | 'processed' | 'reconciled' | 'cancelled' | 'returned'; +export type PaymentStatus = 'pending' | 'processed' | 'reconciled' | 'cancelled' | 'returned' | 'confirmed'; @Entity('ap_payments', { schema: 'finance' }) @Index(['tenantId', 'accountPayableId']) @@ -57,7 +57,7 @@ export class APPayment { @Column({ type: 'enum', - enum: ['pending', 'processed', 'reconciled', 'cancelled', 'returned'], + enum: ['pending', 'processed', 'reconciled', 'cancelled', 'returned', 'confirmed'], enumName: 'payment_status', default: 'pending', }) @@ -129,6 +129,13 @@ export class APPayment { @Column({ name: 'reconciled_at', type: 'timestamptz', nullable: true }) reconciledAt?: Date; + // Confirmación + @Column({ name: 'confirmed_at', type: 'timestamptz', nullable: true }) + confirmedAt?: Date; + + @Column({ name: 'confirmed_by_id', type: 'uuid', nullable: true }) + confirmedById?: string; + // Notas y metadatos @Column({ type: 'text', nullable: true }) notes?: string; @@ -151,4 +158,19 @@ export class APPayment { @Column({ name: 'deleted_at', type: 'timestamptz', nullable: true }) deletedAt?: Date; + + // Aliases for service compatibility + get paymentAmount(): number { + return this.amount; + } + set paymentAmount(value: number) { + this.amount = value; + } + + get currencyCode(): string { + return this.currency; + } + set currencyCode(value: string) { + this.currency = value; + } } diff --git a/src/modules/finance/entities/ar-payment.entity.ts b/src/modules/finance/entities/ar-payment.entity.ts index 8b26b474..d27af7a5 100644 --- a/src/modules/finance/entities/ar-payment.entity.ts +++ b/src/modules/finance/entities/ar-payment.entity.ts @@ -20,7 +20,7 @@ import { AccountReceivable } from './account-receivable.entity'; import { BankAccount } from './bank-account.entity'; export type CollectionMethod = 'cash' | 'check' | 'transfer' | 'card' | 'compensation' | 'other'; -export type CollectionStatus = 'pending' | 'deposited' | 'reconciled' | 'cancelled' | 'returned'; +export type CollectionStatus = 'pending' | 'deposited' | 'reconciled' | 'cancelled' | 'returned' | 'confirmed'; @Entity('ar_payments', { schema: 'finance' }) @Index(['tenantId', 'accountReceivableId']) @@ -57,7 +57,7 @@ export class ARPayment { @Column({ type: 'enum', - enum: ['pending', 'deposited', 'reconciled', 'cancelled', 'returned'], + enum: ['pending', 'deposited', 'reconciled', 'cancelled', 'returned', 'confirmed'], enumName: 'collection_status', default: 'pending', }) @@ -129,6 +129,13 @@ export class ARPayment { @Column({ name: 'reconciled_at', type: 'timestamptz', nullable: true }) reconciledAt?: Date; + // Confirmación + @Column({ name: 'confirmed_at', type: 'timestamptz', nullable: true }) + confirmedAt?: Date; + + @Column({ name: 'confirmed_by_id', type: 'uuid', nullable: true }) + confirmedById?: string; + // Notas y metadatos @Column({ type: 'text', nullable: true }) notes?: string; @@ -151,4 +158,19 @@ export class ARPayment { @Column({ name: 'deleted_at', type: 'timestamptz', nullable: true }) deletedAt?: Date; + + // Aliases for service compatibility + get collectionAmount(): number { + return this.amount; + } + set collectionAmount(value: number) { + this.amount = value; + } + + get currencyCode(): string { + return this.currency; + } + set currencyCode(value: string) { + this.currency = value; + } } diff --git a/src/modules/finance/entities/chart-of-accounts.entity.ts b/src/modules/finance/entities/chart-of-accounts.entity.ts index 5718f13a..cce8449e 100644 --- a/src/modules/finance/entities/chart-of-accounts.entity.ts +++ b/src/modules/finance/entities/chart-of-accounts.entity.ts @@ -98,12 +98,31 @@ export class ChartOfAccounts { @Column({ name: 'sap_code', length: 50, nullable: true }) sapCode?: string; + @Column({ name: 'sat_code', length: 50, nullable: true }) + satCode?: string; + + @Column({ name: 'sat_description', length: 255, nullable: true }) + satDescription?: string; + + @Column({ name: 'currency_code', length: 3, nullable: true }) + currencyCode?: string; + @Column({ name: 'contpaqi_code', length: 50, nullable: true }) contpaqiCode?: string; @Column({ name: 'aspel_code', length: 50, nullable: true }) aspelCode?: string; + // Configuración adicional de cuenta + @Column({ name: 'is_group_account', type: 'boolean', default: false }) + isGroupAccount!: boolean; + + @Column({ name: 'accepts_movements', type: 'boolean', default: true }) + acceptsMovements!: boolean; + + @Column({ name: 'last_movement_date', type: 'date', nullable: true }) + lastMovementDate?: Date; + // Saldos (actualizados periódicamente) @Column({ name: 'initial_balance', @@ -148,4 +167,19 @@ export class ChartOfAccounts { @Column({ name: 'deleted_at', type: 'timestamptz', nullable: true }) deletedAt?: Date; + + // Aliases for service compatibility + get fullPath(): string { + return this.code; + } + set fullPath(value: string) { + this.code = value; + } + + get balance(): number { + return this.currentBalance; + } + set balance(value: number) { + this.currentBalance = value; + } } diff --git a/tsconfig.json b/tsconfig.json index dda36abe..3dd10e47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -36,7 +36,6 @@ "node_modules", "dist", "**/*.spec.ts", - "**/*.test.ts", - "src/modules/finance/**/*" + "**/*.test.ts" ] }