-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexDashboard.php
129 lines (110 loc) · 5.05 KB
/
indexDashboard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
<link rel="stylesheet" href="styleGeral.css">
<link rel="stylesheet" href="styleDashboard.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
</head>
<body>
<div class="container">
<!-- Contêiner para o menu dinâmico -->
<div id="main-menu"></div>
<!-- Dashboard principal -->
<main class="dashboard">
<header>
<h1 class="merriweather-black">DASHBOARD</h1>
<p class="poppins-regular">Bem vindo(a), <span id="welcome-user-name">Fulano</span>!</p>
</header>
<?php
include 'conexao.php';
try {
// Calcula o total de receitas
$sqlReceitas = "SELECT SUM(valor) AS total_receitas FROM receitas";
$stmtReceitas = $pdo->prepare($sqlReceitas);
$stmtReceitas->execute();
$totalReceitas = $stmtReceitas->fetch(PDO::FETCH_ASSOC)['total_receitas'] ?? 0;
// Calcula o total de gastos
$sqlGastos = "SELECT SUM(valor) AS total_gastos FROM gastos";
$stmtGastos = $pdo->prepare($sqlGastos);
$stmtGastos->execute();
$totalGastos = $stmtGastos->fetch(PDO::FETCH_ASSOC)['total_gastos'] ?? 0;
// Calcula o saldo atual
$saldoAtual = $totalReceitas - $totalGastos;
} catch (PDOException $e) {
echo "<p>Erro ao calcular os valores: " . $e->getMessage() . "</p>";
$totalReceitas = 0;
$totalGastos = 0;
$saldoAtual = 0;
}
?>
<section class="cards">
<!-- Cartões de resumo -->
<div class="resume-cards">
<div class="summary-card saldo">
<p class="poppins-regular">Saldo Atual:</p>
<h2>R$ <?php echo number_format($saldoAtual, 2, ',', '.'); ?></h2>
</div>
<div class="summary-card gastos">
<p class="poppins-regular">Gastos:</p>
<h2>R$ <?php echo number_format($totalGastos, 2, ',', '.'); ?></h2>
</div>
<div class="summary-card receitas">
<p class="poppins-regular">Receitas:</p>
<h2>R$ <?php echo number_format($totalReceitas, 2, ',', '.'); ?></h2>
</div>
</div>
<!-- Cartões de categorias -->
<div class="category-cards">
<div class="category-card gastos-categorias">
<h3 class="poppins-regular">Categorias de Gastos:</h3>
<ul>
<?php
// Consulta de categorias de gastos e seus valores
$sqlGastosCategoria = "SELECT categoria, SUM(valor) AS total FROM gastos GROUP BY categoria";
$stmtGastosCategoria = $pdo->prepare($sqlGastosCategoria);
$stmtGastosCategoria->execute();
$categoriasGastos = $stmtGastosCategoria->fetchAll(PDO::FETCH_ASSOC);
foreach ($categoriasGastos as $gasto) {
echo "<li>";
echo "<span class='category-name'>" . htmlspecialchars($gasto['categoria']) . "</span>";
echo "<span class='category-value'>R$ " . number_format($gasto['total'], 2, ',', '.') . "</span>";
echo "</li>";
}
?>
</ul>
</div>
<div class="category-card receitas-categorias">
<h3 class="poppins-regular">Categorias de Receitas:</h3>
<ul>
<?php
// Consulta de categorias de receitas e seus valores
$sqlReceitasCategoria = "SELECT categoria, SUM(valor) AS total FROM receitas GROUP BY categoria";
$stmtReceitasCategoria = $pdo->prepare($sqlReceitasCategoria);
$stmtReceitasCategoria->execute();
$categoriasReceitas = $stmtReceitasCategoria->fetchAll(PDO::FETCH_ASSOC);
foreach ($categoriasReceitas as $receita) {
echo "<li>";
echo "<span class='category-name'>" . htmlspecialchars($receita['categoria']) . "</span>";
echo "<span class='category-value'>R$ " . number_format($receita['total'], 2, ',', '.') . "</span>";
echo "</li>";
}
?>
</ul>
</div>
</div>
</section>
<!-- Footer -->
<footer class="footer">
<p>© 2024 Programação para a Web. Todos os direitos reservados.</p>
</footer>
</main>
</div>
<!-- Script -->
<script src="scriptGeral.js"></script>
<script src="scriptPerfil.js"></script>
<script src="scriptAddTransacao.js"></script>
</body>
</html>