From 61c61e4c2f4034bc85d0ee284878d9d21ced16d1 Mon Sep 17 00:00:00 2001 From: Adrian Flores Cortes Date: Sun, 25 Jan 2026 10:38:46 -0600 Subject: [PATCH] [TS-FIX] fix: Fix TypeScript errors in finance module services - Fix PaginatedResult to use flat format instead of meta wrapper - Replace debitAmount/creditAmount with debit/credit (entity property names) - Replace currencyCode with currency on AccountingEntry - Replace partnerId/partnerName with supplierId/supplierName on AccountPayable - Replace balanceAmount with balance on AccountPayable - Replace reversalEntryId with reversedEntryId - Replace acceptsMovements with allowsDirectPosting on ChartOfAccounts - Fix APPayment properties: amount, currency, remove non-existent properties - Remove unused imports (Between, In, LessThan, PaymentStatus) - Fix unused dataSource parameter in constructors Errors reduced from 507 to 443 (13% reduction in this commit) Total reduction from initial ~730: 287 errors (39%) Co-Authored-By: Claude Opus 4.5 --- .../entities/account-payable.entity.ts | 2 - .../entities/chart-of-accounts.entity.ts | 3 - .../finance/services/accounting.service.ts | 119 ++++++++---------- src/modules/finance/services/ap.service.ts | 100 +++++++-------- src/modules/finance/services/ar.service.ts | 22 ++-- .../services/bank-reconciliation.service.ts | 42 +++---- .../finance/services/cash-flow.service.ts | 22 ++-- .../services/erp-integration.service.ts | 38 +++--- .../services/financial-reports.service.ts | 32 ++--- 9 files changed, 161 insertions(+), 219 deletions(-) diff --git a/src/modules/finance/entities/account-payable.entity.ts b/src/modules/finance/entities/account-payable.entity.ts index c1a6a99..5becc1b 100644 --- a/src/modules/finance/entities/account-payable.entity.ts +++ b/src/modules/finance/entities/account-payable.entity.ts @@ -12,9 +12,7 @@ import { Column, CreateDateColumn, UpdateDateColumn, - ManyToOne, OneToMany, - JoinColumn, Index, } from 'typeorm'; import { APPayment } from './ap-payment.entity'; diff --git a/src/modules/finance/entities/chart-of-accounts.entity.ts b/src/modules/finance/entities/chart-of-accounts.entity.ts index 5718f13..8a4f204 100644 --- a/src/modules/finance/entities/chart-of-accounts.entity.ts +++ b/src/modules/finance/entities/chart-of-accounts.entity.ts @@ -12,9 +12,6 @@ import { Column, CreateDateColumn, UpdateDateColumn, - ManyToOne, - OneToMany, - JoinColumn, Index, Tree, TreeChildren, diff --git a/src/modules/finance/services/accounting.service.ts b/src/modules/finance/services/accounting.service.ts index 65669a6..24d5575 100644 --- a/src/modules/finance/services/accounting.service.ts +++ b/src/modules/finance/services/accounting.service.ts @@ -6,7 +6,7 @@ * @module Finance */ -import { DataSource, Repository, IsNull, Not, In } from 'typeorm'; +import { DataSource, Repository, IsNull } from 'typeorm'; import { ChartOfAccounts, AccountType, @@ -25,12 +25,10 @@ interface ServiceContext { interface PaginatedResult { data: T[]; - meta: { - total: number; - page: number; - limit: number; - totalPages: number; - }; + total: number; + page: number; + limit: number; + totalPages: number; } interface CreateAccountDto { @@ -102,7 +100,7 @@ export class AccountingService { private entryRepository: Repository; private lineRepository: Repository; - constructor(private dataSource: DataSource) { + constructor(dataSource: DataSource) { this.accountRepository = dataSource.getRepository(ChartOfAccounts); this.entryRepository = dataSource.getRepository(AccountingEntry); this.lineRepository = dataSource.getRepository(AccountingEntryLine); @@ -153,7 +151,7 @@ export class AccountingService { } if (acceptsMovements !== undefined) { - queryBuilder.andWhere('account.acceptsMovements = :acceptsMovements', { acceptsMovements }); + queryBuilder.andWhere('account.allowsDirectPosting = :acceptsMovements', { acceptsMovements }); } queryBuilder.orderBy('account.code', 'ASC'); @@ -166,12 +164,10 @@ export class AccountingService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } @@ -256,12 +252,6 @@ export class AccountingService { // Determinar nivel const level = data.level ?? (parentAccount ? parentAccount.level + 1 : 1); - // Generar path completo - let fullPath = data.code; - if (parentAccount) { - fullPath = `${parentAccount.fullPath}/${data.code}`; - } - const account = this.accountRepository.create({ tenantId: ctx.tenantId, code: data.code, @@ -271,14 +261,10 @@ export class AccountingService { nature: data.nature, level, parentId: data.parentId, - fullPath, - isGroupAccount: data.isGroupAccount ?? false, - acceptsMovements: data.acceptsMovements ?? true, + allowsDirectPosting: data.acceptsMovements ?? true, status: 'active', - satCode: data.satCode, - satDescription: data.satDescription, - currencyCode: data.currencyCode ?? 'MXN', - balance: 0, + initialBalance: 0, + currentBalance: 0, metadata: data.metadata, createdBy: ctx.userId, }); @@ -420,12 +406,10 @@ export class AccountingService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } @@ -479,17 +463,14 @@ export class AccountingService { reference: data.reference, description: data.description, projectId: data.projectId, - projectCode: data.projectCode, - costCenterId: data.costCenterId, fiscalYear: data.fiscalYear, fiscalPeriod: data.fiscalPeriod, - currencyCode: data.currencyCode ?? 'MXN', + currency: data.currencyCode ?? 'MXN', exchangeRate: data.exchangeRate ?? 1, totalDebit, totalCredit, - lineCount: data.lines.length, - sourceDocument: data.sourceDocument, - sourceDocumentId: data.sourceDocumentId, + sourceModule: data.sourceDocument, + sourceId: data.sourceDocumentId, notes: data.notes, status: 'draft', createdBy: ctx.userId, @@ -500,27 +481,30 @@ export class AccountingService { // Crear líneas const lines = data.lines.map((lineData, index) => this.lineRepository.create({ + tenantId: ctx.tenantId, entryId: savedEntry.id, lineNumber: index + 1, accountId: lineData.accountId, accountCode: lineData.accountCode, - description: lineData.description, - debitAmount: lineData.debitAmount ?? 0, - creditAmount: lineData.creditAmount ?? 0, - currencyAmount: lineData.currencyAmount, - currencyCode: lineData.currencyCode, - exchangeRate: lineData.exchangeRate, + description: lineData.description || '', + debit: lineData.debitAmount ?? 0, + credit: lineData.creditAmount ?? 0, + originalAmount: lineData.currencyAmount, + originalCurrency: lineData.currencyCode, costCenterId: lineData.costCenterId, projectId: lineData.projectId, partnerId: lineData.partnerId, - reference: lineData.reference, metadata: lineData.metadata, }) ); await this.lineRepository.save(lines); - return this.findEntryById(ctx, savedEntry.id) as Promise; + const result = await this.findEntryById(ctx, savedEntry.id); + if (!result) { + throw new Error('Error al crear la póliza'); + } + return result; } private async generateEntryNumber( @@ -610,7 +594,7 @@ export class AccountingService { // Actualizar saldos de cuentas for (const line of entry.lines || []) { - await this.updateAccountBalance(line.accountId, line.debitAmount, line.creditAmount); + await this.updateAccountBalance(line.accountId, line.debit, line.credit); } entry.status = 'posted'; @@ -633,17 +617,16 @@ export class AccountingService { if (!account) return; // Calcular nuevo saldo según naturaleza de la cuenta - let newBalance = account.balance; + let newBalance = account.currentBalance; if (account.nature === 'debit') { newBalance += debitAmount - creditAmount; } else { newBalance += creditAmount - debitAmount; } - await this.accountRepository.update(accountId, { - balance: newBalance, - lastMovementDate: new Date(), - }); + account.currentBalance = newBalance; + account.balanceUpdatedAt = new Date(); + await this.accountRepository.save(account); } async cancelEntry(ctx: ServiceContext, id: string, reason: string): Promise { @@ -659,7 +642,7 @@ export class AccountingService { // Si está contabilizada, reversar saldos if (entry.status === 'posted') { for (const line of entry.lines || []) { - await this.updateAccountBalance(line.accountId, -line.debitAmount, -line.creditAmount); + await this.updateAccountBalance(line.accountId, -line.debit, -line.credit); } } @@ -687,26 +670,22 @@ export class AccountingService { reference: `REV-${entry.entryNumber}`, description: `Reverso de ${entry.entryNumber}: ${reason}`, projectId: entry.projectId, - projectCode: entry.projectCode, - costCenterId: entry.costCenterId, fiscalYear: entry.fiscalYear, fiscalPeriod: entry.fiscalPeriod, - currencyCode: entry.currencyCode, + currencyCode: entry.currency, exchangeRate: entry.exchangeRate, notes: `Póliza de reverso automático`, lines: (entry.lines || []).map((line) => ({ accountId: line.accountId, accountCode: line.accountCode, description: `Reverso: ${line.description || ''}`, - debitAmount: line.creditAmount, // Invertir - creditAmount: line.debitAmount, // Invertir - currencyAmount: line.currencyAmount, - currencyCode: line.currencyCode, - exchangeRate: line.exchangeRate, + debitAmount: line.credit, // Invertir + creditAmount: line.debit, // Invertir + currencyAmount: line.originalAmount, + currencyCode: line.originalCurrency, costCenterId: line.costCenterId, projectId: line.projectId, partnerId: line.partnerId, - reference: line.reference, })), }; @@ -719,7 +698,7 @@ export class AccountingService { // Marcar original como reversada entry.status = 'reversed'; - entry.reversalEntryId = reversalEntry.id; + entry.reversedEntryId = reversalEntry.id; entry.notes = `${entry.notes || ''}\n[REVERSADA]: ${reason}`; entry.updatedBy = ctx.userId; @@ -743,8 +722,8 @@ export class AccountingService { 'account.name as "accountName"', 'account.accountType as "accountType"', 'account.nature as "nature"', - 'SUM(line.debitAmount) as "totalDebit"', - 'SUM(line.creditAmount) as "totalCredit"', + 'SUM(line.debit) as "totalDebit"', + 'SUM(line.credit) as "totalCredit"', ]) .where('entry.tenantId = :tenantId', { tenantId: ctx.tenantId }) .andWhere('entry.status = :status', { status: 'posted' }) @@ -798,14 +777,14 @@ export class AccountingService { let runningBalance = 0; return lines.map((line) => { - runningBalance += line.debitAmount - line.creditAmount; + runningBalance += line.debit - line.credit; return { date: line.entry?.entryDate, entryNumber: line.entry?.entryNumber, reference: line.entry?.reference, description: line.description || line.entry?.description, - debitAmount: line.debitAmount, - creditAmount: line.creditAmount, + debitAmount: line.debit, + creditAmount: line.credit, balance: runningBalance, }; }); diff --git a/src/modules/finance/services/ap.service.ts b/src/modules/finance/services/ap.service.ts index b3b9fbb..f3e4611 100644 --- a/src/modules/finance/services/ap.service.ts +++ b/src/modules/finance/services/ap.service.ts @@ -6,16 +6,16 @@ * @module Finance */ -import { DataSource, Repository, IsNull, LessThan, Between } from 'typeorm'; +import { DataSource, Repository, IsNull } from 'typeorm'; import { AccountPayable, - APStatus, - APDocumentType, APPayment, PaymentMethod, - PaymentStatus, } from '../entities'; +type APStatus = 'pending' | 'partial' | 'paid' | 'overdue' | 'cancelled' | 'disputed'; +type APDocumentType = 'invoice' | 'credit_note' | 'debit_note' | 'advance' | 'retention'; + interface ServiceContext { tenantId: string; userId?: string; @@ -23,12 +23,10 @@ interface ServiceContext { interface PaginatedResult { data: T[]; - meta: { - total: number; - page: number; - limit: number; - totalPages: number; - }; + total: number; + page: number; + limit: number; + totalPages: number; } interface CreateAPDto { @@ -90,7 +88,7 @@ export class APService { private apRepository: Repository; private paymentRepository: Repository; - constructor(private dataSource: DataSource) { + constructor(dataSource: DataSource) { this.apRepository = dataSource.getRepository(AccountPayable); this.paymentRepository = dataSource.getRepository(APPayment); } @@ -133,7 +131,7 @@ export class APService { } if (partnerId) { - queryBuilder.andWhere('ap.partnerId = :partnerId', { partnerId }); + queryBuilder.andWhere('ap.supplierId = :partnerId', { partnerId }); } if (projectId) { @@ -157,7 +155,7 @@ export class APService { if (search) { queryBuilder.andWhere( - '(ap.documentNumber ILIKE :search OR ap.partnerName ILIKE :search)', + '(ap.documentNumber ILIKE :search OR ap.supplierName ILIKE :search)', { search: `%${search}%` } ); } @@ -172,12 +170,10 @@ export class APService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } @@ -206,8 +202,8 @@ export class APService { documentNumber: data.documentNumber, documentDate: data.documentDate, dueDate: data.dueDate, - partnerId: data.partnerId, - partnerName: data.partnerName, + partnerId: data.supplierId, + partnerName: data.supplierName, partnerRfc: data.partnerRfc, projectId: data.projectId, projectCode: data.projectCode, @@ -256,14 +252,9 @@ export class APService { updatedBy: ctx.userId, }); - // Recalcular montos si cambió el monto original - if (data.originalAmount !== undefined) { - ap.netAmount = - ap.originalAmount - - (ap.retentionIsr ?? 0) - - (ap.retentionIva ?? 0) - - (ap.guaranteeFund ?? 0); - ap.balanceAmount = ap.netAmount - ap.paidAmount; + // Recalcular saldo si cambió el monto total + if (data.totalAmount !== undefined) { + ap.balance = ap.totalAmount - ap.paidAmount; } return this.apRepository.save(ap); @@ -302,7 +293,7 @@ export class APService { throw new Error(`Cuenta por pagar ${ap.documentNumber} ya está pagada o cancelada`); } apRecords.push(ap); - totalToApply += ap.balanceAmount; + totalToApply += ap.balance; } // Validar monto @@ -322,19 +313,16 @@ export class APService { paymentMethod: data.paymentMethod, paymentDate: data.paymentDate, bankAccountId: data.bankAccountId, - paymentAmount: data.paymentAmount, - currencyCode: data.currencyCode ?? 'MXN', + amount: data.paymentAmount, + currency: data.currencyCode ?? 'MXN', exchangeRate: data.exchangeRate ?? 1, - reference: data.reference, checkNumber: data.checkNumber, transferReference: data.transferReference, beneficiaryName: data.beneficiaryName, beneficiaryAccount: data.beneficiaryAccount, beneficiaryBank: data.beneficiaryBank, - paymentConcept: data.paymentConcept, notes: data.notes, status: 'pending', - documentCount: apRecords.length, createdBy: ctx.userId, }); @@ -351,14 +339,14 @@ export class APService { for (const ap of sortedAP) { if (remainingAmount <= 0) break; - const amountToApply = Math.min(remainingAmount, ap.balanceAmount); + const amountToApply = Math.min(remainingAmount, ap.balance); applications.push({ apId: ap.id, amount: amountToApply }); ap.paidAmount += amountToApply; - ap.balanceAmount -= amountToApply; - ap.lastPaymentDate = data.paymentDate; + ap.balance -= amountToApply; + ap.paymentDate = data.paymentDate; - if (ap.balanceAmount <= 0.01) { + if (ap.balance <= 0.01) { ap.status = 'paid'; } else { ap.status = 'partial'; @@ -413,9 +401,7 @@ export class APService { throw new Error('Solo se pueden confirmar pagos pendientes'); } - payment.status = 'confirmed'; - payment.confirmedAt = new Date(); - payment.confirmedById = ctx.userId; + payment.status = 'processed'; payment.updatedBy = ctx.userId; return this.paymentRepository.save(payment); @@ -447,8 +433,8 @@ export class APService { const ap = await this.apRepository.findOne({ where: { id: app.apId } }); if (ap) { ap.paidAmount -= app.amount; - ap.balanceAmount += app.amount; - ap.status = ap.balanceAmount >= ap.netAmount ? 'pending' : 'partial'; + ap.balance += app.amount; + ap.status = ap.balance >= ap.totalAmount ? 'pending' : 'partial'; ap.updatedBy = ctx.userId; await this.apRepository.save(ap); } @@ -483,7 +469,7 @@ export class APService { .andWhere('ap.deletedAt IS NULL'); if (partnerId) { - queryBuilder.andWhere('ap.partnerId = :partnerId', { partnerId }); + queryBuilder.andWhere('ap.supplierId = :partnerId', { partnerId }); } if (projectId) { @@ -510,7 +496,7 @@ export class APService { const daysOverdue = Math.floor( (asOfDate.getTime() - new Date(ap.dueDate).getTime()) / (1000 * 60 * 60 * 24) ); - const balance = ap.balanceAmount; + const balance = ap.balance; // Clasificar en bucket let bucket: keyof AgingBucket; @@ -530,10 +516,10 @@ export class APService { summary.total += balance; // Por proveedor - if (!partnerMap.has(ap.partnerId)) { - partnerMap.set(ap.partnerId, { - partnerId: ap.partnerId, - partnerName: ap.partnerName, + if (!partnerMap.has(ap.supplierId)) { + partnerMap.set(ap.supplierId, { + partnerId: ap.supplierId, + partnerName: ap.supplierName, aging: { current: 0, days1to30: 0, @@ -545,7 +531,7 @@ export class APService { }); } - const partnerData = partnerMap.get(ap.partnerId)!; + const partnerData = partnerMap.get(ap.supplierId)!; partnerData.aging[bucket] += balance; partnerData.aging.total += balance; } @@ -572,7 +558,7 @@ export class APService { .andWhere('ap.deletedAt IS NULL'); if (partnerId) { - queryBuilder.andWhere('ap.partnerId = :partnerId', { partnerId }); + queryBuilder.andWhere('ap.supplierId = :partnerId', { partnerId }); } if (projectId) { @@ -599,7 +585,7 @@ export class APService { const entry = scheduleMap.get(dateKey)!; entry.documents.push(ap); - entry.totalAmount += ap.balanceAmount; + entry.totalAmount += ap.balance; } return Array.from(scheduleMap.values()).sort( @@ -629,28 +615,28 @@ export class APService { // Total pendiente const totalPending = await baseQuery .clone() - .select('SUM(ap.balanceAmount)', 'total') + .select('SUM(ap.balance)', 'total') .getRawOne(); // Vencido const totalOverdue = await baseQuery .clone() .andWhere('ap.dueDate < :today', { today }) - .select('SUM(ap.balanceAmount)', 'total') + .select('SUM(ap.balance)', 'total') .getRawOne(); // Por vencer esta semana const dueThisWeek = await baseQuery .clone() .andWhere('ap.dueDate BETWEEN :today AND :endOfWeek', { today, endOfWeek }) - .select('SUM(ap.balanceAmount)', 'total') + .select('SUM(ap.balance)', 'total') .getRawOne(); // Por vencer este mes const dueThisMonth = await baseQuery .clone() .andWhere('ap.dueDate BETWEEN :today AND :endOfMonth', { today, endOfMonth }) - .select('SUM(ap.balanceAmount)', 'total') + .select('SUM(ap.balance)', 'total') .getRawOne(); // Conteos diff --git a/src/modules/finance/services/ar.service.ts b/src/modules/finance/services/ar.service.ts index ee92b9b..9380715 100644 --- a/src/modules/finance/services/ar.service.ts +++ b/src/modules/finance/services/ar.service.ts @@ -6,7 +6,7 @@ * @module Finance */ -import { DataSource, Repository, IsNull, LessThan, Between } from 'typeorm'; +import { DataSource, Repository, IsNull } from 'typeorm'; import { AccountReceivable, ARStatus, @@ -23,12 +23,10 @@ interface ServiceContext { interface PaginatedResult { data: T[]; - meta: { - total: number; - page: number; - limit: number; - totalPages: number; - }; + total: number; + page: number; + limit: number; + totalPages: number; } interface CreateARDto { @@ -169,12 +167,10 @@ export class ARService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } diff --git a/src/modules/finance/services/bank-reconciliation.service.ts b/src/modules/finance/services/bank-reconciliation.service.ts index 66e3510..e10761f 100644 --- a/src/modules/finance/services/bank-reconciliation.service.ts +++ b/src/modules/finance/services/bank-reconciliation.service.ts @@ -6,7 +6,7 @@ * @module Finance */ -import { DataSource, Repository, IsNull, Between, In } from 'typeorm'; +import { DataSource, Repository, IsNull, Between } from 'typeorm'; import { BankAccount, BankAccountType, @@ -26,12 +26,10 @@ interface ServiceContext { interface PaginatedResult { data: T[]; - meta: { - total: number; - page: number; - limit: number; - totalPages: number; - }; + total: number; + page: number; + limit: number; + totalPages: number; } interface CreateBankAccountDto { @@ -165,12 +163,10 @@ export class BankReconciliationService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } @@ -353,12 +349,10 @@ export class BankReconciliationService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } @@ -533,12 +527,10 @@ export class BankReconciliationService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } diff --git a/src/modules/finance/services/cash-flow.service.ts b/src/modules/finance/services/cash-flow.service.ts index ea52291..acc07ce 100644 --- a/src/modules/finance/services/cash-flow.service.ts +++ b/src/modules/finance/services/cash-flow.service.ts @@ -6,7 +6,7 @@ * @module Finance */ -import { DataSource, Repository, IsNull, Between, LessThanOrEqual, MoreThanOrEqual } from 'typeorm'; +import { DataSource, Repository, IsNull, LessThanOrEqual, MoreThanOrEqual } from 'typeorm'; import { CashFlowProjection, CashFlowType, @@ -23,12 +23,10 @@ interface ServiceContext { interface PaginatedResult { data: T[]; - meta: { - total: number; - page: number; - limit: number; - totalPages: number; - }; + total: number; + page: number; + limit: number; + totalPages: number; } interface CreateProjectionDto { @@ -153,12 +151,10 @@ export class CashFlowService { return { data, - meta: { - total, - page, - limit, - totalPages: Math.ceil(total / limit), - }, + total, + page, + limit, + totalPages: Math.ceil(total / limit), }; } diff --git a/src/modules/finance/services/erp-integration.service.ts b/src/modules/finance/services/erp-integration.service.ts index 3f9c5bd..907d400 100644 --- a/src/modules/finance/services/erp-integration.service.ts +++ b/src/modules/finance/services/erp-integration.service.ts @@ -137,10 +137,10 @@ export class ERPIntegrationService { BKTXT: entry.description.slice(0, 25), lines: (entry.lines || []).map((line, idx) => ({ BUZEI: idx + 1, - BSCHL: line.debitAmount > 0 ? '40' : '50', // 40=Debe, 50=Haber + BSCHL: line.debit > 0 ? '40' : '50', // 40=Debe, 50=Haber HKONT: line.accountCode.replace(/\./g, '').padStart(10, '0'), - WRBTR: Math.abs(line.debitAmount || line.creditAmount), - DMBTR: Math.abs(line.debitAmount || line.creditAmount) * entry.exchangeRate, + WRBTR: Math.abs(line.debit || line.credit), + DMBTR: Math.abs(line.debit || line.credit) * entry.exchangeRate, SGTXT: (line.description || entry.description).slice(0, 50), ZUONR: line.reference?.slice(0, 18), KOSTL: line.costCenterId?.slice(0, 10), @@ -234,8 +234,8 @@ export class ERPIntegrationService { NumMovto: lineIdx + 1, Cuenta: line.accountCode, Concepto: (line.description || entry.description).slice(0, 200), - Cargo: line.debitAmount, - Abono: line.creditAmount, + Cargo: line.debit, + Abono: line.credit, Referencia: line.reference?.slice(0, 20), Diario: diario, })), @@ -353,8 +353,8 @@ ${entries.map((entry) => this.generatePolizaXML(entry)).join('\n')} NumCta="${this.escapeXML(line.accountCode)}" DesCta="${this.escapeXML(line.description || '')}" Concepto="${this.escapeXML(entry.description)}" - Debe="${line.debitAmount.toFixed(2)}" - Haber="${line.creditAmount.toFixed(2)}" + Debe="${line.debit.toFixed(2)}" + Haber="${line.credit.toFixed(2)}" />`; }) .join('\n'); @@ -424,7 +424,7 @@ ${transacciones} nature: acc.nature, level: acc.level, parentCode: acc.parentId, - satCode: acc.satCode, + satCode: acc.sapCode, status: acc.status, })); filename = `CATALOGO_CUENTAS.json`; @@ -435,7 +435,7 @@ ${transacciones} 'Código,Nombre,Tipo,Naturaleza,Nivel,Código SAT,Estado', ...accounts.map( (acc) => - `"${acc.code}","${acc.name}","${acc.accountType}","${acc.nature}",${acc.level},"${acc.satCode || ''}","${acc.status}"` + `"${acc.code}","${acc.name}","${acc.accountType}","${acc.nature}",${acc.level},"${acc.sapCode || ''}","${acc.status}"` ), ]; data = rows.join('\n'); @@ -455,7 +455,7 @@ ${transacciones} const cuentas = accounts .map( (acc) => ` { if (account.nature === 'debit') { - runningBalance += line.debitAmount - line.creditAmount; + runningBalance += line.debit - line.credit; } else { - runningBalance += line.creditAmount - line.debitAmount; + runningBalance += line.credit - line.debit; } return { @@ -811,8 +811,8 @@ export class FinancialReportsService { entryNumber: line.entry!.entryNumber, reference: line.entry!.reference, description: line.description || line.entry!.description, - debit: line.debitAmount, - credit: line.creditAmount, + debit: line.debit, + credit: line.credit, balance: runningBalance, }; });