[#67] BusinessDocument: Add OrganicOperatorId to footer

This commit is contained in:
2026-09-29 19:04:01 +02:00
parent 03867bcd74
commit 96441a6701
2 changed files with 44 additions and 13 deletions
+8 -4
View File
@@ -137,11 +137,15 @@ namespace Elwig.Documents {
return new KernedParagraph(10) return new KernedParagraph(10)
.AddAll(Utils.GenerateFooter("\n", " \u00b7 ") .AddAll(Utils.GenerateFooter("\n", " \u00b7 ")
.Item(c.NameFull).NextLine() .Item(c.NameFull).NextLine()
.Item(c.Address).Item($"{c.Plz} {c.Ort}").Item("Österreich").Item("Tel.", c.PhoneNr).Item("Fax", c.FaxNr).NextLine() .Item(c.Address).Item($"{c.Plz} {c.Ort}").Item("Österreich").NextGroup()
.Item(c.EmailAddress != null ? link1 : null) .Item("Tel.", c.PhoneNr).Item("Fax", c.FaxNr).NextGroup()
.Item(c.Website != null ? link2 : null) .Item(c.EmailAddress != null ? link1 : null).NextLine()
.Item("Betriebs-Nr.", c.LfbisNr).Item("Bio-KSt.", c.OrganicAuthorityCode).NextLine() .Item(c.Website != null ? link2 : null).NextGroup()
.Item("Betriebs-Nr.", c.LfbisNr).NextGroup()
.Item("Bio-KSt.", c.OrganicAuthorityCode).NextGroup()
.Item("OOC-ID", c.OrganicOperatorId).NextLine()
.Item("UID", c.UstIdNr).Item("BIC", c.Bic).Item("IBAN", c.Iban) .Item("UID", c.UstIdNr).Item("BIC", c.Bic).Item("IBAN", c.Iban)
.RebalanceLines()
.ToLeafElements()); .ToLeafElements());
} }
+36 -9
View File
@@ -323,7 +323,7 @@ namespace Elwig.Helpers {
} }
public class Footer { public class Footer {
private readonly List<List<object>> Items = [[]]; private readonly List<List<List<object>>> Items = [[[]]];
private readonly string LineBreak; private readonly string LineBreak;
private readonly string Separator; private readonly string Separator;
@@ -334,7 +334,7 @@ namespace Elwig.Helpers {
public Footer Item(object? text) { public Footer Item(object? text) {
if (text == null) return this; if (text == null) return this;
Items[^1].Add(text); Items[^1][^1].Add(text);
return this; return this;
} }
@@ -342,13 +342,38 @@ namespace Elwig.Helpers {
return text == null ? this : Item($"{name}: {text}"); return text == null ? this : Item($"{name}: {text}");
} }
public Footer NextGroup() {
Items[^1].Add([]);
return this;
}
public Footer NextLine() { public Footer NextLine() {
Items.Add([]); Items.Add([[]]);
return this;
}
public Footer RebalanceLines() {
for (int i = 0; i < Items.Count - 1; i++) {
var groups = Items[i];
var nextGroups = Items[i + 1];
if (groups.Count <= 1) continue;
var g = groups[^1];
var gl = g.Sum(i => (i is Text txt ? txt.GetText().Length : i.ToString()?.Length ?? 0) + Separator.Length);
var l1a = groups.SelectMany(g => g).Sum(i => (i is Text txt ? txt.GetText().Length : i.ToString()?.Length ?? 0) + Separator.Length) - Separator.Length;
var l2a = nextGroups.SelectMany(g => g).Sum(i => (i is Text txt ? txt.GetText().Length : i.ToString()?.Length ?? 0) + Separator.Length) - Separator.Length;
var l1b = l1a - gl;
var l2b = l2a + gl;
if (Math.Abs(l1b - l2b) <= Math.Abs(l1a - l2a)) {
Items[i].Remove(g);
Items[i + 1].Insert(0, g);
i--;
}
}
return this; return this;
} }
public override string ToString() { public override string ToString() {
return string.Join(LineBreak, Items.Select(l => string.Join(Separator, l.ToString()))); return string.Join(LineBreak, Items.Select(l => string.Join(Separator, l.SelectMany(g => g).ToString())));
} }
public IList<ILeafElement> ToLeafElements() { public IList<ILeafElement> ToLeafElements() {
@@ -357,10 +382,12 @@ namespace Elwig.Helpers {
foreach (var line in Items) { foreach (var line in Items) {
if (!first1) l.Add(new Text(LineBreak)); if (!first1) l.Add(new Text(LineBreak));
var first2 = true; var first2 = true;
foreach (var item in line) { foreach (var group in line) {
if (!first2) l.Add(new Text(Separator)); foreach (var item in group) {
l.Add(item as ILeafElement ?? new Text(item.ToString() ?? "")); if (!first2) l.Add(new Text(Separator));
first2 = false; l.Add(item as ILeafElement ?? new Text(item.ToString() ?? ""));
first2 = false;
}
} }
first1 = false; first1 = false;
} }
@@ -675,7 +702,7 @@ namespace Elwig.Helpers {
p[2], p[2],
int.Parse(p[3]), int.Parse(p[3]),
p[4], p[4],
p[5].Split(',').Select(a => a.Replace(" | ", "\n")).ToArray(), [.. p[5].Split(',').Select(a => a.Replace(" | ", "\n"))],
p[6], p[6],
p[7].Split(',') p[7].Split(',')
)); ));