v1.3.1 - Zahlerlogik verbessert
This commit is contained in:
111
participant.php
111
participant.php
@@ -38,7 +38,7 @@ while ($row = mysqli_fetch_assoc($users_result)) {
|
||||
}
|
||||
|
||||
$existing_feedback = [];
|
||||
$stmt = mysqli_prepare($conn, "SELECT user_id, attended, wore_color, paid FROM meeting_teilnehmer WHERE meeting_id = ?");
|
||||
$stmt = mysqli_prepare($conn, "SELECT user_id, attended, wore_color, paid, birthday_pay FROM meeting_teilnehmer WHERE meeting_id = ?");
|
||||
mysqli_stmt_bind_param($stmt, "i", $meeting_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
@@ -72,68 +72,75 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
// Neue Daten speichern
|
||||
if (isset($_POST['user_id']) && is_array($_POST['user_id'])) {
|
||||
$stmt_insert = mysqli_prepare($conn, "INSERT INTO meeting_teilnehmer (meeting_id, user_id, attended, wore_color, paid) VALUES (?, ?, ?, ?, ?)");
|
||||
$stmt_insert = mysqli_prepare($conn, "
|
||||
INSERT INTO meeting_teilnehmer
|
||||
(meeting_id, user_id, attended, wore_color, paid, birthday_pay)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
|
||||
$meeting_year = (int)date('Y', strtotime($meeting['meeting_date']));
|
||||
$meeting_month = (int)date('n', strtotime($meeting['meeting_date']));
|
||||
$meeting_day = (int)date('j', strtotime($meeting['meeting_date']));
|
||||
|
||||
foreach ($_POST['user_id'] as $user_id) {
|
||||
$user_id = intval($user_id);
|
||||
$attended = isset($_POST['attended'][$user_id]) ? 1 : 0;
|
||||
$wore_color = isset($_POST['wore_color'][$user_id]) ? 1 : 0;
|
||||
$paid = isset($_POST['paid'][$user_id]) ? 1 : 0;
|
||||
$birthday_pay = 0;
|
||||
|
||||
mysqli_stmt_bind_param($stmt_insert, "iiiii", $meeting_id, $user_id, $attended, $wore_color, $paid);
|
||||
if ($paid) {
|
||||
// Hole Geburtstag des Users
|
||||
$user_stmt = mysqli_prepare($conn, "SELECT birthday FROM users WHERE id = ?");
|
||||
mysqli_stmt_bind_param($user_stmt, "i", $user_id);
|
||||
mysqli_stmt_execute($user_stmt);
|
||||
$user_row = mysqli_fetch_assoc(mysqli_stmt_get_result($user_stmt));
|
||||
mysqli_stmt_close($user_stmt);
|
||||
|
||||
if ($user_row && $user_row['birthday'] && $user_row['birthday'] !== '0000-00-00') {
|
||||
$bday_month = (int)date('n', strtotime($user_row['birthday']));
|
||||
$bday_day = (int)date('j', strtotime($user_row['birthday']));
|
||||
|
||||
// War Geburtstag in diesem Jahr bereits?
|
||||
$birthday_passed = ($bday_month < $meeting_month ||
|
||||
($bday_month == $meeting_month && $bday_day <= $meeting_day));
|
||||
|
||||
if ($birthday_passed) {
|
||||
// Prüfen: Hat er in DIESEM JAHR schon als Geburtstagszahler gezahlt?
|
||||
$check_stmt = mysqli_prepare($conn, "
|
||||
SELECT 1 FROM meeting_teilnehmer mt
|
||||
JOIN meetings m ON mt.meeting_id = m.id
|
||||
WHERE mt.user_id = ?
|
||||
AND mt.birthday_pay = 1
|
||||
AND YEAR(m.meeting_date) = ?
|
||||
LIMIT 1
|
||||
");
|
||||
mysqli_stmt_bind_param($check_stmt, "ii", $user_id, $meeting_year);
|
||||
mysqli_stmt_execute($check_stmt);
|
||||
$already_birthday_paid = mysqli_num_rows(mysqli_stmt_get_result($check_stmt)) > 0;
|
||||
mysqli_stmt_close($check_stmt);
|
||||
|
||||
if (!$already_birthday_paid) {
|
||||
$birthday_pay = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mysqli_stmt_bind_param(
|
||||
$stmt_insert,
|
||||
"iiiiii",
|
||||
$meeting_id,
|
||||
$user_id,
|
||||
$attended,
|
||||
$wore_color,
|
||||
$paid,
|
||||
$birthday_pay
|
||||
);
|
||||
mysqli_stmt_execute($stmt_insert);
|
||||
}
|
||||
mysqli_stmt_close($stmt_insert);
|
||||
|
||||
// 🔹 GEBURTSTAGS-ZAHLUNG BEHANDELN – MIT last_birthday_year
|
||||
$meeting_year = (int)date('Y', strtotime($meeting['meeting_date']));
|
||||
$meeting_month = (int)date('n', strtotime($meeting['meeting_date']));
|
||||
$meeting_day = (int)date('j', strtotime($meeting['meeting_date']));
|
||||
|
||||
foreach ($_POST['user_id'] as $user_id) {
|
||||
$user_id = (int)$user_id;
|
||||
$paid = isset($_POST['paid'][$user_id]) && $_POST['paid'][$user_id] == 1;
|
||||
|
||||
if (!$paid) continue;
|
||||
|
||||
$user_stmt = mysqli_prepare($conn, "SELECT birthday, last_birthday_year FROM users WHERE id = ?");
|
||||
mysqli_stmt_bind_param($user_stmt, "i", $user_id);
|
||||
mysqli_stmt_execute($user_stmt);
|
||||
$user_row = mysqli_fetch_assoc(mysqli_stmt_get_result($user_stmt));
|
||||
mysqli_stmt_close($user_stmt);
|
||||
|
||||
if (!$user_row || !$user_row['birthday'] || $user_row['birthday'] === '0000-00-00') {
|
||||
// Kein Geburtstag → normale Zahlung
|
||||
$update = mysqli_prepare($conn, "UPDATE users SET regular_paid_count = regular_paid_count + 1 WHERE id = ?");
|
||||
mysqli_stmt_bind_param($update, "i", $user_id);
|
||||
mysqli_stmt_execute($update);
|
||||
mysqli_stmt_close($update);
|
||||
continue;
|
||||
}
|
||||
|
||||
$last_bday_year = (int)($user_row['last_birthday_year'] ?? 0);
|
||||
$bday_month = (int)date('n', strtotime($user_row['birthday']));
|
||||
$bday_day = (int)date('j', strtotime($user_row['birthday']));
|
||||
|
||||
$birthday_passed = ($bday_month < $meeting_month ||
|
||||
($bday_month == $meeting_month && $bday_day <= $meeting_day));
|
||||
$birthday_not_paid_yet = ($last_bday_year < $meeting_year);
|
||||
|
||||
if ($birthday_passed && $birthday_not_paid_yet) {
|
||||
// 🎂 Geburtstags-Zahlung
|
||||
$update = mysqli_prepare($conn, "UPDATE users SET last_birthday_year = ? WHERE id = ?");
|
||||
mysqli_stmt_bind_param($update, "ii", $meeting_year, $user_id);
|
||||
mysqli_stmt_execute($update);
|
||||
mysqli_stmt_close($update);
|
||||
} else {
|
||||
// 🔢 Normale Zahlung
|
||||
$update = mysqli_prepare($conn, "UPDATE users SET regular_paid_count = regular_paid_count + 1 WHERE id = ?");
|
||||
mysqli_stmt_bind_param($update, "i", $user_id);
|
||||
mysqli_stmt_execute($update);
|
||||
mysqli_stmt_close($update);
|
||||
}
|
||||
}
|
||||
|
||||
// Meeting abschließen (nur im Index-Modus)
|
||||
if ($source_page === 'index') {
|
||||
$stmt_complete = mysqli_prepare($conn, "UPDATE meetings SET is_completed = 1 WHERE id = ?");
|
||||
|
||||
Reference in New Issue
Block a user