From 56578a0a9deee1c4f1a3acf1ad00f177f88f82e6 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Sun, 15 Oct 2023 00:34:40 +0200 Subject: [PATCH] Documents: Add DeliveryConfirmation --- Elwig/Documents/DeliveryConfirmation.cshtml | 100 ++++++++++++++++++ .../Documents/DeliveryConfirmation.cshtml.cs | 26 +++++ Elwig/Documents/Document.cshtml.cs | 2 + Elwig/Documents/Html.cs | 1 + .../Documents/style-deliveryconfirmation.css | 66 ++++++++++++ Elwig/Models/DeliveryPart.cs | 6 +- 6 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 Elwig/Documents/DeliveryConfirmation.cshtml create mode 100644 Elwig/Documents/DeliveryConfirmation.cshtml.cs create mode 100644 Elwig/Documents/style-deliveryconfirmation.css diff --git a/Elwig/Documents/DeliveryConfirmation.cshtml b/Elwig/Documents/DeliveryConfirmation.cshtml new file mode 100644 index 0000000..e35460e --- /dev/null +++ b/Elwig/Documents/DeliveryConfirmation.cshtml @@ -0,0 +1,100 @@ +@using RazorLight +@inherits TemplatePage +@model Elwig.Documents.DeliveryConfirmation +@{ Layout = "BusinessDocument"; } + +
+

