111 lines
3.7 KiB
PHP
111 lines
3.7 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Statistiken</title>
|
|
<!-- Google Fonts -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
|
|
<!-- Tailwind CSS -->
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<style>
|
|
body {
|
|
font-family: 'Roboto', sans-serif;
|
|
background-color: #f3f4f6;
|
|
color: #111827;
|
|
}
|
|
.card {
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
|
|
}
|
|
.card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
|
|
}
|
|
.table-header {
|
|
background-color: #1f2937;
|
|
color: white;
|
|
}
|
|
.highlight {
|
|
color: #10b981; /* Grün für Gewinn */
|
|
font-weight: 500;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container mx-auto px-4 py-8">
|
|
<h1 class="text-3xl font-bold text-center mb-8 text-gray-800">Auftragsstatistiken</h1>
|
|
|
|
<?php
|
|
mysqli_set_charset($db, "utf8mb4");
|
|
|
|
$sql = "SELECT * FROM aufträge";
|
|
$result = mysqli_query($db, $sql);
|
|
|
|
$yearlyStats = array();
|
|
|
|
while ($row = mysqli_fetch_assoc($result)) {
|
|
$year = date('Y', strtotime($row['auftrag_beginn']));
|
|
|
|
if (!isset($yearlyStats[$year])) {
|
|
$yearlyStats[$year] = array(
|
|
'offeneAufträge' => 0,
|
|
'beendeteAufträge' => 0,
|
|
'umsatz' => 0,
|
|
'gewinn' => 0,
|
|
);
|
|
}
|
|
|
|
if ($row['beendet'] == '1') {
|
|
$yearlyStats[$year]['beendeteAufträge']++;
|
|
} else {
|
|
$yearlyStats[$year]['offeneAufträge']++;
|
|
}
|
|
|
|
$json = json_decode($row['materialien'], true);
|
|
$preis = $row['preis'];
|
|
|
|
$materialienSum = 0;
|
|
foreach ($json as $key => $value) {
|
|
$split = explode(":", $value);
|
|
$materialienSum += str_replace(',', '.', $split[1]);
|
|
}
|
|
|
|
$yearlyStats[$year]['umsatz'] += $preis;
|
|
$yearlyStats[$year]['gewinn'] += ($preis - $materialienSum);
|
|
}
|
|
|
|
krsort($yearlyStats);
|
|
|
|
foreach ($yearlyStats as $year => $stats) {
|
|
?>
|
|
<div class="card p-6 mb-6">
|
|
<h2 class="text-xl font-bold text-gray-700 mb-4">Statistiken für <span class="text-indigo-600"><?php echo $year; ?></span></h2>
|
|
<table class="w-full text-left border-collapse">
|
|
<thead class="table-header">
|
|
<tr>
|
|
<th class="p-3">Offene Aufträge</th>
|
|
<th class="p-3">Beendete Aufträge</th>
|
|
<th class="p-3">Gewinn</th>
|
|
<th class="p-3">Umsatz</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr class="bg-gray-50 hover:bg-gray-100">
|
|
<td class="p-3"><?php echo $stats['offeneAufträge']; ?></td>
|
|
<td class="p-3"><?php echo $stats['beendeteAufträge']; ?></td>
|
|
<td class="p-3 highlight"><?php echo number_format($stats['gewinn'], 2) . " €"; ?></td>
|
|
<td class="p-3"><?php echo number_format($stats['umsatz'], 2) . " €"; ?></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php
|
|
}
|
|
?>
|
|
</div>
|
|
</body>
|
|
</html>
|