removal of provisioning
This commit is contained in:
-152
@@ -3200,7 +3200,6 @@ def admin_invoices():
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
action = _sanitize_text(request.form.get("action") or "", 50)
|
action = _sanitize_text(request.form.get("action") or "", 50)
|
||||||
invoice_id = _sanitize_text(request.form.get("invoice_id") or "", 64)
|
invoice_id = _sanitize_text(request.form.get("invoice_id") or "", 64)
|
||||||
prov_id = _sanitize_text(request.form.get("prov_id") or "", 64)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client, col = _get_collection("invoices")
|
client, col = _get_collection("invoices")
|
||||||
@@ -3238,157 +3237,6 @@ def admin_invoices():
|
|||||||
)
|
)
|
||||||
flash("Rechnung angelegt.", "success")
|
flash("Rechnung angelegt.", "success")
|
||||||
|
|
||||||
elif action == "create_from_provision" and prov_id:
|
|
||||||
# Create an invoice from an instance request
|
|
||||||
req_client = None
|
|
||||||
try:
|
|
||||||
req_client, req_col = _get_collection("instance_requests")
|
|
||||||
prov = req_col.find_one({"_id": ObjectId(prov_id)})
|
|
||||||
if not prov:
|
|
||||||
flash("Instanz-Anfrage nicht gefunden.", "error")
|
|
||||||
return redirect(url_for("admin_invoices"))
|
|
||||||
|
|
||||||
username = prov.get("username") or ""
|
|
||||||
invoice_number = f"INV-{datetime.utcnow().strftime('%Y%m%d%H%M%S')}"
|
|
||||||
period = _sanitize_text(request.form.get("period") or prov.get("period") or "Sofortbuchung", 20)
|
|
||||||
due_date = _sanitize_text(request.form.get("due_date") or date.today().isoformat(), 20)
|
|
||||||
amount = float(prov.get("amount_eur") or 0.0)
|
|
||||||
|
|
||||||
col.insert_one(
|
|
||||||
{
|
|
||||||
"username": username,
|
|
||||||
"invoice_number": invoice_number,
|
|
||||||
"period": period,
|
|
||||||
"amount_eur": amount,
|
|
||||||
"status": "Zu prüfen",
|
|
||||||
"due_date": due_date,
|
|
||||||
"pdf_path": "",
|
|
||||||
"created_at": _utc_now_iso(),
|
|
||||||
"source": "booking_payment",
|
|
||||||
"booking_flow": prov.get("booking_flow"),
|
|
||||||
"booking_package": prov.get("package"),
|
|
||||||
"booking_package_label": prov.get("package_label"),
|
|
||||||
"booking_data": prov.get("booking_data"),
|
|
||||||
"assigned_admin_username": prov.get("assigned_admin_username"),
|
|
||||||
"assigned_admin_display_name": prov.get("assigned_admin_display_name"),
|
|
||||||
"assigned_admin_email": prov.get("assigned_admin_email"),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
req_col.update_one({"_id": prov.get("_id")}, {"$set": {"provision_status": "invoice_created", "updated_at": _utc_now_iso()}})
|
|
||||||
flash("Rechnung aus Instanz-Anfrage erstellt.", "success")
|
|
||||||
except Exception:
|
|
||||||
flash("Fehler beim Erstellen der Rechnung aus Instanz-Anfrage.", "error")
|
|
||||||
finally:
|
|
||||||
if req_client:
|
|
||||||
req_client.close()
|
|
||||||
|
|
||||||
elif action == "update_provision" and prov_id:
|
|
||||||
# Update provision request status (accept/reject/complete)
|
|
||||||
new_status = _sanitize_text(request.form.get("prov_status") or "", 40)
|
|
||||||
req_client = None
|
|
||||||
try:
|
|
||||||
req_client, req_col = _get_collection("instance_requests")
|
|
||||||
req_col.update_one({"_id": ObjectId(prov_id)}, {"$set": {"provision_status": new_status, "updated_at": _utc_now_iso()}})
|
|
||||||
flash("Instanz-Anfrage aktualisiert.", "success")
|
|
||||||
except Exception:
|
|
||||||
flash("Instanz-Anfrage konnte nicht aktualisiert werden.", "error")
|
|
||||||
finally:
|
|
||||||
if req_client:
|
|
||||||
req_client.close()
|
|
||||||
elif action in {"run_provision", "retry_provision", "configure_provision"} and prov_id:
|
|
||||||
# Admin-triggered provisioning actions: start/retry/configure
|
|
||||||
req_client = None
|
|
||||||
try:
|
|
||||||
req_client, req_col = _get_collection("instance_requests")
|
|
||||||
prov = req_col.find_one({"_id": ObjectId(prov_id)})
|
|
||||||
if not prov:
|
|
||||||
flash("Instanz-Anfrage nicht gefunden.", "error")
|
|
||||||
return redirect(url_for("admin_invoices"))
|
|
||||||
|
|
||||||
subdomain = prov.get("subdomain") or _slugify_subdomain(prov.get("booking_data", {}).get("school_name") or prov.get("username") or prov.get("booking_number") or "prov")
|
|
||||||
provision_status = prov.get("provision_status") or "not_started"
|
|
||||||
provision_port = prov.get("provision_port") or None
|
|
||||||
provision_error = ""
|
|
||||||
provision_config_ok = prov.get("provision_config_ok") or False
|
|
||||||
|
|
||||||
if action in {"run_provision", "retry_provision"}:
|
|
||||||
try:
|
|
||||||
port = steering.instace.new(subdomain)
|
|
||||||
except Exception as e:
|
|
||||||
port = False
|
|
||||||
provision_error = str(e)
|
|
||||||
|
|
||||||
if port and port is not False:
|
|
||||||
provision_status = "started"
|
|
||||||
try:
|
|
||||||
provision_port = int(port) if isinstance(port, (int, str)) and str(port).isdigit() else port
|
|
||||||
except Exception:
|
|
||||||
provision_port = port
|
|
||||||
else:
|
|
||||||
provision_status = "failed"
|
|
||||||
if not provision_error:
|
|
||||||
provision_error = "Provisioning script returned failure"
|
|
||||||
|
|
||||||
if action == "configure_provision" or (action in {"run_provision", "retry_provision"} and prov.get("package")):
|
|
||||||
module = prov.get("package")
|
|
||||||
if module in {"inventarsystem", "buecherei", "terminverwaltung", "emailversand", "starter", "advanced"}:
|
|
||||||
try:
|
|
||||||
edit_ok = steering.instace.edit(subdomain, module)
|
|
||||||
provision_config_ok = bool(edit_ok)
|
|
||||||
if not provision_config_ok and not provision_error:
|
|
||||||
provision_error = f"Module configuration failed for {module}"
|
|
||||||
except Exception as e:
|
|
||||||
provision_config_ok = False
|
|
||||||
provision_error = str(e)
|
|
||||||
|
|
||||||
req_col.update_one({"_id": prov.get("_id")}, {"$set": {"provision_status": provision_status, "provision_port": provision_port or "", "provision_config_ok": provision_config_ok, "provision_error": provision_error, "updated_at": _utc_now_iso()}})
|
|
||||||
flash("Provisionierungsaktion ausgeführt.", "success")
|
|
||||||
except Exception as e:
|
|
||||||
flash(f"Provisionierungsaktion fehlgeschlagen: {str(e)}", "error")
|
|
||||||
finally:
|
|
||||||
if req_client:
|
|
||||||
req_client.close()
|
|
||||||
|
|
||||||
elif action == "delete_instance_request" and prov_id:
|
|
||||||
req_client = None
|
|
||||||
try:
|
|
||||||
req_client, req_col = _get_collection("instance_requests")
|
|
||||||
req_col.delete_one({"_id": ObjectId(prov_id)})
|
|
||||||
flash("Instanz-Anfrage gelöscht.", "success")
|
|
||||||
except Exception:
|
|
||||||
flash("Instanz-Anfrage konnte nicht gelöscht werden.", "error")
|
|
||||||
finally:
|
|
||||||
if req_client:
|
|
||||||
req_client.close()
|
|
||||||
|
|
||||||
elif action == "update" and invoice_id:
|
|
||||||
amount_text = _sanitize_text(request.form.get("amount_eur") or "0", 20)
|
|
||||||
invoice_number = _sanitize_text(request.form.get("invoice_number") or "", 120)
|
|
||||||
pdf_path = _save_invoice_pdf(request.files.get("invoice_pdf"), invoice_number or "invoice")
|
|
||||||
try:
|
|
||||||
amount = float(amount_text)
|
|
||||||
except ValueError:
|
|
||||||
amount = 0.0
|
|
||||||
|
|
||||||
update_payload = {
|
|
||||||
"invoice_number": invoice_number,
|
|
||||||
"period": _sanitize_text(request.form.get("period") or "", 20),
|
|
||||||
"status": _sanitize_text(request.form.get("status") or "Zu prüfen", 40),
|
|
||||||
"due_date": _sanitize_text(request.form.get("due_date") or "", 20),
|
|
||||||
"amount_eur": amount,
|
|
||||||
}
|
|
||||||
if pdf_path:
|
|
||||||
update_payload["pdf_path"] = pdf_path
|
|
||||||
|
|
||||||
col.update_one(
|
|
||||||
{"_id": ObjectId(invoice_id)},
|
|
||||||
{
|
|
||||||
"$set": update_payload
|
|
||||||
},
|
|
||||||
)
|
|
||||||
flash("Rechnung aktualisiert.", "success")
|
|
||||||
|
|
||||||
elif action == "delete" and invoice_id:
|
elif action == "delete" and invoice_id:
|
||||||
col.delete_one({"_id": ObjectId(invoice_id)})
|
col.delete_one({"_id": ObjectId(invoice_id)})
|
||||||
flash("Rechnung gelöscht.", "success")
|
flash("Rechnung gelöscht.", "success")
|
||||||
|
|||||||
@@ -81,57 +81,6 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<article class="entry"><p>Noch keine Rechnungen vorhanden.</p></article>
|
<article class="entry"><p>Noch keine Rechnungen vorhanden.</p></article>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if provision_requests %}
|
|
||||||
<h2>Instanz-Anfragen</h2>
|
|
||||||
{% for prov in provision_requests %}
|
|
||||||
<article class="entry">
|
|
||||||
<h3>{{ prov.booking_number or prov.booking_number }}</h3>
|
|
||||||
<p><strong>Nutzer:</strong> {{ prov.username }} | <strong>Subdomain:</strong> {{ prov.subdomain }}</p>
|
|
||||||
<p><strong>Paket:</strong> {{ prov.package_label or prov.package }} | <strong>Betrag:</strong> {{ '%.2f'|format(prov.amount_eur or 0) }} EUR</p>
|
|
||||||
<p><strong>Status:</strong> {{ prov.provision_status or 'not_started' }}{% if prov.provision_error %} | <strong>Fehler:</strong> {{ prov.provision_error }}{% endif %}</p>
|
|
||||||
<p><strong>Kontaktdaten:</strong> {{ prov.booking_data.get('contact_person', '-') }} | {{ prov.booking_data.get('contact_email', '-') }} | {{ prov.booking_data.get('billing_city', '-') }}</p>
|
|
||||||
<form method="post" style="display:inline-block; margin-right:0.6rem;">
|
|
||||||
<input type="hidden" name="action" value="create_from_provision">
|
|
||||||
<input type="hidden" name="prov_id" value="{{ prov.id }}">
|
|
||||||
<input type="file" name="contract_file" accept=".pdf,.png,.jpg,.jpeg,.webp">
|
|
||||||
<input type="text" name="period" placeholder="Zeitraum (optional)">
|
|
||||||
<input type="text" name="due_date" placeholder="Fälligkeit (YYYY-MM-DD)">
|
|
||||||
<button type="submit">Rechnung erzeugen</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" style="display:inline-block; margin-right:0.6rem;">
|
|
||||||
<input type="hidden" name="action" value="update_provision">
|
|
||||||
<input type="hidden" name="prov_id" value="{{ prov.id }}">
|
|
||||||
<select name="prov_status">
|
|
||||||
<option value="accepted">accepted</option>
|
|
||||||
<option value="rejected">rejected</option>
|
|
||||||
<option value="completed">completed</option>
|
|
||||||
</select>
|
|
||||||
<button type="submit">Status setzen</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" style="display:inline-block; margin-right:0.6rem;">
|
|
||||||
<input type="hidden" name="action" value="run_provision">
|
|
||||||
<input type="hidden" name="prov_id" value="{{ prov.id }}">
|
|
||||||
<button type="submit">Provision starten</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" style="display:inline-block; margin-right:0.6rem;">
|
|
||||||
<input type="hidden" name="action" value="retry_provision">
|
|
||||||
<input type="hidden" name="prov_id" value="{{ prov.id }}">
|
|
||||||
<button type="submit">Provision wiederholen</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" style="display:inline-block; margin-right:0.6rem;">
|
|
||||||
<input type="hidden" name="action" value="configure_provision">
|
|
||||||
<input type="hidden" name="prov_id" value="{{ prov.id }}">
|
|
||||||
<button type="submit">Konfiguration ausführen</button>
|
|
||||||
</form>
|
|
||||||
<form method="post" style="display:inline-block; margin-right:0.6rem;">
|
|
||||||
<input type="hidden" name="action" value="delete_instance_request">
|
|
||||||
<input type="hidden" name="prov_id" value="{{ prov.id }}">
|
|
||||||
<button type="submit" class="danger">Löschen</button>
|
|
||||||
</form>
|
|
||||||
</article>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
+192
-153
@@ -64,16 +64,14 @@
|
|||||||
Vertrag öffnen
|
Vertrag öffnen
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<form method="post" enctype="multipart/form-data" class="upload-inline-form">
|
<!-- WICHTIG: Kein Form-Submit mehr, stattdessen JS-Aufruf und 'multiple' -->
|
||||||
<input type="hidden" name="action" value="upload_hauptvertrag">
|
<div class="upload-inline-form">
|
||||||
<input type="hidden" name="invoice_id" value="{{ invoice.id }}">
|
|
||||||
|
|
||||||
<label class="file-dropzone">
|
<label class="file-dropzone">
|
||||||
<input type="file" name="hauptvertrag_file" accept="image/*,application/pdf" required onchange="this.form.submit()">
|
<input type="file" multiple accept="image/*,application/pdf" onchange="openUploadModal(event, '{{ invoice.id }}')">
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
|
||||||
<span>Datei wählen</span>
|
<span>Dateien wählen</span>
|
||||||
</label>
|
</label>
|
||||||
</form>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -91,8 +89,26 @@
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- UPLOAD MODAL -->
|
||||||
|
<div id="uploadModal" class="modal-overlay" style="display: none;">
|
||||||
|
<div class="modal-content">
|
||||||
|
<h2>Dateien für Upload anpassen</h2>
|
||||||
|
<p class="text-muted" style="margin-bottom: 1rem;">Du kannst die Dateinamen anpassen, bevor sie gespeichert werden.</p>
|
||||||
|
|
||||||
|
<div id="fileList" class="file-list"></div>
|
||||||
|
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button type="button" class="btn btn-outline" onclick="closeModal()">Abbrechen</button>
|
||||||
|
<button type="button" class="btn btn-primary" onclick="submitFiles()" id="uploadBtn">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
|
||||||
|
Dateien hochladen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
/* Layout & Container */
|
/* --- Bestehendes Layout & Container --- */
|
||||||
.invoices-container {
|
.invoices-container {
|
||||||
max-width: 1200px;
|
max-width: 1200px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
@@ -101,8 +117,6 @@
|
|||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Header Styling */
|
|
||||||
.invoice-header {
|
.invoice-header {
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border: 1px solid #e2e8f0;
|
border: 1px solid #e2e8f0;
|
||||||
@@ -114,21 +128,8 @@
|
|||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
|
||||||
}
|
}
|
||||||
|
.header-text h1 { margin: 0 0 0.35rem 0; font-size: 1.5rem; color: #1a202c; font-weight: 700; }
|
||||||
.header-text h1 {
|
.header-text p { margin: 0; color: #718096; font-size: 0.925rem; }
|
||||||
margin: 0 0 0.35rem 0;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
color: #1a202c;
|
|
||||||
font-weight: 700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.header-text p {
|
|
||||||
margin: 0;
|
|
||||||
color: #718096;
|
|
||||||
font-size: 0.925rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Table Card */
|
|
||||||
.table-card {
|
.table-card {
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border: 1px solid #e2e8f0;
|
border: 1px solid #e2e8f0;
|
||||||
@@ -136,157 +137,195 @@
|
|||||||
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
.table-responsive { overflow-x: auto; }
|
||||||
.table-responsive {
|
.custom-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.925rem; }
|
||||||
overflow-x: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-table {
|
|
||||||
width: 100%;
|
|
||||||
border-collapse: collapse;
|
|
||||||
text-align: left;
|
|
||||||
font-size: 0.925rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-table th {
|
.custom-table th {
|
||||||
background-color: #f8fafc;
|
background-color: #f8fafc; color: #475569; padding: 1rem 1.25rem;
|
||||||
color: #475569;
|
font-weight: 600; font-size: 0.825rem; text-transform: uppercase;
|
||||||
padding: 1rem 1.25rem;
|
letter-spacing: 0.05em; border-bottom: 1px solid #e2e8f0;
|
||||||
font-weight: 600;
|
|
||||||
font-size: 0.825rem;
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.05em;
|
|
||||||
border-bottom: 1px solid #e2e8f0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-table td {
|
.custom-table td {
|
||||||
padding: 1rem 1.25rem;
|
padding: 1rem 1.25rem; border-bottom: 1px solid #f1f5f9;
|
||||||
border-bottom: 1px solid #f1f5f9;
|
color: #334155; vertical-align: middle;
|
||||||
color: #334155;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
}
|
||||||
|
.custom-table tbody tr:hover { background-color: #f8fafc; }
|
||||||
.custom-table tbody tr:hover {
|
.custom-table tbody tr:last-child td { border-bottom: none; }
|
||||||
background-color: #f8fafc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-table tbody tr:last-child td {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Typography Helpers */
|
|
||||||
.font-semibold { font-weight: 600; color: #0f172a; }
|
.font-semibold { font-weight: 600; color: #0f172a; }
|
||||||
.amount-cell { font-weight: 700; color: #0f172a; }
|
.amount-cell { font-weight: 700; color: #0f172a; }
|
||||||
.text-muted { color: #94a3b8; font-size: 0.875rem; }
|
.text-muted { color: #94a3b8; font-size: 0.875rem; }
|
||||||
|
|
||||||
/* Status Badges */
|
|
||||||
.badge {
|
.badge {
|
||||||
display: inline-block;
|
display: inline-block; padding: 0.35rem 0.75rem; border-radius: 9999px;
|
||||||
padding: 0.35rem 0.75rem;
|
font-size: 0.775rem; font-weight: 600; line-height: 1;
|
||||||
border-radius: 9999px;
|
|
||||||
font-size: 0.775rem;
|
|
||||||
font-weight: 600;
|
|
||||||
line-height: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge-success { background-color: #dcfce7; color: #15803d; }
|
.badge-success { background-color: #dcfce7; color: #15803d; }
|
||||||
.badge-warning { background-color: #fef3c7; color: #b45309; }
|
.badge-warning { background-color: #fef3c7; color: #b45309; }
|
||||||
.badge-info { background-color: #e0f2fe; color: #0369a1; }
|
.badge-info { background-color: #e0f2fe; color: #0369a1; }
|
||||||
|
|
||||||
/* Action Buttons & Links */
|
|
||||||
.btn {
|
.btn {
|
||||||
display: inline-flex;
|
display: inline-flex; align-items: center; gap: 0.4rem;
|
||||||
align-items: center;
|
font-weight: 600; font-size: 0.85rem; padding: 0.5rem 1rem;
|
||||||
gap: 0.4rem;
|
border-radius: 8px; cursor: pointer; transition: all 0.2s ease;
|
||||||
font-weight: 600;
|
border: none; text-decoration: none; font-family: inherit;
|
||||||
font-size: 0.85rem;
|
|
||||||
padding: 0.5rem 1rem;
|
|
||||||
border-radius: 8px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
border: none;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
}
|
||||||
|
.btn-outline { background: #ffffff; border: 1px solid #cbd5e1; color: #334155; }
|
||||||
.btn-outline {
|
.btn-outline:hover { background: #f8fafc; border-color: #94a3b8; }
|
||||||
background: #ffffff;
|
.btn-primary { background: #0284c7; color: #ffffff; }
|
||||||
border: 1px solid #cbd5e1;
|
.btn-primary:hover { background: #0369a1; }
|
||||||
color: #334155;
|
.btn-link { color: #0284c7; background: #f0f9ff; padding: 0.4rem 0.75rem; }
|
||||||
}
|
.btn-link:hover { background: #e0f2fe; color: #0369a1; }
|
||||||
|
.btn-contract { color: #0f766e; background: #f0fdf4; }
|
||||||
.btn-outline:hover {
|
.btn-contract:hover { background: #dcfce7; color: #115e59; }
|
||||||
background: #f8fafc;
|
.upload-inline-form { display: inline-block; }
|
||||||
border-color: #94a3b8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-link {
|
|
||||||
color: #0284c7;
|
|
||||||
background: #f0f9ff;
|
|
||||||
padding: 0.4rem 0.75rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-link:hover {
|
|
||||||
background: #e0f2fe;
|
|
||||||
color: #0369a1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-contract {
|
|
||||||
color: #0f766e;
|
|
||||||
background: #f0fdf4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-contract:hover {
|
|
||||||
background: #dcfce7;
|
|
||||||
color: #115e59;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Custom Inline File Upload Zone */
|
|
||||||
.upload-inline-form {
|
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.file-dropzone {
|
.file-dropzone {
|
||||||
display: inline-flex;
|
display: inline-flex; align-items: center; gap: 0.4rem;
|
||||||
align-items: center;
|
padding: 0.4rem 0.75rem; background-color: #f8fafc;
|
||||||
gap: 0.4rem;
|
border: 1.5px dashed #cbd5e1; border-radius: 8px;
|
||||||
padding: 0.4rem 0.75rem;
|
color: #475569; font-size: 0.825rem; font-weight: 600;
|
||||||
background-color: #f8fafc;
|
cursor: pointer; transition: all 0.2s ease;
|
||||||
border: 1.5px dashed #cbd5e1;
|
|
||||||
border-radius: 8px;
|
|
||||||
color: #475569;
|
|
||||||
font-size: 0.825rem;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
}
|
}
|
||||||
|
.file-dropzone:hover { background-color: #f1f5f9; border-color: #0284c7; color: #0284c7; }
|
||||||
|
.file-dropzone input[type="file"] { display: none; }
|
||||||
|
.empty-state { text-align: center; padding: 3rem 1rem !important; }
|
||||||
|
.empty-state p { margin: 0.5rem 0 0 0; color: #94a3b8; }
|
||||||
|
|
||||||
.file-dropzone:hover {
|
/* --- Neues Modal Styling --- */
|
||||||
background-color: #f1f5f9;
|
.modal-overlay {
|
||||||
border-color: #0284c7;
|
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
|
||||||
color: #0284c7;
|
background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px);
|
||||||
|
display: flex; align-items: center; justify-content: center;
|
||||||
|
z-index: 9999;
|
||||||
}
|
}
|
||||||
|
.modal-content {
|
||||||
.file-dropzone input[type="file"] {
|
background: #ffffff; width: 90%; max-width: 500px;
|
||||||
display: none;
|
border-radius: 16px; padding: 2rem; box-shadow: 0 10px 25px rgba(0,0,0,0.1);
|
||||||
}
|
}
|
||||||
|
.modal-content h2 { margin-top: 0; font-size: 1.25rem; color: #0f172a; margin-bottom: 0.5rem;}
|
||||||
/* Empty State */
|
.file-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; max-height: 300px; overflow-y: auto;}
|
||||||
.empty-state {
|
.file-edit-row { display: flex; gap: 0.5rem; align-items: center; }
|
||||||
text-align: center;
|
.rename-input {
|
||||||
padding: 3rem 1rem !important;
|
flex-grow: 1; padding: 0.5rem; border: 1px solid #cbd5e1;
|
||||||
|
border-radius: 6px; font-family: inherit; font-size: 0.9rem;
|
||||||
}
|
}
|
||||||
|
.rename-input:focus { outline: 2px solid #0284c7; border-color: transparent;}
|
||||||
.empty-state p {
|
.btn-remove {
|
||||||
margin: 0.5rem 0 0 0;
|
background: #fee2e2; color: #ef4444; border: none; padding: 0.5rem;
|
||||||
color: #94a3b8;
|
border-radius: 6px; cursor: pointer; display: flex; align-items: center;
|
||||||
}
|
}
|
||||||
|
.btn-remove:hover { background: #fecaca; }
|
||||||
|
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; }
|
||||||
|
|
||||||
/* Mobile Adjustments */
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.invoice-header {
|
.invoice-header { flex-direction: column; align-items: flex-start; }
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-start;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- UPLOAD LOGIK -->
|
||||||
|
<script>
|
||||||
|
let currentFiles = [];
|
||||||
|
let currentInvoiceId = null;
|
||||||
|
|
||||||
|
// 1. Dateien aufnehmen und Modal öffnen
|
||||||
|
function openUploadModal(event, invoiceId) {
|
||||||
|
currentInvoiceId = invoiceId;
|
||||||
|
const files = Array.from(event.target.files);
|
||||||
|
|
||||||
|
if(files.length === 0) return;
|
||||||
|
|
||||||
|
// Erzeuge State-Objekte für jede ausgewählte Datei
|
||||||
|
currentFiles = files.map(file => ({
|
||||||
|
id: window.crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(),
|
||||||
|
originalFile: file,
|
||||||
|
customName: file.name
|
||||||
|
}));
|
||||||
|
|
||||||
|
// File-Input zurücksetzen, damit gleiche Dateien nochmal gewählt werden können
|
||||||
|
event.target.value = '';
|
||||||
|
|
||||||
|
renderFileList();
|
||||||
|
document.getElementById('uploadModal').style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Dateiliste im Modal rendern
|
||||||
|
function renderFileList() {
|
||||||
|
const container = document.getElementById('fileList');
|
||||||
|
container.innerHTML = '';
|
||||||
|
|
||||||
|
currentFiles.forEach(f => {
|
||||||
|
const row = document.createElement('div');
|
||||||
|
row.className = 'file-edit-row';
|
||||||
|
|
||||||
|
row.innerHTML = `
|
||||||
|
<input type="text" value="${f.customName}"
|
||||||
|
oninput="renameFile('${f.id}', this.value)" class="rename-input">
|
||||||
|
<button type="button" class="btn-remove" onclick="removeFile('${f.id}')" title="Datei entfernen">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
container.appendChild(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (currentFiles.length === 0) {
|
||||||
|
closeModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Name aktualisieren
|
||||||
|
function renameFile(id, newName) {
|
||||||
|
const fileIndex = currentFiles.findIndex(f => f.id === id);
|
||||||
|
if (fileIndex > -1) {
|
||||||
|
currentFiles[fileIndex].customName = newName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Datei aus Auswahl entfernen
|
||||||
|
function removeFile(id) {
|
||||||
|
currentFiles = currentFiles.filter(f => f.id !== id);
|
||||||
|
renderFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Modal abbrechen
|
||||||
|
function closeModal() {
|
||||||
|
document.getElementById('uploadModal').style.display = 'none';
|
||||||
|
currentFiles = [];
|
||||||
|
currentInvoiceId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. An den Server senden
|
||||||
|
async function submitFiles() {
|
||||||
|
if (currentFiles.length === 0 || !currentInvoiceId) return;
|
||||||
|
|
||||||
|
const btn = document.getElementById('uploadBtn');
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.innerHTML = 'Lädt hoch...';
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('action', 'upload_hauptvertrag');
|
||||||
|
formData.append('invoice_id', currentInvoiceId);
|
||||||
|
|
||||||
|
// Fügt alle Dateien unter dem GLEICHEN Schlüssel "hauptvertrag_file" hinzu,
|
||||||
|
// mit dem vom Nutzer angepassten Dateinamen
|
||||||
|
currentFiles.forEach(f => {
|
||||||
|
formData.append('hauptvertrag_file', f.originalFile, f.customName);
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(window.location.href, {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
window.location.reload(); // Seite neu laden, um Tabelle zu aktualisieren
|
||||||
|
} else {
|
||||||
|
alert('Es gab einen Fehler beim Hochladen. Bitte versuche es erneut.');
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = 'Dateien hochladen';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
alert('Netzwerkfehler. Konnte Server nicht erreichen.');
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = 'Dateien hochladen';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user