From 6bdf12b8fe35bb02de9326618a4c8f903c3c613e Mon Sep 17 00:00:00 2001 From: bach Date: Sat, 5 Sep 2026 11:02:01 +0200 Subject: [PATCH] Show the drill-down's own totals in the footer, not the year's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clicking an entrée's "N sorties liées" badge drills down to just that entrée + its linked sorties (filterEntreeId) -- but the footer kept showing the current year's totals throughout, which answers a different question than the one this view exists for ("does this entrée balance against what was paid out"). drilldownTotals() computes the same shape locally (montant_ht/ttc, écart, par_compte) from the already-loaded drill-down rows -- no server round-trip needed, unlike the per-year figures. footerTotals() picks between it and currentYearTotals depending on whether filterEntreeId is set, so the footer swaps automatically and reverts the moment the drill-down is cleared. Verified: montant_ht and every compte column match the drill-down's two rows summed by hand exactly (to the cent), and closing the drill-down correctly restores the normal per-year footer. --- .../custom/figli_compta_ledger/js/home.js | 38 +++++++++++++++++++ .../templates/figli-compta-home.html.twig | 15 +++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/web/modules/custom/figli_compta_ledger/js/home.js b/web/modules/custom/figli_compta_ledger/js/home.js index 785b6d6..0be93c9 100644 --- a/web/modules/custom/figli_compta_ledger/js/home.js +++ b/web/modules/custom/figli_compta_ledger/js/home.js @@ -336,6 +336,44 @@ return true; }); }, + // Footer totals while drilled down into one entrée + its linked + // sorties (see filteredRows' drill-down branch above): the whole + // point of this view is "does this entrée balance against what was + // paid out", so the footer should answer exactly that instead of + // the current year's totals -- and it can be computed locally + // (unlike the per-year figures, this handful of rows is already + // fully loaded), no server round-trip needed. Same shape as + // /lignes/api/totaux so the template can render either the same + // way. + drilldownTotals() { + if (!this.filterEntreeId) return null; + let montantHt = 0; + let montantTtc = 0; + let ecart = 0; + const parCompte = {}; + for (const r of this.filteredRows) { + montantHt += r.montant_ht || 0; + montantTtc += r.montant_ttc || 0; + ecart += r.ecart || 0; + for (const [c, v] of Object.entries(r.parCompte)) { + parCompte[c] = (parCompte[c] || 0) + v; + } + } + const round = (v) => Math.round(v * 100) / 100; + return { + montant_ht: round(montantHt), + montant_ttc: round(montantTtc), + ecart: round(ecart), + par_compte: Object.fromEntries(Object.entries(parCompte).map(([c, v]) => [c, round(v)])), + }; + }, + // What the footer actually renders -- the drill-down's own totals + // while active, otherwise the current year's (see + // detectCurrentYear()/loadCurrentYearTotals()). Switches back + // automatically the moment filterEntreeId clears. + footerTotals() { + return this.filterEntreeId ? this.drilldownTotals : this.currentYearTotals; + }, groupedRows() { const list = this.filteredRows; if (this.groupBy === 'none') return list; diff --git a/web/modules/custom/figli_compta_ledger/templates/figli-compta-home.html.twig b/web/modules/custom/figli_compta_ledger/templates/figli-compta-home.html.twig index 7640b35..5a3b034 100644 --- a/web/modules/custom/figli_compta_ledger/templates/figli-compta-home.html.twig +++ b/web/modules/custom/figli_compta_ledger/templates/figli-compta-home.html.twig @@ -182,13 +182,16 @@ - Solde {{ currentYear || '…' }} (créditeur / débiteur) - chargement… + + - {{ currentYearTotals ? formatEur(currentYearTotals.montant_ht) : '' }} - {{ currentYearTotals ? formatEur(currentYearTotals.montant_ttc) : '' }} - {{ currentYearTotals && currentYearTotals.par_compte[c] !== undefined ? formatEur(currentYearTotals.par_compte[c]) : '' }} - {{ currentYearTotals ? formatEur(currentYearTotals.ecart) : '' }} + {{ footerTotals ? formatEur(footerTotals.montant_ht) : '' }} + {{ footerTotals ? formatEur(footerTotals.montant_ttc) : '' }} + {{ footerTotals && footerTotals.par_compte[c] !== undefined ? formatEur(footerTotals.par_compte[c]) : '' }} + {{ footerTotals ? formatEur(footerTotals.ecart) : '' }}