- Ajout procédure tRPC opex.getBasesRepartition et opex.setBaseRepartition - DsiOpex utilise maintenant les bases de répartition depuis la BDD (priorité BDD > JSON fallback pour 2025) - Total en bas à droite de la vue établissements affiche totalGlobal (somme postes BDD = 1 257 678 €) au lieu de la somme des arrondis par établissement (1 259 641 €) - 0 erreur TypeScript
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import mysql from 'mysql2/promise';
|
|
import { readFileSync } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
import dotenv from 'dotenv';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
dotenv.config({ path: join(__dirname, '..', '.env') });
|
|
|
|
const conn = await mysql.createConnection(process.env.DATABASE_URL);
|
|
const [rows] = await conn.execute('SELECT libelle, montant FROM opex_postes WHERE annee = 2026 ORDER BY colIdx');
|
|
|
|
const data = JSON.parse(readFileSync(join(__dirname, '../client/src/data_opex.json'), 'utf8'));
|
|
const libellesJson = new Set(data.postes.map(p => p.libelle));
|
|
const libellesBdd = new Set(rows.map(r => r.libelle));
|
|
|
|
console.log('Nb postes BDD:', rows.length);
|
|
console.log('Nb postes JSON:', libellesJson.size);
|
|
|
|
let totalBdd = 0;
|
|
rows.forEach(r => { totalBdd += parseFloat(r.montant || '0'); });
|
|
console.log('Total BDD:', totalBdd.toFixed(2));
|
|
|
|
console.log('\n=== En BDD mais PAS dans JSON ===');
|
|
for (const lib of libellesBdd) {
|
|
if (!libellesJson.has(lib)) {
|
|
const row = rows.find(r => r.libelle === lib);
|
|
console.log(' +', lib, ':', row.montant);
|
|
}
|
|
}
|
|
|
|
console.log('\n=== Dans JSON mais PAS en BDD ===');
|
|
for (const lib of libellesJson) {
|
|
if (!libellesBdd.has(lib)) {
|
|
console.log(' -', lib);
|
|
}
|
|
}
|
|
|
|
console.log('\n=== Tous les postes BDD avec montant ===');
|
|
rows.forEach(r => {
|
|
const m = parseFloat(r.montant || '0');
|
|
if (m > 0) console.log(` ${r.libelle}: ${m.toFixed(2)}`);
|
|
});
|
|
|
|
await conn.end();
|