gc-server3 пре 1 недеља
родитељ
комит
b3d5cca053

+ 81 - 4
app/routes.py

@@ -1,6 +1,7 @@
 import io
+import re
 from dataclasses import dataclass
-from datetime import datetime
+from datetime import datetime, timedelta
 from pathlib import Path
 from urllib.parse import unquote, urlencode
 
@@ -69,8 +70,36 @@ def date_format(input: datetime) -> str:
     return input.strftime("%d.%m.%Y")
 
 
+def checked(input: str) -> str:
+    if input in ("J", "1", 1, True):
+        return "checked"
+    return ""
+
+
+def selected(input: str) -> str:
+    if input in ("J", "1", 1, True):
+        return "selected"
+    return ""
+
+
+def truefalse(input: str) -> str:
+    if input in ("J", "1", 1, True):
+        return "true"
+    return "false"
+
+
+def show(input: str) -> str:
+    if input in ("J", "1", 1, True):
+        return "show"
+    return ""
+
+
 templates.env.filters["number_format"] = number_format
 templates.env.filters["date_format"] = date_format
+templates.env.filters["checked"] = checked
+templates.env.filters["selected"] = selected
+templates.env.filters["truefalse"] = truefalse
+templates.env.filters["show"] = show
 
 
 def single_quote(text: str):
