Update: nueva version Horux Despachos
This commit is contained in:
39
apps/api/scripts/validate-ingresos.ts
Normal file
39
apps/api/scripts/validate-ingresos.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Paridad dashboard vs drill para INGRESOS de un contribuyente en un año.
|
||||
* Similar a validate-gastos pero para el lado emisor.
|
||||
*/
|
||||
import { prisma, tenantDb } from '../src/config/database.js';
|
||||
import { calcularIngresosPorRegimen } from '../src/services/dashboard.service.js';
|
||||
|
||||
const tenantRfc = process.argv[2] || 'DESPACHO_MO3NI6U8_B9VGG';
|
||||
const contribuyenteId = process.argv[3] || '414b22a8-c6e2-4f39-be0f-7537a848107e';
|
||||
const año = Number(process.argv[4] || '2025');
|
||||
|
||||
async function main() {
|
||||
const tenant = await prisma.tenant.findFirst({ where: { rfc: tenantRfc }, select: { id: true, databaseName: true } });
|
||||
if (!tenant) { console.error('Tenant not found'); process.exit(1); }
|
||||
const pool = await tenantDb.getPool(tenant.id, tenant.databaseName);
|
||||
|
||||
console.log(`\n=== Ingresos ${año} Contribuyente ${contribuyenteId} ===\n`);
|
||||
console.log(`mes | total por régimen | total mes`);
|
||||
|
||||
let totalAño = 0;
|
||||
for (let m = 1; m <= 12; m++) {
|
||||
const lastDay = new Date(año, m, 0).getDate();
|
||||
const mm = String(m).padStart(2, '0');
|
||||
const fi = `${año}-${mm}-01`;
|
||||
const ff = `${año}-${mm}-${String(lastDay).padStart(2, '0')}`;
|
||||
|
||||
const ingresos = await calcularIngresosPorRegimen(
|
||||
pool, tenant.id, fi, ff, undefined, undefined, false, contribuyenteId,
|
||||
);
|
||||
|
||||
const porReg = ingresos.porRegimen.map(r => `${r.regimenClave}:${r.monto.toFixed(2)}`).join(' / ');
|
||||
console.log(`${mm} | ${porReg || '(sin datos)'} | ${ingresos.total.toFixed(2)}`);
|
||||
totalAño += ingresos.total;
|
||||
}
|
||||
console.log(`\nTotal año: ${totalAño.toFixed(2)}`);
|
||||
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
main().catch(async e => { console.error(e); await prisma.$disconnect().catch(() => {}); process.exit(1); });
|
||||
Reference in New Issue
Block a user