Die Migration in participants/ledger_entries ist abgeschlossen: kein
Teilnehmer traegt noch eine legacy_mitarbeiter_id, kein Journaleintrag eine
legacy_table. Damit war der jeweils zweite Zweig ("Default-Mandant schreibt
zusaetzlich nach kl_Einzahlungen/kl_Kaffeeverbrauch/kl_Mitarbeiter") in
sechs Dateien nicht mehr erreichbar - er musste aber bei jeder Aenderung
mitgepflegt werden, zuletzt bei der Bemerkung fuer Einzahlungen.
Entfernt:
- Dual-Write beim Buchen: einzahlung.php, stricheintragen.php, index.php,
jahresauswertung.php, app/imports.php, app/paypal-inbox.php
- Dual-Write in der Mitgliederverwaltung: ledger_create_participant,
ledger_update_participant, ledger_set_participant_active,
ledger_anonymize_participant
- die verwaisten Spiegelfunktionen ledger_mirror_legacy_payment,
ledger_mirror_legacy_consumption und ledger_void_entry_by_legacy_id
Nebenbei behoben: kaffeeliste.php hat die Teilnehmer-Detailseite nur fuer
Mitglieder mit legacy_mitarbeiter_id verlinkt - die hat seit der Migration
niemand mehr, die Seite war also fuer alle unerreichbar. Verlinkt und
adressiert wird jetzt ueber participant_id; "user_id" bleibt als Alias
erhalten. Der Mandanten-Isolationstest prueft jetzt ledger_void_entry, also
den Pfad, den letzteneintraege.php tatsaechlich nutzt.
Pruefskripte unveraendert gegenueber der Baseline vor dem Umbau
(http-smoke 27/6, role-matrix 55/0); die Isolationspruefung steigt von
9 auf 11 PASS bei gleichem vorbestehendem Fehler.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
204 lines
7.0 KiB
PHP
204 lines
7.0 KiB
PHP
<?php
|
|
|
|
include "functions.php";
|
|
require_once __DIR__ . "/app/ledger.php";
|
|
|
|
// Teilnehmer-ID aus dem Journal. "user_id" bleibt als Alias erhalten, damit
|
|
// aeltere Links und Lesezeichen weiter funktionieren.
|
|
$participantId = filter_input(INPUT_GET, 'participant_id', FILTER_VALIDATE_INT);
|
|
if ($participantId === null || $participantId === false) {
|
|
$participantId = filter_input(INPUT_GET, 'user_id', FILTER_VALIDATE_INT);
|
|
}
|
|
if ($participantId === null) {
|
|
http_response_code(400);
|
|
exit('Fehlender Parameter');
|
|
}
|
|
if ($participantId === false || $participantId <= 0) {
|
|
http_response_code(400);
|
|
exit('Ungültige Teilnehmer-ID');
|
|
}
|
|
|
|
$pdo = app_db_pdo();
|
|
$saasUser = saas_current_user($pdo);
|
|
$tenantId = 0;
|
|
$hasAccess = false;
|
|
|
|
if ($saasUser !== null && saas_user_has_role(['owner', 'admin', 'treasurer'], $saasUser)) {
|
|
$tenantId = (int)$saasUser['tenant_id'];
|
|
$hasAccess = true;
|
|
}
|
|
|
|
if (!$hasAccess && $saasUser === null && checkKaffeelisteAdmin($conn, $mailadress)) {
|
|
$tenant = ledger_fetch_default_tenant($pdo);
|
|
if ($tenant !== null) {
|
|
$tenantId = (int)$tenant['id'];
|
|
$hasAccess = true;
|
|
}
|
|
}
|
|
|
|
$participant = $hasAccess
|
|
? ledger_fetch_participant_summary($pdo, $tenantId, $participantId)
|
|
: null;
|
|
$settings = $hasAccess ? saas_fetch_tenant_settings($pdo, $tenantId) : null;
|
|
$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,
|
|
])
|
|
: [];
|
|
|
|
function teilnehmerauswertung_money(int $cents): string
|
|
{
|
|
return saas_format_money_cents($cents) . ' €';
|
|
}
|
|
|
|
function teilnehmerauswertung_date(string $value): string
|
|
{
|
|
try {
|
|
return (new DateTimeImmutable($value))->format('d.m.Y');
|
|
} catch (Throwable $e) {
|
|
return $value;
|
|
}
|
|
}
|
|
|
|
function teilnehmerauswertung_current_name(?array $saasUser, mixed $conn, string $mailadress): string
|
|
{
|
|
$name = trim((string)($saasUser['display_name'] ?? ''));
|
|
if ($name !== '') {
|
|
return $name;
|
|
}
|
|
|
|
return trim((string)getUserName($conn, $mailadress));
|
|
}
|
|
|
|
function teilnehmerauswertung_paypal_action(string $template, string $amount): string
|
|
{
|
|
return trim($template) . $amount;
|
|
}
|
|
|
|
function teilnehmerauswertung_render_payments(array $entries): void
|
|
{
|
|
echo "<h4>Letzte Einzahlungen</h4>";
|
|
echo "<table><tr><th style='width:120px'>Datum</th><th>Einzahlung</th></tr>";
|
|
if ($entries === []) {
|
|
echo "<tr><td colspan='2'>Keine Einzahlungen vorhanden.</td></tr>";
|
|
}
|
|
foreach ($entries as $entry) {
|
|
echo "<tr>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_date((string)$entry['booked_at'])) . "</td>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_money((int)$entry['amount_cents'])) . "</td>";
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
|
|
function teilnehmerauswertung_render_consumption(array $entries): void
|
|
{
|
|
echo "<h4>Letzte Striche</h4>";
|
|
echo "<table><tr><th style='width:120px'>Datum</th><th>Striche</th><th>Kosten</th></tr>";
|
|
if ($entries === []) {
|
|
echo "<tr><td colspan='3'>Keine Striche vorhanden.</td></tr>";
|
|
}
|
|
foreach ($entries as $entry) {
|
|
echo "<tr>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_date((string)$entry['booked_at'])) . "</td>";
|
|
echo "<td>" . number_format((int)($entry['marks_count'] ?? 0), 0, ',', '.') . "</td>";
|
|
echo "<td>" . saas_html(teilnehmerauswertung_money(abs((int)$entry['amount_cents']))) . "</td>";
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
|
|
include "header.php";
|
|
include "headerline.php";
|
|
include "nav.php";
|
|
?>
|
|
|
|
<section id="banner">
|
|
<div class="content">
|
|
<?php
|
|
if ($hasAccess && $participant !== null) {
|
|
$balanceCents = (int)$participant['balance_cents'];
|
|
$balance = teilnehmerauswertung_money($balanceCents);
|
|
$currentName = teilnehmerauswertung_current_name($saasUser, $conn, $mailadress);
|
|
$paypalEnabled = $settings !== null
|
|
&& (int)$settings['paypal_enabled'] === 1
|
|
&& trim((string)$settings['paypal_url_template']) !== '';
|
|
?>
|
|
<h2>Auswertung</h2>
|
|
<?php if ($currentName !== ''): ?>
|
|
Hallo <?php echo saas_html($currentName); ?>!<br><br>
|
|
<?php endif; ?>
|
|
|
|
<h2>Gesamtausgabe und Gesamtstriche</h2>
|
|
<p>Name: <?php echo saas_html($participant['display_name']); ?></p>
|
|
<p>E-Mail: <?php echo saas_html((string)($participant['email'] ?? '')); ?></p>
|
|
Gesamtausgabe: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['total_costs_cents'])); ?><br>
|
|
Gesamtstriche: <?php echo number_format((int)$participant['total_marks'], 0, ',', '.'); ?><br>
|
|
<p>Gesamteinzahlung: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['total_payments_cents'])); ?></p>
|
|
<?php
|
|
if ($balanceCents > 0) {
|
|
echo "<p><b>Aktueller Stand: " . saas_html($balance) . " (Guthaben)</b></p>";
|
|
} elseif ($balanceCents < 0) {
|
|
echo "<p><b>Aktueller Stand: " . saas_html($balance) . " (Schulden)</b></p>";
|
|
} else {
|
|
echo "<p><b>Aktueller Stand: " . saas_html($balance) . "</b></p>";
|
|
}
|
|
?>
|
|
|
|
<h2>Jahresübersicht</h2>
|
|
Ausgabe im aktuellen Jahr: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['year_costs_cents'])); ?><br>
|
|
Gesamtstriche im aktuellen Jahr: <?php echo number_format((int)$participant['year_marks'], 0, ',', '.'); ?><br>
|
|
<p>Gesamteinzahlung im aktuellen Jahr: <?php echo saas_html(teilnehmerauswertung_money((int)$participant['year_payments_cents'])); ?></p>
|
|
|
|
<?php if ($paypalEnabled): ?>
|
|
<h2>PayPal-Einzahlungen</h2>
|
|
<b>Bezahle immer über die Freunde-Funktion von PayPal. Ansonsten stellen wir 20% des Betrags als Gebühr in Rechnung.</b><br>
|
|
<br>
|
|
<?php
|
|
$paypalTemplate = trim((string)$settings['paypal_url_template']);
|
|
if ($balanceCents < 0) {
|
|
$debtCents = abs($balanceCents);
|
|
$debtAmount = teilnehmerauswertung_money($debtCents);
|
|
echo '<form action="' . saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, saas_format_money_cents($debtCents))) . '" target="_blank"><button type="submit">' . saas_html($debtAmount) . ' bezahlen</button></form>';
|
|
}
|
|
?>
|
|
<ul class="actions">
|
|
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '5')); ?>" target="_blank"><button type="submit">5,00 € einzahlen</button></form></li>
|
|
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '10')); ?>" target="_blank"><button type="submit">10,00 € einzahlen</button></form></li>
|
|
<li><form action="<?php echo saas_html(teilnehmerauswertung_paypal_action($paypalTemplate, '15')); ?>" target="_blank"><button type="submit">15,00 € einzahlen</button></form></li>
|
|
</ul>
|
|
<?php endif; ?>
|
|
|
|
<br><br>
|
|
<?php
|
|
teilnehmerauswertung_render_payments($paymentEntries);
|
|
echo "<br>";
|
|
teilnehmerauswertung_render_consumption($consumptionEntries);
|
|
?>
|
|
<br><br>
|
|
|
|
<form action="namenanpassen.php" method="get">
|
|
<button type="submit">Namensanpassung</button>
|
|
</form>
|
|
<?php
|
|
} elseif ($hasAccess) {
|
|
echo "<h2>Auswertung</h2>";
|
|
echo "<p>Mitarbeiter wurde im aktuellen Mandanten nicht gefunden.</p>";
|
|
} else {
|
|
echo "<h2>Kein Zugriff</h2>";
|
|
}
|
|
?>
|
|
</div>
|
|
</section>
|
|
|
|
<?php include "footer.php"; ?>
|