diff --git a/Elwig/Documents/CreditNote.cs b/Elwig/Documents/CreditNote.cs index 2ffa8e3..e987e41 100644 --- a/Elwig/Documents/CreditNote.cs +++ b/Elwig/Documents/CreditNote.cs @@ -101,11 +101,8 @@ namespace Elwig.Documents { MemberTotalUnderDelivery -= (season.PenaltyNone ?? 0) + (season.PenaltyPerShareNone * (Member.Shares + Member.SharesRed + Member.SharesWhite) ?? 0); } if (ConsiderAutoBusinessShares) { - var fromDate = $"{season.Year}-01-01"; - var toDate = $"{season.Year}-12-31"; MemberAutoBusinessShares = await ctx.MemberHistory - .Where(h => h.ToMgNr == Member.MgNr && h.Reason == "auto") - .Where(h => h.DateString.CompareTo(fromDate) >= 0 && h.DateString.CompareTo(toDate) <= 0) + .Where(h => h.ToMgNr == Member.MgNr && h.DeductYear == season.Year) .SumAsync(h => h.Shares); MemberAutoBusinessSharesAmount = MemberAutoBusinessShares * (-season.BusinessShareValue ?? 0); } @@ -205,7 +202,7 @@ namespace Elwig.Documents { penalty += MemberTotalUnderDelivery; } if (MemberAutoBusinessSharesAmount != 0) { - tbl2.AddCells(FormatRow($"Autom. Nachz. von GA ({MemberAutoBusinessShares})", MemberAutoBusinessSharesAmount, add: true)); + tbl2.AddCells(FormatRow($"Nachzeichnung von GA ({MemberAutoBusinessShares})", MemberAutoBusinessSharesAmount, add: true)); penalty += MemberAutoBusinessSharesAmount; } if (CustomPayment?.Amount != null) { diff --git a/Elwig/Documents/PaymentVariantSummary.cs b/Elwig/Documents/PaymentVariantSummary.cs index 159e61b..0fad8d9 100644 --- a/Elwig/Documents/PaymentVariantSummary.cs +++ b/Elwig/Documents/PaymentVariantSummary.cs @@ -139,7 +139,7 @@ namespace Elwig.Documents { .AddCell(NewSectionTh("Datum/Überw.:", overflow: true)) .AddCell(NewTd($"{Variant.Date:dd.MM.yyyy} / {Variant.TransferDate:dd.MM.yyyy}", colspan: 4, center: true)) - .AddCell(NewSectionTh("Automatische Nachzeichnung der GA:", colspan: 2, borderLeft: true)) + .AddCell(NewSectionTh("(Automatische) Nachzeichnung von GA:", colspan: 2, borderLeft: true)) .AddCell(NewTd(BillingData.ConsiderAutoBusinessShares ? "Ja" : "Nein", center: true)) .AddCell(NewSectionTh("Berechnung:")) diff --git a/Elwig/Helpers/Billing/Billing.cs b/Elwig/Helpers/Billing/Billing.cs index 5fd6ba0..d65ad61 100644 --- a/Elwig/Helpers/Billing/Billing.cs +++ b/Elwig/Helpers/Billing/Billing.cs @@ -54,10 +54,10 @@ namespace Elwig.Helpers.Billing { if (addMinShares < 1) addMinShares = 1; using var cnx = await AppDbContext.ConnectAsync(); await cnx.ExecuteBatch($""" - DELETE FROM member_history WHERE source = 'elwig' AND reason = 'auto' AND SUBSTR(date, 1, 4) = '{Year}'; - INSERT INTO member_history (histnr, from_mgnr, from_type, to_mgnr, to_type, date, reason, source, shares, value_per_share, currency) + DELETE FROM member_history WHERE source = 'elwig' AND reason = 'auto' AND deduct_year = {Year}; + INSERT INTO member_history (histnr, from_mgnr, from_type, to_mgnr, to_type, date, reason, source, deduct_year, shares, value_per_share, currency) SELECT COALESCE((SELECT MAX(histnr) AS histnr FROM member_history), 0) + ROW_NUMBER() OVER(ORDER BY m.mgnr), - NULL, NULL, u.mgnr, 1, '{date:yyyy-MM-dd}', 'auto', 'elwig', + NULL, NULL, u.mgnr, 1, '{date:yyyy-MM-dd}', 'auto', 'elwig', s.year, CEIL((u.diff - {allowanceKg}.0 - {allowanceKgPerShare}.0 * u.shares) / s.max_kg_per_share - {allowanceShares.ToString(CultureInfo.InvariantCulture)} - {allowanceRel.ToString(CultureInfo.InvariantCulture)} * u.shares) AS adjust_shares, @@ -72,7 +72,7 @@ namespace Elwig.Helpers.Billing { public async Task UnAdjustBusinessShares() { using var cnx = await AppDbContext.ConnectAsync(); await cnx.ExecuteBatch($""" - DELETE FROM member_history WHERE source = 'elwig' AND reason = 'auto' AND SUBSTR(date, 1, 4) = '{Year}'; + DELETE FROM member_history WHERE source = 'elwig' AND reason = 'auto' AND deduct_year = {Year}; """); } diff --git a/Elwig/Models/Entities/MemberHistory.cs b/Elwig/Models/Entities/MemberHistory.cs index 393ac92..2e10dae 100644 --- a/Elwig/Models/Entities/MemberHistory.cs +++ b/Elwig/Models/Entities/MemberHistory.cs @@ -50,6 +50,9 @@ namespace Elwig.Models.Entities { [Column("currency")] public string? CurrencyCode { get; set; } + [Column("deduct_year")] + public int? DeductYear { get; set; } + [Column("comment")] public string? Comment { get; set; } diff --git a/Elwig/Resources/Sql/39-40.sql b/Elwig/Resources/Sql/39-40.sql index 9248bc6..244270d 100644 --- a/Elwig/Resources/Sql/39-40.sql +++ b/Elwig/Resources/Sql/39-40.sql @@ -27,6 +27,7 @@ CREATE TABLE member_history_new ( shares INTEGER NOT NULL, value_per_share INTEGER DEFAULT NULL, currency TEXT DEFAULT NULL, + deduct_year INTEGER DEFAULT NULL, comment TEXT DEFAULT NULL, CONSTRAINT pk_member_history PRIMARY KEY (histnr), @@ -44,8 +45,8 @@ CREATE TABLE member_history_new ( ((to_mgnr IS NULL AND to_type IS NULL) OR (to_mgnr IS NOT NULL AND to_type IS NOT NULL))) ) STRICT; -INSERT INTO member_history_new (histnr, from_mgnr, from_type, to_mgnr, to_type, date, reason, source, shares, value_per_share, currency, comment) -SELECT ROW_NUMBER() OVER(ORDER BY h.date, h.mgnr), NULL, NULL, h.mgnr, 1, h.date, h.type, 'elwig', h.business_shares, s.bs_value / POW(10, s.precision - 2), s.currency, comment +INSERT INTO member_history_new (histnr, from_mgnr, from_type, to_mgnr, to_type, date, reason, source, shares, value_per_share, currency, deduct_year, comment) +SELECT ROW_NUMBER() OVER(ORDER BY h.date, h.mgnr), NULL, NULL, h.mgnr, 1, h.date, h.type, 'elwig', h.business_shares, s.bs_value / POW(10, s.precision - 2), s.currency, IIF(h.type = 'auto', s.year, NULL), comment FROM member_history h JOIN season s ON s.year = SUBSTR(h.date, 1, 4); diff --git a/Elwig/Windows/PaymentAdjustmentWindow.xaml b/Elwig/Windows/PaymentAdjustmentWindow.xaml index eada57c..e30d309 100644 --- a/Elwig/Windows/PaymentAdjustmentWindow.xaml +++ b/Elwig/Windows/PaymentAdjustmentWindow.xaml @@ -194,7 +194,7 @@ - diff --git a/Elwig/Windows/PaymentAdjustmentWindow.xaml.cs b/Elwig/Windows/PaymentAdjustmentWindow.xaml.cs index f857572..46706f7 100644 --- a/Elwig/Windows/PaymentAdjustmentWindow.xaml.cs +++ b/Elwig/Windows/PaymentAdjustmentWindow.xaml.cs @@ -60,7 +60,7 @@ namespace Elwig.Windows { CustomPayments = await ctx.CustomPayments.Where(p => p.Year == Year).ToDictionaryAsync(p => p.MgNr, p => p); var history = await ctx.MemberHistory - .Where(h => h.DateString.CompareTo($"{Year}-01-01") >= 0 && h.DateString.CompareTo($"{Year}-12-31") <= 0 && h.Reason == "auto" && h.Shares > 0) + .Where(h => h.DeductYear == Year) .GroupBy(h => h.ToMember) .ToDictionaryAsync(h => h.Key.MgNr, h => h.Sum(g => g.Shares)); diff --git a/Elwig/Windows/PaymentVariantsWindow.xaml b/Elwig/Windows/PaymentVariantsWindow.xaml index 55e220c..fd0bb76 100644 --- a/Elwig/Windows/PaymentVariantsWindow.xaml +++ b/Elwig/Windows/PaymentVariantsWindow.xaml @@ -188,7 +188,7 @@ Margin="110,135,10,10" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Checked="ConsiderPenaltyInput_Changed" Unchecked="ConsiderPenaltyInput_Changed"/>