0) { $summaries = ledger_fetch_participant_summaries($pdo, $tenantId, [ 'user_ids' => [$saasUserId], ]); $participant = $summaries[0] ?? null; } if ($participant === null && $emailNorm !== '') { $summaries = ledger_fetch_participant_summaries($pdo, $tenantId, [ 'email_norms' => [$emailNorm], ]); $participant = $summaries[0] ?? null; } } $settings = $hasAccess ? saas_fetch_tenant_settings($pdo, $tenantId) : null; $entryMessage = null; $entryError = null; // Ergebnis einer vorangegangenen Aktion (Post-Redirect-Get): nach dem Buchen // bzw. Stornieren wird auf index.php zurueckgeleitet, damit ein Browser-Refresh // die Aktion nicht ein zweites Mal ausloest. if (isset($_SESSION['flash_dashboard'])) { $flash = $_SESSION['flash_dashboard']; unset($_SESSION['flash_dashboard']); if (($flash['type'] ?? '') === 'success') { $entryMessage = (string)$flash['text']; } else { $entryError = (string)$flash['text']; } } function dashboard_money(int $cents): string { return saas_format_money_cents($cents) . ' €'; } function dashboard_date(string $value): string { try { return (new DateTimeImmutable($value))->format('d.m.Y'); } catch (Throwable $e) { return $value; } } function dashboard_current_name(?array $saasUser, ?array $participant, mixed $conn, string $mailadress): string { $name = trim((string)($saasUser['display_name'] ?? '')); if ($name !== '') { return $name; } $name = trim((string)($participant['display_name'] ?? '')); if ($name !== '') { return $name; } return trim((string)getUserName($conn, $mailadress)); } function dashboard_paypal_action(string $template, string $amount): string { return trim($template) . $amount; } /** * @return array{ok: bool, message?: string, error?: string} */ function dashboard_record_self_entry(PDO $pdo, array $participant, array $settings, mixed $marksValue, ?int $actorUserId): array { if ((int)$settings['self_entry_enabled'] !== 1) { return ['ok' => false, 'error' => 'Die eigene Stricherfassung ist aktuell deaktiviert.']; } $marks = filter_var($marksValue, FILTER_VALIDATE_INT); if ($marks !== 1 && $marks !== 2) { return ['ok' => false, 'error' => 'Bitte einen oder zwei Striche auswählen.']; } $unitPriceCents = (int)$settings['mark_price_cents']; if ($unitPriceCents <= 0) { return ['ok' => false, 'error' => 'Der Preis pro Strich ist nicht gültig konfiguriert.']; } try { ledger_record_consumption( $pdo, (int)$participant['tenant_id'], (int)$participant['participant_id'], $marks, $unitPriceCents, 'self_entry', $actorUserId ); } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } return ['ok' => false, 'error' => 'Die Stricheintragung konnte nicht gespeichert werden.']; } return ['ok' => true, 'message' => 'Stricheintragung wurde erfolgreich eingetragen.']; } function dashboard_render_payments(array $entries): void { echo "

Letzte Einzahlungen

"; echo ""; if ($entries === []) { echo ""; } foreach ($entries as $entry) { echo ""; echo ""; echo ""; echo ""; } echo "
DatumEinzahlung
Keine Einzahlungen vorhanden.
" . saas_html(dashboard_date((string)$entry['booked_at'])) . "" . saas_html(dashboard_money((int)$entry['amount_cents'])) . "
"; } function dashboard_render_consumption(array $entries): void { echo "

Letzte Striche

"; echo ""; if ($entries === []) { echo ""; } foreach ($entries as $entry) { echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
DatumStricheKosten
Keine Striche vorhanden.
" . saas_html(dashboard_date((string)$entry['booked_at'])) . "" . number_format((int)($entry['marks_count'] ?? 0), 0, ',', '.') . "" . saas_html(dashboard_money(abs((int)$entry['amount_cents']))) . "
"; } if ($_SERVER["REQUEST_METHOD"] === "POST") { $flash = ['type' => 'error', 'text' => 'Die Aktion konnte nicht ausgeführt werden.']; if ($hasAccess && $participant !== null && $settings !== null) { $aktion = (string)($_POST['aktion'] ?? 'strich_eintragen'); if ($aktion === 'strich_stornieren') { $result = ledger_void_own_self_entry($pdo, $tenantId, (int)$participant['participant_id']); $flash = $result['ok'] ? ['type' => 'success', 'text' => 'Dein zuletzt selbst eingetragener Strich wurde storniert.'] : ['type' => 'error', 'text' => $result['error'] ?? 'Der Strich konnte nicht storniert werden.']; } else { $result = dashboard_record_self_entry($pdo, $participant, $settings, $_POST["anzahlStriche"] ?? null, $saasUser['user_id'] ?? null); $flash = $result['ok'] ? ['type' => 'success', 'text' => $result['message'] ?? 'Stricheintragung wurde erfolgreich eingetragen.'] : ['type' => 'error', 'text' => $result['error'] ?? 'Die Stricheintragung konnte nicht gespeichert werden.']; } } // Post-Redirect-Get: Ergebnis in die Session legen und per GET erneut // anzeigen, damit ein Refresh die Buchung/Stornierung nicht wiederholt. $_SESSION['flash_dashboard'] = $flash; header('Location: index.php'); exit; } $paymentEntries = $participant !== null ? ledger_fetch_recent_entries($pdo, $tenantId, [ 'participant_id' => $participant['participant_id'], 'type' => 'payment', 'limit' => 100, ]) : []; $consumptionEntries = $participant !== null ? ledger_fetch_recent_entries($pdo, $tenantId, [ 'participant_id' => $participant['participant_id'], 'type' => 'consumption', 'limit' => 100, ]) : []; include "header.php"; include "headerline.php"; include "nav.php"; ?>