diff --git a/modules/budget/views/suivi.php b/modules/budget/views/suivi.php index c9b875e..0ff0bff 100644 --- a/modules/budget/views/suivi.php +++ b/modules/budget/views/suivi.php @@ -19,9 +19,8 @@ $nextLink = "?tab=suivi&m=$nextM&y=$nextY"; $todayLink = "?tab=suivi"; // ============================================================================ -// NOUVEAU : CONFIGURATION DU CYCLE (Dates personnalisées) +// CONFIGURATION DU CYCLE (Dates personnalisées) // ============================================================================ -// 1. On lit la configuration du mois en cours $stmtConfig = $pdo->prepare("SELECT content FROM pf_notes WHERE note_type = 'month_config' AND reference_id = ?"); $stmtConfig->execute([$currentMonthKey]); $configJson = $stmtConfig->fetchColumn(); @@ -30,14 +29,12 @@ $monthConfig = $configJson ? json_decode($configJson, true) : null; $customStartDate = $monthConfig['start_date'] ?? "$currentYear-$currentMonth-01"; $customStartBalance = $monthConfig['start_balance'] ?? 0; -// 2. On lit la configuration du mois SUIVANT pour fermer le cycle proprement $nextMonthKey = str_pad($nextM, 2, '0', STR_PAD_LEFT) . '-' . $nextY; $stmtNextConfig = $pdo->prepare("SELECT content FROM pf_notes WHERE note_type = 'month_config' AND reference_id = ?"); $stmtNextConfig->execute([$nextMonthKey]); $nextConfigJson = $stmtNextConfig->fetchColumn(); $nextConfig = $nextConfigJson ? json_decode($nextConfigJson, true) : null; -// La date de fin est soit la veille du prochain cycle, soit la fin du mois calendaire if ($nextConfig && !empty($nextConfig['start_date'])) { $customEndDate = date('Y-m-d', strtotime($nextConfig['start_date'] . ' -1 day')); } else { @@ -177,8 +174,8 @@ $reste_a_venir = 0; $today_day = (int)date('j'); $fixedChargesList = []; $incomeList = []; +$pending_charges = []; // Stockage détaillé des charges à venir -// MODIFICATION : Les requêtes ciblent désormais les bornes du CYCLE personnalisé, plus le mois strict ! $stmtIds = $pdo->prepare("SELECT DISTINCT budget_item_id FROM pf_expenses WHERE date_exp >= ? AND date_exp <= ? AND budget_item_id IS NOT NULL"); $stmtIds->execute([$customStartDate, $customEndDate]); $paidItemIds = $stmtIds->fetchAll(PDO::FETCH_COLUMN); @@ -234,7 +231,10 @@ while ($item = $stmt->fetch(PDO::FETCH_ASSOC)) { } } } - if (!$isPaid) $reste_a_venir += $absAmount; + if (!$isPaid) { + $reste_a_venir += $absAmount; + $pending_charges[] = ['name' => $name, 'amount' => $absAmount]; + } } if ($name === 'Estimacio F&B & beauty') $budget_fmcg = $amt; @@ -283,7 +283,7 @@ $categoriesConfig['LivretA'] = ['type'=>'debit', 'label'=>'Epargne', 'budget'=>0 // ============================================================================ $csvData = []; $showPreview = false; -// ... (Gestion CSV Upload inchangée ici) + if (isset($_FILES['csv_file']) && $_FILES['csv_file']['error'] == 0) { $file = $_FILES['csv_file']['tmp_name']; $handle = fopen($file, "r"); @@ -311,7 +311,6 @@ if (isset($_FILES['csv_file']) && $_FILES['csv_file']['error'] == 0) { $showPreview = true; } -// MODIFICATION : Dépenses ciblées sur les bornes du cycle ! $stmt = $pdo->prepare("SELECT * FROM pf_expenses WHERE date_exp >= ? AND date_exp <= ? ORDER BY date_exp DESC"); $stmt->execute([$customStartDate, $customEndDate]); $allExpenses = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -330,7 +329,6 @@ foreach ($allExpenses as $exp) { $val = (float)$exp['amount']; - // 1. UI Cards if ($cat === 'Income') { $totals[$cat] += $val; } else { @@ -339,26 +337,29 @@ foreach ($allExpenses as $exp) { } $expensesByCategory[$cat][] = $exp; - // 2. Mathématiques pures if ($val > 0) { if ($cat === 'Income' || $cat !== 'Frais') { - $total_rentrees += $val; // Rentrées d'argent + $total_rentrees += $val; } else { - $depenses_reelles -= $val; // Remboursement d'une charge fixe + $depenses_reelles -= $val; } } else { $depenses_reelles += abs($val); } } -// 3. Calcul de la Capacité Max Dynamique $rentrees_salaires_reels = $totals['Income']; $rentrees_autres = $total_rentrees - $rentrees_salaires_reels; - -// Capacité Max = Solde de départ + (le plus grand entre le salaire prévu et reçu) + rentrées annexes $capacite_max = $solde_initial + max($rentrees_salaires_reels, $budget_income_prevu) + $rentrees_autres; -// SOLDE THÉORIQUE = Solde initial + Toutes les rentrées réelles - Dépenses - Charges à venir +// Ajout du reste estimé pour l'École dans les charges à venir +$ecole_depense = isset($totals['School']) ? $totals['School'] : 0; +$reste_ecole = max(0, $budget_school - $ecole_depense); +if ($reste_ecole > 0) { + $reste_a_venir += $reste_ecole; + $pending_charges[] = ['name' => 'École / Garde (Reste estimé)', 'amount' => $reste_ecole]; +} + $solde_theorique = ($solde_initial + $total_rentrees) - $depenses_reelles - $reste_a_venir; $solde_net = max(0, $solde_actuel - $reste_a_venir); @@ -428,11 +429,27 @@ $cycleDisplay = date('d/m', strtotime($customStartDate)) . ' au ' . date('d/m', -
-
Charges fixes à venir
+
+
+ Charges à venir + +
-
+ +
@@ -822,13 +839,11 @@ $cycleDisplay = date('d/m', strtotime($customStartDate)) . ' au ' . date('d/m',