diff --git a/Elwig/Documents/CreditNote.cs b/Elwig/Documents/CreditNote.cs index 4a8ac16..7a15b12 100644 --- a/Elwig/Documents/CreditNote.cs +++ b/Elwig/Documents/CreditNote.cs @@ -40,8 +40,14 @@ namespace Elwig.Documents { Payment = p; Credit = p.Credit; var season = p.Variant.Season; + if (considerCustomModifiers) { + CustomPayment = ctx.CustomPayments.Find(p.Year, p.MgNr); + } + var mod = App.Client.IsMatzen ? ctx.Modifiers.Where(m => m.Year == season.Year && m.Name.StartsWith("Treue")).FirstOrDefault() : null; - if (mod != null) { + if (CustomPayment?.ModComment != null) { + MemberModifier = CustomPayment.ModComment; + } else if (mod != null) { MemberModifier = $"{mod.Name} ({mod.ValueStr})"; } else { MemberModifier = "Sonstige Zu-/Abschläge"; @@ -88,8 +94,5 @@ namespace Elwig.Documents { .Where(u => u.Item3 != 0) .ToList(); } - if (considerCustomModifiers) { - CustomPayment = ctx.CustomPayments.Find(p.Year, p.MgNr); - } } }} diff --git a/Elwig/Documents/CreditNote.cshtml b/Elwig/Documents/CreditNote.cshtml index 3dede94..4dd0b4f 100644 --- a/Elwig/Documents/CreditNote.cshtml +++ b/Elwig/Documents/CreditNote.cshtml @@ -157,9 +157,9 @@ @Raw(FormatRow($"Autom. Nachz. von GA ({Model.MemberAutoBusinessShares})", Model.MemberAutoBusinessSharesAmount, add: true)); penalty += Model.MemberAutoBusinessSharesAmount; } - @if (Model.CustomPayment != null) { - @Raw(FormatRow(Model.CustomPayment.Comment ?? (Model.CustomPayment.Amount < 0 ? "Weitere Abzüge" : "Weitere Zuschläge"), Model.CustomPayment.Amount, add: true)); - penalty += Model.CustomPayment.Amount; + @if (Model.CustomPayment?.Amount != null) { + @Raw(FormatRow(Model.CustomPayment.Comment ?? ((Model.CustomPayment.Amount.Value) < 0 ? "Weitere Abzüge" : "Weitere Zuschläge"), Model.CustomPayment.Amount.Value, add: true)); + penalty += Model.CustomPayment.Amount.Value; } @if (Model.Credit == null) { diff --git a/Elwig/Helpers/AppDbUpdater.cs b/Elwig/Helpers/AppDbUpdater.cs index 3af451e..bf02d55 100644 --- a/Elwig/Helpers/AppDbUpdater.cs +++ b/Elwig/Helpers/AppDbUpdater.cs @@ -9,7 +9,7 @@ namespace Elwig.Helpers { public static class AppDbUpdater { // Don't forget to update value in Tests/fetch-resources.bat! - public static readonly int RequiredSchemaVersion = 27; + public static readonly int RequiredSchemaVersion = 28; private static int VersionOffset = 0; diff --git a/Elwig/Helpers/Billing/BillingVariant.cs b/Elwig/Helpers/Billing/BillingVariant.cs index 3afafdb..721356f 100644 --- a/Elwig/Helpers/Billing/BillingVariant.cs +++ b/Elwig/Helpers/Billing/BillingVariant.cs @@ -29,6 +29,8 @@ namespace Elwig.Helpers.Billing { await CalculatePrices(cnx); if (Data.ConsiderDelieryModifiers) { await CalculateDeliveryModifiers(cnx); + } + if (Data.ConsiderCustomModifiers) { await CalculateMemberModifiers(cnx); } await tx.CommitAsync(); @@ -128,6 +130,16 @@ namespace Elwig.Helpers.Billing { mod_rel = mod_rel + excluded.mod_rel """); } + await AppDbContext.ExecuteBatch(cnx, $""" + INSERT INTO payment_member (year, avnr, mgnr, net_amount, mod_abs, mod_rel) + SELECT x.year, {AvNr}, x.mgnr, 0, COALESCE(x.mod_abs * POW(10, s.precision - 2), 0), COALESCE(x.mod_rel, 0) + FROM payment_custom x + JOIN season s ON s.year = x.year + WHERE x.year = {Year} + ON CONFLICT DO UPDATE + SET mod_abs = mod_abs + excluded.mod_abs, + mod_rel = mod_rel + excluded.mod_rel + """); } protected async Task CalculatePrices(SqliteConnection cnx) { diff --git a/Elwig/Models/Entities/PaymentCustom.cs b/Elwig/Models/Entities/PaymentCustom.cs index 549ad2a..04416ec 100644 --- a/Elwig/Models/Entities/PaymentCustom.cs +++ b/Elwig/Models/Entities/PaymentCustom.cs @@ -11,12 +11,31 @@ namespace Elwig.Models.Entities { [Column("mgnr")] public int MgNr { get; set; } - [Column("amount")] - public long AmountValue { get; set; } + [Column("mod_abs")] + public long? ModAbsValue { get; set; } [NotMapped] - public decimal Amount { - get => Utils.DecFromDb(AmountValue, 2); - set => AmountValue = Utils.DecToDb(value, 2); + public decimal? ModAbs { + get => ModAbsValue != null ? Utils.DecFromDb(ModAbsValue.Value, 2) : null; + set => ModAbsValue = value != null ? Utils.DecToDb(value.Value, 2) : null; + } + + [Column("mod_rel")] + public double? ModRelValue { get; set; } + [NotMapped] + public decimal? ModRel { + get => ModRelValue != null ? (decimal)ModRelValue.Value : null; + set => ModRelValue = value != null ? (double)value.Value : null; + } + + [Column("mod_comment")] + public string? ModComment { get; set; } + + [Column("amount")] + public long? AmountValue { get; set; } + [NotMapped] + public decimal? Amount { + get => AmountValue != null ? Utils.DecFromDb(AmountValue.Value, 2) : null; + set => AmountValue = value != null ? Utils.DecToDb(value.Value, 2) : null; } [Column("comment")] diff --git a/Elwig/Resources/Sql/27-28.sql b/Elwig/Resources/Sql/27-28.sql new file mode 100644 index 0000000..25c9b17 --- /dev/null +++ b/Elwig/Resources/Sql/27-28.sql @@ -0,0 +1,13 @@ +-- schema version 27 to 28 + +ALTER TABLE payment_custom ADD COLUMN mod_abs INTEGER DEFAULT NULL; +ALTER TABLE payment_custom ADD COLUMN mod_rel REAL DEFAULT NULL; +ALTER TABLE payment_custom ADD COLUMN mod_comment TEXT DEFAULT NULL; + +PRAGMA writable_schema = ON; + +UPDATE sqlite_schema SET sql = REPLACE(REPLACE(sql, 'amount INTEGER NOT NULL', 'amount INTEGER DEFAULT NULL'), 'comment TEXT', 'comment TEXT DEFAULT NULL') +WHERE type = 'table' AND name = 'payment_custom'; + +PRAGMA schema_version = 2701; +PRAGMA writable_schema = OFF; diff --git a/Elwig/Windows/PaymentAdjustmentWindow.xaml b/Elwig/Windows/PaymentAdjustmentWindow.xaml index c911898..c29d2f0 100644 --- a/Elwig/Windows/PaymentAdjustmentWindow.xaml +++ b/Elwig/Windows/PaymentAdjustmentWindow.xaml @@ -6,7 +6,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Elwig.Windows" xmlns:ctrl="clr-namespace:Elwig.Controls" - Title="Auszahlung anpassen - Elwig" Height="600" Width="1000" MinHeight="400" MinWidth="850"> + Title="Auszahlung anpassen - Elwig" Height="600" Width="1000" MinHeight="560" MinWidth="850"> @@ -83,6 +83,20 @@ + + + + + + + + + + - +