Checkpoint: Correction des montants des lignes de ventilation : application d'un coefficient de redistribution proportionnel (totalTtc_officiel / totalTtc_calculé) sur chaque ligne pour que leur somme corresponde exactement au total TTC officiel FreePro. Les montants sont maintenant cohérents avec le portail.
This commit is contained in:
@@ -516,6 +516,14 @@ export async function runFreeproAutoImport(userId: number): Promise<AutoImportRe
|
||||
// car la somme ligne par ligne peut différer (remises globales, arrondis, taxes spécifiques).
|
||||
const officialTotalTtc = invoice.amount > 0 ? invoice.amount : processed.totalTtc;
|
||||
|
||||
// Calculer le coefficient de redistribution pour que la somme des lignes
|
||||
// corresponde exactement au total TTC officiel FreePro.
|
||||
// Si le total calculé depuis les lignes (processed.totalTtc) diffère du total
|
||||
// officiel (officialTotalTtc), on applique un facteur proportionnel sur chaque ligne.
|
||||
const calculatedTotal = processed.totalTtc;
|
||||
const redistributionFactor =
|
||||
calculatedTotal > 0 ? officialTotalTtc / calculatedTotal : 1;
|
||||
|
||||
await createFreeproImport(
|
||||
{
|
||||
userId,
|
||||
@@ -530,7 +538,7 @@ export async function runFreeproAutoImport(userId: number): Promise<AutoImportRe
|
||||
processed.lines.map((l) => ({
|
||||
structure: l.structure ?? null,
|
||||
type: l.type,
|
||||
montantCentimes: Math.round(l.montant * 100),
|
||||
montantCentimes: Math.round(l.montant * redistributionFactor * 100),
|
||||
}))
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user