@@ -101,13 +101,17 @@ $totalRevenus = 0;
|
|||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<?php foreach ($items as $item):
|
<?php
|
||||||
|
// Initialisation du tableau de verrouillage des catégories avant la boucle
|
||||||
|
$usedCategories = [];
|
||||||
|
|
||||||
|
foreach ($items as $item):
|
||||||
// 1. Calculs de base
|
// 1. Calculs de base
|
||||||
$targetAbs = abs((float)$item['amount']);
|
$targetAbs = abs((float)$item['amount']);
|
||||||
$amountToAdd = ($item['type'] === 'Annuel') ? $targetAbs / 12 : $targetAbs;
|
$amountToAdd = ($item['type'] === 'Annuel') ? $targetAbs / 12 : $targetAbs;
|
||||||
$totalDepenses += $amountToAdd;
|
$totalDepenses += $amountToAdd;
|
||||||
|
|
||||||
// 2. RÉINITIALISATION STRICTE ET CALCUL DU RÉEL
|
// 2. RÉINITIALISATION STRICTE
|
||||||
$realSum = 0;
|
$realSum = 0;
|
||||||
$hasMatchingExpense = false;
|
$hasMatchingExpense = false;
|
||||||
|
|
||||||
@@ -116,12 +120,14 @@ $totalRevenus = 0;
|
|||||||
$realSum = (float)$realTotalsById[$item['id']];
|
$realSum = (float)$realTotalsById[$item['id']];
|
||||||
$hasMatchingExpense = true;
|
$hasMatchingExpense = true;
|
||||||
}
|
}
|
||||||
// B. Correspondance par Catégorie système (Priorité 2 : rattrape les NULL de Juin)
|
// B. Correspondance par Catégorie (Priorité 2 : avec verrouillage pour éviter le cumul)
|
||||||
elseif (!empty($item['category']) && isset($realTotalsByCat[$item['category']])) {
|
elseif (!empty($item['category']) && isset($realTotalsByCat[$item['category']]) && !isset($usedCategories[$item['category']])) {
|
||||||
$realSum = (float)$realTotalsByCat[$item['category']];
|
$realSum = (float)$realTotalsByCat[$item['category']];
|
||||||
$hasMatchingExpense = true;
|
$hasMatchingExpense = true;
|
||||||
|
// On marque la catégorie comme "consommée" pour ne pas la recompter sur la ligne suivante
|
||||||
|
$usedCategories[$item['category']] = true;
|
||||||
}
|
}
|
||||||
// C. Correspondance par mots-clés bancaires (Priorité 3 : affinement manuel)
|
// C. Correspondance par mots-clés bancaires (Priorité 3)
|
||||||
elseif (!empty($item['mapping_keywords'])) {
|
elseif (!empty($item['mapping_keywords'])) {
|
||||||
$keywords = array_map('trim', explode(',', $item['mapping_keywords']));
|
$keywords = array_map('trim', explode(',', $item['mapping_keywords']));
|
||||||
foreach ($unlinkedExpenses as $uexp) {
|
foreach ($unlinkedExpenses as $uexp) {
|
||||||
@@ -135,9 +141,8 @@ $totalRevenus = 0;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Finalisation de la ligne
|
// 3. Finalisation des variables d'affichage
|
||||||
$realAbs = abs($realSum);
|
$realAbs = abs($realSum);
|
||||||
// Un item est validé si le montant réel est proche du prévu
|
|
||||||
$isAutoChecked = ($hasMatchingExpense && ($realAbs >= ($targetAbs - 0.10)));
|
$isAutoChecked = ($hasMatchingExpense && ($realAbs >= ($targetAbs - 0.10)));
|
||||||
$rowClass = 'row-expense' . ($item['is_estimate'] ? ' row-estimate' : '');
|
$rowClass = 'row-expense' . ($item['is_estimate'] ? ' row-estimate' : '');
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user