Cotisation diffuseur URSSAF (1,1%) : nouveau champ, TTC calculé en cascade
Architecture métier corrigée : la SAS devise HT, ajoute (quand
applicable -- pas systématique) 1,1% de cotisation diffuseur URSSAF
pour l'usage de freelances, puis applique la TVA sur ce montant
augmenté -- pas sur le HT brut. La répartition entre comptes reste
basée sur le HT seul, inchangée.
- field_cotisation_active (case à cocher, "Entrée client" uniquement,
cochée par défaut sur une nouvelle ligne -- optionnelle puisque tous
les devis ne l'incluent pas historiquement).
- field_cotisation_urssaf ("1,1%", montant calculé HT × 1,011, jamais
éditable).
- Montant TTC = round(cotisation × (1 + TVA/100), 2) quand la
cotisation s'applique, round(HT × (1 + TVA/100), 2) sinon --
inchangé pour tous les types hors "Entrée client".
Migration (update hooks 8006/8007) : toutes les lignes "Entrée client"
de field_tva rétro-calculées par figli_compta_ledger_update_8005()
étaient fausses dès que la cotisation s'appliquait (taux mixte HT->TTC,
pas le vrai taux de TVA) -- corrigées avec la même prudence que la
migration précédente : 2021 laissée de côté (pratique non confirmée
sur cette année), et par ligne, un taux déjà "propre" (0/2,1/5,5/10/20
%) signifie qu'aucune cotisation n'a été appliquée (laissé tel quel) ;
sinon le nouveau taux recalculé n'est retenu que s'il retombe lui-même
sur un taux officiel, sinon la ligne reste inchangée plutôt que de
deviner. Montant TTC historique jamais réécrit, comme pour toute
migration de ce module. Résultat : 154 lignes corrigées (cotisation
active), 90 déjà correctes (cotisation inactive), 40 ambiguës laissées
telles quelles, 43 lignes 2021 ignorées.
Formulaire réorganisé en grille à 4 colonnes (HT | 1,1% | TVA | TTC),
case à cocher masquée hors "Entrée client" via #states réel (fiable
ici, contrairement au select TVA -- watch sur field_type_ligne, un
vrai champ, pas un élément ajouté à la main). Colonne "1,1%" ajoutée
au grand livre entre HT et TVA.
This commit is contained in:
@@ -369,6 +369,7 @@
|
||||
facture: attrs.field_numero_facture || null,
|
||||
libelle: attrs.field_notes || attrs.title,
|
||||
montant_ht: montantHt,
|
||||
cotisation: attrs.field_cotisation_urssaf !== null && attrs.field_cotisation_urssaf !== undefined ? parseFloat(attrs.field_cotisation_urssaf) : null,
|
||||
tva: attrs.field_tva !== null && attrs.field_tva !== undefined ? parseFloat(attrs.field_tva) : null,
|
||||
montant_ttc: attrs.field_montant_ttc !== null && attrs.field_montant_ttc !== undefined ? parseFloat(attrs.field_montant_ttc) : null,
|
||||
parCompte,
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
var tva = form.querySelector('[name="field_tva[0][value]"]');
|
||||
var rate = form.querySelector('[name="field_tva_rate"]');
|
||||
var ttc = form.querySelector('[name="field_montant_ttc[0][value]"]');
|
||||
var type = form.querySelector('[name="field_type_ligne"]');
|
||||
var cotisationActive = form.querySelector('[name="field_cotisation_active[value]"]');
|
||||
var cotisationAmount = form.querySelector('[name="field_cotisation_urssaf[0][value]"]');
|
||||
if (!tva || !ttc) {
|
||||
return;
|
||||
}
|
||||
@@ -42,6 +45,13 @@
|
||||
return parseFloat(tva.value);
|
||||
}
|
||||
|
||||
// Mirrors figli_compta_ledger_node_presave()'s $cotisation_applies:
|
||||
// only "Entrée client" lines with the checkbox on ever go through
|
||||
// the +1,1% step before TVA.
|
||||
function cotisationApplies() {
|
||||
return !!type && type.value === 'entree' && !!cotisationActive && cotisationActive.checked;
|
||||
}
|
||||
|
||||
function recompute() {
|
||||
var htValue = parseFloat(ht.value);
|
||||
if (isNaN(htValue)) {
|
||||
@@ -51,7 +61,17 @@
|
||||
if (isNaN(tvaValue)) {
|
||||
tvaValue = 0;
|
||||
}
|
||||
ttc.value = (htValue * (1 + tvaValue / 100)).toFixed(2);
|
||||
var base = htValue;
|
||||
if (cotisationApplies()) {
|
||||
base = Math.round(htValue * 1.011 * 100) / 100;
|
||||
if (cotisationAmount) {
|
||||
cotisationAmount.value = base.toFixed(2);
|
||||
}
|
||||
}
|
||||
else if (cotisationAmount) {
|
||||
cotisationAmount.value = '';
|
||||
}
|
||||
ttc.value = (base * (1 + tvaValue / 100)).toFixed(2);
|
||||
}
|
||||
|
||||
// Deliberately not called once up front on an existing (edit)
|
||||
@@ -60,17 +80,23 @@
|
||||
// the centime (see figli_compta_ledger_update_8005()'s
|
||||
// docblock) -- showing a recomputed number the instant the
|
||||
// modal opens, before the associate has touched anything, would
|
||||
// misrepresent what's actually saved. Only recompute once HT,
|
||||
// TVA, or the rate select are actually edited, matching the
|
||||
// same "only overwrite Montant TTC when HT/TVA actually
|
||||
// changed" guard in figli_compta_ledger_node_presave(). Harmless
|
||||
// no-op on a genuinely new/blank line either way (HT is empty,
|
||||
// recompute() bails out above).
|
||||
// misrepresent what's actually saved. Only recompute once an
|
||||
// actual input happens, matching the same "only overwrite
|
||||
// Montant TTC when an input actually changed" guard in
|
||||
// figli_compta_ledger_node_presave(). Harmless no-op on a
|
||||
// genuinely new/blank line either way (HT is empty, recompute()
|
||||
// bails out above).
|
||||
ht.addEventListener('input', recompute);
|
||||
tva.addEventListener('input', recompute);
|
||||
if (rate) {
|
||||
rate.addEventListener('change', recompute);
|
||||
}
|
||||
if (type) {
|
||||
type.addEventListener('change', recompute);
|
||||
}
|
||||
if (cotisationActive) {
|
||||
cotisationActive.addEventListener('change', recompute);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user