feat: RLA API v1.0.0 — API complète + exports + thème McKinsey

- 9 endpoints métier : synthese, alertes, en-service, en-cours,
  par-region, clotures, pilotage-proactif, matrice-risque
- Exports PDF (tous rôles) / XLSX PPTX DOCX (superadmin)
- services/calc.js : helpers normalisés partagés
- services/export-pdf.js : PDF async PDFKit par vue
- Thème McKinsey (#1C2B4B / bleu pétrole / gris sobre)
- Boutons XLSX/DOCX front (superadmin uniquement)
- BASEROW_API_URL → https://baserow.bolbol.tn/api/
- dotenv override: true

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Nabil Derouiche
2026-03-12 23:47:10 +01:00
co-authored by Claude Sonnet 4.6
commit 88a0dbe6d2
39 changed files with 7622 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
const express = require('express');
const router = express.Router();
const { getMarches } = require('../services/baserow');
const DELAI_CRITIQUE = 45;
const DELAI_ATTENTION = 90;
function parseNum(v) {
const n = parseFloat(String(v || '').replace(',', '.'));
return isNaN(n) ? 0 : n;
}
function getDelaiRestant(r) {
if (r.delai_restant != null) return parseInt(r.delai_restant, 10);
const fin = r.date_fin || r.datefin;
if (!fin) return null;
const d = new Date(fin);
if (isNaN(d.getTime())) return null;
return Math.ceil((d - new Date()) / 86400000);
}
function isCloture(r) {
const obs = String(r.observation || '').toLowerCase();
return obs.includes('clôtur') || obs.includes('clotur') || !!r.date_cloture;
}
// GET /api/stats
router.get('/', async (req, res) => {
try {
const rows = await getMarches();
const actifs = rows.filter(r => !isCloture(r));
// Nb marchés par statut
const parStatut = {};
for (const r of rows) {
const s = String(r.statut || 'Inconnu');
parStatut[s] = (parStatut[s] || 0) + 1;
}
// Taux d'avancement physique moyen (marchés actifs)
const tauxList = actifs.map(r => parseNum(r.taux_phy)).filter(v => v > 0);
const tauxMoyen = tauxList.length
? Math.round(tauxList.reduce((a, b) => a + b, 0) / tauxList.length * 10) / 10
: 0;
// Alertes délais
const alertes = actifs
.map(r => ({ ...r, _delai: getDelaiRestant(r) }))
.filter(r => r._delai !== null && r._delai <= DELAI_ATTENTION)
.map(r => ({
id: r.id,
ref: r.ref || r.reference || '',
entrepreneur: r.entrepreneur || '',
projet: r.projet || '',
region: r.region || '',
avt_fin: parseNum(r.avt_fin ?? r.avtfin),
delai_restant: r._delai,
niveau: r._delai <= DELAI_CRITIQUE ? 'critique' : 'attention',
}));
res.json({
total: rows.length,
actifs: actifs.length,
clotures: rows.length - actifs.length,
par_statut: parStatut,
taux_avancement_moyen: tauxMoyen,
alertes_delais: {
count: alertes.length,
critique: alertes.filter(a => a.niveau === 'critique').length,
attention: alertes.filter(a => a.niveau === 'attention').length,
items: alertes,
},
});
} catch (err) {
res.status(502).json({ error: 'Erreur Baserow', detail: err.message });
}
});
module.exports = router;