Ajout du type Intérêt plateforme pour les remboursements

This commit is contained in:
ocroguennec committed 2026-08-16 16:49:20 +02:00
1 parent 37f9f8b8a7
commit 1bab97b5b3
9 files changed
+248 -66

No files matched your search

+39
View File
@@ -2301,4 +2301,43 @@ db.exec('CREATE INDEX IF NOT EXISTS idx_api_keys_hash ON api_keys(key_hash)');
}
}
// ── Migration : v_interets_annuels — inclure les "Intérêts plateforme" ──
// Nouveau type de remboursement (intérêts versés par une plateforme, hors
// investissement précis, rattachés via bonus_plateforme_id/bonus_investisseur_id
// comme les bonus). Contrairement aux bonus (cashback non imposable), ce sont
// de vrais intérêts fiscalisés : ils doivent compter dans le récap annuel au
// même titre que les intérêts d'investissement classiques.
{
const viewRow = db.prepare(
"SELECT sql FROM sqlite_master WHERE type='view' AND name='v_interets_annuels'"
).get();
if (viewRow && !viewRow.sql.includes('interets_plateforme')) {
db.exec('DROP VIEW IF EXISTS v_interets_annuels');
db.exec(`
CREATE VIEW v_interets_annuels AS
SELECT investisseur_id, annee,
SUM(interets_bruts) AS interets_bruts,
SUM(prelev_sociaux) AS prelev_sociaux,
SUM(prelev_forfaitaire) AS prelev_forfaitaire,
SUM(net_recu) AS net_recu
FROM (
SELECT i.investisseur_id AS investisseur_id,
substr(r.date_remb,1,4) AS annee,
r.interets_bruts, r.prelev_sociaux, r.prelev_forfaitaire, r.net_recu
FROM remboursements r
JOIN investissements i ON i.id = r.investissement_id
WHERE r.statut IN ('paye','partiel') AND r.type = 'normal'
UNION ALL
SELECT r.bonus_investisseur_id AS investisseur_id,
substr(r.date_remb,1,4) AS annee,
r.interets_bruts, r.prelev_sociaux, r.prelev_forfaitaire, r.net_recu
FROM remboursements r
WHERE r.statut IN ('paye','partiel') AND r.type = 'interets_plateforme'
)
GROUP BY investisseur_id, annee
`);
console.log('[DB] v_interets_annuels: vue recréée (inclut interets_plateforme)');
}
}
export default db;