|
|
|
@@ -72,9 +72,10 @@
|
|
|
|
|
color: #1f2937;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Angepasst für 4 Filter-Felder statt 3 */
|
|
|
|
|
.filter-bar {
|
|
|
|
|
display: grid;
|
|
|
|
|
grid-template-columns: 1fr 220px 220px;
|
|
|
|
|
grid-template-columns: 1fr 140px 180px 180px;
|
|
|
|
|
gap: 10px;
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
}
|
|
|
|
@@ -121,6 +122,7 @@
|
|
|
|
|
letter-spacing: 0.04em;
|
|
|
|
|
color: #64748b;
|
|
|
|
|
background: var(--ui-surface-soft);
|
|
|
|
|
user-select: none; /* Verhindert Textmarkierung beim Klicken */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.library-table tr:hover td {
|
|
|
|
@@ -149,11 +151,13 @@
|
|
|
|
|
.badge-open { background: #fee2e2; color: #991b1b; }
|
|
|
|
|
.badge-paid { background: #dcfce7; color: #166534; }
|
|
|
|
|
.badge-damaged { background: #fee2e2; color: #991b1b; }
|
|
|
|
|
.badge-class { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; } /* Neues Badge für Klasse */
|
|
|
|
|
|
|
|
|
|
.row-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.row-actions form {
|
|
|
|
@@ -196,7 +200,7 @@
|
|
|
|
|
<div class="library-admin-hero">
|
|
|
|
|
<div>
|
|
|
|
|
<h1>Bibliotheks-Ausleihen</h1>
|
|
|
|
|
<p>Nur Bibliotheksmedien. Hier kannst du offene Ausleihen abschließen, Rechnungen bezahlen und defekte Medien direkt zurücksetzen.</p>
|
|
|
|
|
<p>Nur Bibliotheksmedien. Hier kannst du offene Ausleihen abschließen, Rechnungen bezahlen und defekte Medien verwalten.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="hero-actions">
|
|
|
|
|
<a class="btn btn-secondary" href="{{ url_for('library_view') }}">Bibliothek öffnen</a>
|
|
|
|
@@ -215,21 +219,36 @@
|
|
|
|
|
<div class="value">{{ damaged_items|length }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="summary-card">
|
|
|
|
|
<span class="label">Direkt reparierbar</span>
|
|
|
|
|
<span class="label">Direkt bearbeitbar</span>
|
|
|
|
|
<div class="value">{{ damaged_items|length }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="filter-bar">
|
|
|
|
|
<input id="library-search" type="text" placeholder="Nach Element, Benutzer, Ausweis oder Rechnung suchen...">
|
|
|
|
|
<input id="library-search" type="text" placeholder="Nach Element, Benutzer, Klasse, Ausweis oder Rechnung suchen...">
|
|
|
|
|
|
|
|
|
|
<!-- NEU: Klassen-Filter -->
|
|
|
|
|
<select id="class-filter">
|
|
|
|
|
<option value="all">Alle Klassen</option>
|
|
|
|
|
{% set classes = [] %}
|
|
|
|
|
{% for e in loan_entries %}
|
|
|
|
|
{% if e.klasse and e.klasse not in classes %}
|
|
|
|
|
{% set _ = classes.append(e.klasse) %}
|
|
|
|
|
{% endif %}
|
|
|
|
|
{% endfor %}
|
|
|
|
|
{% for c in classes|sort %}
|
|
|
|
|
<option value="{{ c|lower }}">{{ c }}</option>
|
|
|
|
|
{% endfor %}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="loan-status-filter">
|
|
|
|
|
<option value="">Alle Ausleihen</option>
|
|
|
|
|
<option value="">Alle Status</option>
|
|
|
|
|
<option value="active">Aktiv</option>
|
|
|
|
|
<option value="planned">Geplant</option>
|
|
|
|
|
<option value="completed">Abgeschlossen</option>
|
|
|
|
|
</select>
|
|
|
|
|
<select id="damage-filter">
|
|
|
|
|
<option value="all">Alle Einträge</option>
|
|
|
|
|
<option value="all">Alle Zustände</option>
|
|
|
|
|
<option value="damage">Nur defekt</option>
|
|
|
|
|
<option value="clean">Nur ohne Schaden</option>
|
|
|
|
|
</select>
|
|
|
|
@@ -241,18 +260,31 @@
|
|
|
|
|
<table class="library-table" id="loans-table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Status</th>
|
|
|
|
|
<th>Element</th>
|
|
|
|
|
<th>Benutzer</th>
|
|
|
|
|
<th>Zeit</th>
|
|
|
|
|
<th>Rechnung</th>
|
|
|
|
|
<th>Schaden</th>
|
|
|
|
|
<!-- NEU: onClick Handler zum Sortieren hinzugefügt -->
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 0)">Status ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 1)">Element ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 2)">Benutzer ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 3)">Klasse ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 4)">Zeit ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 5)">Rechnung ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('loans-table', 6)">Schaden ↕</th>
|
|
|
|
|
<th>Aktionen</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<!-- NEU: data-klasse hinzugefügt -->
|
|
|
|
|
{% for e in loan_entries %}
|
|
|
|
|
<tr class="loan-row" data-borrow-id="{{ e.id }}" data-item-id="{{ e.item_id }}" data-item-name="{{ e.item_name }}" data-item-code="{{ e.item_code }}" data-item-cost="{{ e.item_cost_raw }}" data-user-name="{{ e.user }}" data-search="{{ (e.item_name ~ ' ' ~ e.item_code ~ ' ' ~ e.user ~ ' ' ~ e.invoice_number ~ ' ' ~ e.item_author ~ ' ' ~ e.item_isbn)|lower }}" data-status="{{ e.status }}" data-has-damage="{{ '1' if e.has_damage else '0' }}">
|
|
|
|
|
<tr class="loan-row"
|
|
|
|
|
data-borrow-id="{{ e.id }}"
|
|
|
|
|
data-item-id="{{ e.item_id }}"
|
|
|
|
|
data-item-name="{{ e.item_name }}"
|
|
|
|
|
data-item-code="{{ e.item_code }}"
|
|
|
|
|
data-item-cost="{{ e.item_cost_raw }}"
|
|
|
|
|
data-user-name="{{ e.user }}"
|
|
|
|
|
data-klasse="{{ (e.klasse|default(''))|lower }}"
|
|
|
|
|
data-search="{{ (e.item_name ~ ' ' ~ e.item_code ~ ' ' ~ e.user ~ ' ' ~ (e.klasse|default('')) ~ ' ' ~ e.invoice_number ~ ' ' ~ e.item_author ~ ' ' ~ e.item_isbn)|lower }}"
|
|
|
|
|
data-status="{{ e.status }}"
|
|
|
|
|
data-has-damage="{{ '1' if e.has_damage else '0' }}">
|
|
|
|
|
<td>
|
|
|
|
|
{% if e.status == 'active' %}
|
|
|
|
|
<span class="badge-pill badge-active">Aktiv</span>
|
|
|
|
@@ -267,15 +299,23 @@
|
|
|
|
|
<div class="muted">{{ e.item_author or '—' }}</div>
|
|
|
|
|
<div class="mono">{{ e.item_code or '—' }}</div>
|
|
|
|
|
<div style="margin-top:6px;">
|
|
|
|
|
<a class="btn btn-outline-secondary btn-sm" href="{{ url_for('library_item_invoices', item_id=e.item_id) }}">Rechnungen</a>
|
|
|
|
|
<a class="btn btn-outline-secondary btn-sm" href="{{ url_for('library_item_invoices', item_id=e.item_id) }}">Rechnungen / Historie</a>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<div>{{ e.user }}</div>
|
|
|
|
|
<div class="muted">{{ e.start }}{% if e.end %} bis {{ e.end }}{% endif %}</div>
|
|
|
|
|
<div><strong>{{ e.user }}</strong></div>
|
|
|
|
|
</td>
|
|
|
|
|
<!-- NEU: Klasse Spalte -->
|
|
|
|
|
<td>
|
|
|
|
|
{% if e.klasse %}
|
|
|
|
|
<span class="badge-pill badge-class">{{ e.klasse }}</span>
|
|
|
|
|
{% else %}
|
|
|
|
|
<span class="muted">—</span>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<div>{{ e.period or '—' }}</div>
|
|
|
|
|
<div class="muted">{{ e.start }}{% if e.end %} bis {{ e.end }}{% endif %}</div>
|
|
|
|
|
{% if e.notes %}<div class="muted">{{ e.notes }}</div>{% endif %}
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
@@ -311,35 +351,29 @@
|
|
|
|
|
{% if e.status == 'active' %}
|
|
|
|
|
<button type="button" class="btn btn-outline-danger btn-sm" onclick="openDamageReportPrompt(this)">Schaden melden</button>
|
|
|
|
|
{% endif %}
|
|
|
|
|
{% if e.invoice_number and ((not e.invoice_paid) or e.has_damage) %}
|
|
|
|
|
<form method="post" action="{{ url_for('admin_finalize_invoice_and_repair', borrow_id=e.id) }}" onsubmit="return confirm('Rechnung als bezahlt und Element als repariert markieren?');">
|
|
|
|
|
<button type="submit" class="btn btn-success btn-sm">
|
|
|
|
|
{% if not e.invoice_paid and e.has_damage %}
|
|
|
|
|
Bezahlt + repariert
|
|
|
|
|
{% elif not e.invoice_paid %}
|
|
|
|
|
Als bezahlt markieren
|
|
|
|
|
{% else %}
|
|
|
|
|
Als repariert markieren
|
|
|
|
|
{% endif %}
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
|
|
|
|
{% elif e.has_damage %}
|
|
|
|
|
<form method="post" action="{{ url_for('mark_damage_repaired', id=e.item_id) }}" onsubmit="return confirm('Medium als repariert markieren?');">
|
|
|
|
|
<button type="submit" class="btn btn-success btn-sm">Als repariert markieren</button>
|
|
|
|
|
|
|
|
|
|
{% if e.invoice_number and not e.invoice_paid %}
|
|
|
|
|
<form method="post" action="{{ url_for('admin_mark_invoice_paid', borrow_id=e.id) }}" onsubmit="return confirm('Rechnung als bezahlt markieren?');">
|
|
|
|
|
<button type="submit" class="btn btn-success btn-sm">Als bezahlt markieren</button>
|
|
|
|
|
</form>
|
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
|
{% if e.has_damage %}
|
|
|
|
|
<!-- Aufruf des Reparatur-Auswahl-Modals -->
|
|
|
|
|
<button type="button" class="btn btn-warning btn-sm" onclick="openRepairModal('{{ e.item_id }}', '{{ e.item_code }}')">Reparieren / Ersetzen</button>
|
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
|
{% if e.invoice_number %}
|
|
|
|
|
<form method="post" action="{{ url_for('admin_add_invoice_correction', borrow_id=e.id) }}" onsubmit="return confirm('Korrekturbuchung hinzufügen?');">
|
|
|
|
|
<input type="text" name="correction_reason" placeholder="Korrekturgrund" required style="padding:6px; border:1px solid #ddd; border-radius:6px; min-width:140px;">
|
|
|
|
|
<input type="text" name="amount_delta" placeholder="Delta optional" style="padding:6px; border:1px solid #ddd; border-radius:6px; width:120px;">
|
|
|
|
|
<form method="post" action="{{ url_for('admin_add_invoice_correction', borrow_id=e.id) }}" onsubmit="return confirm('Korrekturbuchung hinzufügen?');" style="display: flex; gap: 6px; align-items: center; flex-wrap: wrap;">
|
|
|
|
|
<input type="text" name="correction_reason" value="Korrektur zu {{ e.invoice_number }}" placeholder="Korrekturgrund" required style="padding:6px; border:1px solid #ddd; border-radius:6px; min-width:160px; max-width:180px;">
|
|
|
|
|
<input type="text" name="amount_delta" placeholder="z.B. -{{ e.invoice_amount }}" style="padding:6px; border:1px solid #ddd; border-radius:6px; width:120px;">
|
|
|
|
|
<button type="submit" class="btn btn-outline-danger btn-sm">Korrektur</button>
|
|
|
|
|
</form>
|
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
|
|
{% if e.status in ['active', 'planned'] %}
|
|
|
|
|
<form method="post" action="{{ url_for('admin_reset_borrowing', borrow_id=e.id) }}" onsubmit="return confirm('Ausleihe zurücksetzen?');">
|
|
|
|
|
<button type="submit" class="btn btn-warning btn-sm">Zurücksetzen</button>
|
|
|
|
|
<button type="submit" class="btn btn-secondary btn-sm">Zurücksetzen</button>
|
|
|
|
|
</form>
|
|
|
|
|
{% endif %}
|
|
|
|
|
</div>
|
|
|
|
@@ -360,10 +394,11 @@
|
|
|
|
|
<table class="library-table" id="damaged-table">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>Element</th>
|
|
|
|
|
<th>Code</th>
|
|
|
|
|
<th>Schaden</th>
|
|
|
|
|
<th>Status</th>
|
|
|
|
|
<!-- NEU: onClick Handler zum Sortieren hinzugefügt -->
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('damaged-table', 0)">Element ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('damaged-table', 1)">Code ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('damaged-table', 2)">Schaden ↕</th>
|
|
|
|
|
<th style="cursor: pointer;" onclick="sortTable('damaged-table', 3)">Status ↕</th>
|
|
|
|
|
<th>Aktion</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
@@ -392,9 +427,8 @@
|
|
|
|
|
<div class="row-actions" style="margin-bottom:8px;">
|
|
|
|
|
<a class="btn btn-outline-secondary btn-sm" href="{{ url_for('library_item_invoices', item_id=item.id) }}">Rechnungen</a>
|
|
|
|
|
</div>
|
|
|
|
|
<form method="post" action="{{ url_for('mark_damage_repaired', id=item.id) }}" onsubmit="return confirm('Dieses Medium als repariert und wieder verfügbar markieren?');">
|
|
|
|
|
<button type="submit" class="btn btn-success btn-sm">Als repariert markieren</button>
|
|
|
|
|
</form>
|
|
|
|
|
<!-- Aufruf des Reparatur-Auswahl-Modals -->
|
|
|
|
|
<button type="button" class="btn btn-warning btn-sm" onclick="openRepairModal('{{ item.id }}', '{{ item.code }}')">Reparieren / Ersetzen</button>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
{% endfor %}
|
|
|
|
@@ -407,14 +441,15 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div id="damage-invoice-modal" style="display:none; position:fixed; inset:0; background:rgba(15,23,42,0.72); z-index:9999; padding:20px; overflow:auto;">
|
|
|
|
|
<!-- Modal: Rechnung für Schaden erstellen -->
|
|
|
|
|
<div id="damage-invoice-modal" role="dialog" aria-modal="true" aria-labelledby="modal-title" style="display:none; position:fixed; inset:0; background:rgba(15,23,42,0.72); z-index:9999; padding:20px; overflow:auto;">
|
|
|
|
|
<div style="max-width:760px; margin:40px auto; background: var(--ui-surface); border-radius:12px; padding:24px; box-shadow:0 20px 60px rgba(0,0,0,0.3);">
|
|
|
|
|
<div style="display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:18px;">
|
|
|
|
|
<div>
|
|
|
|
|
<h2 style="margin:0;">Rechnung erstellen</h2>
|
|
|
|
|
<h2 id="modal-title" style="margin:0;">Rechnung erstellen</h2>
|
|
|
|
|
<p style="margin:6px 0 0; color:#666;">Die Rechnung nutzt das bestehende Rechnungssystem und kann direkt nach der Schadensmeldung erstellt werden.</p>
|
|
|
|
|
</div>
|
|
|
|
|
<button type="button" class="btn btn-secondary" onclick="closeDamageInvoiceModal()">Schließen</button>
|
|
|
|
|
<button type="button" class="btn btn-secondary" onclick="closeDamageInvoiceModal()" aria-label="Modal schließen">Schließen</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<form id="damage-invoice-form" method="post" action="">
|
|
|
|
@@ -432,7 +467,10 @@
|
|
|
|
|
<input id="damage-invoice-code" type="text" readonly style="width:100%; padding:10px; border:1px solid #ddd; border-radius:6px; background: var(--ui-surface-soft);">
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<label for="damage-invoice-amount" style="display:block; font-weight:700; margin-bottom:6px;">Preis</label>
|
|
|
|
|
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:6px;">
|
|
|
|
|
<label for="damage-invoice-amount" style="font-weight:700; margin:0;">Preis</label>
|
|
|
|
|
<button type="button" id="damage-invoice-replace-btn" class="btn btn-outline-secondary btn-sm" style="padding: 2px 8px; font-size: 0.75rem;">Komplett ersetzen</button>
|
|
|
|
|
</div>
|
|
|
|
|
<input id="damage-invoice-amount" name="invoice_amount" type="text" required style="width:100%; padding:10px; border:1px solid #ddd; border-radius:6px;" placeholder="z.B. 12,50">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
@@ -461,15 +499,44 @@
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Neues Modal: Reparatur-Optionen (Reparieren, Ersetzen mit neuem Code_4, Löschen) -->
|
|
|
|
|
<div id="repair-action-modal" role="dialog" aria-modal="true" aria-labelledby="repair-modal-title" style="display:none; position:fixed; inset:0; background:rgba(15,23,42,0.72); z-index:9999; padding:20px; overflow:auto;">
|
|
|
|
|
<div style="max-width:540px; margin:60px auto; background: var(--ui-surface); border-radius:12px; padding:24px; box-shadow:0 20px 60px rgba(0,0,0,0.3);">
|
|
|
|
|
<div style="display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:16px;">
|
|
|
|
|
<h2 id="repair-modal-title" style="margin:0; font-size: 1.3rem;">Medium-Bearbeitung nach Reparatur</h2>
|
|
|
|
|
<button type="button" class="btn btn-secondary btn-sm" onclick="closeRepairModal()">Schließen</button>
|
|
|
|
|
</div>
|
|
|
|
|
<p style="color: #666; margin-bottom: 18px; font-size: 0.95rem;">Wähle aus, wie mit diesem beschädigten Medium weiter verfahren werden soll:</p>
|
|
|
|
|
|
|
|
|
|
<form id="repair-action-form" method="post" action="">
|
|
|
|
|
<input type="hidden" name="action" id="repair-action-input" value="repair">
|
|
|
|
|
|
|
|
|
|
<div style="margin-bottom: 16px; display: none;" id="new-code-container">
|
|
|
|
|
<label for="modal-new-code-4" style="display:block; font-weight:700; margin-bottom:6px;">Neuer Code 4 (Inventarnummer / Barcode)</label>
|
|
|
|
|
<input type="text" id="modal-new-code-4" name="new_code_4" placeholder="Neuen Code 4 eingeben..." style="width:100%; padding:10px; border:1px solid #ddd; border-radius:6px;">
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div style="display: flex; flex-direction: column; gap: 10px;">
|
|
|
|
|
<button type="button" class="btn btn-success" onclick="submitRepairAction('repair')">Nur Reparieren (Wieder verfügbar machen)</button>
|
|
|
|
|
<button type="button" class="btn btn-primary" onclick="toggleReplaceMode()">Ersetzen (Neuen Code 4 zuweisen)</button>
|
|
|
|
|
<button type="submit" id="submit-replace-btn" class="btn btn-primary" style="display:none;" onclick="document.getElementById('repair-action-input').value='replace'; return confirm('Medium wirklich mit neuem Code aktualisieren?');">Änderung speichern</button>
|
|
|
|
|
<button type="submit" class="btn btn-danger" onclick="document.getElementById('repair-action-input').value='delete'; return confirm('Achtung: Soll dieses Medium wirklich gelöscht und der Bestand aktualisiert werden?');">Löschen & Bestand anpassen</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
(function() {
|
|
|
|
|
const searchInput = document.getElementById('library-search');
|
|
|
|
|
const classFilter = document.getElementById('class-filter'); // NEU: Klassenfilter hinzugefügt
|
|
|
|
|
const statusFilter = document.getElementById('loan-status-filter');
|
|
|
|
|
const damageFilter = document.getElementById('damage-filter');
|
|
|
|
|
const loanRows = Array.from(document.querySelectorAll('.loan-row'));
|
|
|
|
|
const damagedRows = Array.from(document.querySelectorAll('.damaged-row'));
|
|
|
|
|
const loansEmpty = document.getElementById('loans-empty');
|
|
|
|
|
const damagedEmpty = document.getElementById('damaged-empty');
|
|
|
|
|
|
|
|
|
|
const damageInvoiceModal = document.getElementById('damage-invoice-modal');
|
|
|
|
|
const damageInvoiceForm = document.getElementById('damage-invoice-form');
|
|
|
|
|
const damageInvoiceItem = document.getElementById('damage-invoice-item');
|
|
|
|
@@ -477,61 +544,138 @@
|
|
|
|
|
const damageInvoiceCode = document.getElementById('damage-invoice-code');
|
|
|
|
|
const damageInvoiceAmount = document.getElementById('damage-invoice-amount');
|
|
|
|
|
const damageInvoiceReason = document.getElementById('damage-invoice-reason');
|
|
|
|
|
const damageInvoiceReplaceBtn = document.getElementById('damage-invoice-replace-btn');
|
|
|
|
|
|
|
|
|
|
// NEU: Globale Sortier-Richtungsobjekte
|
|
|
|
|
let sortDirections = {};
|
|
|
|
|
|
|
|
|
|
// NEU: Sortier-Funktion
|
|
|
|
|
window.sortTable = function(tableId, columnIndex) {
|
|
|
|
|
const table = document.getElementById(tableId);
|
|
|
|
|
const tbody = table.tBodies[0];
|
|
|
|
|
const rows = Array.from(tbody.querySelectorAll("tr"));
|
|
|
|
|
|
|
|
|
|
if (rows.length === 0) return;
|
|
|
|
|
|
|
|
|
|
const sortKey = tableId + "-" + columnIndex;
|
|
|
|
|
if (!(sortKey in sortDirections)) {
|
|
|
|
|
sortDirections[sortKey] = true;
|
|
|
|
|
} else {
|
|
|
|
|
sortDirections[sortKey] = !sortDirections[sortKey];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isAscending = sortDirections[sortKey];
|
|
|
|
|
const multiplier = isAscending ? 1 : -1;
|
|
|
|
|
|
|
|
|
|
// Pfeil im Header aktualisieren
|
|
|
|
|
const headers = table.querySelectorAll("th");
|
|
|
|
|
headers.forEach(th => {
|
|
|
|
|
if(th.innerHTML.includes('↕') || th.innerHTML.includes('▲') || th.innerHTML.includes('▼')) {
|
|
|
|
|
th.innerHTML = th.innerHTML.replace(/[↕▲▼]/g, '↕');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const currentTh = headers[columnIndex];
|
|
|
|
|
if (currentTh) {
|
|
|
|
|
currentTh.innerHTML = currentTh.innerHTML.replace('↕', isAscending ? '▲' : '▼');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zeilen sortieren
|
|
|
|
|
rows.sort((a, b) => {
|
|
|
|
|
const cellA = a.cells[columnIndex].textContent.trim();
|
|
|
|
|
const cellB = b.cells[columnIndex].textContent.trim();
|
|
|
|
|
return cellA.localeCompare(cellB, 'de', { numeric: true, sensitivity: 'base' }) * multiplier;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Neu einfügen
|
|
|
|
|
rows.forEach(row => tbody.appendChild(row));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Funktionen für das Reparatur-Modal
|
|
|
|
|
window.openRepairModal = function(itemId, currentCode) {
|
|
|
|
|
const modal = document.getElementById('repair-action-modal');
|
|
|
|
|
const form = document.getElementById('repair-action-form');
|
|
|
|
|
const codeContainer = document.getElementById('new-code-container');
|
|
|
|
|
const replaceBtn = document.getElementById('submit-replace-btn');
|
|
|
|
|
|
|
|
|
|
form.action = `/admin/items/${itemId}/resolve_repair`;
|
|
|
|
|
|
|
|
|
|
document.getElementById('repair-action-input').value = 'repair';
|
|
|
|
|
document.getElementById('modal-new-code-4').value = currentCode || '';
|
|
|
|
|
codeContainer.style.display = 'none';
|
|
|
|
|
replaceBtn.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
modal.style.display = 'block';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.closeRepairModal = function() {
|
|
|
|
|
document.getElementById('repair-action-modal').style.display = 'none';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.toggleReplaceMode = function() {
|
|
|
|
|
const codeContainer = document.getElementById('new-code-container');
|
|
|
|
|
const replaceBtn = document.getElementById('submit-replace-btn');
|
|
|
|
|
document.getElementById('repair-action-input').value = 'replace';
|
|
|
|
|
|
|
|
|
|
codeContainer.style.display = 'block';
|
|
|
|
|
replaceBtn.style.display = 'block';
|
|
|
|
|
document.getElementById('modal-new-code-4').focus();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.submitRepairAction = function(actionType) {
|
|
|
|
|
const form = document.getElementById('repair-action-form');
|
|
|
|
|
document.getElementById('repair-action-input').value = actionType;
|
|
|
|
|
if (confirm('Medium als regulär repariert markieren?')) {
|
|
|
|
|
form.submit();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function openDamageReportPrompt(button) {
|
|
|
|
|
const row = button.closest('.loan-row');
|
|
|
|
|
if (!row) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!row) return;
|
|
|
|
|
|
|
|
|
|
const itemId = row.dataset.itemId || '';
|
|
|
|
|
const itemName = row.dataset.itemName || 'Bibliotheksmedium';
|
|
|
|
|
const noteInput = prompt('Schadensmeldung für dieses Bibliotheksmedium:\nNotiz zum Schaden (optional):', '');
|
|
|
|
|
|
|
|
|
|
if (noteInput === null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (noteInput === null) return;
|
|
|
|
|
|
|
|
|
|
const description = noteInput.trim() || 'Schaden erneut gemeldet';
|
|
|
|
|
const originalText = button.textContent;
|
|
|
|
|
button.disabled = true;
|
|
|
|
|
button.textContent = 'Speichere...';
|
|
|
|
|
|
|
|
|
|
fetch(`/report_damage/${itemId}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({ description })
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json().then(data => ({ ok: response.ok, data })))
|
|
|
|
|
.then(({ ok, data }) => {
|
|
|
|
|
if (!ok || !data.success) {
|
|
|
|
|
.then(async response => {
|
|
|
|
|
const data = await response.json().catch(() => ({}));
|
|
|
|
|
if (!response.ok || !data.success) {
|
|
|
|
|
throw new Error(data.message || 'Fehler beim Speichern der Schadensmeldung.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
})
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (confirm('Schaden gespeichert. Soll direkt eine Rechnung erstellt werden?')) {
|
|
|
|
|
openDamageInvoiceModal(row, description);
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
button.textContent = originalText;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.location.reload();
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
alert(error.message || 'Fehler beim Speichern der Schadensmeldung.');
|
|
|
|
|
alert(error.message || 'Ein unbekannter Fehler ist aufgetreten.');
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
button.textContent = originalText;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.openDamageReportPrompt = openDamageReportPrompt;
|
|
|
|
|
|
|
|
|
|
function openDamageInvoiceModal(row, description) {
|
|
|
|
|
const modal = document.getElementById('damage-invoice-modal');
|
|
|
|
|
const form = document.getElementById('damage-invoice-form');
|
|
|
|
|
const inputItem = document.getElementById('damage-invoice-item');
|
|
|
|
|
const inputBorrower = document.getElementById('damage-invoice-borrower');
|
|
|
|
|
const inputCode = document.getElementById('damage-invoice-code');
|
|
|
|
|
const inputAmount = document.getElementById('damage-invoice-amount');
|
|
|
|
|
const inputReason = document.getElementById('damage-invoice-reason');
|
|
|
|
|
|
|
|
|
|
if (!modal || !form) {
|
|
|
|
|
console.error("Modal oder Formular nicht gefunden.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!damageInvoiceModal || !damageInvoiceForm) return;
|
|
|
|
|
|
|
|
|
|
const borrowId = row.dataset.borrowId || '';
|
|
|
|
|
const itemName = row.dataset.itemName || '';
|
|
|
|
@@ -539,27 +683,36 @@
|
|
|
|
|
const itemCode = row.dataset.itemCode || '';
|
|
|
|
|
const itemCost = row.dataset.itemCost || '';
|
|
|
|
|
|
|
|
|
|
form.action = "{{ url_for('admin_create_invoice', borrow_id='__BORROW_ID__') }}".replace('__BORROW_ID__', borrowId);
|
|
|
|
|
damageInvoiceForm.action = "{{ url_for('admin_create_invoice', borrow_id='__BORROW_ID__') }}".replace('__BORROW_ID__', borrowId);
|
|
|
|
|
|
|
|
|
|
inputItem.value = itemName;
|
|
|
|
|
inputBorrower.value = borrower;
|
|
|
|
|
inputCode.value = itemCode;
|
|
|
|
|
damageInvoiceItem.value = itemName;
|
|
|
|
|
damageInvoiceBorrower.value = borrower;
|
|
|
|
|
damageInvoiceCode.value = itemCode;
|
|
|
|
|
damageInvoiceAmount.value = '';
|
|
|
|
|
|
|
|
|
|
inputAmount.value = String(itemCost).replace(' EUR', '').trim();
|
|
|
|
|
if (damageInvoiceReplaceBtn) {
|
|
|
|
|
damageInvoiceReplaceBtn.dataset.acquisition_costs = String(itemCost).replace(' EUR', '').trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inputReason.value = description || `Schaden gemeldet für ${itemName}`;
|
|
|
|
|
|
|
|
|
|
modal.style.display = 'block';
|
|
|
|
|
inputAmount.focus();
|
|
|
|
|
damageInvoiceReason.value = description || `Schaden gemeldet für ${itemName}`;
|
|
|
|
|
damageInvoiceModal.style.display = 'block';
|
|
|
|
|
damageInvoiceAmount.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeDamageInvoiceModal() {
|
|
|
|
|
const modal = document.getElementById('damage-invoice-modal');
|
|
|
|
|
if (modal) {
|
|
|
|
|
modal.style.display = 'none';
|
|
|
|
|
if (damageInvoiceModal) {
|
|
|
|
|
damageInvoiceModal.style.display = 'none';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (damageInvoiceReplaceBtn) {
|
|
|
|
|
damageInvoiceReplaceBtn.addEventListener('click', function() {
|
|
|
|
|
if (this.dataset.acquisition_costs) {
|
|
|
|
|
damageInvoiceAmount.value = this.dataset.acquisition_costs;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.openDamageInvoiceModal = openDamageInvoiceModal;
|
|
|
|
|
window.closeDamageInvoiceModal = closeDamageInvoiceModal;
|
|
|
|
|
|
|
|
|
@@ -571,22 +724,26 @@
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.closeDamageInvoiceModal = closeDamageInvoiceModal;
|
|
|
|
|
|
|
|
|
|
// NEU: Kombinierte Filter-Funktion (Suche + Status + Schaden + Klasse)
|
|
|
|
|
function applyFilters() {
|
|
|
|
|
const search = (searchInput.value || '').trim().toLowerCase();
|
|
|
|
|
const status = statusFilter.value;
|
|
|
|
|
const damage = damageFilter.value;
|
|
|
|
|
const klasse = classFilter.value; // NEU
|
|
|
|
|
|
|
|
|
|
let visibleLoans = 0;
|
|
|
|
|
loanRows.forEach(row => {
|
|
|
|
|
const haystack = row.dataset.search || '';
|
|
|
|
|
const rowStatus = row.dataset.status || '';
|
|
|
|
|
const rowKlasse = row.dataset.klasse || ''; // NEU
|
|
|
|
|
const hasDamage = row.dataset.hasDamage === '1';
|
|
|
|
|
|
|
|
|
|
const searchMatch = !search || haystack.includes(search);
|
|
|
|
|
const statusMatch = !status || rowStatus === status;
|
|
|
|
|
const classMatch = klasse === 'all' || rowKlasse === klasse; // NEU
|
|
|
|
|
const damageMatch = damage === 'all' || (damage === 'damage' && hasDamage) || (damage === 'clean' && !hasDamage);
|
|
|
|
|
const show = searchMatch && statusMatch && damageMatch;
|
|
|
|
|
|
|
|
|
|
const show = searchMatch && statusMatch && classMatch && damageMatch; // NEU
|
|
|
|
|
row.style.display = show ? '' : 'none';
|
|
|
|
|
if (show) visibleLoans++;
|
|
|
|
|
});
|
|
|
|
@@ -597,10 +754,17 @@
|
|
|
|
|
const haystack = row.dataset.search || '';
|
|
|
|
|
const rowStatus = row.dataset.status || '';
|
|
|
|
|
const hasDamage = row.dataset.hasDamage === '1';
|
|
|
|
|
|
|
|
|
|
const searchMatch = !search || haystack.includes(search);
|
|
|
|
|
const statusMatch = !status || rowStatus === status || status === '';
|
|
|
|
|
const damageMatch = damage === 'all' || (damage === 'damage' && hasDamage) || (damage === 'clean' && !hasDamage);
|
|
|
|
|
const show = searchMatch && statusMatch && damageMatch;
|
|
|
|
|
|
|
|
|
|
// Defekte-Medien-Tabelle hat keine verknüpfte "Klasse", deshalb blenden wir sie nur bei Klassen-Filter "all" ein,
|
|
|
|
|
// oder wenn gar nicht nach Klasse gefiltert wird, damit sie nicht verschwindet.
|
|
|
|
|
// Falls sie bei aktiver Klassensuche komplett verschwinden soll, passe die Bedingung an:
|
|
|
|
|
const classMatch = klasse === 'all';
|
|
|
|
|
|
|
|
|
|
const show = searchMatch && statusMatch && damageMatch && classMatch;
|
|
|
|
|
row.style.display = show ? '' : 'none';
|
|
|
|
|
if (show) visibleDamaged++;
|
|
|
|
|
});
|
|
|
|
@@ -608,9 +772,10 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchInput.addEventListener('input', applyFilters);
|
|
|
|
|
classFilter.addEventListener('change', applyFilters); // NEU
|
|
|
|
|
statusFilter.addEventListener('change', applyFilters);
|
|
|
|
|
damageFilter.addEventListener('change', applyFilters);
|
|
|
|
|
applyFilters();
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
{% endblock %}
|
|
|
|
|
{% endblock %}
|