CreditNote: Add switches to control which deductions are shown
This commit is contained in:
@ -20,7 +20,15 @@ namespace Elwig.Documents {
|
||||
public decimal MemberTotalUnderDelivery;
|
||||
public decimal MemberAutoBusinessShares;
|
||||
|
||||
public CreditNote(AppDbContext ctx, PaymentMember p, CreditNoteDeliveryData data, Dictionary<string, UnderDelivery>? underDeliveries = null) :
|
||||
public CreditNote(
|
||||
AppDbContext ctx,
|
||||
PaymentMember p,
|
||||
CreditNoteDeliveryData data,
|
||||
bool considerContractPenalties,
|
||||
bool considerTotalPenalty,
|
||||
bool considerAutoBusinessShares,
|
||||
Dictionary<string, UnderDelivery>? underDeliveries = null
|
||||
) :
|
||||
base($"{Name} {(p.Credit != null ? $"Nr. {p.Credit.Year}/{p.Credit.TgNr:000}" : p.Member.Name)} – {p.Variant.Name}", p.Member) {
|
||||
UseBillingAddress = true;
|
||||
ShowDateAndLocation = true;
|
||||
@ -34,16 +42,6 @@ namespace Elwig.Documents {
|
||||
} else {
|
||||
MemberModifier = "Sonstige Zu-/Abschläge";
|
||||
}
|
||||
var total = data.Rows.SelectMany(r => r.Buckets).Sum(b => b.Value);
|
||||
var totalUnderDelivery = total - p.Member.BusinessShares * season.MinKgPerBusinessShare;
|
||||
MemberTotalUnderDelivery = totalUnderDelivery < 0 ? totalUnderDelivery * (season.PenaltyPerKg ?? 0) - (season.PenaltyAmount ?? 0) : 0;
|
||||
var fromDate = $"{season.Year}-06-01";
|
||||
var toDate = $"{season.Year + 1}-06-01";
|
||||
MemberAutoBusinessShares = ctx.MemberHistory
|
||||
.Where(h => h.MgNr == p.Member.MgNr && h.Type == "auto")
|
||||
.Where(h => h.DateString.CompareTo(fromDate) >= 0 && h.DateString.CompareTo(toDate) < 0)
|
||||
.Sum(h => h.BusinessShares) * (-season.BusinessShareValue ?? 0);
|
||||
if (total == 0) MemberTotalUnderDelivery -= (season.PenaltyNone ?? 0);
|
||||
Aside = Aside.Replace("</table>", "") +
|
||||
$"<thead><tr><th colspan='2'>Gutschrift</th></tr></thead><tbody>" +
|
||||
$"<tr><th>TG-Nr.</th><td>{(p.Credit != null ? $"{p.Credit.Year}/{p.Credit.TgNr:000}" : "-")}</td></tr>" +
|
||||
@ -55,18 +53,35 @@ namespace Elwig.Documents {
|
||||
CurrencySymbol = season.Currency.Symbol ?? season.Currency.Code;
|
||||
Precision = season.Precision;
|
||||
|
||||
var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||
var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||
var comTypes = ctx.AreaCommitmentTypes.ToDictionary(t => t.VtrgId, t => t);
|
||||
MemberUnderDeliveries = underDeliveries?
|
||||
.OrderBy(u => u.Key)
|
||||
.Select(u => (
|
||||
varieties[u.Key[..2]].Name + (u.Key.Length > 2 ? " " + attributes[u.Key[2..]].Name : ""),
|
||||
u.Value.Diff,
|
||||
u.Value.Diff * (comTypes[u.Key].PenaltyPerKg ?? 0)
|
||||
- (comTypes[u.Key].PenaltyAmount ?? 0)
|
||||
- ((u.Value.Weight == 0 ? comTypes[u.Key].PenaltyNone : null) ?? 0)))
|
||||
.Where(u => u.Item3 != 0)
|
||||
.ToList();
|
||||
if (considerTotalPenalty) {
|
||||
var total = data.Rows.SelectMany(r => r.Buckets).Sum(b => b.Value);
|
||||
var totalUnderDelivery = total - p.Member.BusinessShares * season.MinKgPerBusinessShare;
|
||||
MemberTotalUnderDelivery = totalUnderDelivery < 0 ? totalUnderDelivery * (season.PenaltyPerKg ?? 0) - (season.PenaltyAmount ?? 0) : 0;
|
||||
if (total == 0)
|
||||
MemberTotalUnderDelivery -= (season.PenaltyNone ?? 0);
|
||||
}
|
||||
if (considerAutoBusinessShares) {
|
||||
var fromDate = $"{season.Year}-01-01";
|
||||
var toDate = $"{season.Year}-12-31";
|
||||
MemberAutoBusinessShares = ctx.MemberHistory
|
||||
.Where(h => h.MgNr == p.Member.MgNr && h.Type == "auto")
|
||||
.Where(h => h.DateString.CompareTo(fromDate) >= 0 && h.DateString.CompareTo(toDate) <= 0)
|
||||
.Sum(h => h.BusinessShares) * (-season.BusinessShareValue ?? 0);
|
||||
}
|
||||
if (considerContractPenalties) {
|
||||
var varieties = ctx.WineVarieties.ToDictionary(v => v.SortId, v => v);
|
||||
var attributes = ctx.WineAttributes.ToDictionary(a => a.AttrId, a => a);
|
||||
var comTypes = ctx.AreaCommitmentTypes.ToDictionary(t => t.VtrgId, t => t);
|
||||
MemberUnderDeliveries = underDeliveries?
|
||||
.OrderBy(u => u.Key)
|
||||
.Select(u => (
|
||||
varieties[u.Key[..2]].Name + (u.Key.Length > 2 ? " " + attributes[u.Key[2..]].Name : ""),
|
||||
u.Value.Diff,
|
||||
u.Value.Diff * (comTypes[u.Key].PenaltyPerKg ?? 0)
|
||||
- (comTypes[u.Key].PenaltyAmount ?? 0)
|
||||
- ((u.Value.Weight == 0 ? comTypes[u.Key].PenaltyNone : null) ?? 0)))
|
||||
.Where(u => u.Item3 != 0)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
@ -519,7 +519,15 @@ namespace Elwig.Windows {
|
||||
var payments = await Context.MemberPayments.Where(p => p.Year == v.Year && p.AvNr == v.AvNr).ToDictionaryAsync(c => c.MgNr);
|
||||
await Context.GetMemberAreaCommitmentBuckets(Year, 0);
|
||||
using var doc = Document.Merge(list.Select(m =>
|
||||
new CreditNote(Context, payments[m.MgNr], data[m.MgNr], Context.GetMemberUnderDelivery(Year, m.MgNr).GetAwaiter().GetResult())
|
||||
new CreditNote(
|
||||
Context,
|
||||
payments[m.MgNr],
|
||||
data[m.MgNr],
|
||||
BillingData?.ConsiderContractPenalties ?? false,
|
||||
BillingData?.ConsiderTotalPenalty ?? false,
|
||||
BillingData?.ConsiderAutoBusinessShares ?? false,
|
||||
Context.GetMemberUnderDelivery(Year, m.MgNr).GetAwaiter().GetResult()
|
||||
)
|
||||
));
|
||||
await doc.Generate(new Progress<double>(v => {
|
||||
ProgressBar.Value = v;
|
||||
|
Reference in New Issue
Block a user