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;
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.'];
}
$legacyMitarbeiterId = $participant['legacy_mitarbeiter_id'] !== null
? (int)$participant['legacy_mitarbeiter_id']
: 0;
try {
if ($legacyMitarbeiterId > 0) {
// Migrierter Default-Mandant: weiterhin in die Legacy-Tabelle
// schreiben, damit die noch-legacy Sammelseiten (stricheintragen.php)
// den Eintrag ebenfalls sehen; der Ledger-Eintrag entsteht per
// Spiegelung.
$bookedAt = date('Y-m-d H:i:s');
$cost = (($marks * $unitPriceCents) / 100);
$unitPrice = ($unitPriceCents / 100);
$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();
} else {
// SaaS-native Mandanten (alle ausser dem migrierten Default-
// Mandanten) haben keine Legacy-Schattentabelle - direkt ins
// Ledger buchen.
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 "Datum Einzahlung ";
if ($entries === []) {
echo "Keine Einzahlungen vorhanden. ";
}
foreach ($entries as $entry) {
echo "";
echo "" . saas_html(dashboard_date((string)$entry['booked_at'])) . " ";
echo "" . saas_html(dashboard_money((int)$entry['amount_cents'])) . " ";
echo " ";
}
echo "
";
}
function dashboard_render_consumption(array $entries): void
{
echo "Letzte Striche ";
echo "Datum Striche Kosten ";
if ($entries === []) {
echo "Keine Striche vorhanden. ";
}
foreach ($entries as $entry) {
echo "";
echo "" . saas_html(dashboard_date((string)$entry['booked_at'])) . " ";
echo "" . number_format((int)($entry['marks_count'] ?? 0), 0, ',', '.') . " ";
echo "" . saas_html(dashboard_money(abs((int)$entry['amount_cents']))) . " ";
echo " ";
}
echo "
";
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
if ($hasAccess && $participant !== null && $settings !== null) {
$result = dashboard_record_self_entry($pdo, $participant, $settings, $_POST["anzahlStriche"] ?? null, $saasUser['user_id'] ?? 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";
?>
Kaffeeliste
Hallo !
Du kannst den Eintrag weiter unten kontrollieren.
0) {
echo "
Aktueller Stand: " . saas_html($balance) . " (Guthaben)
";
} elseif ($balanceCents < 0) {
echo "
Aktueller Stand: " . saas_html($balance) . " (Schulden)
";
} else {
echo "
Aktueller Stand: " . saas_html($balance) . "
";
}
?>
Jahresübersicht
Ausgabe im aktuellen Jahr:
Gesamtstriche im aktuellen Jahr:
Gesamteinzahlung im aktuellen Jahr:
Eintrag in die Strichliste
Hier kannst du einen oder zwei Striche für dich in der Kaffeeliste eintragen. Dafür benötigst du keinen Eintrag auf der Liste durchführen.
Aktueller Preis pro Strich:
PayPal-Einzahlungen
Bezahle immer über die Freunde-Funktion von PayPal. Ansonsten stellen wir 20% des Betrags als Gebühr in Rechnung.
' . saas_html($debtAmount) . ' bezahlen ';
}
?>
";
dashboard_render_consumption($consumptionEntries);
?>
Kaffeeliste";
echo "
Für dein Konto wurde im aktuellen Mandanten kein Teilnehmer gefunden.
";
} else {
echo "
Sie haben keinen Zugang zu dieser Webseite ";
}
?>