{% extends "base/base.html" %}
{% block content %}

<h3>Kommentare</h3>

<table class="table table-striped table-bordered">
  <thead>
    <tr>
        <th>Timestamp</th>
        <th>Name</th>
        <th>Rolle</th>
        <th>Begründung</th>
        <th>Wiedervorlage</th>
        <th>Kommentar</th>
    </tr>
  </thead>
  <tbody>
    {% for row in forderung_kommentar %}
    <tr>
      <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 %}
  </tbody>
</table>


<h3>Dateien</h3>

<table class="table table-striped table-bordered">
  <thead>
    <tr>
        <th>Datum</th>
        <th>Dateiname</th>
    </tr>
  </thead>
  <tbody>
    {% for row in files %}
    <tr>
      <td></td>
      <td>{{ row }}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>

<h3>Eingabemaske</h3>

<form class="row g-3">
  <div class="col-md-6">
    <label for="inputEmail4" class="form-label">Email</label>
    <input type="email" class="form-control" id="inputEmail4">
  </div>
  <div class="col-md-6">
    <label for="inputPassword4" class="form-label">Password</label>
    <input type="password" class="form-control" id="inputPassword4">
  </div>
  <div class="col-12">
    <label for="inputAddress" class="form-label">Address</label>
    <input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St">
  </div>
  <div class="col-12">
    <label for="inputAddress2" class="form-label">Address 2</label>
    <input type="text" class="form-control" id="inputAddress2" placeholder="Apartment, studio, or floor">
  </div>
  <div class="col-md-6">
    <label for="inputCity" class="form-label">City</label>
    <input type="text" class="form-control" id="inputCity">
  </div>
  <div class="col-md-4">
    <label for="inputState" class="form-label">State</label>
    <select id="inputState" class="form-select">
      <option selected>Choose...</option>
      <option>...</option>
    </select>
  </div>
  <div class="col-md-2">
    <label for="inputZip" class="form-label">Zip</label>
    <input type="text" class="form-control" id="inputZip">
  </div>
  <div class="col-12">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="gridCheck">
      <label class="form-check-label" for="gridCheck">
        Check me out
      </label>
    </div>
  </div>
  <div class="col-12">
    <a class="btn btn-secondary" href="/app/forderungen/export/{{forderung_kopf[0].Client_DB}}_{{forderung_kopf[0].Document_No}}">Mahnung erstellen</a>
  </div>
</form>





<h3>Forderung Details</h3>

<table class="table table-striped table-bordered">
  <tbody>
    {% for row in forderung_kopf %}
    
    {% for key, value in row._asdict().items() %}
    <tr>
      <th>{{ key }}</th>
      <td>{{ value }}</td>
    </tr>
      {% endfor %}
    {% endfor %}
  </tbody>
</table>


<h3>Mahnungen</h3>

<table class="table table-striped table-bordered">
  <thead>
    <tr>
        <th>Kunde_Nr</th>
        <th>Mahnung_Nr</th>
        <th>Mahndatum</th>
        <th>Mahnstufe</th>
        <th>Rechnung_Nr</th>
        <th>Rechnung_Datum</th>
        <th>Betrag</th>
        <th>Offen</th>
    </tr>
  </thead>
  <tbody>
    {% for row in forderung_mahnung %}
    <tr>
      <td>{{ row.Kunde_Nr }}</td>
      <td>{{ row.Mahnung_Nr }}</td>
      <td>{{ row.Mahndatum|date_format }}</td>
      <td>{{ row.Rechnung_Nr }}</td>
      <td>{{ row.Rechnung_Datum|date_format }}</td>
      <td>{{ row.Betrag|number_format }}</td>
      <td>{{ row.Offen|number_format }}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>



<h3>Auftragspositionen</h3>

<table class="table table-striped table-bordered">
  <thead>
    <tr>
        <th>Auftrag_Nr</th>
        <th>Auftrag_Position</th>
        <th>Betrag</th>
    </tr>
  </thead>
  <tbody>
    {% for row in auftrag_positionen %}
    <tr>
      <td>{{ row.Auftrag_Nr }}</td>
      <td>{{ row.Auftrag_Position }}</td>
      <td>{{ row.Betrag|number_format }}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>



<div class="card mb-3">
  <div class="card-body">
    <h5 class="card-title">Rechnung {{ forderung.rechnungsnummer }}</h5>
    <p>Kunde: {{ forderung.kunde.name if forderung.kunde else '' }}</p>
    <p>Betrag: {{ forderung.betrag }}</p>
    <p>Fälligkeit: {{ forderung.faelligkeit }}</p>
    <div class="mt-3">
      <a class="btn btn-outline-secondary me-2" href="/detail/{{ forderung.id }}/export/docx">Export DOCX</a>
      <a class="btn btn-outline-primary" href="mailto:?subject=Rechnung%20{{ forderung.rechnungsnummer }}&body=Sie%20finden%20Details%20unter%20{{ request.url }}">E-Mail (mailto)</a>
    </div>
  </div>
</div>

<div class="card">
  <div class="card-body">
    <h6>Neue Bemerkung</h6>
    <form method="post" action="/detail/{{ forderung.id }}/bemerkung">
      <div class="mb-2">
        <textarea name="bemerkung" class="form-control" rows="3"></textarea>
      </div>
      <div class="mb-2">
        <label>Wiedervorlage</label>
        <input type="date" name="wiedervorlage_datum" class="form-control" />
      </div>
      <button class="btn btn-primary" type="submit">Speichern</button>
      <a class="btn btn-secondary ms-2" href="/forderungen">Zurück</a>
    </form>
  </div>
</div>

{% if forderung.bemerkungen %}
<div class="mt-3">
  <h5>Bemerkungen</h5>
  <ul class="list-group">
    {% for b in forderung.bemerkungen %}
    <li class="list-group-item">{{ b.zeitstempel }} - {{ b.benutzer }}: {{ b.bemerkung }} {% if b.wiedervorlage_datum %} (WV: {{ b.wiedervorlage_datum }}){% endif %}</li>
    {% endfor %}
  </ul>
</div>
{% endif %}



{% endblock %}
