Ajoute la TVA (%) et calcule automatiquement le Montant TTC

Architecture : Montant HT reste saisi à la main, un nouveau champ TVA
(%) le complète, et Montant TTC = round(HT * (1 + TVA/100), 2) devient
une valeur calculée plutôt que saisie -- champ readonly dans le
formulaire (aperçu live en JS), calcul faisant foi côté serveur dans
figli_compta_ledger_node_presave().

Migration (update hooks 8004/8005) : Montant TTC n'est **jamais**
modifié pour les données historiques -- seul un TVA effectif est
rétro-calculé depuis HT/TTC existants et ajouté en tant que nouvelle
métadonnée (1498 lignes renseignées, 58 laissées vides faute de TTC
source). Précision du champ TVA fixée à 4 décimales après vérification
empirique sur les 1556 lignes existantes : reconstruire TTC = HT * (1 +
TVA/100) avec un taux arrondi à 4 décimales ne s'écarte du TTC réel que
pour 9 lignes (probables factures multi-taux), contre 74 à 2 décimales.

Garde-fou supplémentaire dans le presave : le recalcul du TTC ne se
déclenche que si HT ou TVA ont réellement changé par rapport à la
révision précédente (comparaison à $node->original) -- sans ça,
rouvrir une ancienne ligne migrée pour corriger un simple libellé
aurait silencieusement dérivé son TTC historique de ±0,01€ à cause de
l'arrondi du taux rétro-calculé, ce qu'interdit la règle du projet de
ne jamais corriger les données historiques.

Réorganisation du formulaire : N° Facture rejoint Client sur une même
ligne, Montant HT/TVA/Montant TTC forment la ligne suivante -- les
poids de champs doivent rester des entiers (Drupal tronque silencieusement
tout poids fractionnaire lors de la sauvegarde de l'affichage).
This commit is contained in:
2026-09-07 11:36:53 +02:00
parent f00f680143
commit b7490eb76a
9 changed files with 354 additions and 29 deletions
@@ -59,12 +59,14 @@ html.gin--dark-mode .figli-ledger-form {
display: none;
}
/* Row layout. Everything not listed here (Montant HT / N° Facture /
Montant TTC) is left to grid auto-placement, which -- given they're
the only three single-column items appearing consecutively in DOM
order -- lines them up as one row of three for free. */
/* Row layout, fully explicit (not left to grid auto-placement) --
there are now two separate 1-col-plus-2-col row groupings (Client +
N° Facture, then Montant HT + TVA + Montant TTC) and relying on DOM
order alone to keep them from bleeding into each other got fragile
once a 4th financial field (TVA) entered the picture. This must stay
in sync with the field weights set in
figli_compta_ledger_update_8004()/_figli_compta_ledger_create_node_type_ligne_comptable(). */
.figli-ledger-form > .field--name-title,
.figli-ledger-form > .field--name-field-client,
.figli-ledger-form > .field--name-field-entree-liee,
.figli-ledger-form > .field--name-field-repartition,
.figli-ledger-form > .field--name-field-notes,
@@ -77,6 +79,21 @@ html.gin--dark-mode .figli-ledger-form {
.figli-ledger-form > .field--name-field-type-ligne {
grid-column: 2 / 4;
}
.figli-ledger-form > .field--name-field-client {
grid-column: 1 / 3;
}
.figli-ledger-form > .field--name-field-numero-facture {
grid-column: 3 / 4;
}
.figli-ledger-form > .field--name-field-montant-ht {
grid-column: 1 / 2;
}
.figli-ledger-form > .field--name-field-tva {
grid-column: 2 / 3;
}
.figli-ledger-form > .field--name-field-montant-ttc {
grid-column: 3 / 4;
}
/* Field basics */
.figli-ledger-form .form-item__label {
@@ -118,6 +135,14 @@ html.gin--dark-mode .figli-ledger-form {
outline: 2px solid var(--flform-accent);
outline-offset: 1px;
}
/* Montant TTC: readonly, computed from HT + TVA (see
figli_compta_ledger_node_presave()) -- a faint fill instead of the
plain white/transparent of an editable field reads as "there but not
for you to type in" without looking disabled/greyed-out. */
.figli-ledger-form input[readonly].form-element {
background: var(--flform-bg-subtle);
cursor: default;
}
.figli-ledger-form input[type="date"].form-element {
width: auto;
min-width: 9.5rem;