Documents: Replace Razor templates with iText
All checks were successful
Test / Run tests (push) Successful in 2m24s
All checks were successful
Test / Run tests (push) Successful in 2m24s
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
using Elwig.Models.Dtos;
|
||||
using iText.Kernel.Pdf;
|
||||
using iText.Layout.Element;
|
||||
using iText.Layout.Properties;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Documents {
|
||||
public class DeliveryAncmtList : Document {
|
||||
@@ -7,15 +11,58 @@ namespace Elwig.Documents {
|
||||
public new static string Name => "Anmeldeliste";
|
||||
|
||||
public string Filter;
|
||||
public IEnumerable<DeliveryAncmtListRow> Announcements;
|
||||
public List<DeliveryAncmtListRow> Announcements;
|
||||
|
||||
public DeliveryAncmtList(string filter, IEnumerable<DeliveryAncmtListRow> announcements) : base($"{Name} {filter}") {
|
||||
public DeliveryAncmtList(string filter, IEnumerable<DeliveryAncmtListRow> announcements) :
|
||||
base($"{Name} {filter}") {
|
||||
Filter = filter;
|
||||
Announcements = announcements;
|
||||
Announcements = [.. announcements];
|
||||
}
|
||||
|
||||
public DeliveryAncmtList(string filter, DeliveryAncmtListData data) :
|
||||
this(filter, data.Rows) {
|
||||
}
|
||||
|
||||
protected override void RenderBody(iText.Layout.Document doc, PdfDocument pdf) {
|
||||
base.RenderBody(doc, pdf);
|
||||
doc.Add(new KernedParagraph(Name, 24)
|
||||
.SetTextAlignment(TextAlignment.CENTER).SetFont(BF)
|
||||
.SetMarginsMM(0, 0, 2, 0));
|
||||
doc.Add(new KernedParagraph(Filter, 14)
|
||||
.SetTextAlignment(TextAlignment.CENTER).SetFont(BF)
|
||||
.SetMarginsMM(0, 0, 2, 0));
|
||||
doc.Add(NewAncmtTable(Announcements));
|
||||
}
|
||||
|
||||
protected Table NewAncmtTable(List<DeliveryAncmtListRow> ancmts) {
|
||||
var tbl = new Table(ColsMM(15, 12, 50, 25, 38, 11, 14), true)
|
||||
.SetWidth(UnitValue.CreatePercentValue(100)).SetFixedLayout()
|
||||
.SetBorderCollapse(BorderCollapsePropertyValue.COLLAPSE);
|
||||
|
||||
tbl.AddHeaderCell(NewTh("Datum", rowspan: 2))
|
||||
.AddHeaderCell(NewTh("MgNr.", rowspan: 2))
|
||||
.AddHeaderCell(NewTh("Mitglied", rowspan: 2, left: true))
|
||||
.AddHeaderCell(NewTh("Ort", rowspan: 2, left: true))
|
||||
.AddHeaderCell(NewTh("Sorte", rowspan: 2, left: true))
|
||||
.AddHeaderCell(NewTh("Anmldg.", rowspan: 2))
|
||||
.AddHeaderCell(NewTh("Menge"))
|
||||
.AddHeaderCell(NewTh("[kg]"));
|
||||
|
||||
foreach (var a in ancmts) {
|
||||
tbl.AddCell(NewTd($"{a.Date:dd.MM.yyyy}", 8))
|
||||
.AddCell(NewTd($"{a.MgNr}", right: true))
|
||||
.AddCell(NewTd(a.AdministrativeName))
|
||||
.AddCell(NewTd(a.DefaultKg, 8))
|
||||
.AddCell(NewTd(a.Variety))
|
||||
.AddCell(NewTd(a.Status ?? "-", 8, center: true))
|
||||
.AddCell(NewTd($"{a.Weight:N0}", right: true));
|
||||
}
|
||||
|
||||
tbl.AddCell(NewTd("Gesamt:", colspan: 2, bold: true, borderTop: true))
|
||||
.AddCell(NewTd($"Anmeldungen: {ancmts.Count:N0}", colspan: 3, bold: true, borderTop: true))
|
||||
.AddCell(NewTd($"{ancmts.Sum(a => a.Weight):N0}", colspan: 2, right: true, bold: true, borderTop: true));
|
||||
|
||||
return tbl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user