From 6e1c421e5b235c9613f89f9d2601137524114f94 Mon Sep 17 00:00:00 2001 From: bach Date: Wed, 9 Sep 2026 21:42:17 +0200 Subject: [PATCH] =?UTF-8?q?ecarts=20de=200.01=E2=82=AC=20visible=20dans=20?= =?UTF-8?q?le=20tableau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/figli_compta_ledger/js/home.js | 7 ++++++- .../custom/figli_compta_ledger/js/ledger-form.js | 16 ++++++++++++---- .../src/Controller/LedgerRowsController.php | 8 +++++++- 3 files changed, 25 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 7e99bbc..e79010c 100644 --- a/web/modules/custom/figli_compta_ledger/js/home.js +++ b/web/modules/custom/figli_compta_ledger/js/home.js @@ -445,7 +445,12 @@ parCompte, somme, ecart, - hasError: Math.abs(ecart) > 0.01, + // Visible écart = non-zero to the centime (a 0.01 mismatch is + // savable -- the blocking threshold stays at 0.01 server-side -- + // but must still be shown; mirrors LedgerRowsController's + // hasError). 0.005 guards against float representation of + // stored centimes. + hasError: Math.abs(ecart) > 0.005, linkable: LINKABLE_TYPES.includes(attrs.field_type_ligne), entreeLieeIds: entreeLieeNodes.map((n) => n.id), entreeLieeLabels: entreeLieeNodes.map((n) => n.attributes.title || n.id), diff --git a/web/modules/custom/figli_compta_ledger/js/ledger-form.js b/web/modules/custom/figli_compta_ledger/js/ledger-form.js index cb7e290..c39823a 100644 --- a/web/modules/custom/figli_compta_ledger/js/ledger-form.js +++ b/web/modules/custom/figli_compta_ledger/js/ledger-form.js @@ -154,8 +154,10 @@ * remainder is negative; * - triggers: row added/removed (Paragraphs AJAX re-render -> * behavior attach), HT change, manual amount edit; - * - live "Réparti / Écart" line under the widget, mirroring the - * server's round(HT − somme, 2) and its 0.01 tolerance. + * - live "Réparti / Écart" line in the widget's title cell: green when + * the écart is zero to the centime, red otherwise (a 0.01 écart is + * savable -- blocking stays at 0.01 server-side -- but is shown, + * same as /lignes does). * * "Manual vs assist" detection rests on a DOM property: assigning * input.value programmatically fires no event, only a real user edit @@ -338,8 +340,14 @@ row.querySelector('.figli-repartition-ecart-sum').textContent = 'Réparti : ' + eur(somme); var val = row.querySelector('.figli-repartition-ecart-val'); val.textContent = isNaN(ecart) ? 'Écart : —' : 'Écart : ' + eur(ecart); - row.classList.toggle('is-ok', !isNaN(ecart) && Math.abs(ecart) <= 0.01); - row.classList.toggle('is-ko', !isNaN(ecart) && Math.abs(ecart) > 0.01); + // Green only when the écart is zero to the centime: a 0.01 + // mismatch is still savable (the server's blocking threshold + // stays at 0.01) but it IS an écart -- signaled here in red, + // exactly as /lignes now displays it (LedgerRowsController's + // hasError). 0.005 guards against float representations of + // centime values. + row.classList.toggle('is-ok', !isNaN(ecart) && Math.abs(ecart) <= 0.005); + row.classList.toggle('is-ko', !isNaN(ecart) && Math.abs(ecart) > 0.005); } // One delegated listener on the form (survives every Paragraphs diff --git a/web/modules/custom/figli_compta_ledger/src/Controller/LedgerRowsController.php b/web/modules/custom/figli_compta_ledger/src/Controller/LedgerRowsController.php index d66f1ef..159c63b 100644 --- a/web/modules/custom/figli_compta_ledger/src/Controller/LedgerRowsController.php +++ b/web/modules/custom/figli_compta_ledger/src/Controller/LedgerRowsController.php @@ -172,7 +172,13 @@ class LedgerRowsController extends ControllerBase { 'parCompte' => (object) $parCompte, 'somme' => $somme, 'ecart' => $ecart, - 'hasError' => abs($ecart) > 0.01, + // "Écart visible" == non-zero to the centime. The presave/validation + // BLOCKING threshold stays at > 0.01 (tolerated rounding noise is + // savable), but a 0.01 écart is still a real mismatch and must be + // shown in the table -- at > 0.01 here it displayed nothing at all. + // 0.005 (not 0.0) keeps float representations of stored centimes + // from misclassifying. + 'hasError' => abs($ecart) > 0.005, 'linkable' => in_array($type, self::LINKABLE_TYPES, TRUE), 'entreeLieeIds' => array_map(fn ($n) => $n->uuid(), $entreeLieeNodes), 'entreeLieeLabels' => array_map(fn ($n) => $n->getTitle() ?: $n->uuid(), $entreeLieeNodes),