|
- // assets/scripts/report.js
-
- document.addEventListener('DOMContentLoaded', () => {
- document.addEventListener('click', async (e) => {
- const btn = e.target.closest('[data-action="toggle-invoiced"]');
- if (!btn) return;
-
- const row = btn.closest('[data-entry-id]');
- if (!row) return;
-
- const id = row.dataset.entryId;
-
- try {
- const res = await fetch(`/api/entries/${id}/invoiced`, { method: 'PATCH' });
- if (!res.ok) throw new Error(`HTTP ${res.status}`);
-
- const data = await res.json();
- const invoiced = data.invoiced;
-
- row.dataset.invoiced = invoiced ? 'true' : 'false';
- row.classList.toggle('report-table__row--invoiced', invoiced);
-
- btn.classList.toggle('report-lock--invoiced', invoiced);
- btn.title = invoiced
- ? (window.REPORT?.i18n?.btnUnlock ?? '')
- : (window.REPORT?.i18n?.btnLock ?? '');
-
- } catch (err) {
- console.error('Fehler beim Toggeln des Abrechnungsstatus:', err);
- }
- });
- });
|