@ -1,5 +1,7 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Documents {
|
||||
public abstract class BusinessDocument : Document {
|
||||
@ -32,5 +34,93 @@ namespace Elwig.Documents {
|
||||
return (addr is BillingAddr ? $"{addr.Name}\n" : "") + $"{Member.AdministrativeName}\n{addr.Address}\n{plz?.Plz} {plz?.Ort.Name.Split(",")[0]}\n{addr.PostalDest.Country.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
public string PrintSortenaufteilung(int year, Dictionary<string, MemberBucket> buckets) {
|
||||
return "";
|
||||
}
|
||||
|
||||
private enum RowMode {
|
||||
GA_CONFIRMATION, CONFIRMATION, GA_NOTE, NOTE
|
||||
}
|
||||
|
||||
private static string FormatRow(RowMode mode, int obligation, int right, int delivery, int? payment = null) {
|
||||
var isGa = (mode == RowMode.GA_CONFIRMATION || mode == RowMode.GA_NOTE);
|
||||
var showPayment = (mode == RowMode.GA_CONFIRMATION || mode == RowMode.CONFIRMATION);
|
||||
payment ??= delivery;
|
||||
var baseline = showPayment ? payment : delivery;
|
||||
return $"<td>{(obligation == 0 ? "-" : $"{obligation:N0}")}</td>" +
|
||||
$"<td>{(right == 0 ? "-" : $"{right:N0}")}</td>" +
|
||||
$"<td>{(baseline < obligation ? $"<b>{obligation - baseline:N0}</b>" : "-")}</td>" +
|
||||
$"<td>{(baseline >= obligation && delivery <= right ? $"{right - delivery:N0}" : "-")}</td>" +
|
||||
$"<td>{(obligation == 0 && right == 0 ? "-" : (delivery > right ? ((isGa ? "<b>" : "") + $"{delivery - right:N0}" + (isGa ? "</b>" : "")) : "-"))}</td>" +
|
||||
(showPayment ? $"<td>{(isGa ? "" : obligation == 0 && right == 0 ? "-" : $"{payment:N0}")}</td>" : "") +
|
||||
$"<td>{delivery:N0}</td>";
|
||||
}
|
||||
|
||||
private static string FormatRow(RowMode mode, MemberBucket bucket) {
|
||||
return FormatRow(mode, bucket.Obligation, bucket.Right, bucket.Delivery, bucket.Payment);
|
||||
}
|
||||
|
||||
public string PrintBucketTable(Season season, Dictionary<string, MemberBucket> buckets, bool includePayment = false, bool isTiny = false, IEnumerable<string>? filter = null) {
|
||||
int[] colGroups = includePayment ? [45, 17, 17, 17, 19, 16, 17, 17] : [45, 20, 20, 20, 20, 20, 20];
|
||||
string tbl = "<colgroup>\n" + string.Join("\n", colGroups.Select(g => $"<col style=\"width: {g}mm;\"/>")) + "\n</colgroup>\n";
|
||||
tbl += $"""
|
||||
<thead>
|
||||
<tr>
|
||||
<th><b>Lese {season.Year}</b> per {Date:dd.MM.yyyy} [kg]</th>
|
||||
<th>Lieferpflicht</th>
|
||||
<th>Lieferrecht</th>
|
||||
<th>Unterliefert</th>
|
||||
<th>Noch lieferbar</th>
|
||||
<th>Überliefert</th>
|
||||
{(includePayment ? "<th>Zugeteilt</th>" : "")}
|
||||
<th>Geliefert</th>
|
||||
</tr>
|
||||
</thead>
|
||||
""";
|
||||
|
||||
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<tbody>\n";
|
||||
tbl += $"<tr><th>Gesamtlieferung lt. gez. GA</th>{FormatRow(
|
||||
includePayment ? RowMode.GA_CONFIRMATION : RowMode.GA_NOTE,
|
||||
Member.BusinessShares * season.MinKgPerBusinessShare,
|
||||
Member.BusinessShares * season.MaxKgPerBusinessShare,
|
||||
Member.Deliveries.Where(d => d.Year == season.Year).Sum(d => d.Weight)
|
||||
)}</tr>";
|
||||
if (fbs.Any()) {
|
||||
tbl += $"<tr class=\"subheading{(filter == null ? " border" : "")}\"><th colspan=\"{(includePayment ? 8 : 7)}\">" +
|
||||
$"Flächenbindungen{(vtr.Any() ? " (inkl. Verträge)" : "")}:</th></tr>";
|
||||
foreach (var (id, b) in fbs) {
|
||||
tbl += $"<tr><th>{b.Name}</th>{FormatRow(includePayment ? RowMode.CONFIRMATION : RowMode.NOTE, b)}</tr>";
|
||||
}
|
||||
}
|
||||
if (vtr.Any()) {
|
||||
tbl += $"<tr class=\"subheading{(filter == null ? " border" : "")}\"><th colspan=\"{(includePayment ? 8 : 7)}\">" +
|
||||
"Verträge:</th></tr>";
|
||||
foreach (var (id, b) in vtr) {
|
||||
tbl += $"<tr><th>{b.Name}</th>{FormatRow(includePayment ? RowMode.CONFIRMATION : RowMode.NOTE, b)}</tr>";
|
||||
}
|
||||
}
|
||||
tbl += "\n</tbody>\n";
|
||||
|
||||
return $"<table class=\"{(isTiny ? "tiny" : "small")} number cohere\">\n" + tbl + "\n</table>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user