LuminaWebsite/admin/dues.php
Maaxxs 785eab611e Legion dues: an admin page tracks who paid, with a rhythm, exemptions and suspended cycles
Asked for: the legion collects dues in Kina; a separate, purely administrative page to set a cycle and an
amount, tick off who has paid, exempt members for one or more cycles and suspend a cycle for everyone. On
the site it is called "Legionsbeiträge" and the currency "Kina", like everywhere else.

- includes/dues.php: settings dues_amount/_unit/_every/_start/_anchor (every 1-12 weeks or months). The
  cycles (dues_cycles) form a series from the anchor (months on the same day, in shorter months the last
  one) and exist up to the running one plus the next. Until something is ticked or suspended, a new setting
  rebuilds all cycles; afterwards a new amount applies to the coming cycles (optionally the running one) and
  a new rhythm starts after the last cycle that has begun or has data. The amount also takes 500k, 1,5kk or
  2 Mio.
- Who owes: every active account that was a member when the cycle started (Discord join, else account
  creation), unless exempt or the cycle is suspended; a ticked payment always counts. Former members only
  show up with payments in the visible cycles.
- admin/dues.php: key figures (running cycle, paid, collected of expected, arrears), a table of members x
  the last six cycles with paging, a click toggles a payment (dues_entries with who and when; without
  reload via assets/js/dues.js, the button sends the state it sets), search and filters (open, paid,
  exempt, arrears), suspend/resume per cycle with an optional reason, exemptions (dues_exemptions:
  members, from which cycle, 1-12 cycles or until further notice, reason; end or delete) and the settings.
  On phones the table opens at the running cycle, the exemption list stacks.
- admin/dues_action.php: settings, toggle (JSON with the redrawn cell, column figures, arrears and key
  figures), cycle, exempt_add/_end/_delete. Settings, suspensions and exemptions go to the audit log and the
  Discord log channel, ticks only to the audit log (area "Legionsbeiträge"); ticking is exempt from the
  general form rate limit.
- New right dues.manage (Administrator and the groups with roles.manage), menu item in the admin section
  with a coins icon, schema version 61 (tables also in sql/schema.sql).
- Privacy: privacy policy (what is stored, only the leadership sees it, account deletion), data export
  section legionsbeitraege, account deletion removes exemptions and keeps payments without the name, data
  reset area.
- Patch notes (leadership) and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 23:33:22 +02:00

