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) : '' }}