[$emailNorm], ]); $participant = $summaries[0] ?? null; } $settings = $hasAccess ? saas_fetch_tenant_settings($pdo, $tenantId) : null; $entryMessage = null; $entryError = null; 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_legacy_self_entry(PDO $pdo, array $participant, array $settings, mixed $marksValue): array { $legacyMitarbeiterId = $participant['legacy_mitarbeiter_id'] !== null ? (int)$participant['legacy_mitarbeiter_id'] : 0; if ($legacyMitarbeiterId <= 0) { return ['ok' => false, 'error' => 'Für diesen Teilnehmer ist die eigene Stricherfassung noch nicht verfügbar.']; } 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.']; } $bookedAt = date('Y-m-d H:i:s'); $cost = (($marks * $unitPriceCents) / 100); $unitPrice = ($unitPriceCents / 100); try { $pdo->beginTransaction(); $stmt = $pdo->prepare( 'INSERT INTO kl_Kaffeeverbrauch (MitarbeiterID, AnzahlStriche, Kosten, KostenproStrich, Datum, Eintragsart) VALUES (?, ?, ?, ?, ?, 2)' ); $stmt->execute([$legacyMitarbeiterId, $marks, $cost, $unitPrice, $bookedAt]); $legacyConsumptionId = (int)$pdo->lastInsertId(); if ($legacyConsumptionId <= 0) { throw new RuntimeException('Legacy-Strich konnte nicht angelegt werden.'); } ledger_mirror_legacy_consumption($pdo, (int)$participant['tenant_id'], $legacyConsumptionId); $pdo->commit(); } 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") { if ($hasAccess && $participant !== null && $settings !== null) { $result = dashboard_record_legacy_self_entry($pdo, $participant, $settings, $_POST["anzahlStriche"] ?? null); if ($result['ok']) { $entryMessage = $result['message'] ?? null; $participant = ledger_fetch_participant_summary($pdo, $tenantId, (int)$participant['participant_id']); } else { $entryError = $result['error'] ?? 'Die Stricheintragung konnte nicht gespeichert werden.'; } } else { $entryError = 'Die Stricheintragung konnte nicht gespeichert werden.'; } } $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"; ?>