<!DOCTYPE html>
<html lang="de" dir="ltr" xmlns:th="http://www.thymeleaf.org">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=0.75, user-scalable=no">
      <title>Lieferanten Details</title>
      <script th:src="@{/js/filterTable.js}"></script>
      <link rel="stylesheet" th:href="@{/css/ecom.css}"/>
   </head>
   <body>
      <nav th:replace="fragments/header :: header">Header</nav>
      <div class="sidebar-layout content-width">
         <nav></nav>
         <div>
            <h1>Lieferant <span th:text="${SupplierDetail.name}"></span></h1>
            <script th:src="@{/js/back.js}"></script>
            <div class="back" data-group="intern" data-insert="true"></div>
         </div>
      </div>
      <main class="sidebar-layout content-width">
         <nav th:replace="fragments/intern :: sidebar"></nav>
         <div class="content-width">
            <h2>Bestellungen</h2>
            <p>
            <table id="order-table">
               <tr>
                  <th colspan="9">
                     <input type="text" placeholder="Filtern" class="smaller jsFilterTable full-width"
                        data-target-id="main-table">
                  </th>
               </tr>
               <thead>
                  <tr>
                     <th>Bestellnummer</th>
                     <th>Datum</th>
                     <th>Artikel</th>
                     <th>Preis/Stk (Netto)</th>
                     <th>Menge</th>
                     <th>Gesamtpreis (Netto)</th>
                     <th>Status</th>
                  </tr>
               </thead>
               <tbody>
                  <tr th:each="order : ${SupplierDetail.orders}">
                     <td><span th:text="${order.id}"></span></td>
                     <td><span th:text="${order.dateOrder}"></span></td>
                     <td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="button smaller" th:text="${order.articleName}"></a></td>
                     <td><span th:text="${order.priceNet}"></span> €</td>
                     <td><span th:text="${order.quantity}"></span></td>
                     <td><span th:text="${order.priceTotal}"></span> €</td>
                     <td>
                        <div th:if="${order.arrived}">
                           Angekommen
                        </div>
                        <!-- ELSE -->
                        <div th:unless="${order.arrived}">
                           Unterwegs <br>
                           <form class="detailgrid" action="#" th:action="@{/intern/supplierOrders/store/{id}(id = ${order.id})}" method="POST">
                              <input class="button smaller" type="submit" value="Eingang verbuchen" />
                           </form>
                        </div>
                     </td>
                  </tr>
               </tbody>
            </table>
            </p>
            <h2>Buchungen</h2>
            <div>
               <h4> Kontostand </h4>
               <h3 th:text="${SupplierDetail.balance}" />
            </div>
            <p>
            <table id="booking-table">
               <thead>
                  <tr>
                     <th>Zeitpunkt</th>
                     <th>Betrag</th>
                     <th>Von</th>
                     <th>Kontostand</th>
                     <th>Grund</th>
                     <th>Referenz</th>
                  </tr>
               </thead>
               <tbody>
                  <tr>
                  <tr th:each="booking : ${SupplierDetail.bookings}">
                     <td th:text="${booking.datetime}" />
                     <td th:text="${booking.amount}" />

                     <td th:if="${booking.sourceAddr}"><a th:href="@{${booking.sourceAddr}}" th:text="${booking.source}" /></td>
                     <td th:unless="${booking.sourceAddr}" th:text="${booking.source}" />

                     <td th:text="${booking.balance}" />

                     <td th:text="${booking.reason}" />
                     <td th:if="${booking.referenceAddr}"><a th:href="@{${booking.referenceAddr}}" th:text="${booking.reference}" /></td>
                     <td th:unless="${booking.referenceAddr}" th:text="${booking.reference}" />
                  </tr>
               </tbody>
            </table>
            </p>
         </div>
      </main>
      <footer th:replace="fragments/footer :: footer"></footer>
   </body>
</html>
