Fix of an issue with the data being use for the button insert
Release Inventarsystem / release-docker (push) Successful in 2m16s
Release Inventarsystem / release-docker (push) Successful in 2m16s
This commit is contained in:
@@ -3382,6 +3382,7 @@ def library_loans_admin():
|
|||||||
'item_code': item_doc.get('Code_4', ''),
|
'item_code': item_doc.get('Code_4', ''),
|
||||||
'item_author': item_doc.get('Author', ''),
|
'item_author': item_doc.get('Author', ''),
|
||||||
'item_isbn': item_doc.get('ISBN', ''),
|
'item_isbn': item_doc.get('ISBN', ''),
|
||||||
|
'item_cost_raw': item_doc.get('Anschaffungskosten', ''),
|
||||||
'user': decrypted_user,
|
'user': decrypted_user,
|
||||||
'status': record.get('Status', ''),
|
'status': record.get('Status', ''),
|
||||||
'start': fmt_dt(record.get('Start')),
|
'start': fmt_dt(record.get('Start')),
|
||||||
|
|||||||
@@ -407,14 +407,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</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;">
|
<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="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 style="display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:18px;">
|
||||||
<div>
|
<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>
|
<p style="margin:6px 0 0; color:#666;">Die Rechnung nutzt das bestehende Rechnungssystem und kann direkt nach der Schadensmeldung erstellt werden.</p>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
<form id="damage-invoice-form" method="post" action="">
|
<form id="damage-invoice-form" method="post" action="">
|
||||||
@@ -498,42 +498,48 @@
|
|||||||
|
|
||||||
const description = noteInput.trim() || 'Schaden erneut gemeldet';
|
const description = noteInput.trim() || 'Schaden erneut gemeldet';
|
||||||
|
|
||||||
|
// Visuelles Feedback: Button deaktivieren und Text ändern
|
||||||
|
const originalText = button.textContent;
|
||||||
|
button.disabled = true;
|
||||||
|
button.textContent = 'Speichere...';
|
||||||
|
|
||||||
fetch(`/report_damage/${itemId}`, {
|
fetch(`/report_damage/${itemId}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ description })
|
body: JSON.stringify({ description })
|
||||||
})
|
})
|
||||||
.then(response => response.json().then(data => ({ ok: response.ok, data })))
|
.then(async response => {
|
||||||
.then(({ ok, data }) => {
|
// Robustes JSON-Parsing (verhindert Absturz, falls der Server kein JSON zurückgibt)
|
||||||
if (!ok || !data.success) {
|
const data = await response.json().catch(() => ({}));
|
||||||
|
if (!response.ok || !data.success) {
|
||||||
throw new Error(data.message || 'Fehler beim Speichern der Schadensmeldung.');
|
throw new Error(data.message || 'Fehler beim Speichern der Schadensmeldung.');
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
if (confirm('Schaden gespeichert. Soll direkt eine Rechnung erstellt werden?')) {
|
if (confirm('Schaden gespeichert. Soll direkt eine Rechnung erstellt werden?')) {
|
||||||
openDamageInvoiceModal(row, description);
|
openDamageInvoiceModal(row, description);
|
||||||
|
// Button wieder zurücksetzen, da die Seite nicht neu geladen wird
|
||||||
|
button.disabled = false;
|
||||||
|
button.textContent = originalText;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bei "Abbrechen" im Confirm -> Neuladen der Tabelle
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
alert(error.message || 'Fehler beim Speichern der Schadensmeldung.');
|
alert(error.message || 'Ein unbekannter Fehler ist aufgetreten.');
|
||||||
|
// Fehlerbehandlung: Button wieder aktiv schalten
|
||||||
|
button.disabled = false;
|
||||||
|
button.textContent = originalText;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.openDamageReportPrompt = openDamageReportPrompt;
|
window.openDamageReportPrompt = openDamageReportPrompt;
|
||||||
|
|
||||||
function openDamageInvoiceModal(row, description) {
|
function openDamageInvoiceModal(row, description) {
|
||||||
const modal = document.getElementById('damage-invoice-modal');
|
if (!damageInvoiceModal || !damageInvoiceForm) {
|
||||||
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');
|
|
||||||
const replaceBtn = document.getElementById('damage-invoice-replace-btn');
|
|
||||||
|
|
||||||
if (!modal || !form) {
|
|
||||||
console.error("Modal oder Formular nicht gefunden.");
|
console.error("Modal oder Formular nicht gefunden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -542,32 +548,35 @@
|
|||||||
const itemName = row.dataset.itemName || '';
|
const itemName = row.dataset.itemName || '';
|
||||||
const borrower = row.dataset.userName || '';
|
const borrower = row.dataset.userName || '';
|
||||||
const itemCode = row.dataset.itemCode || '';
|
const itemCode = row.dataset.itemCode || '';
|
||||||
const itemCost = row.dataset.acquisition_costs || '';
|
|
||||||
|
|
||||||
form.action = "{{ url_for('admin_create_invoice', borrow_id='__BORROW_ID__') }}".replace('__BORROW_ID__', borrowId);
|
// KORREKTUR: Jetzt greifen wir auf das richtige dataset-Attribut zu
|
||||||
|
const itemCost = row.dataset.itemCost || '';
|
||||||
|
|
||||||
inputItem.value = itemName;
|
damageInvoiceForm.action = "{{ url_for('admin_create_invoice', borrow_id='__BORROW_ID__') }}".replace('__BORROW_ID__', borrowId);
|
||||||
inputBorrower.value = borrower;
|
|
||||||
inputCode.value = itemCode;
|
damageInvoiceItem.value = itemName;
|
||||||
|
damageInvoiceBorrower.value = borrower;
|
||||||
|
damageInvoiceCode.value = itemCode;
|
||||||
|
|
||||||
// Feld zunächst leeren, damit der Ersetzen-Button genutzt werden kann
|
// Feld zunächst leeren, damit der Ersetzen-Button genutzt werden kann
|
||||||
inputAmount.value = '';
|
damageInvoiceAmount.value = '';
|
||||||
|
|
||||||
// Original-Preis im Button als data-Attribut hinterlegen
|
// Original-Preis im Button als data-Attribut hinterlegen
|
||||||
if (replaceBtn) {
|
if (damageInvoiceReplaceBtn) {
|
||||||
replaceBtn.dataset.acquisition_costs = String(itemCost).replace(' EUR', '').trim();
|
damageInvoiceReplaceBtn.dataset.acquisition_costs = String(itemCost).replace(' EUR', '').trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
inputReason.value = description || `Schaden gemeldet für ${itemName}`;
|
damageInvoiceReason.value = description || `Schaden gemeldet für ${itemName}`;
|
||||||
|
|
||||||
modal.style.display = 'block';
|
damageInvoiceModal.style.display = 'block';
|
||||||
inputAmount.focus();
|
|
||||||
|
// Accessibility: Fokus ins erste aktivierbare Feld setzen
|
||||||
|
damageInvoiceAmount.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeDamageInvoiceModal() {
|
function closeDamageInvoiceModal() {
|
||||||
const modal = document.getElementById('damage-invoice-modal');
|
if (damageInvoiceModal) {
|
||||||
if (modal) {
|
damageInvoiceModal.style.display = 'none';
|
||||||
modal.style.display = 'none';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user