Übersicht Kasse hinzugefügt
This commit is contained in:
187
kasse.php
Executable file
187
kasse.php
Executable file
@@ -0,0 +1,187 @@
|
|||||||
|
<?php
|
||||||
|
// PHP-Logik für die Datenabfrage
|
||||||
|
include('inc/check_login.php');
|
||||||
|
require_once('inc/db.php');
|
||||||
|
|
||||||
|
// --- 1. Jährliche Strafen-Statistik ---
|
||||||
|
// Passen Sie hier das Datum der Abschlussveranstaltung an.
|
||||||
|
$last_reset_date = '2024-01-01';
|
||||||
|
|
||||||
|
$penalties_data = [];
|
||||||
|
$total_penalties = 0;
|
||||||
|
$total_due = 0;
|
||||||
|
// Passen Sie hier die Höhe der Strafe in Euro an.
|
||||||
|
$penalty_amount = 1;
|
||||||
|
|
||||||
|
// SQL-Abfrage, um Strafen pro Benutzer seit dem letzten Reset-Datum zu zählen
|
||||||
|
// Strafe = anwesend (attended=1) aber Farbe nicht getragen (wore_color=0)
|
||||||
|
$sql_penalties = "
|
||||||
|
SELECT
|
||||||
|
u.username,
|
||||||
|
COUNT(mt.user_id) AS penalty_count
|
||||||
|
FROM meeting_teilnehmer mt
|
||||||
|
JOIN meetings m ON mt.meeting_id = m.id
|
||||||
|
JOIN users u ON mt.user_id = u.id
|
||||||
|
WHERE m.meeting_date >= ? AND mt.attended = 1 AND mt.wore_color = 0
|
||||||
|
GROUP BY u.username
|
||||||
|
ORDER BY penalty_count DESC
|
||||||
|
";
|
||||||
|
$stmt = mysqli_prepare($conn, $sql_penalties);
|
||||||
|
// Überprüfen, ob das Statement erfolgreich vorbereitet wurde
|
||||||
|
if ($stmt === false) {
|
||||||
|
die("Fehler bei der SQL-Abfrage: " . mysqli_error($conn));
|
||||||
|
}
|
||||||
|
mysqli_stmt_bind_param($stmt, "s", $last_reset_date);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
|
|
||||||
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
|
$penalties_data[] = $row;
|
||||||
|
$total_penalties += $row['penalty_count'];
|
||||||
|
$total_due += $row['penalty_count'] * $penalty_amount;
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
|
||||||
|
// Neue Statistik: Ranking nach bezahlten Strafen
|
||||||
|
$paid_stats = [];
|
||||||
|
$sql_paid = "
|
||||||
|
SELECT
|
||||||
|
u.username,
|
||||||
|
COUNT(mt.user_id) AS paid_count
|
||||||
|
FROM meeting_teilnehmer mt
|
||||||
|
JOIN users u ON mt.user_id = u.id
|
||||||
|
WHERE mt.paid = 1
|
||||||
|
GROUP BY u.username
|
||||||
|
ORDER BY paid_count ASC
|
||||||
|
";
|
||||||
|
$result_paid = mysqli_query($conn, $sql_paid);
|
||||||
|
while ($row = mysqli_fetch_assoc($result_paid)) {
|
||||||
|
$paid_stats[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'inc/header.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h2 class="mb-4">Kasse & Auswertung</h2>
|
||||||
|
|
||||||
|
<div class="card shadow mb-4">
|
||||||
|
<div class="card-header bg-danger-subtle text-danger">
|
||||||
|
<h4 class="mb-0">Strafen seit letztem Abschluss</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<p class="fs-5 fw-bold text-center">
|
||||||
|
Gesamtzahl der Strafen: <span class="badge bg-danger"><?= $total_penalties ?></span><br>
|
||||||
|
Fälliger Gesamtbetrag: <span class="text-danger fw-bold"><?= number_format($total_due, 2, ',', '.'); ?> €</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<?php if (empty($penalties_data)): ?>
|
||||||
|
<div class="alert alert-info text-center" role="alert">
|
||||||
|
Bisher wurden keine Strafen verzeichnet.
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-striped table-hover">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Benutzer</th>
|
||||||
|
<th>Anzahl Strafen</th>
|
||||||
|
<th>Fälliger Betrag</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach ($penalties_data as $penalty): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?= htmlspecialchars($penalty['username']); ?></td>
|
||||||
|
<td><?= htmlspecialchars($penalty['penalty_count']); ?></td>
|
||||||
|
<td><?= number_format($penalty['penalty_count'] * $penalty_amount, 2, ',', '.'); ?> €</td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Neuer Bereich für bezahlte Rechnungen -->
|
||||||
|
<div class="card shadow mb-4">
|
||||||
|
<div class="card-header bg-success-subtle text-success">
|
||||||
|
<h4 class="mb-0">Rechnungen</h4>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title text-center">Ranking - Rechnung übernommen</h5>
|
||||||
|
<p class="text-center text-muted mt-2 mb-3">
|
||||||
|
Der mit der geringsten Anzahl ist das nächste Mal dran.
|
||||||
|
</p>
|
||||||
|
<div style="height: 40vh;">
|
||||||
|
<canvas id="paidChart"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
// Daten für "Gezahlt"-Diagramm
|
||||||
|
const paidData = {
|
||||||
|
labels: <?= json_encode(array_column($paid_stats, 'username')); ?>,
|
||||||
|
datasets: [{
|
||||||
|
label: 'Gezahlte Strafen',
|
||||||
|
data: <?= json_encode(array_column($paid_stats, 'paid_count')); ?>,
|
||||||
|
backgroundColor: 'rgba(153, 102, 255, 0.8)',
|
||||||
|
borderColor: 'rgb(153, 102, 255)',
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const paidConfig = {
|
||||||
|
type: 'bar',
|
||||||
|
data: paidData,
|
||||||
|
options: {
|
||||||
|
indexAxis: 'y',
|
||||||
|
responsive: true,
|
||||||
|
maintainAspectRatio: false,
|
||||||
|
plugins: {
|
||||||
|
legend: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
display: true,
|
||||||
|
text: 'Anzahl der bezahlten Essen pro Benutzer'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
scales: {
|
||||||
|
x: {
|
||||||
|
beginAtZero: true
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
ticks: {
|
||||||
|
font: {
|
||||||
|
size: 10
|
||||||
|
},
|
||||||
|
callback: function(value, index, ticks) {
|
||||||
|
const username = this.getLabelForValue(value);
|
||||||
|
const maxChars = 15;
|
||||||
|
if (username.length > maxChars) {
|
||||||
|
return username.substring(0, maxChars) + '...';
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new Chart(
|
||||||
|
document.getElementById('paidChart'),
|
||||||
|
paidConfig
|
||||||
|
);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?php include('inc/footer.php'); ?>
|
||||||
Reference in New Issue
Block a user