cols = [40];
cols.AddRange(names.Select(_ => 125.0 / names.Count));
string tbl = GetColGroup(cols);
tbl += "" +
$"Sortenaufteilung [kg] | " +
string.Join("", names.Select(c => $"{c} | ")) +
"
";
tbl += string.Join("\n", buckets
.GroupBy(b => (b.Key[..2], b.Value.Name.Split("(")[0].Trim()))
.Where(g => g.Sum(a => a.Value.DeliveryStrict) > 0)
.OrderBy(g => g.Key.Item1)
.Select(g => {
var dict = g.ToDictionary(a => a.Key[2..], a => a.Value);
var vals = attributes.Select(a => dict.TryGetValue(a, out MemberBucket value) ? value.DeliveryStrict : 0).ToList();
return $"{g.Key.Item2} | " + string.Join("", vals.Select(v => "" + (v == 0 ? "-" : $"{v:N0}") + " | ")) +
$"{dict.Values.Select(v => v.DeliveryStrict).Sum():N0} |
";
})
);
var totalDict = buckets.GroupBy(b => b.Key[2..]).ToDictionary(g => g.Key, g => g.Sum(a => a.Value.DeliveryStrict));
var totals = attributes.Select(a => totalDict.TryGetValue(a, out int value) ? value : 0);
tbl += " | " + string.Join("", totals.Select(v => $"{v:N0} | ")) +
$"{totalDict.Values.Sum():N0} |
";
return "";
}
private static string FormatRow(int obligation, int right, int delivery, int? payment = null, bool isGa = false, bool showPayment = false) {
payment ??= delivery;
var baseline = showPayment ? payment : delivery;
return $"{(obligation == 0 ? "-" : $"{obligation:N0}")} | " +
$"{(right == 0 ? "-" : $"{right:N0}")} | " +
$"{(baseline < obligation ? $"{obligation - baseline:N0}" : "-")} | " +
$"{(baseline >= obligation && delivery <= right ? $"{right - delivery:N0}" : "-")} | " +
$"{(obligation == 0 && right == 0 ? "-" : (delivery > right ? ((isGa ? "" : "") + $"{delivery - right:N0}" + (isGa ? "" : "")) : "-"))} | " +
(showPayment ? $"{(isGa ? "" : obligation == 0 && right == 0 ? "-" : $"{payment:N0}")} | " : "") +
$"{delivery:N0} | ";
}
private static string FormatRow(MemberBucket bucket, bool isGa = false, bool showPayment = false) {
return FormatRow(bucket.Obligation, bucket.Right, bucket.Delivery, bucket.Payment, isGa, showPayment);
}
public string PrintBucketTable(Season season, Dictionary buckets, bool includePayment = false, bool isTiny = false, IEnumerable? filter = null) {
string tbl = GetColGroup(includePayment ? [45, 17, 17, 17, 19, 16, 17, 17] : [45, 20, 20, 20, 20, 20, 20]);
tbl += $"""
Lese {season.Year} per {Date:dd.MM.yyyy} [kg] |
Lieferpflicht |
Lieferrecht |
Unterliefert |
Noch lieferbar |
Überliefert |
{(includePayment ? "Zugeteilt | " : "")}
Geliefert |
""";
var mBuckets = buckets
.Where(b => (b.Value.Right > 0 || b.Value.Obligation > 0 || b.Value.Delivery > 0) && (filter == null || filter.Contains(b.Key[..2])))
.ToList();
var fbVars = mBuckets
.Where(b => b.Value.Right > 0 || b.Value.Obligation > 0)
.Select(b => b.Key.Replace("_", ""))
.Order()
.ToArray();
var fbs = mBuckets
.Where(b => fbVars.Contains(b.Key) && b.Key.Length == 2)
.OrderBy(b => b.Value.Name);
var vtr = mBuckets
.Where(b => fbVars.Contains(b.Key) && b.Key.Length > 2)
.OrderBy(b => b.Value.Name);
var rem = mBuckets
.Where(b => !fbVars.Contains(b.Key))
.OrderBy(b => b.Value.Name);
tbl += "\n\n";
tbl += $"Gesamtlieferung lt. gez. GA | {FormatRow(
Member.BusinessShares * season.MinKgPerBusinessShare,
Member.BusinessShares * season.MaxKgPerBusinessShare,
Member.Deliveries.Where(d => d.Year == season.Year).Sum(d => d.Weight),
isGa: true, showPayment: includePayment
)}
";
if (fbs.Any()) {
tbl += $"" +
$"Flächenbindungen{(vtr.Any() ? " (inkl. Verträge)" : "")}: |
";
foreach (var (id, b) in fbs) {
tbl += $"{b.Name} | {FormatRow(b, showPayment: includePayment)}
";
}
}
if (vtr.Any()) {
tbl += $"" +
"Verträge: |
";
foreach (var (id, b) in vtr) {
tbl += $"{b.Name} | {FormatRow(b, showPayment: includePayment)}
";
}
}
tbl += "\n\n";
return $"";
}
}
}