diff --git a/modules/budget/includes/api/manage-item.php b/modules/budget/includes/api/manage-item.php
index 7565a16..af790db 100644
--- a/modules/budget/includes/api/manage-item.php
+++ b/modules/budget/includes/api/manage-item.php
@@ -10,18 +10,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($action === 'save') {
$id = $_POST['id'] ?? '';
$name = $_POST['name'];
- $amount = $_POST['amount'];
$category = $_POST['category'];
$type = $_POST['type'];
- $payment_day = $_POST['payment_day'];
+ $payment_day = empty($_POST['payment_day']) ? null : (int)$_POST['payment_day'];
$is_estimate = $_POST['is_estimate'];
$reg_month = $_POST['reg_month'];
-
$keywords = $_POST['mapping_keywords'] ?? '';
-
- // NOUVEAU : Récupération de l'ID des vacances
$holiday_id = !empty($_POST['holiday_id']) ? (int)$_POST['holiday_id'] : null;
+ // ==========================================
+ // NOUVELLE NORME COMPTABLE : Dépense = Négatif
+ // ==========================================
+ // On récupère le montant en valeur absolue (pour éviter les erreurs si l'utilisateur a tapé un '-')
+ $amount = abs((float)$_POST['amount']);
+
+ // Si c'est un frais, on l'enregistre en négatif
+ if ($category === 'expense') {
+ $amount = -$amount;
+ }
+ // ==========================================
+
if ($id) {
// UPDATE
$stmt = $pdo->prepare("UPDATE pf_budget_items SET name=?, amount=?, category=?, type=?, payment_day=?, is_estimate=?, reg_month=?, mapping_keywords=?, holiday_id=? WHERE id=?");
@@ -31,6 +39,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt = $pdo->prepare("INSERT INTO pf_budget_items (name, amount, category, type, payment_day, is_estimate, reg_month, mapping_keywords, holiday_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords, $holiday_id]);
}
+
+ // Redirection
header('Location: /budget.php?tab=recap');
exit;
}
diff --git a/modules/budget/views/epargne.php b/modules/budget/views/epargne.php
index 4e768d1..4b52cd5 100644
--- a/modules/budget/views/epargne.php
+++ b/modules/budget/views/epargne.php
@@ -123,7 +123,7 @@ input[type="number"].no-spinners {
- - = number_format($amount, 0, ',', ' ') ?> €
+ = number_format($amount, 0, ',', ' ') ?> €
|