CreditNote: Display under deliveries of area commitments
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models.Dtos;
|
||||
using Elwig.Models.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Documents {
|
||||
@ -13,8 +14,9 @@ namespace Elwig.Documents {
|
||||
public string CurrencySymbol;
|
||||
public int Precision;
|
||||
public string MemberModifier;
|
||||
public IEnumerable<(string Name, int Kg, decimal Amount)>? MemberUnderDeliveries;
|
||||
|
||||
public CreditNote(AppDbContext ctx, PaymentMember p, CreditNoteData data) :
|
||||
public CreditNote(AppDbContext ctx, PaymentMember p, CreditNoteData data, Dictionary<string, UnderDelivery>? underDeliveries = null) :
|
||||
base($"Traubengutschrift {(p.Credit != null ? $"Nr. {p.Credit.Year}/{p.Credit.TgNr:000}" : p.Member.Name)} – {p.Variant.Name}", p.Member) {
|
||||
UseBillingAddress = true;
|
||||
ShowDateAndLocation = true;
|
||||
@ -38,5 +40,19 @@ namespace Elwig.Documents {
|
||||
DocumentId = $"Tr.-Gutschr. " + (p.Credit != null ? $"{p.Credit.Year}/{p.Credit.TgNr:000}" : p.MgNr);
|
||||
CurrencySymbol = season.Currency.Symbol ?? season.Currency.Code;
|
||||
Precision = season.Precision;
|
||||
|
||||
var variants = 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 => (
|
||||
variants[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();
|
||||
}
|
||||
}}
|
||||
|
@ -79,12 +79,12 @@
|
||||
}
|
||||
</tbody>
|
||||
@{
|
||||
string FormatRow(string name, decimal? value, bool add = false, bool halfLine = true, bool bold = false) {
|
||||
string FormatRow(string name, decimal? value, bool add = false, bool halfLine = true, bool bold = false, bool subCat = false) {
|
||||
return $"<tr class=\"{(halfLine || add ? "" : "sum")} {(bold ? "large bold" : "")}\">"
|
||||
+ $"<td colspan=\"4\"></td>"
|
||||
+ $"<td class=\"{(halfLine && !add ? "sum" : "")}\" colspan=\"4\">{name}:</td>"
|
||||
+ $"<td class=\"number large {(halfLine && !add ? "sum" : "")}\">{(value < 0 ? "–" : (add ? "+" : ""))}</td>"
|
||||
+ $"<td colspan=\"2\" class=\"number large {(halfLine && !add ? "sum" : "")}\">"
|
||||
+ $"<td class=\"{(halfLine && !add ? "sum" : "")} {(subCat ? "small" : "")}\" colspan=\"4\" style=\"overflow: visible;\">{name}:</td>"
|
||||
+ $"<td class=\"number {(subCat ? "small" : "large")} {(halfLine && !add ? "sum" : "")}\">{(value < 0 ? "–" : (add ? "+" : ""))}</td>"
|
||||
+ $"<td colspan=\"2\" class=\"number {(subCat ? "small" : "large")} {(halfLine && !add ? "sum" : "")}\">"
|
||||
+ $"<span class=\"fleft\">{Model.CurrencySymbol}</span>{Math.Abs(value ?? 0):N2}</td>"
|
||||
+ $"</tr>\n";
|
||||
}
|
||||
@ -116,5 +116,33 @@
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
<tbody style="break-inside: avoid;">
|
||||
@{ decimal penalty = 0; }
|
||||
|
||||
@if (Model.MemberUnderDeliveries != null && Model.MemberUnderDeliveries.Count() > 0) {
|
||||
<tr class="small">
|
||||
<td colspan="4"></td>
|
||||
<td colspan="5" style="padding-top: 5mm;">Anfallende Pönalen durch Unterlieferungen:</td>
|
||||
<td colspan="2"></td>
|
||||
</tr>
|
||||
foreach (var u in Model.MemberUnderDeliveries) {
|
||||
@Raw(FormatRow($"{u.Name} ({u.Kg:N0} kg)", u.Amount, add: true, subCat: true))
|
||||
penalty += u.Amount;
|
||||
}
|
||||
penalty = Math.Round(penalty, 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
@if (Model.Credit == null) {
|
||||
@Raw(FormatRow("Auszahlungsbetrag", (Model.Payment?.Amount + penalty) ?? (sum + penalty), bold: true))
|
||||
} else {
|
||||
if (Model.Credit.Modifiers - penalty != 0) {
|
||||
@Raw(FormatRow("Weitere Abzüge", Model.Credit.Modifiers - penalty, add: true))
|
||||
}
|
||||
if (Model.Credit.PrevModifiers != null && Model.Credit.PrevModifiers != 0) {
|
||||
@Raw(FormatRow("Bereits berücksichtigte Abzüge", -Model.Credit.PrevModifiers, add: true))
|
||||
}
|
||||
@Raw(FormatRow("Auszahlungsbetrag", Model.Credit.Amount, bold: true))
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</main>
|
||||
|
Reference in New Issue
Block a user