prepare($sql); foreach ($budgets as $category => $amount) { if (is_numeric($amount) && $amount >= 0) { $stmt->execute([ 'client_id' => $client_id, 'user_id' => $user_id, 'category' => $category, 'amount' => $amount, 'budget_month' => $posted_month ]); } } $success_message = 'Orçamentos salvos com sucesso!'; // Redirecionar para o mesmo mês para mostrar a atualização header('Location: budgets.php?month=' . date('Y-m', strtotime($posted_month))); exit; } catch (PDOException $e) { $error_message = 'Erro ao salvar orçamentos: ' . $e->getMessage(); } } // Buscar orçamentos existentes para o mês selecionado $existing_budgets = []; try { $stmt = $pdo->prepare("SELECT category, amount FROM budgets WHERE client_id = :client_id AND budget_month = :budget_month"); $stmt->execute(['client_id' => $client_id, 'budget_month' => $budget_month_date]); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($results as $row) { $existing_budgets[$row['category']] = $row['amount']; } } catch (PDOException $e) { $error_message = "Erro ao buscar orçamentos existentes."; } // Obter todas as categorias (macro áreas ativas) para os dropdowns $stmt_categories = $pdo->prepare("SELECT nome, slug FROM macro_areas WHERE client_id = :client_id AND ativo = 1 ORDER BY nome ASC"); $stmt_categories->execute(['client_id' => $client_id]); $categories = $stmt_categories->fetchAll(PDO::FETCH_ASSOC); include __DIR__ . '/includes/header.php'; ?>

Gerenciar Orçamentos


' . htmlspecialchars($_SESSION['success_message']) . '
'; unset($_SESSION['success_message']); }?>

Orçamentos para

R$