368 lines
22 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Legionsbeitraege verwalten (includes/dues.php, nur dues.manage): Betrag und Rhythmus einstellen, je Zyklus abhaken,
* wer bezahlt hat, Mitglieder befreien und Zyklen fuer alle aussetzen. Aenderungen gehen an admin/dues_action.php, das
* Abhaken klappt mit JavaScript ohne Neuladen (assets/js/dues.js).
* /admin/dues.php die neuesten Zyklen (bis zum naechsten)
* /admin/dues.php?bis=ID aeltere: die Zyklen bis einschliesslich ID
*/
require_once __DIR__ . '/../includes/bootstrap.php';
require_once __DIR__ . '/../includes/dues.php';
require_permission('dues.manage');
$settings = dues_settings();
$configured = dues_configured($settings);
dues_sync($settings);
$cycles = dues_cycles();
['current' => $current, 'next' => $next] = dues_current($cycles);
$focus = $current ?? $next;
$hasData = dues_has_data();
$today = date('Y-m-d');
$currentEnd = dues_current_end($cycles);
// Sichtbare Zyklen: hoechstens DUES_VISIBLE_CYCLES bis zum gewaehlten (Standard: der neueste, also der naechste)
$cycleIds = array_keys($cycles);
$lastIndex = count($cycleIds) - 1;
$untilId = (int) ($_GET['bis'] ?? 0);
$untilIndex = isset($cycles[$untilId]) ? (int) array_search($untilId, $cycleIds, true) : $lastIndex;
$firstIndex = max(0, $untilIndex - DUES_VISIBLE_CYCLES + 1);
$visible = [];
foreach ($cycleIds ? array_slice($cycleIds, $firstIndex, $untilIndex - $firstIndex + 1) : [] as $id) {
$visible[$id] = $cycles[$id];
}
$olderUntil = $firstIndex > 0 ? $cycleIds[$firstIndex - 1] : null;
$newerUntil = $untilIndex < $lastIndex ? $cycleIds[min($lastIndex, $untilIndex + DUES_VISIBLE_CYCLES)] : null;
$bis = $untilIndex < $lastIndex ? (int) $cycleIds[$untilIndex] : 0;
$entries = dues_entries();
// Ehemalige Mitglieder nur, wenn sie in den gezeigten Zyklen (oder im laufenden) bezahlt haben
$formerIds = [];
foreach (array_merge(array_keys($visible), $focus !== null ? [$focus['id']] : []) as $id) {
array_push($formerIds, ...array_keys($entries[$id] ?? []));
}
$members = dues_members($formerIds);
$exemptions = dues_exemptions();
$arrears = dues_arrears($cycles, $members, $entries, $exemptions);
$totals = [];
foreach ($visible as $id => $cycle) {
$totals[$id] = dues_cycle_totals($cycle, $members, $entries, $exemptions);
}
$focusTotals = $focus !== null ? ($totals[$focus['id']] ?? dues_cycle_totals($focus, $members, $entries, $exemptions)) : null;
// Filter oben in der Tabelle: nach dem Stand im laufenden (sonst naechsten) Zyklus
$focusStatus = [];
foreach ($members as $member) {
$focusStatus[$member['id']] = $focus !== null ? dues_status($focus, $member, $entries, $exemptions) : '';
}
$activeMembers = array_filter($members, static fn (array $member): bool => $member['active']);
$filterCounts = [
'open' => count(array_filter($focusStatus, static fn (string $status): bool => $status === 'open')),
'paid' => count(array_filter($focusStatus, static fn (string $status): bool => $status === 'paid')),
'exempt' => count(array_filter($focusStatus, static fn (string $status): bool => $status === 'exempt')),
'arrears' => count(array_filter($arrears, static fn (array $row): bool => $row['count'] > 0)),
];
// Befreiungen: "Ab" - die letzten vergangenen Zyklen, der laufende, der naechste und weitere aus der Vorschau
$choices = dues_cycle_choices($cycles, $settings);
$choiceFocus = 0;
foreach ($choices as $index => $choice) {
if ($choice['ends_on'] >= $today) {
$choiceFocus = $index;
break;
}
}
$fromChoices = array_slice($choices, max(0, $choiceFocus - DUES_EXEMPT_PAST_CYCLES), DUES_EXEMPT_PAST_CYCLES + DUES_EXEMPT_MAX_CYCLES, true);
$exemptionRows = [];
foreach ($exemptions as $userId => $rows) {
foreach ($rows as $row) {
$row['member'] = $members[$userId]['name'] ?? ('Konto #' . $userId);
$row['is_active'] = isset($members[$userId]) && $members[$userId]['active'];
$exemptionRows[] = $row;
}
}
usort($exemptionRows, static fn (array $a, array $b): int => [$a['starts_on'], mb_strtolower($a['member'])] <=> [$b['starts_on'], mb_strtolower($b['member'])]);
$endsBefore = $focus['starts_on'] ?? $today;
$currentExemptions = array_filter($exemptionRows, static fn (array $row): bool => $row['ends_on'] === null || $row['ends_on'] >= $endsBefore);
$pastExemptions = array_reverse(array_filter($exemptionRows, static fn (array $row): bool => $row['ends_on'] !== null && $row['ends_on'] < $endsBefore));
$shortPeriod = static fn (array $cycle): string => (new DateTimeImmutable($cycle['starts_on']))->format('d.m.') . '–' . (new DateTimeImmutable($cycle['ends_on']))->format('d.m.');
$dateLabel = static fn (?string $date): string => $date !== null ? (new DateTimeImmutable($date))->format('d.m.Y') : '';
$pageTitle = 'Legionsbeiträge';
$containerWide = true;
include __DIR__ . '/../includes/header.php';
?>
<div class="panel dues-panel">
<div class="dues-head">
<div>
<h1>Legionsbeiträge</h1>
<?php if ($configured): ?>
<p class="text-muted">
<?= e(ucfirst(dues_rhythm_label($settings['unit'], $settings['every']))) ?> <?= e(dues_kina($settings['amount'])) ?> je Mitglied
· erster Zyklus ab <?= e($dateLabel($settings['start'])) ?>
· <a href="#einstellungen">Einstellungen</a>
</p>
<?php else: ?>
<p class="text-muted">Hier hältst du fest, wer seinen Beitrag in Kina bezahlt hat. Nur für die Verwaltung – die Mitglieder sehen diese Seite nicht.</p>
<?php endif; ?>
</div>
</div>
<?php if ($configured): ?>
<?= dues_summary_html($focus, $focusTotals, $arrears) ?>
<?php endif; ?>
</div>
<?php if ($configured && $visible): ?>
<div class="panel" id="zahlungen">
<div class="dues-section-head">
<h2>Wer hat bezahlt?</h2>
<nav class="dues-pager" aria-label="Zyklen blättern">
<?php if ($olderUntil !== null): ?>
<a class="button button-secondary button-small" href="/admin/dues.php?bis=<?= (int) $olderUntil ?>#zahlungen">← Ältere</a>
<?php endif; ?>
<?php if ($newerUntil !== null): ?>
<a class="button button-secondary button-small" href="/admin/dues.php<?= $newerUntil !== $cycleIds[$lastIndex] ? '?bis=' . (int) $newerUntil : '' ?>#zahlungen">Neuere →</a>
<?php endif; ?>
</nav>
</div>
<p class="text-muted dues-hint">
Ein Klick auf ein Feld hakt die Zahlung ab, ein zweiter nimmt sie zurück. Wer zu Beginn eines Zyklus noch nicht dabei war,
befreit ist oder wessen Zyklus ausgesetzt wurde, muss nichts zahlen – abhaken lässt sich trotzdem, falls doch jemand zahlt.
</p>
<div class="list-toolbar dues-toolbar">
<label class="search-field">
<?= icon('search') ?>
<input type="search" placeholder="Mitglied suchen …" autocomplete="off" aria-label="Mitglieder durchsuchen" data-dues-search>
</label>
<div class="members-chips" role="group" aria-label="Nach Stand filtern" data-dues-filters>
<button type="button" class="members-chip active" data-value="" aria-pressed="true">Alle <span class="chip-count"><?= count($members) ?></span></button>
<?php if ($focus !== null): ?>
<button type="button" class="members-chip" data-value="open" aria-pressed="false" title="Im <?= $current !== null ? 'laufenden' : 'nächsten' ?> Zyklus noch offen">Offen <span class="chip-count" data-dues-count="open"><?= $filterCounts['open'] ?></span></button>
<button type="button" class="members-chip" data-value="paid" aria-pressed="false" title="Im <?= $current !== null ? 'laufenden' : 'nächsten' ?> Zyklus bezahlt">Bezahlt <span class="chip-count" data-dues-count="paid"><?= $filterCounts['paid'] ?></span></button>
<button type="button" class="members-chip" data-value="exempt" aria-pressed="false" title="Im <?= $current !== null ? 'laufenden' : 'nächsten' ?> Zyklus befreit">Befreit <span class="chip-count" data-dues-count="exempt"><?= $filterCounts['exempt'] ?></span></button>
<?php endif; ?>
<button type="button" class="members-chip" data-value="arrears" aria-pressed="false" title="Offene Zahlungen aus früheren Zyklen">Rückstand <span class="chip-count" data-dues-count="arrears"><?= $filterCounts['arrears'] ?></span></button>
</div>
</div>
<?php // Aussetzen/Fortsetzen: Knoepfe im Kopf der Tabelle gehoeren zu diesem Formular (form="dues-cycle-form") ?>
<form method="post" action="/admin/dues_action.php" id="dues-cycle-form" class="dues-hidden-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="cycle">
<input type="hidden" name="bis" value="<?= $bis ?>">
<input type="hidden" name="note" value="">
</form>
<form method="post" action="/admin/dues_action.php" class="dues-form" data-dues-form>
<?= csrf_field() ?>
<input type="hidden" name="action" value="toggle">
<input type="hidden" name="bis" value="<?= $bis ?>">
<div class="table-scroll dues-scroll">
<table class="dues-table">
<thead>
<tr>
<th scope="col" class="dues-member-col">Mitglied</th>
<?php foreach ($visible as $id => $cycle): ?>
<?php
$isCurrent = $current !== null && $current['id'] === $id;
$isNext = $next !== null && $next['id'] === $id;
$period = dues_period_label($cycle['starts_on'], $cycle['ends_on']);
?>
<th scope="col" class="dues-col<?= $isCurrent ? ' is-current' : '' ?><?= $isNext ? ' is-next' : '' ?><?= $cycle['suspended'] ? ' is-suspended' : '' ?>" title="<?= e($period . ($cycle['suspended'] && $cycle['note'] ? ' – ausgesetzt: ' . $cycle['note'] : '')) ?>">
<span class="dues-col-period"><?= e($shortPeriod($cycle)) ?></span>
<span class="dues-col-tag"><?= $cycle['suspended'] ? 'ausgesetzt' : ($isCurrent ? 'laufend' : ($isNext ? 'nächster' : (new DateTimeImmutable($cycle['starts_on']))->format('Y'))) ?></span>
<span class="dues-col-amount"><?= e(number_format($cycle['amount'], 0, ',', '.')) ?></span>
<?= dues_cycle_stats_html($cycle, $totals[$id]) ?>
<?php if ($cycle['suspended']): ?>
<button type="submit" form="dues-cycle-form" name="cycle" value="resume:<?= (int) $id ?>" class="icon-button dues-col-action"
title="Aussetzen zurücknehmen" aria-label="Aussetzen zurücknehmen: <?= e($period) ?>"
data-confirm="Im Zyklus <?= e($period) ?> müssen wieder alle zahlen, die nicht befreit sind." data-confirm-title="Zyklus fortsetzen?" data-confirm-ok="Fortsetzen"><?= icon('play') ?></button>
<?php else: ?>
<button type="submit" form="dues-cycle-form" name="cycle" value="suspend:<?= (int) $id ?>" class="icon-button dues-col-action"
title="Für alle aussetzen" aria-label="Für alle aussetzen: <?= e($period) ?>"
data-confirm="Im Zyklus <?= e($period) ?> muss niemand zahlen. Schon abgehakte Zahlungen bleiben stehen." data-confirm-title="Zyklus für alle aussetzen?"
data-confirm-ok="Aussetzen" data-confirm-input="note" data-confirm-placeholder="Grund (optional), z. B. Event-Woche"><?= icon('pause') ?></button>
<?php endif; ?>
</th>
<?php endforeach; ?>
<th scope="col" class="dues-arrears-col" title="Offene Zahlungen aus Zyklen, die schon vorbei sind">Rückstand</th>
</tr>
</thead>
<tbody>
<?php foreach ($members as $member): ?>
<tr data-dues-row="<?= (int) $member['id'] ?>" data-name="<?= e(mb_strtolower($member['name'])) ?>"
data-status="<?= e($focusStatus[$member['id']]) ?>" data-arrears="<?= (int) $arrears[$member['id']]['count'] ?>"<?= $member['active'] ? '' : ' class="is-former"' ?>>
<th scope="row" class="dues-member">
<span class="dues-member-inner">
<?= avatar_html($member, 26) ?>
<span class="dues-member-name"><?= e($member['name']) ?></span>
<?php if (!$member['active']): ?><span class="badge" title="Nicht mehr in der Legion">ehemalig</span><?php endif; ?>
</span>
</th>
<?php foreach ($visible as $id => $cycle): ?>
<td class="dues-cell-wrap<?= $current !== null && $current['id'] === $id ? ' is-current' : '' ?>">
<?= dues_cell_html($cycle, $member, dues_status($cycle, $member, $entries, $exemptions), $entries, $exemptions) ?>
</td>
<?php endforeach; ?>
<td class="dues-arrears-wrap"><?= dues_arrears_html($member['id'], $arrears[$member['id']]) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<p class="text-muted dues-no-match" data-dues-no-match hidden>Niemand passt zur Suche.</p>
</form>
<p class="dues-legend text-muted">
<span class="dues-cell is-paid" aria-hidden="true"><?= icon('check') ?></span> bezahlt
<span class="dues-cell is-open" aria-hidden="true"></span> offen
<span class="dues-cell is-exempt" aria-hidden="true"><span class="dues-cell-text">befreit</span></span>
<span class="dues-cell is-suspended" aria-hidden="true"><span class="dues-cell-text">–</span></span> ausgesetzt
<span class="dues-cell is-none" aria-hidden="true"><span class="dues-cell-text">·</span></span> noch nicht dabei
</p>
</div>
<?php elseif ($configured): ?>
<div class="panel"><p class="text-muted">Noch kein Zyklus angelegt.</p></div>
<?php endif; ?>
<?php if ($configured): ?>
<div class="panel" id="befreiungen">
<h2>Befreiungen</h2>
<p class="text-muted">
Befreite Mitglieder müssen in den gewählten Zyklen nichts zahlen – für einen Zyklus, mehrere oder bis auf Weiteres.
Einen ganzen Zyklus für alle setzt du oben in der Tabelle aus (<span class="dues-inline-icon"><?= icon('pause') ?></span>).
</p>
<form method="post" action="/admin/dues_action.php" class="dues-exempt-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="exempt_add">
<input type="hidden" name="bis" value="<?= $bis ?>">
<div class="dues-exempt-grid">
<fieldset class="dues-exempt-members">
<legend>Mitglieder</legend>
<label class="search-field">
<?= icon('search') ?>
<input type="search" placeholder="Mitglied suchen …" autocomplete="off" aria-label="Mitglieder für die Befreiung durchsuchen" data-dues-exempt-search>
</label>
<div class="checkbox-grid dues-member-picker" data-dues-exempt-list>
<?php foreach ($activeMembers as $member): ?>
<label data-name="<?= e(mb_strtolower($member['name'])) ?>">
<input type="checkbox" name="user_ids[]" value="<?= (int) $member['id'] ?>"> <?= e($member['name']) ?>
</label>
<?php endforeach; ?>
</div>
</fieldset>
<div class="dues-exempt-options">
<label for="dues-exempt-from">Ab Zyklus</label>
<select id="dues-exempt-from" name="from">
<?php foreach ($fromChoices as $index => $choice): ?>
<option value="<?= e($choice['starts_on']) ?>"<?= $index === $choiceFocus ? ' selected' : '' ?>>
<?= e(dues_period_label($choice['starts_on'], $choice['ends_on'])) ?><?= $choice['starts_on'] <= $today && $choice['ends_on'] >= $today ? ' (laufend)' : ($choice['ends_on'] < $today ? ' (vorbei)' : '') ?>
</option>
<?php endforeach; ?>
</select>
<label for="dues-exempt-cycles">Für</label>
<select id="dues-exempt-cycles" name="cycles">
<?php for ($n = 1; $n <= DUES_EXEMPT_MAX_CYCLES; $n++): ?>
<option value="<?= $n ?>"><?= $n ?> <?= $n === 1 ? 'Zyklus' : 'Zyklen' ?></option>
<?php endfor; ?>
<option value="0">bis auf Weiteres</option>
</select>
<label for="dues-exempt-note">Grund <span class="text-muted">(optional)</span></label>
<input type="text" id="dues-exempt-note" name="note" maxlength="255" placeholder="z. B. Urlaub, neu dabei, Zweitaccount">
<button type="submit">Befreien</button>
</div>
</div>
</form>
<?php if ($currentExemptions): ?>
<div class="table-scroll dues-exempt-table-wrap">
<table class="dues-exempt-table">
<thead><tr><th>Mitglied</th><th>Zeitraum</th><th>Grund</th><th>Eingetragen</th><th></th></tr></thead>
<tbody>
<?php foreach ($currentExemptions as $row): ?>
<?= dues_exemption_row_html($row, $bis, $currentEnd) ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p class="text-muted">Gerade ist niemand befreit.</p>
<?php endif; ?>
<?php if ($pastExemptions): ?>
<details class="dues-past-exemptions">
<summary>Frühere Befreiungen (<?= count($pastExemptions) ?>)</summary>
<div class="table-scroll dues-exempt-table-wrap">
<table class="dues-exempt-table">
<thead><tr><th>Mitglied</th><th>Zeitraum</th><th>Grund</th><th>Eingetragen</th><th></th></tr></thead>
<tbody>
<?php foreach ($pastExemptions as $row): ?>
<?= dues_exemption_row_html($row, $bis, $currentEnd) ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</details>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="panel" id="einstellungen">
<h2><?= $configured ? 'Einstellungen' : 'Beiträge einrichten' ?></h2>
<form method="post" action="/admin/dues_action.php" class="dues-settings-form">
<?= csrf_field() ?>
<input type="hidden" name="action" value="settings">
<div class="dues-settings-row">
<div>
<label for="dues-amount">Beitrag je Mitglied und Zyklus</label>
<div class="dues-amount-field">
<input type="text" id="dues-amount" name="amount" inputmode="numeric" required maxlength="20"
value="<?= $settings['amount'] > 0 ? e(number_format($settings['amount'], 0, ',', '.')) : '' ?>" placeholder="z. B. 500.000">
<span>Kina</span>
</div>
<div class="field-hint">Auch mit Kürzel wie im Spiel: 500k, 1,5kk, 2 Mio.</div>
</div>
<div>
<label for="dues-every">Rhythmus</label>
<div class="dues-rhythm-field">
<span>alle</span>
<input type="number" id="dues-every" name="every" min="1" max="<?= DUES_EVERY_MAX ?>" step="1" required value="<?= (int) $settings['every'] ?>">
<select name="unit" aria-label="Einheit">
<?php foreach (DUES_UNITS as $unit => [$one, $many]): ?>
<option value="<?= e($unit) ?>"<?= $settings['unit'] === $unit ? ' selected' : '' ?>><?= e($one) ?>(n)</option>
<?php endforeach; ?>
</select>
</div>
<div class="field-hint">z. B. alle 1 Woche = wöchentlich, alle 1 Monat = monatlich.</div>
</div>
<div>
<label for="dues-start">Erster Zyklus beginnt am</label>
<?php if ($hasData): ?>
<p class="dues-fixed"><?= e($dateLabel($settings['start'])) ?></p>
<div class="field-hint">Steht fest, sobald etwas abgehakt oder ausgesetzt ist.</div>
<?php else: ?>
<input type="date" id="dues-start" name="start" required value="<?= e($settings['start'] ?? $today) ?>"
min="<?= e(dues_day_shift($today, -366)) ?>" max="<?= e(dues_day_shift($today, 366)) ?>">
<div class="field-hint">Monatlich: an diesem Tag jeden Monat. Liegt er zurück, entstehen die Zyklen seitdem.</div>
<?php endif; ?>
</div>
</div>
<?php if ($hasData && $current !== null && !$current['suspended']): ?>
<label class="checkbox-label">
<input type="checkbox" name="apply_current" value="1">
Neuen Betrag schon für den laufenden Zyklus (<?= e(dues_period_label($current['starts_on'], $current['ends_on'])) ?>) übernehmen
</label>
<?php endif; ?>
<p class="field-hint">
<?php if ($hasData): ?>
Ein neuer Betrag gilt für alle kommenden Zyklen. Ein neuer Rhythmus beginnt nach dem laufenden Zyklus (bzw. nach dem letzten, in dem schon
etwas abgehakt oder der ausgesetzt ist); vergangene Zyklen bleiben, wie sie waren.
<?php else: ?>
Solange nichts abgehakt oder ausgesetzt ist, rechnet jede Änderung alle Zyklen neu – du kannst also gefahrlos ausprobieren.
<?php endif; ?>
</p>
<button type="submit"><?= $configured ? 'Einstellungen speichern' : 'Beiträge einrichten' ?></button>
</form>
</div>
<script src="<?= e(asset_url('/assets/js/dues.js')) ?>" defer></script>
<?php include __DIR__ . '/../includes/footer.php'; ?>