<!DOCTYPE html>
<html dir="ltr" lang="de" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=0.75, user-scalable=no" name="viewport">

    <title>Lager</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>Lagerbuchungen</h1>

        <script th:src="@{/js/back.js}"></script>
        <div class="back" data-group="intern" data-insert="false" data-name="Zurück zu den Lagerbuchungen."></div>
    </div>
</div>
<main class="sidebar-layout content-width">
    <nav th:replace="fragments/intern :: sidebar"></nav>
    <div class="content-width">
        <p>
            Die Lagerbestände nach Artikel können Sie unter den <a th:href="@{/intern/listedArticles/}">gelisteten
            Artikeln</a> einsehen.
        </p>
        <p>
        <table id="main-table">
            <tr>
                <th colspan="7">
                    <input class="smaller jsFilterTable full-width" data-target-id="main-table" placeholder="Filtern"
                           type="text"></input>
                </th>
            </tr>
            <tr>
                <th>Zeitpunkt</th>
                <th>Artikel</th>
                <th>Anzahl</th>
                <th>Von</th>
                <th>Nach</th>
                <th>Status</th>
            </tr>

            <th:block th:each="booking : ${bookings}">
                <tr th:data-group="${booking.id}">
                    <td th:text="${booking.created.toString()}"></td>
                    <td class="l" colspan="4" th:if="${booking.reason.isManuel}">
                        Manuell: <small th:text="${booking.reason.comment}"></small>
                    </td>
                    <td class="l" colspan="4" th:if="${booking.reason.isStartBooking}">
                        Startbuchung
                    </td>
                    <td class="l" colspan="4" th:if="${booking.reason.customerOrder != null}">
                        <a th:href="${'/intern/customerOrders/' + booking.reason.customerOrder.id}">
                            Bestellung: <span th:text="${booking.reason.customerOrder.id}"></span>
                        </a>
                    </td>
                    <td class="l" colspan="4" th:if="${booking.reason.supplierOrder != null}">
                        <a th:href="${'/intern/supplierOrders/#q=' + booking.reason.supplierOrder.id}">
                            Lieferung: <span th:text="${booking.reason.supplierOrder.id}"></span>
                        </a>
                    </td>

                    <td th:if="${!booking.isInProgress && !booking.isDone}">
                        Auf Warteliste
                    </td>
                    <td th:if="${booking.isInProgress && !booking.isDone}">
                        Wird bearbeitet
                    </td>
                    <td th:if="${booking.isInProgress && booking.isDone}">
                        Fertig
                    </td>
                </tr>

                <tr th:data-group="${booking.id}" th:each="pos : ${booking.positions}">
                    <td></td>
                    <td><a th:href="@{/intern/articles/{id}(id=${pos.article.id})}"
                           th:text="${pos.article.title}"></a></td>
                    <th:block th:if="${pos.amount > 0}">
                        <td th:text="${pos.amount}"></td>
                        <td> -</td>
                        <td><a th:href="${'/intern/warehouse/slots/#q=%23' + pos.slotEntry.slot.slotNum}">Lagerplatz
                            <span th:text="${pos.slotEntry.slot.slotNum}"></span> </a></td>
                    </th:block>
                    <th:block th:if="${pos.amount < 0}">
                        <td th:text="${pos.amount * -1}"></td>
                        <td><a th:href="${'/intern/warehouse/slots/#q=%23' + pos.slotEntry.slot.slotNum}">Lagerplatz
                            <span th:text="${pos.slotEntry.slot.slotNum}"></span> </a></td>
                        <td> -</td>
                    </th:block>
                    <th:block th:if="${pos.amount == 0}">
                        <td th:text="${pos.amount}"></td>
                        <td> -</td>
                        <td> -</td>
                    </th:block>
                    <td></td>
                </tr>
            </th:block>

        </table>
        </p>
    </div>
</main>
<footer th:replace="fragments/footer :: footer"></footer>
</body>

</html>
