diff --git a/modules/budget/includes/api/manage-item.php b/modules/budget/includes/api/manage-item.php index 7eee3c5..0a0b244 100644 --- a/modules/budget/includes/api/manage-item.php +++ b/modules/budget/includes/api/manage-item.php @@ -8,31 +8,30 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // --- ACTION : SAUVEGARDER (AJOUT OU MODIF) --- if ($action === 'save') { - $id = !empty($_POST['id']) ? $_POST['id'] : null; - $name = $_POST['name']; - $amount = str_replace(',', '.', $_POST['amount']); - $type = $_POST['type']; - $day = !empty($_POST['payment_day']) ? $_POST['payment_day'] : null; - $month = $_POST['reg_month'] ?: null; - $cat = $_POST['category']; - $is_estimate = isset($_POST['is_estimate']) ? (int)$_POST['is_estimate'] : 0; + $id = $_POST['id'] ?? ''; + $name = $_POST['name']; + $amount = $_POST['amount']; + $category = $_POST['category']; + $type = $_POST['type']; + $payment_day = $_POST['payment_day']; + $is_estimate = $_POST['is_estimate']; + $reg_month = $_POST['reg_month']; + + // NOUVEAU : Récupération des mots-clés + $keywords = $_POST['mapping_keywords'] ?? ''; - if ($id) { - // Update : on ajoute is_estimate - $sql = "UPDATE pf_budget_items SET name=?, amount=?, type=?, payment_day=?, reg_month=?, category=?, is_estimate=? WHERE id=?"; - $stmt = $pdo->prepare($sql); - $stmt->execute([$name, $amount, $type, $day, $month, $cat, $is_estimate, $id]); - } else { - // Insert : on ajoute is_estimate - $sql = "INSERT INTO pf_budget_items (name, amount, type, payment_day, reg_month, category, is_estimate) VALUES (?, ?, ?, ?, ?, ?, ?)"; - $stmt = $pdo->prepare($sql); - $stmt->execute([$name, $amount, $type, $day, $month, $cat, $is_estimate]); - } - - // Redirection après sauvegarde classique - header('Location: /budget.php?tab=recap'); - exit; + if ($id) { + // UPDATE + $stmt = $pdo->prepare("UPDATE pf_budget_items SET name=?, amount=?, category=?, type=?, payment_day=?, is_estimate=?, reg_month=?, mapping_keywords=? WHERE id=?"); + $stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords, $id]); + } else { + // INSERT + $stmt = $pdo->prepare("INSERT INTO pf_budget_items (name, amount, category, type, payment_day, is_estimate, reg_month, mapping_keywords) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords]); } + header('Location: /budget.php?tab=recap'); // Ou ta redirection habituelle + exit; +} // --- ACTION : COCHER/DÉCOCHER RAPIDE (VIA JS FETCH) --- if ($action === 'toggle-check') { diff --git a/modules/budget/views/recap.php b/modules/budget/views/recap.php index 3d96bcf..236b4cd 100644 --- a/modules/budget/views/recap.php +++ b/modules/budget/views/recap.php @@ -1,12 +1,20 @@ query("SELECT * FROM pf_budget_items ORDER BY category DESC, sort_order ASC, name ASC"); $items = $stmt->fetchAll(); -$totalDepensesMensuelles = 0; -$totalRevenusMensuels = 0; +// 2. Récupération des Dépenses Réelles du mois (Pour le matching auto) +$currentMonth = date('m'); +$currentYear = date('Y'); +$stmtExp = $pdo->prepare("SELECT label FROM pf_expenses WHERE MONTH(date_exp) = ? AND YEAR(date_exp) = ?"); +$stmtExp->execute([$currentMonth, $currentYear]); +// On stocke tous les libellés réels dans un tableau simple +$realExpensesLabels = $stmtExp->fetchAll(PDO::FETCH_COLUMN); + +$totalDepenses = 0; +$totalRevenus = 0; ?>
* Note : Les frais de type "Annuel" sont affichés pour information mais ne sont pas inclus dans le calcul de l'équilibre mensuel.
+* Les lignes marquées Auto ✅ ont été détectées automatiquement dans les dépenses réelles du mois.