Amélioration de l'API
This commit is contained in:
1 parent
5dc6f21e61
commit
4ad6ea79e8
8 files changed
+387
-47
No files matched your search
@@ -201,15 +201,7 @@ router.get('/export', (req, res) => {
|
||||
res.send('\uFEFF' + csv);
|
||||
});
|
||||
|
||||
/* ── CERFA 2561 — synthèse par plateforme × investisseur ── */
|
||||
router.get('/cerfa2561', (req, res) => {
|
||||
const annee = req.query.annee || String(new Date().getFullYear() - 1);
|
||||
const scopeAll = req.query.scope === 'all';
|
||||
const invCond = scopeAll
|
||||
? 'i.investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'i.investisseur_id = ?';
|
||||
const invArg = scopeAll ? req.user.id : req.investisseur.id;
|
||||
|
||||
function buildCerfa2561(annee, invCond, invCondBonus2561, invArg) {
|
||||
const rows = db.prepare(`
|
||||
SELECT
|
||||
p.id AS plateforme_id,
|
||||
@@ -239,9 +231,6 @@ router.get('/cerfa2561', (req, res) => {
|
||||
// bonus_investisseur_id) : fusionnés sur la même ligne plateforme × investisseur que
|
||||
// les intérêts d'investissement classiques, car la fiscalité (domiciliation/fiscalite/
|
||||
// type_produit_fiscal) dépend de la plateforme, pas de l'investissement précis.
|
||||
const invCondBonus2561 = scopeAll
|
||||
? 'r.bonus_investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'r.bonus_investisseur_id = ?';
|
||||
const rowsInteretsPlateforme = db.prepare(`
|
||||
SELECT
|
||||
p.id AS plateforme_id,
|
||||
@@ -399,7 +388,23 @@ router.get('/cerfa2561', (req, res) => {
|
||||
mois: moisMap[`${l.plateforme_id}_${l.investisseur_id}`] ?? {},
|
||||
}));
|
||||
|
||||
res.json({ annee, lignes: lignesWithMois });
|
||||
return { annee, lignes: lignesWithMois };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ── CERFA 2561 — synthèse par plateforme × investisseur ── */
|
||||
router.get('/cerfa2561', (req, res) => {
|
||||
const annee = req.query.annee || String(new Date().getFullYear() - 1);
|
||||
const scopeAll = req.query.scope === 'all';
|
||||
const invCond = scopeAll
|
||||
? 'i.investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'i.investisseur_id = ?';
|
||||
const invCondBonus2561 = scopeAll
|
||||
? 'r.bonus_investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'r.bonus_investisseur_id = ?';
|
||||
const invArg = scopeAll ? req.user.id : req.investisseur.id;
|
||||
res.json(buildCerfa2561(annee, invCond, invCondBonus2561, invArg));
|
||||
});
|
||||
|
||||
/* ── CERFA 2561 — détail des remboursements par plateforme × investisseur ── */
|
||||
@@ -506,15 +511,7 @@ router.get('/years', (req, res) => {
|
||||
|
||||
|
||||
|
||||
/* ── 2778-SD — matrice mensuelle par plateforme étrangère ── */
|
||||
router.get('/2778', (req, res) => {
|
||||
const annee = req.query.annee || String(new Date().getFullYear() - 1);
|
||||
const scopeAll = req.query.scope === 'all';
|
||||
const invCond = scopeAll
|
||||
? 'i.investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'i.investisseur_id = ?';
|
||||
const invArg = scopeAll ? req.user.id : req.investisseur.id;
|
||||
|
||||
function build2778(annee, invCond, invCondBonus2778, invArg) {
|
||||
// Plateformes étrangères × investisseur avec au moins un remboursement sur l'année
|
||||
const platRows = db.prepare(`
|
||||
SELECT DISTINCT p.id, p.nom, inv.id AS investisseur_id, inv.nom AS investisseur_nom, inv.prenom AS investisseur_prenom
|
||||
@@ -532,9 +529,6 @@ router.get('/2778', (req, res) => {
|
||||
|
||||
// Intérêts plateforme (pas d'investissement) sur des plateformes étrangères — même
|
||||
// logique de fusion que pour le 2561 : rattachés à la ligne plateforme × investisseur.
|
||||
const invCondBonus2778 = scopeAll
|
||||
? 'r.bonus_investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'r.bonus_investisseur_id = ?';
|
||||
const platRowsInteretsPlateforme = db.prepare(`
|
||||
SELECT DISTINCT p.id, p.nom, inv.id AS investisseur_id, inv.nom AS investisseur_nom, inv.prenom AS investisseur_prenom
|
||||
FROM remboursements r
|
||||
@@ -620,26 +614,28 @@ router.get('/2778', (req, res) => {
|
||||
mois: moisMap[`${p.id}_${p.investisseur_id}`] ?? {},
|
||||
}));
|
||||
|
||||
res.json({ annee, plateformes });
|
||||
});
|
||||
return { annee, plateformes };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ── 2047 — Cadre 2, rubrique 230 (Intérêts) — vision annuelle par pays/plateforme ──
|
||||
Détermine, pour chaque plateforme étrangère × investisseur, si les intérêts perçus
|
||||
ouvrent droit à un crédit d'impôt conventionnel (cases 231-238) ou non (case 250),
|
||||
en s'appuyant sur le référentiel pays "taux_credit_impot" (paramétrage admin).
|
||||
Éligibilité = convention active + taux d'intérêt renseigné + non "exclusif résidence"
|
||||
(le pictogramme c/ de la notice signifie imposable exclusivement en France : aucun
|
||||
crédit d'impôt possible, même si la plateforme a réellement prélevé une taxe locale). ── */
|
||||
router.get('/2047', (req, res) => {
|
||||
|
||||
|
||||
/* ── 2778-SD — matrice mensuelle par plateforme étrangère ── */
|
||||
router.get('/2778', (req, res) => {
|
||||
const annee = req.query.annee || String(new Date().getFullYear() - 1);
|
||||
const scopeAll = req.query.scope === 'all';
|
||||
const invCond = scopeAll
|
||||
? 'i.investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'i.investisseur_id = ?';
|
||||
const invCondBonus2778 = scopeAll
|
||||
? 'r.bonus_investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'r.bonus_investisseur_id = ?';
|
||||
const invArg = scopeAll ? req.user.id : req.investisseur.id;
|
||||
res.json(build2778(annee, invCond, invCondBonus2778, invArg));
|
||||
});
|
||||
|
||||
function build2047(annee, invCond, invCondBonus2047, invArg) {
|
||||
const rows = db.prepare(`
|
||||
SELECT
|
||||
p.id AS plateforme_id, p.nom AS plateforme_nom, p.domiciliation,
|
||||
@@ -663,10 +659,6 @@ router.get('/2047', (req, res) => {
|
||||
GROUP BY p.id, inv.id
|
||||
`).all(invArg, annee);
|
||||
|
||||
// Intérêts plateforme (bonus, sans investissement rattaché) — même logique de fusion que /2778
|
||||
const invCondBonus2047 = scopeAll
|
||||
? 'r.bonus_investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'r.bonus_investisseur_id = ?';
|
||||
const rowsInteretsPlateforme = db.prepare(`
|
||||
SELECT
|
||||
p.id AS plateforme_id, p.nom AS plateforme_nom, p.domiciliation,
|
||||
@@ -789,7 +781,29 @@ router.get('/2047', (req, res) => {
|
||||
// (info complémentaire, non reportée sur une case du formulaire) reste arrondi au centime.
|
||||
totals.montant_avant_local = round2(totals.montant_avant_local);
|
||||
|
||||
res.json({ annee, lignes, totals });
|
||||
return { annee, lignes, totals };
|
||||
}
|
||||
|
||||
|
||||
/* ── 2047 — Cadre 2, rubrique 230 (Intérêts) — vision annuelle par pays/plateforme ──
|
||||
Détermine, pour chaque plateforme étrangère × investisseur, si les intérêts perçus
|
||||
ouvrent droit à un crédit d'impôt conventionnel (cases 231-238) ou non (case 250),
|
||||
en s'appuyant sur le référentiel pays "taux_credit_impot" (paramétrage admin).
|
||||
Éligibilité = convention active + taux d'intérêt renseigné + non "exclusif résidence"
|
||||
(le pictogramme c/ de la notice signifie imposable exclusivement en France : aucun
|
||||
crédit d'impôt possible, même si la plateforme a réellement prélevé une taxe locale). ── */
|
||||
router.get('/2047', (req, res) => {
|
||||
const annee = req.query.annee || String(new Date().getFullYear() - 1);
|
||||
const scopeAll = req.query.scope === 'all';
|
||||
const invCond = scopeAll
|
||||
? 'i.investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'i.investisseur_id = ?';
|
||||
const invCondBonus2047 = scopeAll
|
||||
? 'r.bonus_investisseur_id IN (SELECT id FROM investisseurs WHERE user_id = ?)'
|
||||
: 'r.bonus_investisseur_id = ?';
|
||||
const invArg = scopeAll ? req.user.id : req.investisseur.id;
|
||||
res.json(build2047(annee, invCond, invCondBonus2047, invArg));
|
||||
});
|
||||
|
||||
export { buildCerfa2561, build2778, build2047 };
|
||||
export default router;
|
||||
Reference in new issue
Block a user