Asked for: alliances ("Consilium Elyseum") with their own view, a member-list tab with the allied legions and their
members, an own raid area, a calendar that shows them only alliance entries, and live map sessions the legion can
share with them - watching only, or drawing only with an extra permission. There is one Discord role "Consilium
Elyseum" for all allies, so which legion each ally belongs to is stored on the website.
- Permissions consilium.view / consilium.draw / consilium.manage. An account with consilium.view but without
dashboard.view is a guest of the Consilium (consilium_only(), sql_is_consilium_only()) and sees only the alliance
area; raids, calendar and map stay restricted even with extra rights like raids.view or map.view.
- includes/consilium.php; consilium.php is the allies' start page instead of the dashboard (next raids and entries,
legions, running shared map sessions); admin/consilium.php: setup hints, allied legions, member assignment.
users.consilium_legion_id, table consilium_legions (schema 69); allies pick their legion under Mein Profil.
- Members: new tab "Consilium Elyseum" (legions with their members), the only tab allies see. Legion-only lists
(dues, Lumipunkte, member pickers, raid and activity points) leave allies out.
- Raids: two areas, legion and Consilium, told apart by the Discord channel ("Consilium-Raids" under Verwaltung ->
Discord-Bot, settings.consilium_raid_channel; the bot API returns channel_id). Allies only see and sign up for
Consilium raids, which give no Lumipunkte; raids created in the Consilium area are posted to its channel.
- Calendar: audience "Consilium Elyseum". Allies see only those entries and the Consilium raids (also in their iCal
subscription), their own entries are always Consilium entries; the public calendar shows no Consilium raids; the
legion sees them marked with 🤝.
- Map: whoever may edit a public tactic shares its running live session with the Consilium (consilium_share, logged).
The share lives in the bot's live relay and only for that session: it ends with "Freigabe beenden" or 60 s after
the last legion member left; making the tactic private or deleting it ends it as well. Allies see only running
shared sessions under Karte (and on their start page), join and watch; with consilium.draw they add strokes,
areas, points and text - no figures, nothing moved, erased or undone, no tactics, steps, copies or history.
Enforced in tactics_api.php (guest branch: shared tactics only, only live_token and shape_create) and in the relay
(guest tickets, event whitelist, guests are disconnected when the share ends). Needs the bot update (api.py,
database/db.py, live_tactics.py).
- Navigation, privacy page, patch note, README.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
493 lines
23 KiB
PHP
493 lines
23 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
/**
|
||
* Legionsbeitraege (admin/dues.php, Recht dues.manage): Die Legion sammelt in einem festen Rhythmus einen Beitrag in
|
||
* Kina ein. Die Leitung legt Betrag, Rhythmus (alle N Wochen oder Monate) und den Beginn fest; daraus entstehen die
|
||
* Zyklen (dues_cycles) - immer bis zum laufenden und dazu der naechste, damit man ihn schon vorbereiten kann. Je Zyklus
|
||
* und Mitglied wird abgehakt, wer bezahlt hat (dues_entries). Befreiungen (dues_exemptions) gelten fuer alle Zyklen,
|
||
* die in ihrem Zeitraum beginnen: fuer einen Zyklus, mehrere oder bis auf Weiteres. Ein Zyklus laesst sich fuer alle
|
||
* aussetzen. Mitglieder sind alle freigeschalteten Konten; sie schulden einen Zyklus, wenn sie zu seinem Beginn schon
|
||
* dabei waren. Reine Verwaltungsseite - die Mitglieder selbst sehen davon nichts.
|
||
*
|
||
* Die Zyklen bilden eine Reihe ab dem Anker (dues_anchor): Zyklus k beginnt k * N Wochen bzw. Monate danach (Monate am
|
||
* selben Tag, in kuerzeren Monaten am letzten), so verschiebt sich nichts. Aendert die Leitung den Rhythmus, beginnt
|
||
* eine neue Reihe nach dem letzten Zyklus, der schon laeuft oder Daten hat.
|
||
*/
|
||
|
||
// Einstellungen (Tabelle settings)
|
||
const DUES_SETTING_AMOUNT = 'dues_amount';
|
||
const DUES_SETTING_UNIT = 'dues_unit';
|
||
const DUES_SETTING_EVERY = 'dues_every';
|
||
const DUES_SETTING_START = 'dues_start';
|
||
const DUES_SETTING_ANCHOR = 'dues_anchor';
|
||
// Rhythmus: Einheit => [Einzahl, Mehrzahl]
|
||
const DUES_UNITS = ['week' => ['Woche', 'Wochen'], 'month' => ['Monat', 'Monate']];
|
||
const DUES_EVERY_MAX = 12;
|
||
const DUES_AMOUNT_MAX = 999999999999;
|
||
// So viele Zyklen zeigt die Tabelle auf einmal
|
||
const DUES_VISIBLE_CYCLES = 6;
|
||
// Befreiungen: fuer hoechstens so viele Zyklen am Stueck (sonst "bis auf Weiteres"), ab so vielen vergangenen Zyklen
|
||
const DUES_EXEMPT_MAX_CYCLES = 12;
|
||
const DUES_EXEMPT_PAST_CYCLES = 3;
|
||
// Stand eines Mitglieds in einem Zyklus => Beschriftung
|
||
const DUES_STATUS_LABELS = [
|
||
'paid' => 'Bezahlt',
|
||
'open' => 'Offen',
|
||
'exempt' => 'Befreit',
|
||
'suspended' => 'Ausgesetzt',
|
||
'none' => 'Noch nicht dabei',
|
||
'gone' => 'Nicht mehr dabei',
|
||
];
|
||
|
||
/**
|
||
* Die Einstellungen: ['amount' => Kina, 'unit' => 'week'|'month', 'every' => N, 'start' => Beginn des ersten Zyklus,
|
||
* 'anchor' => Beginn der aktuellen Reihe] - start null: noch nicht eingerichtet.
|
||
*/
|
||
function dues_settings(): array
|
||
{
|
||
$unit = setting_get(DUES_SETTING_UNIT);
|
||
$start = dues_date(setting_get(DUES_SETTING_START));
|
||
return [
|
||
'amount' => max(0, (int) setting_get(DUES_SETTING_AMOUNT)),
|
||
'unit' => isset(DUES_UNITS[$unit]) ? $unit : 'week',
|
||
'every' => max(1, min(DUES_EVERY_MAX, (int) setting_get(DUES_SETTING_EVERY) ?: 1)),
|
||
'start' => $start,
|
||
'anchor' => dues_date(setting_get(DUES_SETTING_ANCHOR)) ?? $start,
|
||
];
|
||
}
|
||
|
||
/** Einstellungen speichern (setting_get liest sie erst beim naechsten Aufruf neu - danach mit $settings weiterarbeiten). */
|
||
function dues_settings_store(array $settings): void
|
||
{
|
||
setting_set(DUES_SETTING_AMOUNT, (string) $settings['amount']);
|
||
setting_set(DUES_SETTING_UNIT, $settings['unit']);
|
||
setting_set(DUES_SETTING_EVERY, (string) $settings['every']);
|
||
setting_set(DUES_SETTING_START, (string) $settings['start']);
|
||
setting_set(DUES_SETTING_ANCHOR, (string) $settings['anchor']);
|
||
}
|
||
|
||
function dues_configured(array $settings): bool
|
||
{
|
||
return $settings['start'] !== null && $settings['anchor'] !== null && $settings['amount'] > 0;
|
||
}
|
||
|
||
/** Datum als 'Y-m-d' pruefen: gueltig - der Text, sonst null. */
|
||
function dues_date(mixed $value): ?string
|
||
{
|
||
$value = is_string($value) ? trim($value) : '';
|
||
$date = DateTimeImmutable::createFromFormat('!Y-m-d', $value);
|
||
return $date !== false && $date->format('Y-m-d') === $value ? $value : null;
|
||
}
|
||
|
||
/** Tag davor bzw. danach ('Y-m-d'). */
|
||
function dues_day_shift(string $date, int $days): string
|
||
{
|
||
return (new DateTimeImmutable($date))->modify(($days >= 0 ? '+' : '') . $days . ' days')->format('Y-m-d');
|
||
}
|
||
|
||
/** Beginn des k-ten Zyklus einer Reihe ab $anchor - Monate am selben Tag, in kuerzeren Monaten am letzten. */
|
||
function dues_series_start(string $anchor, string $unit, int $every, int $k): string
|
||
{
|
||
$date = new DateTimeImmutable($anchor);
|
||
if ($unit !== 'month') {
|
||
return $date->modify('+' . (7 * $every * $k) . ' days')->format('Y-m-d');
|
||
}
|
||
$day = (int) $date->format('j');
|
||
$month = $date->modify('first day of this month')->modify('+' . ($every * $k) . ' months');
|
||
return $month->setDate((int) $month->format('Y'), (int) $month->format('n'), min($day, (int) $month->format('t')))->format('Y-m-d');
|
||
}
|
||
|
||
/**
|
||
* Die Zyklen der Reihe, die nach $after beginnen (null: ab dem Anker): [['starts_on', 'ends_on'], …] - so viele wie
|
||
* $count. Fuer neue Zyklen und fuer die Vorschau (Befreiungen fuer kuenftige Zyklen).
|
||
*/
|
||
function dues_series_after(array $settings, ?string $after, int $count): array
|
||
{
|
||
$anchor = (string) $settings['anchor'];
|
||
$k = 0;
|
||
while ($after !== null && dues_series_start($anchor, $settings['unit'], $settings['every'], $k) <= $after) {
|
||
if (++$k > 10000) {
|
||
return [];
|
||
}
|
||
}
|
||
$out = [];
|
||
for ($i = 0; $i < $count; $i++, $k++) {
|
||
$out[] = [
|
||
'starts_on' => dues_series_start($anchor, $settings['unit'], $settings['every'], $k),
|
||
'ends_on' => dues_day_shift(dues_series_start($anchor, $settings['unit'], $settings['every'], $k + 1), -1),
|
||
];
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
/**
|
||
* Fehlende Zyklen anlegen: alle bis zum laufenden und dazu den naechsten. Doppelte verhindert der eindeutige Beginn,
|
||
* falls zwei Seitenaufrufe gleichzeitig kommen.
|
||
*/
|
||
function dues_sync(?array $settings = null): void
|
||
{
|
||
$settings ??= dues_settings();
|
||
if (!dues_configured($settings)) {
|
||
return;
|
||
}
|
||
$pdo = db();
|
||
$today = date('Y-m-d');
|
||
$lastEnd = $pdo->query('SELECT MAX(ends_on) FROM dues_cycles')->fetchColumn();
|
||
$lastEnd = is_string($lastEnd) ? $lastEnd : null;
|
||
if ($lastEnd !== null && $lastEnd > $today) {
|
||
$next = $pdo->prepare('SELECT 1 FROM dues_cycles WHERE starts_on > ? LIMIT 1');
|
||
$next->execute([$today]);
|
||
if ($next->fetchColumn()) {
|
||
return;
|
||
}
|
||
}
|
||
$insert = $pdo->prepare('INSERT IGNORE INTO dues_cycles (starts_on, ends_on, amount) VALUES (?, ?, ?)');
|
||
// Auch wenn die Seite lange niemand geoeffnet hat, auf einmal nachholen (600 Wochen sind ueber elf Jahre)
|
||
foreach (dues_series_after($settings, $lastEnd, 600) as $cycle) {
|
||
$insert->execute([$cycle['starts_on'], $cycle['ends_on'], $settings['amount']]);
|
||
if ($cycle['starts_on'] > $today) {
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
/** Gibt es schon Zahlungen oder ausgesetzte Zyklen? Solange nicht, rechnet eine neue Einstellung alles neu. */
|
||
function dues_has_data(): bool
|
||
{
|
||
return (bool) db()->query('SELECT EXISTS (SELECT 1 FROM dues_entries) OR EXISTS (SELECT 1 FROM dues_cycles WHERE suspended = 1)')->fetchColumn();
|
||
}
|
||
|
||
/**
|
||
* Betrag aus dem Formular: "500000", "500.000", "500 000" oder mit Kuerzel wie im Spiel ("500k", "1,5kk", "2 Mio").
|
||
* Null, wenn nichts Brauchbares drinsteht.
|
||
*/
|
||
function dues_parse_kina(string $value): ?int
|
||
{
|
||
$value = mb_strtolower(str_replace([' ', "\u{00A0}", "'"], '', trim($value)));
|
||
$factors = ['k' => 1e3, 'kk' => 1e6, 'kkk' => 1e9, 'm' => 1e6, 'mio' => 1e6, 'mrd' => 1e9];
|
||
if (preg_match('/^(\d+(?:[.,]\d+)?)(k{1,3}|m|mio|mrd)$/', $value, $m)) {
|
||
$number = (float) str_replace(',', '.', $m[1]) * $factors[$m[2]];
|
||
} elseif (preg_match('/^(?:\d+|\d{1,3}(?:[.,]\d{3})+)$/', $value)) {
|
||
$number = (float) preg_replace('/\D/', '', $value);
|
||
} else {
|
||
return null;
|
||
}
|
||
$number = (int) round($number);
|
||
return $number >= 1 && $number <= DUES_AMOUNT_MAX ? $number : null;
|
||
}
|
||
|
||
/** "1.500.000 Kina" */
|
||
function dues_kina(int $amount): string
|
||
{
|
||
return number_format($amount, 0, ',', '.') . ' Kina';
|
||
}
|
||
|
||
/** "wöchentlich", "alle 2 Wochen", "monatlich", "alle 3 Monate" */
|
||
function dues_rhythm_label(string $unit, int $every): string
|
||
{
|
||
if ($every === 1) {
|
||
return $unit === 'month' ? 'monatlich' : 'wöchentlich';
|
||
}
|
||
return 'alle ' . $every . ' ' . DUES_UNITS[$unit][1];
|
||
}
|
||
|
||
/** Zeitraum eines Zyklus: "28.09.–04.10.2026", ueber den Jahreswechsel "29.12.2026–04.01.2027". */
|
||
function dues_period_label(string $start, string $end): string
|
||
{
|
||
$from = new DateTimeImmutable($start);
|
||
$to = new DateTimeImmutable($end);
|
||
return $from->format($from->format('Y') === $to->format('Y') ? 'd.m.' : 'd.m.Y') . '–' . $to->format('d.m.Y');
|
||
}
|
||
|
||
/** Alle Zyklen, aeltester zuerst: [id => Zeile mit int-Werten]. */
|
||
function dues_cycles(): array
|
||
{
|
||
$cycles = [];
|
||
foreach (db()->query('SELECT id, starts_on, ends_on, amount, suspended, note FROM dues_cycles ORDER BY starts_on')->fetchAll() as $row) {
|
||
$row['id'] = (int) $row['id'];
|
||
$row['amount'] = (int) $row['amount'];
|
||
$row['suspended'] = (int) $row['suspended'] === 1;
|
||
$cycles[$row['id']] = $row;
|
||
}
|
||
return $cycles;
|
||
}
|
||
|
||
/** Laufender Zyklus (heute darin) und der danach: ['current' => Zeile|null, 'next' => Zeile|null]. */
|
||
function dues_current(array $cycles): array
|
||
{
|
||
$today = date('Y-m-d');
|
||
$current = null;
|
||
$next = null;
|
||
foreach ($cycles as $cycle) {
|
||
if ($cycle['starts_on'] <= $today && $cycle['ends_on'] >= $today) {
|
||
$current = $cycle;
|
||
} elseif ($cycle['starts_on'] > $today && $next === null) {
|
||
$next = $cycle;
|
||
}
|
||
}
|
||
return ['current' => $current, 'next' => $next];
|
||
}
|
||
|
||
/**
|
||
* Mitglieder fuer die Tabelle: alle freigeschalteten Konten der Legion (nicht die verbuendeter Legionen im Consilium
|
||
* Elyseum - die zahlen keinen Beitrag und bekommen keine Erinnerung) und dazu $extraIds (ehemalige mit Zahlungen in den
|
||
* gezeigten Zyklen), nach Name - [id => ['id', 'name', 'joined' (Y-m-d), 'active', Felder fuer avatar_html]].
|
||
*/
|
||
function dues_members(array $extraIds = []): array
|
||
{
|
||
$extra = array_values(array_unique(array_map('intval', $extraIds)));
|
||
$stmt = db()->prepare(
|
||
"SELECT u.id, u.username, u.display_name, u.avatar_filename, u.status, u.deleted_at,
|
||
DATE(COALESCE(u.discord_joined_at, u.created_at)) AS joined
|
||
FROM users u WHERE (u.status = 'active' AND " . sql_is_legion_member('u') . ')'
|
||
. ($extra ? ' OR u.id IN (' . implode(',', array_fill(0, count($extra), '?')) . ')' : '')
|
||
);
|
||
$stmt->execute($extra);
|
||
$members = [];
|
||
foreach ($stmt->fetchAll() as $row) {
|
||
$row['id'] = (int) $row['id'];
|
||
$row['name'] = $row['display_name'] !== '' ? (string) $row['display_name'] : (string) $row['username'];
|
||
$row['active'] = $row['status'] === 'active';
|
||
$members[$row['id']] = $row;
|
||
}
|
||
uasort($members, static fn (array $a, array $b): int => [!$a['active'], mb_strtolower($a['name'])] <=> [!$b['active'], mb_strtolower($b['name'])]);
|
||
return $members;
|
||
}
|
||
|
||
/** Zahlungen der Zyklen (leer = aller): [cycle_id => [user_id => Zeile samt Name dessen, der abgehakt hat]]. */
|
||
function dues_entries(?array $cycleIds = null): array
|
||
{
|
||
if ($cycleIds === []) {
|
||
return [];
|
||
}
|
||
$sql = "SELECT e.cycle_id, e.user_id, e.updated_at, COALESCE(NULLIF(u.display_name, ''), u.username) AS updated_by_name
|
||
FROM dues_entries e LEFT JOIN users u ON u.id = e.updated_by";
|
||
if ($cycleIds !== null) {
|
||
$sql .= ' WHERE e.cycle_id IN (' . implode(',', array_map('intval', $cycleIds)) . ')';
|
||
}
|
||
$entries = [];
|
||
foreach (db()->query($sql)->fetchAll() as $row) {
|
||
$entries[(int) $row['cycle_id']][(int) $row['user_id']] = $row;
|
||
}
|
||
return $entries;
|
||
}
|
||
|
||
/** Alle Befreiungen: [user_id => [Zeile, …]] (neueste zuerst). */
|
||
function dues_exemptions(): array
|
||
{
|
||
$out = [];
|
||
$rows = db()->query(
|
||
"SELECT x.id, x.user_id, x.starts_on, x.ends_on, x.note, x.created_at, COALESCE(NULLIF(u.display_name, ''), u.username) AS created_by_name
|
||
FROM dues_exemptions x LEFT JOIN users u ON u.id = x.created_by ORDER BY x.starts_on DESC, x.id DESC"
|
||
)->fetchAll();
|
||
foreach ($rows as $row) {
|
||
$row['id'] = (int) $row['id'];
|
||
$out[(int) $row['user_id']][] = $row;
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
/** Die Befreiung, die einen Zyklus (nach seinem Beginn) abdeckt - oder null. */
|
||
function dues_exemption_for(array $exemptions, int $userId, string $cycleStart): ?array
|
||
{
|
||
foreach ($exemptions[$userId] ?? [] as $exemption) {
|
||
if ($exemption['starts_on'] <= $cycleStart && ($exemption['ends_on'] === null || $exemption['ends_on'] >= $cycleStart)) {
|
||
return $exemption;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* Stand eines Mitglieds in einem Zyklus (DUES_STATUS_LABELS). Eine Zahlung zaehlt immer - auch wenn jemand eigentlich
|
||
* befreit war oder der Zyklus ausgesetzt ist.
|
||
*/
|
||
function dues_status(array $cycle, array $member, array $entries, array $exemptions): string
|
||
{
|
||
if (isset($entries[$cycle['id']][$member['id']])) {
|
||
return 'paid';
|
||
}
|
||
if (!$member['active']) {
|
||
return 'gone';
|
||
}
|
||
if ($cycle['suspended']) {
|
||
return 'suspended';
|
||
}
|
||
if ((string) $member['joined'] > $cycle['starts_on']) {
|
||
return 'none';
|
||
}
|
||
return dues_exemption_for($exemptions, $member['id'], $cycle['starts_on']) !== null ? 'exempt' : 'open';
|
||
}
|
||
|
||
/**
|
||
* Zahlen eines Zyklus ueber die Mitglieder der Tabelle: ['paid', 'open', 'exempt', 'collected', 'expected'] - Soll ist,
|
||
* wer bezahlt hat oder noch offen ist.
|
||
*/
|
||
function dues_cycle_totals(array $cycle, array $members, array $entries, array $exemptions): array
|
||
{
|
||
$totals = ['paid' => 0, 'open' => 0, 'exempt' => 0];
|
||
foreach ($members as $member) {
|
||
$status = dues_status($cycle, $member, $entries, $exemptions);
|
||
if (isset($totals[$status])) {
|
||
$totals[$status]++;
|
||
}
|
||
}
|
||
$totals['collected'] = $totals['paid'] * $cycle['amount'];
|
||
$totals['expected'] = ($totals['paid'] + $totals['open']) * $cycle['amount'];
|
||
return $totals;
|
||
}
|
||
|
||
/**
|
||
* Rueckstand der aktiven Mitglieder: offene Zyklen, die schon vorbei sind - [user_id => ['count' => n, 'kina' => Summe]].
|
||
* Der laufende Zyklus zaehlt noch nicht.
|
||
*/
|
||
function dues_arrears(array $cycles, array $members, array $entries, array $exemptions): array
|
||
{
|
||
$today = date('Y-m-d');
|
||
$out = [];
|
||
foreach ($members as $member) {
|
||
$out[$member['id']] = ['count' => 0, 'kina' => 0];
|
||
if (!$member['active']) {
|
||
continue;
|
||
}
|
||
foreach ($cycles as $cycle) {
|
||
if ($cycle['ends_on'] < $today && dues_status($cycle, $member, $entries, $exemptions) === 'open') {
|
||
$out[$member['id']]['count']++;
|
||
$out[$member['id']]['kina'] += $cycle['amount'];
|
||
}
|
||
}
|
||
}
|
||
return $out;
|
||
}
|
||
|
||
/**
|
||
* Zyklen, ab denen sich jemand befreien laesst, und die, ueber die eine Befreiung reichen kann: die vorhandenen und
|
||
* danach die der Reihe (Vorschau) - [['starts_on', 'ends_on'], …], aeltester zuerst.
|
||
*/
|
||
function dues_cycle_choices(array $cycles, array $settings, int $future = 24): array
|
||
{
|
||
$list = [];
|
||
foreach ($cycles as $cycle) {
|
||
$list[] = ['starts_on' => $cycle['starts_on'], 'ends_on' => $cycle['ends_on']];
|
||
}
|
||
if (dues_configured($settings)) {
|
||
array_push($list, ...dues_series_after($settings, $list ? $list[count($list) - 1]['ends_on'] : null, $future));
|
||
}
|
||
return $list;
|
||
}
|
||
|
||
/**
|
||
* Kennzahlen oben auf der Seite: der laufende (sonst der naechste) Zyklus mit Zahlungen und Kina, dazu der Rueckstand
|
||
* aller Mitglieder. Beim Abhaken per JavaScript kommt der Kasten neu gezeichnet zurueck.
|
||
*/
|
||
function dues_summary_html(?array $focus, ?array $totals, array $arrears): string
|
||
{
|
||
$debtors = array_filter($arrears, static fn (array $row): bool => $row['count'] > 0);
|
||
$html = '<div class="dues-summary" id="dues-summary">';
|
||
if ($focus !== null && $totals !== null) {
|
||
$running = $focus['starts_on'] <= date('Y-m-d');
|
||
$html .= '<div class="dues-stat"><span class="dues-stat-label">' . ($running ? 'Laufender Zyklus' : 'Nächster Zyklus') . '</span>'
|
||
. '<strong>' . e(dues_period_label($focus['starts_on'], $focus['ends_on'])) . '</strong>'
|
||
. '<span class="dues-stat-sub">' . ($focus['suspended'] ? 'für alle ausgesetzt' : e(dues_kina($focus['amount'])) . ' je Mitglied') . '</span></div>'
|
||
. '<div class="dues-stat"><span class="dues-stat-label">Bezahlt</span>'
|
||
. '<strong>' . $totals['paid'] . ' von ' . ($totals['paid'] + $totals['open']) . '</strong>'
|
||
. '<span class="dues-stat-sub">' . $totals['open'] . ' offen' . ($totals['exempt'] > 0 ? ', ' . $totals['exempt'] . ' befreit' : '') . '</span></div>'
|
||
. '<div class="dues-stat"><span class="dues-stat-label">Eingenommen</span>'
|
||
. '<strong>' . e(dues_kina($totals['collected'])) . '</strong>'
|
||
. '<span class="dues-stat-sub">von ' . e(dues_kina($totals['expected'])) . '</span></div>';
|
||
}
|
||
$html .= '<div class="dues-stat' . ($debtors ? ' has-arrears' : '') . '"><span class="dues-stat-label">Rückstand aus früheren Zyklen</span>'
|
||
. '<strong>' . ($debtors ? count($debtors) . (count($debtors) === 1 ? ' Mitglied' : ' Mitglieder') : 'keiner') . '</strong>'
|
||
. '<span class="dues-stat-sub">' . ($debtors ? e(dues_kina((int) array_sum(array_column($debtors, 'kina')))) . ' offen' : 'alle vorigen Zyklen sind bezahlt') . '</span></div>';
|
||
return $html . '</div>';
|
||
}
|
||
|
||
/** Zeitraum einer Befreiung: "ab 28.09.2026", "28.09.–18.10.2026" oder "bis auf Weiteres". */
|
||
function dues_exemption_label(array $exemption): string
|
||
{
|
||
if ($exemption['ends_on'] === null) {
|
||
return 'ab ' . (new DateTimeImmutable($exemption['starts_on']))->format('d.m.Y') . ', bis auf Weiteres';
|
||
}
|
||
return dues_period_label($exemption['starts_on'], $exemption['ends_on']);
|
||
}
|
||
|
||
/** Letzter Tag des laufenden Zyklus (ohne laufenden: heute) - bis dahin gilt eine beendete Befreiung noch. */
|
||
function dues_current_end(array $cycles): string
|
||
{
|
||
return dues_current($cycles)['current']['ends_on'] ?? date('Y-m-d');
|
||
}
|
||
|
||
/**
|
||
* Eine Befreiung in der Liste (admin/dues.php): Mitglied, Zeitraum, Grund, wer sie eingetragen hat, dazu "Beenden"
|
||
* (laeuft sie gerade, gilt sie ab dem naechsten Zyklus nicht mehr) und "Loeschen" (als haette es sie nie gegeben).
|
||
* $row braucht dazu 'member' (Name) und 'is_active', $currentEnd kommt von dues_current_end().
|
||
*/
|
||
function dues_exemption_row_html(array $row, int $bis, string $currentEnd): string
|
||
{
|
||
$running = $row['starts_on'] <= date('Y-m-d') && ($row['ends_on'] === null || $row['ends_on'] > $currentEnd);
|
||
$form = static fn (string $action, string $attributes, string $button): string
|
||
=> '<form method="post" action="/admin/dues_action.php" class="inline-form"' . $attributes . '>' . csrf_field()
|
||
. '<input type="hidden" name="action" value="' . $action . '"><input type="hidden" name="id" value="' . (int) $row['id'] . '">'
|
||
. '<input type="hidden" name="bis" value="' . $bis . '">' . $button . '</form>';
|
||
return '<tr>'
|
||
. '<td>' . e($row['member']) . ($row['is_active'] ? '' : ' <span class="badge" title="Nicht mehr in der Legion">ehemalig</span>') . '</td>'
|
||
. '<td>' . e(dues_exemption_label($row)) . '</td>'
|
||
. '<td>' . e((string) ($row['note'] ?? '')) . '</td>'
|
||
. '<td class="text-muted">' . e((new DateTimeImmutable((string) $row['created_at']))->format('d.m.Y'))
|
||
. ($row['created_by_name'] !== null ? ' von ' . e((string) $row['created_by_name']) : '') . '</td>'
|
||
. '<td class="dues-exempt-actions">'
|
||
. ($running ? $form('exempt_end', ' data-confirm="' . e($row['member']) . ' muss ab dem nächsten Zyklus wieder zahlen. Die bisherigen Zyklen bleiben befreit."'
|
||
. ' data-confirm-title="Befreiung beenden?" data-confirm-ok="Beenden"', '<button type="submit" class="button-secondary button-small">Beenden</button>') : '')
|
||
. $form('exempt_delete', ' data-confirm="Die Befreiung verschwindet ganz – auch Zyklen, die schon vorbei sind, gelten dann wieder als offen, wenn nicht bezahlt wurde."'
|
||
. ' data-confirm-title="Befreiung löschen?" data-confirm-danger data-confirm-ok="Löschen"',
|
||
'<button type="submit" class="icon-button icon-button-danger" title="Löschen" aria-label="Befreiung von ' . e($row['member']) . ' löschen">' . icon('trash') . '</button>')
|
||
. '</td></tr>';
|
||
}
|
||
|
||
/**
|
||
* Ein Feld der Tabelle: Knopf zum Abhaken mit dem Stand als Symbol und Erklaerung. Er schickt den Zustand mit, den er
|
||
* herstellt (cell=Zyklus:Mitglied:1 = bezahlt, :0 = zuruecknehmen) - zwei gleichzeitige Klicks heben sich so nicht auf.
|
||
*/
|
||
function dues_cell_html(array $cycle, array $member, string $status, array $entries, array $exemptions): string
|
||
{
|
||
$entry = $entries[$cycle['id']][$member['id']] ?? null;
|
||
$title = DUES_STATUS_LABELS[$status];
|
||
if ($status === 'paid' && $entry !== null) {
|
||
$title .= ' – abgehakt' . ($entry['updated_by_name'] !== null ? ' von ' . $entry['updated_by_name'] : '')
|
||
. ' am ' . (new DateTimeImmutable((string) $entry['updated_at']))->format('d.m.Y H:i');
|
||
} elseif ($status === 'exempt' && ($exemption = dues_exemption_for($exemptions, $member['id'], $cycle['starts_on'])) !== null) {
|
||
$title .= ' (' . dues_exemption_label($exemption) . ')' . ($exemption['note'] !== null && $exemption['note'] !== '' ? ': ' . $exemption['note'] : '');
|
||
} elseif ($status === 'none') {
|
||
$title .= ' – Mitglied seit ' . (new DateTimeImmutable((string) $member['joined']))->format('d.m.Y');
|
||
}
|
||
$title .= $status === 'paid' ? '. Klicken, um es zurückzunehmen.' : '. Klicken, wenn bezahlt.';
|
||
$symbol = match ($status) {
|
||
'paid' => icon('check'),
|
||
'exempt' => '<span class="dues-cell-text">befreit</span>',
|
||
'suspended', 'gone' => '<span class="dues-cell-text">–</span>',
|
||
'none' => '<span class="dues-cell-text">·</span>',
|
||
default => '',
|
||
};
|
||
return '<button type="submit" class="dues-cell is-' . $status . '" name="cell" value="' . $cycle['id'] . ':' . $member['id'] . ':' . ($status === 'paid' ? 0 : 1) . '"'
|
||
. ' id="dues-cell-' . $cycle['id'] . '-' . $member['id'] . '" data-dues-cell title="' . e($title) . '"'
|
||
. ' aria-label="' . e($member['name'] . ', ' . dues_period_label($cycle['starts_on'], $cycle['ends_on']) . ': ' . $title) . '"'
|
||
. ' aria-pressed="' . ($status === 'paid' ? 'true' : 'false') . '">' . $symbol . '</button>';
|
||
}
|
||
|
||
/** Zahlen eines Zyklus im Kopf seiner Spalte: "12/30 bezahlt" und die Kina-Summe. */
|
||
function dues_cycle_stats_html(array $cycle, array $totals): string
|
||
{
|
||
$due = $totals['paid'] + $totals['open'];
|
||
return '<span class="dues-col-stats" id="dues-stats-' . $cycle['id'] . '" title="' . e(dues_kina($totals['collected']) . ' von ' . dues_kina($totals['expected'])
|
||
. ($totals['exempt'] > 0 ? ', ' . $totals['exempt'] . ' befreit' : '')) . '">'
|
||
. '<strong>' . $totals['paid'] . '/' . $due . '</strong> bezahlt</span>';
|
||
}
|
||
|
||
/** Rueckstand eines Mitglieds (letzte Spalte). */
|
||
function dues_arrears_html(int $userId, array $arrears): string
|
||
{
|
||
$count = $arrears['count'] ?? 0;
|
||
return '<span class="dues-arrears' . ($count > 0 ? ' has-arrears' : '') . '" id="dues-arrears-' . $userId . '">'
|
||
. ($count > 0 ? $count . ' × · ' . e(dues_kina((int) $arrears['kina'])) : '–') . '</span>';
|
||
}
|