diff --git a/backend/src/db/index.js b/backend/src/db/index.js index d443bc9..f5827ad 100644 --- a/backend/src/db/index.js +++ b/backend/src/db/index.js @@ -493,6 +493,26 @@ db.exec('CREATE INDEX IF NOT EXISTS idx_garantie_types_user ON garantie_types(us } } +// ── Migration : détail des taux 2778-SD sur taux_pfu ───────────────────────── +// Décompose prelev_sociaux en ses 3 composantes pour le calcul de la déclaration +// mensuelle 2778-SD (taux identiques au PFU global mais ventilés par case). +// Taux 2021-2025 : CSG 9,2 % | CRDS 0,5 % | Solidarité 7,5 % → total 17,2 % +// Taux 2026+ : CSG 10,6 %| CRDS 0,5 % | Solidarité 7,5 % → total 18,6 % +{ + const pfuCols = db.prepare('PRAGMA table_info(taux_pfu)').all().map(c => c.name); + if (!pfuCols.includes('csg')) { + db.exec('ALTER TABLE taux_pfu ADD COLUMN csg REAL NOT NULL DEFAULT 9.2'); + // Mise à jour des années 2026+ où la CSG passe à 10,6 % + db.exec('UPDATE taux_pfu SET csg = 10.6 WHERE annee >= 2026'); + } + if (!pfuCols.includes('crds')) { + db.exec('ALTER TABLE taux_pfu ADD COLUMN crds REAL NOT NULL DEFAULT 0.5'); + } + if (!pfuCols.includes('solidarite')) { + db.exec('ALTER TABLE taux_pfu ADD COLUMN solidarite REAL NOT NULL DEFAULT 7.5'); + } +} + // ── Seed taux_pfu si vide ───────────────────────────────────────────── const pfuCount = db.prepare('SELECT COUNT(*) AS n FROM taux_pfu').get().n; if (pfuCount === 0) { @@ -999,25 +1019,6 @@ db.exec(` } } -// ── Migration : détail des taux 2778-SD sur taux_pfu ───────────────────────── -// Décompose prelev_sociaux en ses 3 composantes pour le calcul de la déclaration -// mensuelle 2778-SD (taux identiques au PFU global mais ventilés par case). -// Taux 2021-2025 : CSG 9,2 % | CRDS 0,5 % | Solidarité 7,5 % → total 17,2 % -// Taux 2026+ : CSG 10,6 %| CRDS 0,5 % | Solidarité 7,5 % → total 18,6 % -{ - const pfuCols = db.prepare('PRAGMA table_info(taux_pfu)').all().map(c => c.name); - if (!pfuCols.includes('csg')) { - db.exec('ALTER TABLE taux_pfu ADD COLUMN csg REAL NOT NULL DEFAULT 9.2'); - // Mise à jour des années 2026+ où la CSG passe à 10,6 % - db.exec('UPDATE taux_pfu SET csg = 10.6 WHERE annee >= 2026'); - } - if (!pfuCols.includes('crds')) { - db.exec('ALTER TABLE taux_pfu ADD COLUMN crds REAL NOT NULL DEFAULT 0.5'); - } - if (!pfuCols.includes('solidarite')) { - db.exec('ALTER TABLE taux_pfu ADD COLUMN solidarite REAL NOT NULL DEFAULT 7.5'); - } -} // ── Table taux_credit_impot — Référentiel 2047 crédit d'impôt par pays ───────