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:
Manus
2026-06-08 10:38:58 -04:00
parent ed01a07105
commit 43cacda7ad
2 changed files with 18 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
{
"query": "DELETE FROM freeproVentilationLines WHERE importId IN (SELECT id FROM freeproImports); DELETE FROM freeproImports;",
"command": "mysql --batch --raw --column-names --default-character-set=utf8mb4 --host gateway02.us-east-1.prod.aws.tidbcloud.com --port 4000 --user 4CrrYuB5tme73Qo.bd4328423008 --database fo4DRyBgjsuiigFAgNLuWm --execute DELETE FROM freeproVentilationLines WHERE importId IN (SELECT id FROM freeproImports); DELETE FROM freeproImports;",
"rows": [],
"messages": [],
"stdout": "",
"stderr": "",
"execution_time_ms": 370
}

View File

@@ -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). // car la somme ligne par ligne peut différer (remises globales, arrondis, taxes spécifiques).
const officialTotalTtc = invoice.amount > 0 ? invoice.amount : processed.totalTtc; 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( await createFreeproImport(
{ {
userId, userId,
@@ -530,7 +538,7 @@ export async function runFreeproAutoImport(userId: number): Promise<AutoImportRe
processed.lines.map((l) => ({ processed.lines.map((l) => ({
structure: l.structure ?? null, structure: l.structure ?? null,
type: l.type, type: l.type,
montantCentimes: Math.round(l.montant * 100), montantCentimes: Math.round(l.montant * redistributionFactor * 100),
})) }))
); );