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>
154 lines
6.5 KiB
JavaScript
154 lines
6.5 KiB
JavaScript
/**
|
|
* Legionsbeitraege (admin/dues.php): Zahlungen ohne Neuladen abhaken - das Feld, die Zahlen des Zyklus, der Rueckstand
|
|
* des Mitglieds und die Kennzahlen oben kommen neu gezeichnet von admin/dues_action.php zurueck. Dazu Suche und Filter
|
|
* der Tabelle (nach dem Stand im laufenden Zyklus bzw. dem Rueckstand) und die Suche in der Auswahl fuer Befreiungen.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
function element(html) {
|
|
var template = document.createElement('template');
|
|
template.innerHTML = String(html || '').trim();
|
|
return template.content.firstElementChild;
|
|
}
|
|
|
|
function replaceById(html) {
|
|
var fresh = element(html);
|
|
var old = fresh && fresh.id ? document.getElementById(fresh.id) : null;
|
|
if (old) old.replaceWith(fresh);
|
|
return fresh;
|
|
}
|
|
|
|
function showError(message) {
|
|
if (window.luminaDialog) window.luminaDialog.alert(message, { tone: 'error' });
|
|
else window.alert(message);
|
|
}
|
|
|
|
// ---- Tabelle: auf schmalen Bildschirmen gleich zum laufenden Zyklus scrollen (die Namen bleiben stehen) ----
|
|
var scroller = document.querySelector('.dues-scroll');
|
|
var currentCol = scroller && scroller.querySelector('.dues-col.is-current');
|
|
if (currentCol && scroller.scrollWidth > scroller.clientWidth) {
|
|
var nameCol = scroller.querySelector('.dues-member-col');
|
|
scroller.scrollLeft = Math.max(0, currentCol.offsetLeft - (nameCol ? nameCol.offsetWidth : 0));
|
|
}
|
|
|
|
// ---- Tabelle: Suche und Filter ----
|
|
var search = document.querySelector('[data-dues-search]');
|
|
var filters = document.querySelector('[data-dues-filters]');
|
|
var noMatch = document.querySelector('[data-dues-no-match]');
|
|
var filter = '';
|
|
|
|
function rows() {
|
|
return document.querySelectorAll('[data-dues-row]');
|
|
}
|
|
|
|
function applyFilter() {
|
|
var query = search ? search.value.trim().toLowerCase() : '';
|
|
var shown = 0;
|
|
rows().forEach(function (row) {
|
|
var match = (!query || row.dataset.name.indexOf(query) !== -1)
|
|
&& (filter === '' || (filter === 'arrears' ? Number(row.dataset.arrears) > 0 : row.dataset.status === filter));
|
|
row.hidden = !match;
|
|
if (match) shown++;
|
|
});
|
|
if (noMatch) noMatch.hidden = shown > 0;
|
|
}
|
|
|
|
function updateCounts() {
|
|
var counts = { open: 0, paid: 0, exempt: 0, arrears: 0 };
|
|
rows().forEach(function (row) {
|
|
if (Object.prototype.hasOwnProperty.call(counts, row.dataset.status)) counts[row.dataset.status]++;
|
|
if (Number(row.dataset.arrears) > 0) counts.arrears++;
|
|
});
|
|
document.querySelectorAll('[data-dues-count]').forEach(function (el) {
|
|
el.textContent = counts[el.dataset.duesCount];
|
|
});
|
|
}
|
|
|
|
if (search) search.addEventListener('input', applyFilter);
|
|
if (filters) {
|
|
filters.addEventListener('click', function (event) {
|
|
var chip = event.target.closest('.members-chip');
|
|
if (!chip) return;
|
|
filter = chip.dataset.value || '';
|
|
filters.querySelectorAll('.members-chip').forEach(function (other) {
|
|
var on = other === chip;
|
|
other.classList.toggle('active', on);
|
|
other.setAttribute('aria-pressed', on ? 'true' : 'false');
|
|
});
|
|
applyFilter();
|
|
});
|
|
}
|
|
|
|
// ---- Abhaken ----
|
|
// Ein Mitglied, das man gerade abhakt, bleibt stehen, auch wenn es nicht mehr zum Filter passt - erst ein neuer
|
|
// Filter oder eine Suche raeumt die Liste auf. So laesst sich ein Fehlklick sofort zuruecknehmen.
|
|
var form = document.querySelector('[data-dues-form]');
|
|
var busy = {};
|
|
|
|
function send(cell) {
|
|
var id = cell.id;
|
|
busy[id] = true;
|
|
cell.classList.add('is-busy');
|
|
cell.setAttribute('aria-busy', 'true');
|
|
var body = new FormData(form);
|
|
body.append('cell', cell.value);
|
|
fetch(form.getAttribute('action'), {
|
|
method: 'POST',
|
|
body: body,
|
|
credentials: 'same-origin',
|
|
headers: { 'X-Requested-With': 'fetch', 'Accept': 'application/json' }
|
|
})
|
|
.then(function (response) { return response.json(); })
|
|
.then(function (result) {
|
|
if (!result.ok) throw new Error(result.error || 'Speichern fehlgeschlagen');
|
|
var current = document.getElementById(id) || cell;
|
|
var focused = document.activeElement === current;
|
|
var row = current.closest('[data-dues-row]');
|
|
var fresh = element(result.cell);
|
|
current.replaceWith(fresh);
|
|
if (focused) fresh.focus({ preventScroll: true });
|
|
replaceById(result.stats);
|
|
replaceById(result.arrears);
|
|
replaceById(result.summary);
|
|
if (row) {
|
|
row.dataset.status = result.focus_status || '';
|
|
row.dataset.arrears = String(result.arrears_count || 0);
|
|
}
|
|
updateCounts();
|
|
})
|
|
.catch(function (error) {
|
|
cell.classList.remove('is-busy');
|
|
cell.removeAttribute('aria-busy');
|
|
showError(error.message || 'Speichern fehlgeschlagen');
|
|
})
|
|
.then(function () {
|
|
delete busy[id];
|
|
});
|
|
}
|
|
|
|
if (form && window.fetch && window.FormData) {
|
|
form.addEventListener('click', function (event) {
|
|
var cell = event.target.closest('[data-dues-cell]');
|
|
if (!cell) return;
|
|
event.preventDefault();
|
|
if (!busy[cell.id]) send(cell);
|
|
});
|
|
}
|
|
|
|
// ---- Befreiungen: Mitglieder suchen (angehakte bleiben sichtbar) ----
|
|
var exemptSearch = document.querySelector('[data-dues-exempt-search]');
|
|
var exemptList = document.querySelector('[data-dues-exempt-list]');
|
|
if (exemptSearch && exemptList) {
|
|
exemptSearch.addEventListener('input', function () {
|
|
var query = exemptSearch.value.trim().toLowerCase();
|
|
exemptList.querySelectorAll('label[data-name]').forEach(function (label) {
|
|
label.hidden = query !== '' && label.dataset.name.indexOf(query) === -1 && !label.querySelector('input').checked;
|
|
});
|
|
});
|
|
// Enter in der Suche soll nicht gleich die Befreiung abschicken
|
|
exemptSearch.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Enter') event.preventDefault();
|
|
});
|
|
}
|
|
})();
|