v1.3.1 Geburtstaglogik komplett überarbeitet
This commit is contained in:
@@ -85,41 +85,49 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
}
|
||||
mysqli_stmt_close($stmt_insert);
|
||||
|
||||
// 🔹 GEBURTSTAGS-ZAHLUNG BEHANDELN
|
||||
// 🔹 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;
|
||||
|
||||
// Hole aktuellen Status
|
||||
$user_stmt = mysqli_prepare($conn, "SELECT birthday_payer_pending FROM users WHERE id = ?");
|
||||
$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) continue;
|
||||
|
||||
$was_birthday_payer = (bool)$user_row['birthday_payer_pending'];
|
||||
|
||||
if ($was_birthday_payer) {
|
||||
// 🎂 Geburtstags-Zahlung: NICHT zählen, aber Flag zurücksetzen
|
||||
$update = mysqli_prepare($conn, "
|
||||
UPDATE users
|
||||
SET birthday_payer_pending = 0
|
||||
WHERE id = ?
|
||||
");
|
||||
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: reguläre Anzahl erhöhen
|
||||
$update = mysqli_prepare($conn, "
|
||||
UPDATE users
|
||||
SET regular_paid_count = regular_paid_count + 1
|
||||
WHERE id = ?
|
||||
");
|
||||
// 🔢 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);
|
||||
|
||||
Reference in New Issue
Block a user