Models: Add Dtos/
This commit is contained in:
@ -1,33 +1,25 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Dtos;
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Documents {
|
||||
public class DeliveryConfirmation : BusinessDocument {
|
||||
|
||||
public Season Season;
|
||||
public IEnumerable<DeliveryPart> Deliveries;
|
||||
public DeliveryConfirmationData Data;
|
||||
public string? Text = App.Client.TextDeliveryConfirmation;
|
||||
public Dictionary<string, (string, int, int, int, int)> MemberBuckets;
|
||||
|
||||
public DeliveryConfirmation(AppDbContext ctx, int year, Member m, IEnumerable<DeliveryPart>? deliveries = null) :
|
||||
public DeliveryConfirmation(AppDbContext ctx, int year, Member m, DeliveryConfirmationData data) :
|
||||
base($"Anlieferungsbestätigung {year}", m) {
|
||||
Season = ctx.Seasons.Find(year) ?? throw new ArgumentException("invalid season");
|
||||
ShowDateAndLocation = true;
|
||||
UseBillingAddress = true;
|
||||
IncludeSender = true;
|
||||
DocumentId = $"Anl.-Best. {Season.Year}/{m.MgNr}";
|
||||
Deliveries = deliveries ?? ctx.DeliveryParts.FromSqlRaw($"""
|
||||
SELECT p.*
|
||||
FROM v_delivery v
|
||||
JOIN delivery_part p ON (p.year, p.did, p.dpnr) = (v.year, v.did, v.dpnr)
|
||||
WHERE (v.year, v.mgnr) = ({Season.Year}, {m.MgNr})
|
||||
ORDER BY v.sortid, v.abgewertet ASC, v.attribute_prio DESC, COALESCE(v.attrid, '~'), v.kmw DESC, v.lsnr, v.dpnr
|
||||
""")
|
||||
.ToList();
|
||||
Data = data;
|
||||
MemberBuckets = ctx.GetMemberBuckets(Season.Year, m.MgNr).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
@ -41,39 +41,35 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
@{
|
||||
var lastSortId = "";
|
||||
var lastVariant = "";
|
||||
}
|
||||
@foreach (var p in Model.Deliveries) {
|
||||
var buckets = p.Buckets.Where(b => b.Value > 0).OrderByDescending(b => b.BktNr).ToArray();
|
||||
var rowsBuckets = buckets.Length;
|
||||
var mods = p.Modifiers.Select(m => m.Name).ToArray();
|
||||
var rowsMod = mods.Length + 1;
|
||||
var rows = Math.Max(rowsBuckets, rowsMod);
|
||||
@foreach (var p in Model.Data.Rows) {
|
||||
var rows = Math.Max(p.Buckets.Length, p.Modifiers.Length + 1);
|
||||
var first = true;
|
||||
@for (int i = 0; i < rows; i++) {
|
||||
<tr class="@(first ? "first" : "") @(p.SortId != lastSortId && lastSortId != "" ? "new": "") @(rows > i + 1 ? "trailing" : "")">
|
||||
<tr class="@(first ? "first" : "") @(p.Variant != lastVariant && lastVariant != "" ? "new": "") @(rows > i + 1 ? "trailing" : "")">
|
||||
@if (first) {
|
||||
<td rowspan="@rows">@p.Delivery.LsNr</td>
|
||||
<td rowspan="@rows">@p.LsNr</td>
|
||||
<td rowspan="@rows">@p.DPNr</td>
|
||||
<td class="small">@p.Variant.Name</td>
|
||||
<td class="small">@p.Attribute?.Name</td>
|
||||
<td class="small">@p.Quality.Name</td>
|
||||
<td class="small">@p.Variant</td>
|
||||
<td class="small">@p.Attribute</td>
|
||||
<td class="small">@p.QualityLevel</td>
|
||||
<td rowspan="@rows" class="grad">@($"{p.Oe:N0}")</td>
|
||||
<td rowspan="@rows" class="grad">@($"{p.Kmw:N1}")</td>
|
||||
}
|
||||
@if (i > 0 && i <= mods.Length) {
|
||||
<td colspan="3" class="mod">@(mods[i - 1])</td>
|
||||
@if (i > 0 && i <= p.Modifiers.Length) {
|
||||
<td colspan="3" class="mod">@(p.Modifiers[i - 1])</td>
|
||||
} else if (i > 0) {
|
||||
<td colspan="3"></td>
|
||||
}
|
||||
@if (i < buckets.Length) {
|
||||
var bucket = buckets[i];
|
||||
<td class="geb">@(bucket.Discr == "_" ? "ungeb." : $"geb. {p.SortId}{bucket.Discr}"):</td>
|
||||
<td class="weight">@($"{bucket.Value:N0}")</td>
|
||||
@if (i < p.Buckets.Length) {
|
||||
var bucket = p.Buckets[i];
|
||||
<td class="geb">@bucket.Item1:</td>
|
||||
<td class="weight">@($"{bucket.Item2:N0}")</td>
|
||||
} else {
|
||||
<td colspan="2"></td>
|
||||
}
|
||||
@if (i == buckets.Length - 1) {
|
||||
@if (i == p.Buckets.Length - 1) {
|
||||
<td class="weight">@($"{p.Weight:N0}")</td>
|
||||
} else {
|
||||
<td></td>
|
||||
@ -83,12 +79,12 @@
|
||||
first = false;
|
||||
}
|
||||
</tr>
|
||||
lastSortId = p.SortId;
|
||||
lastVariant = p.Variant;
|
||||
}
|
||||
}
|
||||
<tr class="sum">
|
||||
<td colspan="8">Gesamt:</td>
|
||||
<td colspan="2" class="weight">@($"{Model.Deliveries.Sum(p => p.Weight):N0}")</td>
|
||||
<td colspan="2" class="weight">@($"{Model.Data.Rows.Sum(p => p.Weight):N0}")</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
Reference in New Issue
Block a user