@using RazorLight
@inherits TemplatePage<Elwig.Documents.DeliveryJournal>
@model Elwig.Documents.DeliveryJournal
@{ Layout = "Document"; }
<link rel="stylesheet" href="file:///@Raw(Model.DataPath)\resources\DeliveryJournal.css"/>
<main>
    <h1>Lieferjournal</h1>
    <h2>@Model.Filter</h2>
    <table class="journal">
        <colgroup>
            <col style="width: 25mm;"/>
            <col style="width: 5mm;"/>
            <col style="width: 15mm;"/>
            <col style="width: 8mm;"/>
            <col style="width: 12mm;"/>
            <col style="width: 38mm;"/>
            <col style="width: 28mm;"/>
            <col style="width: 10mm;"/>
            <col style="width: 10mm;"/>
            <col style="width: 14mm;"/>
        </colgroup>
        <thead>
            <tr>
                <th rowspan="2" style="text-align: left;">Lieferschein-Nr.</th>
                <th rowspan="2" class="narrow">Pos.</th>
                <th rowspan="2">Datum</th>
                <th rowspan="2">Zeit</th>
                <th rowspan="2">MgNr.</th>
                <th rowspan="2" style="text-align: left;">Mitglied</th>
                <th rowspan="2" style="text-align: left;">Sorte</th>
                <th colspan="2">Gradation</th>
                <th>Gewicht</th>
            </tr>
            <tr>
                <th class="unit">[°Oe]</th>
                <th class="unit narrow">[°KMW]</th>
                <th class="unit">[kg]</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var p in Model.Deliveries) {
                <tr>
                    <td>@p.LsNr</td>
                    <td>@p.Pos</td>
                    <td class="small">@($"{p.Date:dd.MM.yyyy}")</td>
                    <td class="small">@($"{p.Time:HH:mm}")</td>
                    <td class="number">@p.MgNr</td>
                    <td class="small">@p.AdministrativeName</td>
                    <td class="small">@p.Variety</td>
                    <td class="center">@($"{p.Oe:N0}")</td>
                    <td class="center">@($"{p.Kmw:N1}")</td>
                    <td class="number">@($"{p.Weight:N0}")</td>
                </tr>
            }
            <tr class="sum bold">
                @{
                    var kmw = Elwig.Helpers.Utils.AggregateDeliveryPartsKmw(Model.Deliveries);
                    var oe = Elwig.Helpers.Utils.KmwToOe(kmw);
                }
                <td colspan="2">Gesamt:</td>
                <td colspan="5">(Teil-)Lieferungen: @($"{Model.Deliveries.DistinctBy(p => p.LsNr).Count():N0}") (@($"{Model.Deliveries.Count():N0}"))</td>
                <td class="center">@($"{oe:N0}")</td>
                <td class="center">@($"{kmw:N1}")</td>
                <td class="number">@($"{Model.Deliveries.Sum(p => p.Weight):N0}")</td>
            </tr>
        </tbody>
    </table>
</main>