@@ -96,7 +125,7 @@ forderung_filter_config = [
     FilterConfig("Standort", "Standort", "select", "3", "Standort_ID", "Standort_Name"),
     FilterConfig("Bereich", "Bereich", "select", "3", "Bereich", "Bereich"),
     FilterConfig("Verursacher", "Verursacher", "select", "4", "Verursacher", "Verursacher"),
-    FilterConfig("Rechnungsnummer", "Rechnungsnummer", "text", "3", "Document_No", "Document_No"),
+    FilterConfig("Rechnungsnummer", "Rechnungsnummer", "text", "2", "Document_No", "Document_No"),
     FilterConfig(
         "RechnungsdatumVon",
         "Rechnungsdatum von",
@@ -115,7 +144,8 @@ forderung_filter_config = [
         "Invoice_Date",
         default_value="2027-01-01T00:00:00",
     ),
-    FilterConfig("Kunde", "Kunde", "text", "5", "Kunde", "Kunde"),
+    FilterConfig("Kunde", "Kunde", "text", "4", "Kunde", "Kunde"),
+    FilterConfig("Abwarten", "Abwarten", "select", "2", "Abwarten", "Abwarten"),
     FilterConfig(
         "WiedervorlageVon",
         "Wiedervorlage von",
@@ -134,9 +164,10 @@ forderung_filter_config = [
         "Wiedervorlage",
         default_value="2027-01-01T00:00:00",
     ),
-    FilterConfig("Fahrzeug", "Fahrzeug", "select", "4", "VIN", "VIN"),
+    FilterConfig("Fahrzeug", "Fahrzeug", "select", "2", "VIN", "VIN"),
     FilterConfig("Staffel", "Staffel", "select", "2", "Staffel", "Staffel"),
     FilterConfig("Mahnstufe", "Mahnstufe", "select", "2", "Mahnstufe", "Mahnstufe"),
+    FilterConfig("Bearbeitet", "Bearbeitet", "select", "2", "Bearbeitet", "Bearbeitet"),
     FilterConfig("BenutzerSelect", "Benutzer", "hidden", "2", "", "", visible=False, default_value="winter"),
 ]
 
@@ -235,6 +266,7 @@ def forderungen_details(
         "forderung_kommentar",
         "forderung_kopf",
         "forderung_mahnung",
+        "versicherungen",
     ]:
         query = templates.TemplateResponse(request, f"forderungen/queries/{filename}.sql", context).body.decode("utf-8")
         template_context[filename] = db.execute(text(query)).fetchall()
@@ -248,10 +280,55 @@ def forderungen_details(
     fileserver = "C:\\Projekte\\Reisacher-Fileserver"
     files = [f.relative_to(fileserver) for f in Path(f"{fileserver}\\{client_db}\\{document_no}").glob("*")]
     template_context["files"] = files
+    template_context["add7days"] = datetime.now() + timedelta(days=7)
 
     return templates.TemplateResponse(request, "forderungen/details.html", template_context)
 
 
+@router.post("/app/forderungen/details/{client_db}_{document_no}", response_class=HTMLResponse)
+async def post_forderungen_details(
+    request: Request, client_db: str, document_no: str, db: Session = Depends(get_session)
+):
+    data = {
+        "Client_DB": client_db,
+        "Beleg_Nr": document_no,
+        "Bearbeitet": "J",
+        "Versicherung": "N",
+        "Rechtsanwalt": "N",
+        "Reklamation": "N",
+        "Mahnen_aussetzen": "N",
+        "Selbstbeteiligung": "",
+        "Selbstbeteiligung_Betrag": "0.0",
+        "Mwst": "",
+        "Mwst_Betrag": "0.0",
+        "Wiedervorlage": "",
+        "Vers_Adresse_ID": "",
+        "Versicherung_Typ": "",
+        "Reklamation_Begruendung": "",
+        "Rechtsanwalt_Begruendung": "",
+        "Rechtsanwalt_Aktenzeichen": "",
+        "Rechtsanwalt_Stand": "",
+        "Mahnen_Begruendung": "",
+    }
+
+    async with request.form() as form:
+        for k, v in form.items():
+            if k in data:
+                if v == "on":
+                    v = "J"
+                if re.match(r"\d+,?\d*", v):
+                    v = v.replace(",", ".")
+                data[k] = v
+    query = templates.TemplateResponse(
+        request, "forderungen/queries/update_details.sql", context={"data": data}
+    ).body.decode("utf-8")
+    print(query)
+    for subquery in query.split(";"):
+        q = db.execute(text(subquery))
+        print(q.rowcount)
+    db.commit()
+
+
 @router.get("/app/forderungen/dashboard", response_class=HTMLResponse)
 def forderungen_dashboard(request: Request, db: Session = Depends(get_session)):
     context = {"summary": False}

+ 403 - 147
templates/forderungen/details.html

@@ -1,7 +1,324 @@
 {% extends "base/base.html" %}
 {% block content %}
 
+<br>
+<h2>{{forderung_kopf[0].Beleg }}</h2>
+<br>
+<div class="row mb-3">
+  <div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Grunddaten</th>
+      </tr>
+      <tr>
+        <td><strong>Hauptbetrieb:</strong></td>
+        <td>{{forderung_kopf[0].Hauptbetrieb_Name }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Standort:</strong></td>
+        <td>{{forderung_kopf[0].Standort_Name }}</td>
+      </tr>
+      <tr>
+        <td><strong>Benutzer:</strong></td>
+        <td>{{forderung_kopf[0].User_ID }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Verursacher:</strong></td>
+        <td>{{forderung_kopf[0].Verursacher }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Bereich:</strong></td>
+        <td>{{forderung_kopf[0].Bereich }}</td>
+      </tr>
+
+    </table>
+  </div>
+  <div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Beleg</th>
+      </tr>
+      <tr>
+        <td><strong>Belegart:</strong></td>
+        <td>{{forderung_kopf[0].Rechnung_Gutschrift }}</td>
+      </tr>
+      <tr>
+        <td><strong>Beleg-Nr:</strong></td>
+        <td>{{forderung_kopf[0].Document_No }}</td>
+      </tr>
+      <tr>
+        <td><strong>Betrag:</strong></td>
+        <td>{{forderung_kopf[0].offen|number_format }} &euro;</td>
+      </tr>
+      <tr>
+        <td><strong>Rechnungsdatum:</strong></td>
+        <td>{{forderung_kopf[0].Invoice_Date|date_format }}</td>
+      </tr>            
+      <tr>
+        <td><strong>Lieferdatum:</strong></td>
+        <td>{{forderung_kopf[0].Invoice_Date|date_format }}</td>
+      </tr>
+      <tr>
+        <td><strong>Fälligkeitsdatum:</strong></td>
+        <td>{{forderung_kopf[0].Invoice_Date|date_format }}</td>
+      </tr>
+
+
+
+    </table>
+  </div>
+  <div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Forderung</th>
+      </tr>
+      <tr>
+        <td><strong>offen:</strong></td>
+        <td>{{forderung_kopf[0].offen|number_format }} &euro;</td>
+      </tr>
+
+      <tr>
+        <td><strong>offen (Kunde gesamt):</strong></td>
+        <td>{{forderung_kopf[0].offen_Kunde_gesamt|number_format }} &euro;</td>
+      </tr>
+
+      <tr>
+        <td><strong>Tage:</strong></td>
+        <td>{{forderung_kopf[0].Tage }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Staffel:</strong></td>
+        <td>{{forderung_kopf[0].Staffel }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Mahnstufe:</strong></td>
+        <td>{{forderung_kopf[0].Mahnstufe }}</td>
+      </tr>
+    </table>
+  </div>
 
+
+  <div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Kunde</th>
+      </tr>
+
+      <tr>
+        <td><strong>Kunden-Nr:</strong></td>
+        <td>{{forderung_kopf[0].Kunde_Nr }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Name:</strong></td>
+        <td>{{forderung_kopf[0].Kunde_Name }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Adresse:</strong></td>
+        <td>{{forderung_kopf[0].Kunde_Adresse }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>PLZ / Ort:</strong></td>
+        <td>{{forderung_kopf[0].Kunde_PLZ }} {{forderung_kopf[0].Kunde_Ort }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Land:</strong></td>
+        <td>{{forderung_kopf[0].Kunde_Land }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Telefon:</strong></td>
+        <td>{{forderung_kopf[0].Kunde_Telefon }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>E-Mail:</strong></td>
+        <td><a href="mailto:{{forderung_kopf[0].Kunde_Email }}?subject={{forderung_kopf[0].Document_No }}" hx-disable="true">{{forderung_kopf[0].Kunde_Email }}</a></td>
+      </tr>
+
+      <tr>
+        <td><strong>Payment_Terms_Code:</strong></td>
+        <td>{{forderung_kopf[0].Payment_Terms_Code }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Kundengruppe:</strong></td>
+        <td>{{forderung_kopf[0].Customer_Group_Description }}</td>
+      </tr>
+
+    </table>
+  </div>
+{% if forderung_kopf[0].Fahrzeug_Leasing == 'J' %}
+<div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Leasing-Kunde</th>
+      </tr>
+
+      <tr>
+        <td><strong>Kunden-Nr:</strong></td>
+        <td>{{forderung_kopf[0].Leasing_Kunde_Nr }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Name:</strong></td>
+        <td>{{forderung_kopf[0].Leasing_Kunde_Name }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Adresse:</strong></td>
+        <td>{{forderung_kopf[0].Leasing_Kunde_Adresse }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>PLZ / Ort:</strong></td>
+        <td>{{forderung_kopf[0].Leasing_Kunde_PLZ }} {{forderung_kopf[0].Leasing_Kunde_Ort }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Land:</strong></td>
+        <td>{{forderung_kopf[0].Leasing_Kunde_Land }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Telefon:</strong></td>
+        <td>{{forderung_kopf[0].Leasing_Kunde_Telefon }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>E-Mail:</strong></td>
+        <td><a href="mailto:{{forderung_kopf[0].Leasing_Kunde_Email }}?subject={{forderung_kopf[0].Document_No }}" hx-disable="true">{{forderung_kopf[0].Leasing_Kunde_Email }}</a></td>
+      </tr>
+    </table>
+  </div>
+{% endif %}
+
+
+{% if forderung_kopf[0].Versicherung == 'J' and forderung_kopf[0].Vers_Adresse_ID != '' %}
+  <div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Versicherung</th>
+      </tr>
+      <tr>
+        <td><strong>Name:</strong></td>
+        <td>{{forderung_kopf[0].Vers_Name }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Adresse:</strong></td>
+        <td>{{forderung_kopf[0].Vers_Adresse }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>PLZ / Ort:</strong></td>
+        <td>{{forderung_kopf[0].Vers_PLZ }} {{forderung_kopf[0].Vers_Ort }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Telefon:</strong></td>
+        <td>{{forderung_kopf[0].Vers_Telefon }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Telefax:</strong></td>
+        <td>{{forderung_kopf[0].Vers_Telefax }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Webseite:</strong></td>
+        <td><a href="{{forderung_kopf[0].Vers_Web }}" hx-disable="true" target="_blank">{{forderung_kopf[0].Vers_Web }}</a></td>
+      </tr>
+
+      <tr>
+        <td><strong>Vers_Email:</strong></td>
+        <td><a href="mailto:{{forderung_kopf[0].Vers_Email }}?subject={{forderung_kopf[0].Document_No }}" hx-disable="true">{{forderung_kopf[0].Vers_Email }}</a></td>
+      </tr>
+    </table>
+  </div>
+{% endif %}
+
+
+  <div class="col-4">
+    <table class="table table-sm">
+      <tr>
+        <th colspan="2">Fahrzeug</th>
+      </tr>
+      <tr>
+        <td><strong>VIN:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_VIN }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Marke:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Marke_Nr }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Modell:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Modell_Nr }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Modell Name:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Modell_Name }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Kategoriecode:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Kategoriecode }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Halter:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Kunde_Nr }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Kennzeichen:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Kennzeichen }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>KM-Stand:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Kmstand }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Antriebsart:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Antriebsart }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Erstzulassung:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Erstzulassung|date_format }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Kaufdatum:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Kaufdatum|date_format }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Fahrzeug_Vorbesitzer_Anzahl:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Vorbesitzer_Anzahl }}</td>
+      </tr>
+
+      <tr>
+        <td><strong>Vorbesitzer:</strong></td>
+        <td>{{forderung_kopf[0].Fahrzeug_Vorbesitzer_Kunde_Nr }}</td>
+      </tr>
+    </table>
+  </div>
+</div>
 <!--
 
 <h3>Kommentare</h3>
@@ -12,8 +329,6 @@
       <th>Timestamp</th>
       <th>Name</th>
       <th>Rolle</th>
-      <th>Begründung</th>
-      <th>Wiedervorlage</th>
       <th>Kommentar</th>
     </tr>
   </thead>
@@ -23,8 +338,6 @@
       <td>{{ row.Timestamp|date_format }}</td>
       <td>{{ row.Name }}</td>
       <td>{{ row.Rolle }}</td>
-      <td>{{ row.Begründung or '' }}</td>
-      <td>{{ row.Wiedervorlage|date_format }}</td>
       <td>{{ row.Kommentar or '' }}</td>
     </tr>
     {% endfor %}
@@ -36,166 +349,90 @@
 <br>
 <br>
 
-{%include 'base/chat_container.html' %}
+<div class="row g-3">
+<div class="col-5">
 
-<br>
-<br>
+  {%include 'base/chat_container.html' %}
 
-<h3>Eingabemaske</h3>
-<br>
-<br>
+</div>
+<div class="col-1">
+  &nbsp;
+</div>
 
+<div class="col-6">
 <form class="row g-3">
   <div class="col-12">
     <div class="form-check" data-coreui-toggle="collapse" data-coreui-target="#VersicherungCollapse"
-      aria-expanded="false" aria-controls="VersicherungCollapse">
-      <input class="form-check-input" type="checkbox" id="Versicherung">
+      aria-expanded="{{ forderung_kopf[0].Versicherung|truefalse }}" aria-controls="VersicherungCollapse">
+      <input class="form-check-input" type="checkbox" name="Versicherung" id="Versicherung" {{ forderung_kopf[0].Versicherung|checked }}>
       <label class="form-check-label" for="Versicherung">
         <strong>Versicherungsfall</strong>
       </label>
     </div>
   </div>
 
-  <div class="collapse" id="VersicherungCollapse">
+  <div class="collapse {{ forderung_kopf[0].Versicherung|show }}" id="VersicherungCollapse">
     <div class="card card-body">
       <div class="row mb-3">
         <label for="Versicherung_Name" class="col-sm-2 col-form-label">Versicherung</label>
         <div class="col-sm-3">
-          <select id="Versicherung_Name" name="Versicherung_Name" class="form-select">
+          <select id="Versicherung_Name" name="Vers_Adresse_ID" class="form-select">
             <option value="" selected>-</option>
-<option>ADAC Autoversicherung AG</option>
-<option>ADLER Versicherung AG</option>
-<option>Allianz Versicherungs-Aktiengesellschaft</option>
-<option>AllSecur Deutschland AG</option>
-<option>ALTE LEIPZIGER Versicherung Aktiengesellschaft</option>
-<option>ARAG Allgemeine Versicherungs-AG</option>
-<option>AXA Versicherung AG</option>
-<option>Badische Allgemeine Versicherung AG</option>
-<option>Barmenia Allgemeine Versicherungs-AG</option>
-<option>Badischer Gemeinde-Versicherungs-Verband</option>
-<option>Basler Securitas Versicherungs-AG</option>
-<option>Basler Versicherungs-Gesellschaft, Basel, Direktion für Deutschland</option>
-<option>BAYERISCHE BEAMTEN VERSICHERUNG AKTIENGESELLSCHAFT</option>
-<option>Bayerischer VersicherungsverbandVersicherungsaktiengesellschaft</option>
-<option>BRUDERHILFE Sachversicherung Aktiengesellschaft im Raum der Kirchen</option>
-<option>Chartis Europe S.A.</option>
-<option>Concordia Versicherungs-Gesellschaft auf Gegenseitigkeit</option>
-<option>Condor Allgemeine Versicherungs-Aktiengesellschaft</option>
-<option>Continentale</option>
-<option>COSMOS Versicherung Aktiengesellschaft</option>
-<option>DA - Deutsche Allgemeine Versicherung Aktiengesellschaft</option>
-<option>DBV Deutsche Beamten-Versicherung Aktiengesellschaft</option>
-<option>Debeka Allgemeine Versicherung Aktiengesellschaft</option>
-<option>deutsche internet versicherung aktiengesellschaft</option>
-<option>DEVK Fast Lane</option>
-<option>Direct Line Versicherung AG</option>
-<option>ERGO Versicherung Aktiengesellschaft</option>
-<option>EUROPA Sachversicherung AG</option>
-<option>Fahrlehrerversicherung Verein auf Gegenseitigkeit</option>
-<option>Feuersozietät Berlin Brandenburg</option>
-<option>GARANTA Versicherungs-AG</option>
-<option>GEGENSEITIGKEIT Versicherung Oldenburg</option>
-<option>Generali Deutschland Versicherung AG</option>
-<option>Gothaer Allgemeine Versicherung AG</option>
-<option>GVV-Kommunalversicherung VVaG</option>
-<option>GVV-Privatversicherung AG</option>
-<option>Haftpflichtgemeinschaft Dt. Nahverkehrs- u. Versorgungsuntern. Allg. VVaG</option>
-<option>Hannoversche Direktversicherung AG</option>
-<option>HanseMerkur Allgemeine Versicherung AG</option>
-<option>HDI Global SE</option>
-<option>HDI Versicherung AG</option>
-<option>HDI-Gerling Firmen und Privat Versicherung AG</option>
-<option>HDI Haftpflichtverband der Deutschen Industrie VVaG</option>
-<option>Helvetia Schweizerische Versicherungsgesellschaft</option>
-<option>HUK 24 Aktiengesellschaft</option>
-<option>HUK-COBURG-Allgemeine Versicherungs AG</option>
-<option>HUK-COBURG Haftpflicht-Unterstützungs-Kasse kraftfahrender Beamter a.G.</option>
-<option>Itzehoer Versicherung/ Brandgilde von 1691 VVaG</option>
-<option>KRAVAG-ALLGEMEINE Versicherungs-Aktiengesellschaft</option>
-<option>KRAVAG-LOGISTIC Versicherungs-Aktiengesellschaft</option>
-<option>KRAVAG-SACH Versicherung des Deutschen Kraftverkehrs VaG</option>
-<option>Landesschadenhilfe Versicherung VaG</option>
-<option>Lippische Landesbrandversicherung AG</option>
-<option>LVM Landwirtschaftlicher Versicherungsverein Münster a.G.</option>
-<option>Mannheimer Versicherung Aktiengesellschaft</option>
-<option>Mecklenburgische Versicherungs-Gesellschaft a.G.</option>
-<option>MÜNCHENER VEREIN Allgemeine Versicherungs-AG</option>
-<option>NÜRNBERGER Allgemeine Versicherungs-AG</option>
-<option>NÜRNBERGER Beamten Allgemeine Versicherungs-AG</option>
-<option>Oldenburgische Landesbrandkasse</option>
-<option>Optima Versicherungs-Aktiengesellschaft</option>
-<option>OVAG - Ostdeutsche Versicherung Aktiengesellschaft</option>
-<option>Öffentliche Feuerversicherung Sachsen-Anhalt</option>
-<option>Öffentliche Versicherung Braunschweig</option>
-<option>Provinzial Nord Brandkasse Aktiengesellschaft</option>
-<option>Provinzial Rheinland Versicherung AG</option>
-<option>R+V Allgemeine Versicherung AG</option>
-<option>R+V Direktversicherung AG</option>
-<option>S direkt Versicherung AG</option>
-<option>SAARLAND Feuerversicherung AG</option>
-<option>SCHWARZMEER UND OSTSEE Versicherungs-AktiengesellschaftSOVAG</option>
-<option>Signal Iduna Allgemeine Versicherung AG</option>
-<option>SIGNAL Unfallversicherung a.G.</option>
-<option>SV Sparkassen-Versicherung Holding AG</option>
-<option>United Services Automobile Association Direktion für Deutschland</option>
-<option>UniVersa Allgemeine Versicherung AG</option>
-<option>Versicherungskammer Bayern Versicherungsanstalt des öffentlichen Rechts</option>
-<option>Verti Versicherung</option>
-<option>VGH Landschaftliche Brandkasse Hannover</option>
-<option>VHV Allgemeine Versicherung AG</option>
-<option>VHV Vereinigte Hannoversche Versicherung a.G.</option>
-<option>VOLKSWOHL-BUND Sachversicherung Aktiengesellschaft</option>
-<option>Westfälische Provinzial Versicherung Aktiengesellschaft</option>
-<option>WGV-Versicherung AG</option>
-<option>Württembergische Gemeinde-Versicherung a.G.</option>
-<option>Württembergische Versicherung AG</option>
-<option>WWK Allgemeine Versicherung AG</option>
-<option>Zurich Insurance plc</option>
-
-
+            {% for v in versicherungen %}
+            {% if v.Vers_Adresse_ID == forderung_kopf[0].Vers_Adresse_ID %}
+            <option value="{{ v.Vers_Adresse_ID }}" selected>{{ v.Vers_Name }}</option>
+            {% else %}
+            <option value="{{ v.Vers_Adresse_ID }}">{{ v.Vers_Name }}</option>
+            {% endif %}
+            {% endfor %}
           </select>
         </div>
         <div class="col-sm-3">
           <select id="Versicherung_Typ" name="Versicherung_Typ" class="form-select">
             <option value="" selected>-</option>
-            <option>Haftpflicht</option>
-            <option>Teilkasko</option>
-            <option>Vollkasko</option>
-            <option>Ausländisch</option>
-            </select>
-            </div>  
+            {% for v in ('Haftpflicht', 'Teilkasko', 'Vollkasko', 'Ausländisch') %}
+            {% if v == forderung_kopf[0].Versicherung_Typ %}
+            <option value="{{ v }}" selected>{{ v }}</option>
+            {% else %}
+            <option value="{{ v }}">{{ v }}</option>
+            {% endif %}
+            {% endfor %}
+
+          </select>
+        </div>
       </div>
       <div class="row mb-3">
         <label for="Selbstbeteiligung" class="col-sm-2 col-form-label">Selbstbeteiligung</label>
         <div class="col-sm-2">
           <select id="Selbstbeteiligung" name="Selbstbeteiligung" class="form-select">
-            <option value="" selected>-</option>
-            <option>Versicherung</option>
-            <option>Kunde</option>
-            <option>Autohaus</option>
+            <option value="" {{ (forderung_kopf[0].Selbstbeteiligung=="" )|selected }}>-</option>
+            <option {{ (forderung_kopf[0].Selbstbeteiligung=="Versicherung" )|selected }}>Versicherung</option>
+            <option {{ (forderung_kopf[0].Selbstbeteiligung=="Kunde" )|selected }}>Kunde</option>
+            <option {{ (forderung_kopf[0].Selbstbeteiligung=="Autohaus" )|selected }}>Autohaus</option>
           </select>
         </div>
         <div class="col-sm-2">
-          <input type="text" class="form-control" id="Selbstbeteiligung_Betrag" placeholder="Betrag">
+          <input type="text" class="form-control" id="Selbstbeteiligung_Betrag" name="Selbstbeteiligung_Betrag" placeholder="Betrag" value="{{ forderung_kopf[0].Selbstbeteiligung_Betrag }}">
         </div>
       </div>
       <div class="row mb-3">
         <label for="MwSt" class="col-sm-2 col-form-label">MwSt</label>
         <div class="col-sm-2">
-          <select id="MwSt" name="MwSt" class="form-select">
-            <option value="" selected>-</option>
-                        <option>Versicherung</option>
-            <option>Kunde</option>
-            <option>Autohaus</option>
+          <select id="MwSt" name="Mwst" class="form-select">
+            <option value="" {{ (forderung_kopf[0].MwSt=="" )|selected }}>-</option>
+            <option {{ (forderung_kopf[0].Mwst=="Versicherung" )|selected }}>Versicherung</option>
+            <option {{ (forderung_kopf[0].Mwst=="Kunde" )|selected }}>Kunde</option>
+            <option {{ (forderung_kopf[0].Mwst=="Autohaus" )|selected }}>Autohaus</option>
           </select>
         </div>
         <div class="col-sm-2">
-          <input type="text" class="form-control" id="MwSt_Betrag" placeholder="Betrag">
+          <input type="text" class="form-control" id="Mwst_Betrag" name="Mwst_Betrag" placeholder="Betrag" value="{{ forderung_kopf[0].Mwst_Betrag|number_format }}">
         </div>
         <div class="col-sm-2">
-          <span
-            onclick="document.getElementById('MwSt_Betrag').value='{{ forderung_kopf[0].MwSt_Betrag|number_format }}';">{{
-            forderung_kopf[0].MwSt_Betrag|number_format }}</span>
+          <a class="btn btn-primary" hx-disable="true"
+            onclick="document.getElementById('Mwst_Betrag').value='{{ forderung_kopf[0].Mwst_Betrag_berechnet|number_format }}';">
+            <i class="cil-arrow-thick-left"></i>
+            {{ forderung_kopf[0].Mwst_Betrag_berechnet|number_format }}</a>
         </div>
       </div>
       <div class="col-3">
@@ -209,20 +446,20 @@
 
   <div class="col-12">
     <div class="form-check" data-coreui-toggle="collapse" data-coreui-target="#ReklamationCollapse"
-      aria-expanded="false" aria-controls="ReklamationCollapse">
-      <input class="form-check-input" type="checkbox" id="Reklamation">
+      aria-expanded="{{ forderung_kopf[0].Reklamation|truefalse }}" aria-controls="ReklamationCollapse">
+      <input class="form-check-input" type="checkbox" id="Reklamation" name="Reklamation" {{ forderung_kopf[0].Reklamation|checked }}>
       <label class="form-check-label" for="Reklamation">
         <strong>Reklamation</strong>
       </label>
     </div>
   </div>
 
-  <div class="collapse" id="ReklamationCollapse">
+  <div class="collapse {{ forderung_kopf[0].Reklamation|show }}" id="ReklamationCollapse">
     <div class="card card-body">
       <div class="row mb-3">
-        <label for="Reklamation_Begründung" class="col-sm-2 col-form-label">Begründung</label>
+        <label for="Reklamation_Begruendung" class="col-sm-2 col-form-label">Begründung</label>
         <div class="col-sm-3">
-          <input type="text" class="form-control" id="Reklamation_Begründung">
+          <input type="text" class="form-control" id="Reklamation_Begruendung" name="Reklamation_Begruendung" value="{{ forderung_kopf[0].Reklamation_Begruendung }}">
         </div>
       </div>
     </div>
@@ -230,8 +467,8 @@
 
   <div class="col-12">
     <div class="form-check" data-coreui-toggle="collapse" data-coreui-target="#RechtsanwaltCollapse"
-      aria-expanded="false" aria-controls="RechtsanwaltCollapse">
-      <input class="form-check-input" type="checkbox" id="Rechtsanwalt">
+      aria-expanded="{{ forderung_kopf[0].Rechtsanwalt|truefalse }}" aria-controls="RechtsanwaltCollapse">
+      <input class="form-check-input" type="checkbox" id="Rechtsanwalt" name="Rechtsanwalt" {{ forderung_kopf[0].Rechtsanwalt|checked }}>
       <label class="form-check-label" for="Rechtsanwalt">
         <strong>Rechtsanwalt</strong>
       </label>
@@ -239,25 +476,25 @@
   </div>
 
 
-  
-  <div class="collapse" id="RechtsanwaltCollapse">
+
+  <div class="collapse {{ forderung_kopf[0].Rechtsanwalt|show }}" id="RechtsanwaltCollapse">
     <div class="card card-body">
       <div class="row mb-3">
-        <label for="Rechtsanwalt_Begründung" class="col-sm-2 col-form-label">Begründung</label>
+        <label for="Rechtsanwalt_Begruendung" class="col-sm-2 col-form-label">Begründung</label>
         <div class="col-sm-3">
-          <input type="text" class="form-control" id="Rechtsanwalt_Begründung">
+          <input type="text" class="form-control" id="Rechtsanwalt_Begruendung" name="Rechtsanwalt_Begruendung" value="{{ forderung_kopf[0].Rechtsanwalt_Begruendung }}">
         </div>
       </div>
       <div class="row mb-3">
         <label for="Rechtsanwalt_Aktenzeichen" class="col-sm-2 col-form-label">Aktenzeichen</label>
         <div class="col-sm-3">
-          <input type="text" class="form-control" id="Rechtsanwalt_Aktenzeichen">
+          <input type="text" class="form-control" id="Rechtsanwalt_Aktenzeichen" name="Rechtsanwalt_Aktenzeichen" value="{{ forderung_kopf[0].Rechtsanwalt_Aktenzeichen }}">
         </div>
       </div>
       <div class="row mb-3">
         <label for="Rechtsanwalt_Stand" class="col-sm-2 col-form-label">Aktueller Stand</label>
         <div class="col-sm-3">
-          <input type="text" class="form-control" id="Rechtsanwalt_Stand">
+          <input type="text" class="form-control" id="Rechtsanwalt_Stand" name="Rechtsanwalt_Stand" value="{{ forderung_kopf[0].Rechtsanwalt_Stand }}">
         </div>
       </div>
       <div class="col-3">
@@ -270,21 +507,21 @@
 
   <div class="col-12">
     <div class="form-check" data-coreui-toggle="collapse" data-coreui-target="#MahnenCollapse"
-      aria-expanded="false" aria-controls="MahnenCollapse">
-      <input class="form-check-input" type="checkbox" id="Mahnen">
+      aria-expanded="{{ forderung_kopf[0].Mahnen_aussetzen|truefalse }}" aria-controls="MahnenCollapse">
+      <input class="form-check-input" type="checkbox" id="Mahnen" name="Mahnen_aussetzen" {{ forderung_kopf[0].Mahnen_aussetzen|checked }}>
       <label class="form-check-label" for="Mahnen">
         <strong>Mahnlauf aussetzen</strong>
       </label>
     </div>
   </div>
 
-  <div class="collapse" id="MahnenCollapse">
+  <div class="collapse {{ forderung_kopf[0].Mahnen_aussetzen|show }}" id="MahnenCollapse">
     <div class="card card-body">
       <div class="row mb-3">
         <label for="Mahnen_Begründung" class="col-sm-2 col-form-label">Begründung</label>
         <div class="col-sm-3">
-          
-          <input type="text" class="form-control" id="Mahnen_Begründung">
+
+          <input type="text" class="form-control" id="Mahnen_Begruendung" name="Mahnen_Begruendung" value="{{ forderung_kopf[0].Mahnen_Begruendung }}">
         </div>
       </div>
     </div>
@@ -292,18 +529,24 @@
 
   <div class="col-3">
     <label for="Wiedervorlage" class="form-label">Wiedervorlage</label>
-    <input type="date" class="form-control" id="Wiedervorlage" name="Wiedervorlage" value="{{ forderung_kopf[0].Invoice_Date.strftime("%Y-%m-%d") }}">
+    <input type="date" class="form-control" id="Wiedervorlage" name="Wiedervorlage"
+      value="{{ forderung_kopf[0].Wiedervorlage.strftime("%Y-%m-%d") }}">
+  </div>
+  <div class="col-2">
+    <a class="btn btn-primary" 
+    onclick="document.getElementById('Wiedervorlage').value='{{ add7days.strftime("%Y-%m-%d") }}';" hx-disable="true">
+      +7 Tage
+  </a>
   </div>
 
   <div class="col-12">
-    <a class="btn btn-primary" hx-disable="true"
-      href="#">Speichern
-    </a>
+    <button class="btn btn-primary" hx-post=""    hx-trigger="click"    hx-swap="none" hx-push-url="false"  >Speichern</button>
   </div>
 
 
 </form>
-
+</div>
+</div>
 <br>
 <br>
 
@@ -351,6 +594,19 @@
 
 
         <table class="table table-striped table-bordered">
+          <div>
+            <!--
+          {% for row in forderung_kopf %}
+
+            {% for key, value in row._asdict().items() %}
+            <tr>
+              <td><strong>{{ key }}:</strong></td>
+              <td>{{ '{{' }}forderung_kopf[0].{{ key }} {{ '}}' }}</td>
+            </tr>
+            {% endfor %}
+            {% endfor %}
+          -->
+          </div>
           <tbody>
             {% for row in forderung_kopf %}
 

+ 11 - 10
templates/forderungen/liste.html

@@ -4,21 +4,22 @@
 {%include 'forderungen/liste_filter.html' %}
 
 <div  id="liste-content">
-<table class="table table-striped table-bordered">
+<table class="table table-striped table-bordered table-sm">
   <thead>
     <tr>
-        <th>.</th>
-        <th>Filiale</th>
+        <th></th>
+        <th>Filiale / Bereich</th>
         <th>Kunde</th>
-        <th>Bereich</th>
         <th>Verursacher</th>
         <th>RG-Nr.</th>
-        <th>RG-Datum</th>
-        <th>Tage</th>
-        <th>Mahnstufe</th>
-        <th>offen</th>
-        <th>Kunde<br>offen ges.</th>
-        <th>Kommentar</th>
+        <th>RG-Datum<br>/ Fällig</th>
+        <th>RG-Betrag</th>
+        <th>offen /<br>Kunde ges.</th>
+        <th>Mahnstufe<br>/ Staffel</th>
+        <th>Abw.</th>
+        <th>Kommentar<br>Fibu</th>
+        <th>Kommentar<br>Abteilung</th>
+        <th>Wieder-<br>vorlage</th>
     </tr>
   </thead>
   <tbody>

+ 26 - 9
templates/forderungen/liste_zeile.html

@@ -3,16 +3,18 @@
       <td>
         <a href="/app/forderungen/details/{{ row.Client_DB }}_{{ row.Document_No }}" class="btn btn-sm btn-primary"><i class="icon cil-pencil"></i></a>
       </td>
-      <td>{{ row.Standort_Name }}</td>
+      <td>
+        {{ row.Standort_Name }}<br>
+        {{ row.Bereich }}
+      </td>
       <td>
         <a href="/app/forderungen/liste?Kunde={{ row.Kunde|urlencode }}">{{ row.Kunde }}</a>
-        {% if row.Kunde.startswith("K") %}
-        <a href="mailto:dummy@xyz.de?subject={{ row.Document_No }}" class="btn btn-sm btn-outline-secondary">
+        {% if row.Kunde_Email %}
+        <a href="mailto:{{ row.Kunde_Email }}?subject={{ row.Document_No }}" class="btn btn-sm btn-outline-secondary" hx-disable="true">
             <i class="cil-at"></i>
         </a>
         {% endif %}
       </td>
-      <td>{{ row.Bereich }}</td>
       <td>
         <a href="/app/forderungen/liste?Verursacher={{ row.Verursacher|urlencode }}">{{ row.Verursacher }}</a>
         {% if row.Verursacher == 'N.N.' %}
@@ -22,10 +24,25 @@
         {% endif %}
       </td>
       <td>{{ row.Document_No }}</td>
-      <td>{{ row.Invoice_Date|date_format }}</td>
-      <td class="text-end">{{ row.Tage }}</td>
-      <td class="text-end">{{ row.Mahnstufe }}</td>
+      <td>
+        {{ row.Invoice_Date|date_format }}<br>
+        {{ row.Fällig_Datum|date_format }}
+      </td>
       <td class="text-end">{{ row.offen|number_format }}</td>
-      <td class="text-end">{{ row.offen_Kunde_gesamt|number_format }}</td>
-      <td>{{ row.Kommentar_Fibu or '' }}</td>
+      <td class="text-end">
+        {{ row.offen|number_format }}<br>
+        {{ row.offen_Kunde_gesamt|number_format }}
+      </td>
+      <td class="text-end">
+        {{ row.Mahnstufe }}<br>
+        {{ row.Staffel }}
+      </td>
+      <td class="text-end">{{ row.Abwarten }}</td>
+      <td>
+        {{ row.Kommentar_Fibu or '' }}
+      </td>
+      <td>
+        {{ row.Kommentar_Abteilung or '' }}
+      </td>
+      <td class="text-end">{{ row.Wiedervorlage|date_format }}</td>
     </tr>

+ 1 - 1
templates/forderungen/queries/forderung_kommentar.sql

@@ -7,4 +7,4 @@ SELECT Timestamp,
  
 FROM dbo.Forderungen_Kommentar_Benutzer
 WHERE Client_DB = {{ appsmith.URL.queryParams.Client_DB }}
-AND Document_No = {{ appsmith.URL.queryParams.Document_No }}
+AND Beleg_Nr = {{ appsmith.URL.queryParams.Document_No }}

+ 74 - 5
templates/forderungen/queries/forderung_kopf.sql

@@ -1,5 +1,74 @@
-SELECT * 
-    , offen * 0.19 as MwSt_Betrag
-FROM dbo.Forderungen
-WHERE Client_DB = {{ appsmith.URL.queryParams.Client_DB }}
-AND Document_No = {{ appsmith.URL.queryParams.Document_No }}
+SELECT [F].*
+     , round([offen] * 0.19, 2) AS [Mwst_Betrag_berechnet]
+     , [K].[Kunde_Name]
+     , [K].[Kunde_Nachname]
+     , [K].[Kunde_Vorname]
+     , [K].[Kunde_Adresse_ID]
+     , [K].[Kunde_Adresse]
+     , [K].[Kunde_PLZ]
+     , [K].[Kunde_Ort]
+     , [K].[Kunde_Land]
+     , [K].[Kunde_Telefon]
+     , [K].[Kunde_Email]
+     , [K].[Payment_Terms_Code]
+     , [K].[Gen_Bus_Posting_Group]
+     , [K].[Customer_Group_Code]
+     , [K].[Customer_Group_Description]
+     , isnull([FD].[Bearbeitet], 'N') AS [Bearbeitet]
+     , isnull([FD].[Versicherung], 'N') AS [Versicherung]
+     , isnull([FD].[Rechtsanwalt], 'N') AS [Rechtsanwalt]
+     , isnull([FD].[Reklamation], 'N') AS [Reklamation]
+     , isnull([FD].[Mahnen_aussetzen], 'N') AS [Mahnen_aussetzen]
+     , isnull([FD].[Selbstbeteiligung], '') AS [Selbstbeteiligung]
+     , isnull([FD].[Selbstbeteiligung_Betrag], 0.0) AS [Selbstbeteiligung_Betrag]
+     , isnull([FD].[Mwst], '') AS [Mwst]
+     , isnull([FD].[Mwst_Betrag], 0.0) AS [Mwst_Betrag]
+     , isnull([FD].[Vers_Adresse_ID], '') AS [Vers_Adresse_ID]
+     , isnull([FD].[Versicherung_Typ], '') AS [Versicherung_Typ]
+     , isnull([FD].[Reklamation_Begruendung], '') AS [Reklamation_Begruendung]
+     , isnull([FD].[Rechtsanwalt_Begruendung], '') AS [Rechtsanwalt_Begruendung]
+     , isnull([FD].[Rechtsanwalt_Aktenzeichen], '') AS [Rechtsanwalt_Aktenzeichen]
+     , isnull([FD].[Rechtsanwalt_Stand], '') AS [Rechtsanwalt_Stand]
+     , isnull([FD].[Mahnen_Begruendung], '') AS [Mahnen_Begruendung]
+     , isnull([FD].[Wiedervorlage], coalesce([FD].[Wiedervorlage], dateadd(DAY, 14, [F].[Invoice_Date]))) AS [Wiedervorlage]
+     , [V].[Vers_Name]
+     , [V].[Vers_Adresse]
+     , [V].[Vers_PLZ]
+     , [V].[Vers_Ort]
+     , [V].[Vers_Telefon]
+     , [V].[Vers_Telefax]
+     , [V].[Vers_Web]
+     , [V].[Vers_Email]
+     , [FZ].[Fahrzeug_VIN]
+     , [FZ].[Fahrzeug_Marke_Nr]
+     , [FZ].[Fahrzeug_Modell_Nr]
+     , [FZ].[Fahrzeug_Modell_Name]
+     , [FZ].[Fahrzeug_Kategoriecode]
+     , [FZ].[Fahrzeug_Kunde_Nr]
+     , [FZ].[Fahrzeug_Kennzeichen]
+     , [FZ].[Fahrzeug_Kmstand]
+     , [FZ].[Fahrzeug_Antriebsart]
+     , [FZ].[Fahrzeug_Erstzulassung]
+     , [FZ].[Fahrzeug_Kaufdatum]
+     , [FZ].[Fahrzeug_Vorbesitzer_Anzahl]
+     , [FZ].[Fahrzeug_Vorbesitzer_Kunde_Nr]     
+     , iif(K.Kunde_Nr = K2.Kunde_Nr, 'N', 'J') as Fahrzeug_Leasing
+     , [K2].[Kunde_Nr] AS [Leasing_Kunde_Nr]
+     , [K2].[Kunde_Name] AS [Leasing_Kunde_Name]
+     , [K2].[Kunde_Nachname] AS [Leasing_Kunde_Nachname]
+     , [K2].[Kunde_Vorname] AS [Leasing_Kunde_Vorname]
+     , [K2].[Kunde_Adresse_ID] AS [Leasing_Kunde_Adresse_ID]
+     , [K2].[Kunde_Adresse] AS [Leasing_Kunde_Adresse]
+     , [K2].[Kunde_PLZ] AS [Leasing_Kunde_PLZ]
+     , [K2].[Kunde_Ort] AS [Leasing_Kunde_Ort]
+     , [K2].[Kunde_Land] AS [Leasing_Kunde_Land]
+     , [K2].[Kunde_Telefon] AS [Leasing_Kunde_Telefon]
+     , [K2].[Kunde_Email] AS [Leasing_Kunde_Email]     
+FROM [dbo].[Forderungen] [F]
+         LEFT JOIN [dbo].[Kunden] [K] ON [F].[Kunde_Nr] = [K].[Kunde_Nr] AND [F].[Client_DB] = [K].[Client_DB]
+         LEFT JOIN [dbo].[Fahrzeuge] FZ ON F.VIN = FZ.Fahrzeug_Nr AND [F].[Client_DB] = [FZ].[Client_DB]
+         LEFT JOIN [dbo].[Kunden] [K2] ON [FZ].[Fahrzeug_Kunde_Nr] = [K2].[Kunde_Nr] AND [FZ].[Client_DB] = [K2].[Client_DB]
+         LEFT JOIN [dbo].[Forderungen_Details] [FD] ON [F].[Client_DB] = [FD].[Client_DB] AND [F].[Document_No] = [FD].[Beleg_Nr]
+         LEFT JOIN [dbo].[Versicherungen] [V] ON [FD].[Vers_Adresse_ID] = [V].[Vers_Adresse_ID]
+WHERE [F].[Client_DB] = {{ appsmith.URL.queryParams.Client_DB }}
+AND [F].[Document_No] = {{ appsmith.URL.queryParams.Document_No }}

+ 74 - 52
templates/forderungen/queries/forderungen_liste.sql

@@ -1,54 +1,76 @@
-SELECT [T1].[Client_DB]
-     , [T1].[Hauptbetrieb_ID]
-     , [T1].[Hauptbetrieb_Name]
-     , [T1].[Standort_ID]
-     , [T1].[Standort_Name]     
-     , [T1].[Document_No]
-     , [T1].[Rechnung_Gutschrift]     
-     , [T1].[User_ID]
-     , [T1].[VIN]
-     , [T1].[Comment]
-     , [T1].[offen]
-     , [T1].[offen_Kunde_gesamt]
-     , [T1].[Invoice_Date]
-     , [T1].[Verursacher]
-     , [T1].[Kunde]
-     , [T1].[Beleg]
-     , [T1].[Bereich]
-     , [T1].[Tage]
-		 , case when [T1].[Tage] > 90 then 3
-		 when [T1].[Tage] > 60 then 2
-		   when [T1].[Tage] > 30 then 1
-			 else 0 end as [Stufe]
-     , [T1].[Staffel]
-     , [T1].[Mahnstufe]
-     , [T1].[Forderungsart]
-     , [T1].[Abwarten]
-     , [T1].[Verursacher_Benutzer_ID]
-	   , T3.[Kommentar_Fibu]
-     , T3.[Kommentar_Abteilung] 
-		 , T3.[Wiedervorlage]
-		 , T3.[Begründung]
-     , iif([T1].[Kunde] like 'k%', 'kunde@xyz.de', '') as Kunde_Email
+SELECT F.* FROM (
+
+SELECT [F].[Client_DB]
+     , [F].[Hauptbetrieb_ID]
+     , [F].[Hauptbetrieb_Name]
+     , [F].[Standort_ID]
+     , [F].[Standort_Name]
+     , [F].[Document_No]
+     , [F].[Rechnung_Gutschrift]
+     , [F].[User_ID]
+     , [F].[VIN]
+     , [F].[Comment]
+     , [F].[offen]
+     , [F].[offen_Kunde_gesamt]
+     , [F].[Invoice_Date]
+     , [F].[Verursacher]
+     , [F].[Kunde]
+     , [F].[Beleg]
+     , [F].[Bereich]
+     , [F].[Tage]
+     , CASE
+           WHEN [F].[Tage] > 90 THEN 3
+           WHEN [F].[Tage] > 60 THEN 2
+           WHEN [F].[Tage] > 30 THEN 1
+           ELSE 0
+       END AS [Stufe]
+     , replace([F].[Staffel], 'Wochen', 'W.') AS [Staffel]
+     , [F].[Mahnstufe]
+     , [F].[Forderungsart]
+     --, [F].[Abwarten]
+     , [F].[Verursacher_Benutzer_ID]
+     , left(isnull([FK].[Kommentar_Fibu], ''), 50) AS [Kommentar_Fibu]
+     , left(isnull([FK].[Kommentar_Abteilung], ''), 50) AS [Kommentar_Abteilung]
+     , [K].[Kunde_Email] AS [Kunde_Email]
+     , coalesce([FD].[Wiedervorlage], dateadd(DAY, 14, [F].[Invoice_Date])) AS [Wiedervorlage]
+     , CASE
+           WHEN [FD].[Reklamation] = 'J' THEN 'Rekl.'
+           WHEN [FD].[Versicherung] = 'J' THEN 'Vers.'
+           WHEN [FD].[Rechtsanwalt] = 'J' THEN 'RA'
+           WHEN [FD].[Mahnen_aussetzen] = 'J' THEN 'N'
+           ELSE ''
+       END AS [Abwarten]
+     , isnull([FK].[Begründung], '') AS [Begründung]
+     , isnull([FD].[Bearbeitet], 'N') AS [Bearbeitet]
+     , dateadd(DAY, 14, [F].[Invoice_Date]) AS [Fällig_Datum]
+
+FROM [dbo].[Forderungen] [F]
+         LEFT JOIN [dbo].[Kunden] [K] ON [F].[Kunde_Nr] = [K].[Kunde_Nr] AND [F].[Client_DB] = [K].[Client_DB]
+         LEFT JOIN [dbo].[Forderungen_Details] [FD] ON [F].[Client_DB] = [FD].[Client_DB] AND [F].[Document_No] = [FD].[Beleg_Nr]
+         LEFT JOIN [dbo].[Forderungen_Kommentar_letzte] [FK] ON [F].[Client_DB] = [FK].[Client_DB] AND [F].[Document_No] = [FK].[Beleg_Nr]
+
+) AS F
+INNER JOIN [dbo].[Benutzer_Rechte] [BR] ON ([BR].[Benutzer_ID] = {{ BenutzerSelect.selectedOptionValue }} OR BR.Benutzer_ID = '')
+AND [F].[Hauptbetrieb_ID] = [BR].[Hauptbetrieb_ID] 
+AND [F].[Standort_ID] = [BR].[Standort_ID] 
+AND ([BR].[Rolle] = 'Buchhaltung' OR [BR].[Benutzer_ID] = [F].[Verursacher_Benutzer_ID])
 
-FROM [dbo].[Forderungen] T1
-INNER JOIN [dbo].[Benutzer_Rechte] T2 ON (T2.Benutzer_ID = {{ BenutzerSelect.selectedOptionValue }} OR T2.Benutzer_ID = '')
-AND T1.Hauptbetrieb_ID = T2.Hauptbetrieb_ID AND T1.Standort_ID = T2.Standort_ID AND (T2.Rolle = 'Buchhaltung' OR T2.Benutzer_ID = T1.Verursacher_Benutzer_ID)
-LEFT JOIN [dbo].[Forderungen_Kommentar_letzte] T3 ON T1.Client_DB = T3.Client_DB AND T1.Document_No = T3.Document_No
 WHERE 1 = 1
-AND [Invoice_Date] >= {{ RechnungsdatumVon.selectedDate }}
-AND [Invoice_Date] <= {{ RechnungsdatumBis.selectedDate }}
-AND T1.[Client_DB] LIKE '%' + {{ Hauptbetrieb.selectedOptionValue }}
-AND T1.[Standort_ID] LIKE '%' + {{ Standort.selectedOptionValue }}
-AND T1.[Bereich] LIKE '%' + {{ Bereich.selectedOptionValue }}
-AND T1.[Document_No] LIKE '%' + {{ Rechnungsnummer.text }} + '%'
-AND [Kunde] LIKE '%' + {{ Kunde.text }}
-AND [Verursacher] LIKE '%' + {{ Verursacher.selectedOptionValue }}
-AND [VIN] LIKE '%' + {{ Fahrzeug.selectedOptionValue }}
-AND [Staffel] LIKE '%' + {{ Staffel.selectedOptionValue }}
-AND [Mahnstufe] LIKE '%' + {{ Mahnstufe.selectedOptionValue }}
-AND (T3.Wiedervorlage IS NULL OR (
-	T3.Wiedervorlage >= {{ WiedervorlageVon.selectedDate }}
-	AND T3.Wiedervorlage <= {{ WiedervorlageBis.selectedDate }}
-))
-ORDER BY [Tage] DESC, T3.[Wiedervorlage] ASC
+AND F.[Invoice_Date] >= {{ RechnungsdatumVon.selectedDate }}
+AND F.[Invoice_Date] <= {{ RechnungsdatumBis.selectedDate }}
+AND F.[Client_DB] LIKE '%' + {{ Hauptbetrieb.selectedOptionValue }}
+AND F.[Standort_ID] LIKE '%' + {{ Standort.selectedOptionValue }}
+AND F.[Bereich] LIKE '%' + {{ Bereich.selectedOptionValue }}
+AND F.[Document_No] LIKE '%' + {{ Rechnungsnummer.text }} + '%'
+AND F.[Kunde] LIKE '%' + {{ Kunde.text }} + '%'
+AND F.[Verursacher] LIKE '%' + {{ Verursacher.selectedOptionValue }}
+AND F.[VIN] LIKE '%' + {{ Fahrzeug.selectedOptionValue }}
+AND F.[Staffel] LIKE '%' + {{ Staffel.selectedOptionValue }}
+AND F.[Mahnstufe] LIKE '%' + {{ Mahnstufe.selectedOptionValue }}
+AND F.[Bearbeitet] LIKE '%' + {{ Bearbeitet.selectedOptionValue }}
+AND F.[Abwarten] LIKE '%' + {{ Abwarten.selectedOptionValue }}
+AND (
+	F.Wiedervorlage >= {{ WiedervorlageVon.selectedDate }}
+	AND F.Wiedervorlage <= {{ WiedervorlageBis.selectedDate }}
+)
+ORDER BY F.[Wiedervorlage] ASC, F.[Tage] DESC

+ 2 - 9
templates/forderungen/queries/insert_kommentar.sql

@@ -1,9 +1,2 @@
-INSERT INTO dbo.Forderungen_Kommentar (Client_DB, Document_No, Timestamp, Benutzer_ID, Begründung, Wiedervorlage, Kommentar) VALUES (
-	'{{frm_Kommentar.data.txt_Client_DB}}',
-	'{{frm_Kommentar.data.txt_Document_No}}',
-  getdate(),
-	'{{appsmith.URL.queryParams.Benutzer_ID}}',
-	'{{frm_Kommentar.data.Select1.selectedOptionValue}}',
-	'{{frm_Kommentar.data.DatePicker1}}',
-  '{{frm_Kommentar.data.txt_Kommentar}}'
-	)
+INSERT INTO [dbo].[Forderungen_Kommentar] ([Client_DB], [Beleg_Nr], [Timestamp], [Benutzer_ID], [Kommentar])
+VALUES ('{{data.Client_DB}}', '{{data.Beleg_Nr}}', getdate(), '{{data.Benutzer_ID}}', '{{data.Kommentar}}')

+ 30 - 0
templates/forderungen/queries/update_details.sql

@@ -0,0 +1,30 @@
+IF NOT exists (SELECT 1
+               FROM [dbo].[Forderungen_Details]
+               WHERE [Client_DB] = '{{data.Client_DB}}'
+                 AND [Beleg_Nr] = '{{data.Beleg_Nr}}')
+    BEGIN
+        INSERT INTO [dbo].[Forderungen_Details] ( [Client_DB], [Beleg_Nr])
+        VALUES ('{{data.Client_DB}}', '{{data.Beleg_Nr}}')
+    END;
+
+
+UPDATE [dbo].[Forderungen_Details]
+SET [Bearbeitet] = 'J'
+  , [Versicherung] = '{{data.Versicherung}}'
+  , [Rechtsanwalt] = '{{data.Rechtsanwalt}}'
+  , [Reklamation] = '{{data.Reklamation}}'
+  , [Mahnen_aussetzen] = '{{data.Mahnen_aussetzen}}'
+  , [Selbstbeteiligung] = '{{data.Selbstbeteiligung}}'
+  , [Selbstbeteiligung_Betrag] = '{{data.Selbstbeteiligung_Betrag}}'
+  , [Mwst] = '{{data.Mwst}}'
+  , [Mwst_Betrag] = '{{data.Mwst_Betrag}}'
+  , [Wiedervorlage] = '{{data.Wiedervorlage}}'
+  , [Vers_Adresse_ID] = '{{data.Vers_Adresse_ID}}'
+  , [Versicherung_Typ] = '{{data.Versicherung_Typ}}'
+  , [Reklamation_Begruendung] = '{{data.Reklamation_Begruendung}}'
+  , [Rechtsanwalt_Begruendung] = '{{data.Rechtsanwalt_Begruendung}}'
+  , [Rechtsanwalt_Aktenzeichen] = '{{data.Rechtsanwalt_Aktenzeichen}}'
+  , [Rechtsanwalt_Stand] = '{{data.Rechtsanwalt_Stand}}'
+  , [Mahnen_Begruendung] = '{{data.Mahnen_Begruendung}}'
+WHERE [Client_DB] = '{{data.Client_DB}}'
+  AND [Beleg_Nr] = '{{data.Beleg_Nr}}'

+ 2 - 0
templates/forderungen/queries/versicherungen.sql

@@ -0,0 +1,2 @@
+SELECT * 
+FROM [dbo].[Versicherungen]