@Model.Title

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @{ + var lastSortId = ""; + } + @foreach (var p in Model.Deliveries) { + var bins = p.Bins.Select((b, n) => (b, n + 1)).Where(b => b.Item1 > 0).ToArray(); + var rowsBins = bins.Length; + var mods = p.Modifiers.Select(m => m.Name).ToArray(); + var rowsMod = mods.Length + 1; + var rows = Math.Max(rowsBins, rowsMod); + var first = true; + @for (int i = 0; i < rows; i++) { + i + 1 ? "trailing" : "")"> + @if (first) { + + + + + + + + } + @if (i > 0 && i <= mods.Length) { + + } else if (i > 0) { + + } + @if (i < bins.Length) { + var (b, n) = bins[i]; + string name = ""; + switch (n) { + case 1: name = $"geb. {p.SortId}{string.Join("", p.Attributes.Order().Select(a => a.AttrId).Take(2))}"; break; + case 2: name = $"geb. {p.SortId}{p.Attributes.Select(a => a.AttrId).Order().FirstOrDefault()}"; break; + case 3: name = $"geb. {p.SortId}{p.Attributes.Select(a => a.AttrId).Order().Skip(1).FirstOrDefault()}"; break; + case 4: name = $"geb. {p.SortId}"; break; + case 5: name = "ungeb."; break; + } + + + } else { + + } + @if (first) { + + + first = false; + } + + lastSortId = p.SortId; + } + } + + + + + + +
Lieferschein-Nr.Pos.SorteAttribut(e)QualitätsstufeGradationFlächenbindungGewichtDavon
abwerten
[°Oe][°KMW][kg][kg][kg]
@p.Delivery.LsNr@p.DPNr@p.Variant.Name@p.AttributesString@p.Quality.Name@($"{p.Oe:N0}")@($"{p.Kmw:N1}")@(mods[i - 1])@name:@($"{b:N0}")@($"{p.Weight:N0}")
Gesamt:@($"{Model.Deliveries.Sum(p => p.Weight):N0}")
+
diff --git a/Elwig/Documents/DeliveryConfirmation.cshtml.cs b/Elwig/Documents/DeliveryConfirmation.cshtml.cs new file mode 100644 index 0000000..16fede2 --- /dev/null +++ b/Elwig/Documents/DeliveryConfirmation.cshtml.cs @@ -0,0 +1,26 @@ +using Elwig.Helpers; +using Elwig.Models; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.Linq; + +namespace Elwig.Documents { + public class DeliveryConfirmation : BusinessDocument { + + public int Year; + public IEnumerable Deliveries; + + public DeliveryConfirmation(AppDbContext ctx, int year, Member m) : base($"Anlieferungsbestätigung {year} – {m.Name}", m) { + Year = year; + DocumentId = $"Anl.-Best. {Year}/{m.MgNr}"; + 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) = ({Year}, {m.MgNr}) + ORDER BY v.sortid, v.abgewertet ASC, LENGTH(v.attributes) DESC, COALESCE(v.attributes, '~'), v.kmw DESC, v.lsnr, v.dpnr + """) + .ToList(); + } + } +} diff --git a/Elwig/Documents/Document.cshtml.cs b/Elwig/Documents/Document.cshtml.cs index 9d75f73..3cd7949 100644 --- a/Elwig/Documents/Document.cshtml.cs +++ b/Elwig/Documents/Document.cshtml.cs @@ -100,6 +100,8 @@ namespace Elwig.Documents { name = "DeliveryJournal"; } else if (this is Letterhead) { name = "Letterhead"; + } else if (this is DeliveryConfirmation) { + name = "DeliveryConfirmation"; } else { throw new InvalidOperationException("Invalid document object"); } diff --git a/Elwig/Documents/Html.cs b/Elwig/Documents/Html.cs index 4eb2d78..55509ab 100644 --- a/Elwig/Documents/Html.cs +++ b/Elwig/Documents/Html.cs @@ -21,6 +21,7 @@ namespace Elwig.Documents { await e.CompileTemplateAsync("CreditNote"); await e.CompileTemplateAsync("DeliveryJournal"); await e.CompileTemplateAsync("Letterhead"); + await e.CompileTemplateAsync("DeliveryConfirmation"); Engine = e; evtHandler(); diff --git a/Elwig/Documents/style-deliveryconfirmation.css b/Elwig/Documents/style-deliveryconfirmation.css new file mode 100644 index 0000000..a164788 --- /dev/null +++ b/Elwig/Documents/style-deliveryconfirmation.css @@ -0,0 +1,66 @@ + +table.delivery-confirmation { + font-size: 10pt; +} + +table.delivery-confirmation thead { + font-size: 8pt; +} + +table.delivery-confirmation thead th { + font-weight: normal; + font-style: italic; +} + +table.delivery-confirmation td { + overflow: hidden; + white-space: nowrap; +} + +table.delivery-confirmation td[rowspan] { + vertical-align: top; +} + +table.delivery-confirmation .weight { + text-align: right; +} + +table.delivery-confirmation .grad { + text-align: center; +} + +table.delivery-confirmation .geb { + font-size: 8pt; +} + +table.delivery-confirmation .mod { + font-size: 8pt; + padding-left: 5mm; +} + +table.delivery-confirmation .small { + font-size: 8pt; +} + +table.delivery-confirmation tr.new td { + border-top: 0.5pt solid black; +} + +table.delivery-confirmation tr:not(.first) td { + padding-top: 0; +} + +table.delivery-confirmation tr.trailing td { + padding-bottom: 0; +} + +table.delivery-confirmation tr.sum { + border-top: 0.5pt solid black; + break-before: avoid; + font-weight: bold; + font-size: 12pt; +} + +table.delivery-confirmation tr.sum td { + padding-top: 1mm; +} diff --git a/Elwig/Models/DeliveryPart.cs b/Elwig/Models/DeliveryPart.cs index b8583a7..eb4d112 100644 --- a/Elwig/Models/DeliveryPart.cs +++ b/Elwig/Models/DeliveryPart.cs @@ -100,7 +100,7 @@ namespace Elwig.Models { public IEnumerable Attributes => PartAttributes.Select(a => a.Attr); [NotMapped] - public string AttributesString => string.Join("/", Attributes); + public string AttributesString => string.Join(" / ", Attributes); [InverseProperty("Part")] public virtual ISet PartModifiers { get; private set; } @@ -115,10 +115,10 @@ namespace Elwig.Models { public string OriginString => Origin.OriginString + "\n" + (Kg?.Gl != null ? $" / {Kg.Gl.Name}" : "") + (Kg != null ? $" / {Kg.AtKg.Gem.Name} / KG {Kg.AtKg.Name}" : "") + (Rd != null ? $" / Ried {Rd.Name}" : ""); [InverseProperty("Part")] - public virtual DeliveryPartBin Bin { get; private set; } + public virtual DeliveryPartBin? Bin { get; private set; } [NotMapped] - public int[] Bins => (new int?[] { Bin.Bin1, Bin.Bin2, Bin.Bin3, Bin.Bin4, Bin.Bin5, Bin.Bin6, Bin.Bin7, Bin.Bin8, Bin.Bin9 }) + public int[] Bins => (new int?[] { Bin?.Bin1, Bin?.Bin2, Bin?.Bin3, Bin?.Bin4, Bin?.Bin5, Bin?.Bin6, Bin?.Bin7, Bin?.Bin8, Bin?.Bin9 }) .Where(b => b != null).Select(b => b.Value).ToArray(); } }