From 4ce6ce824802ef2735623d7c03b042b5ddc702bb Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Wed, 2 Dec 2026 16:28:10 +0100 Subject: [PATCH] Elwig: Fix abgewertet/depreciated behaviour and rename to devalued --- CHANGELOG.md | 2 +- Elwig/Dialogs/DeliverySplittingDialog.xaml | 2 +- Elwig/Dialogs/DeliverySplittingDialog.xaml.cs | 6 +- Elwig/Documents/DeliveryConfirmation.cs | 2 +- ...tionList.cs => DeliveryDevaluationList.cs} | 6 +- Elwig/Helpers/AppDbUpdater.cs | 2 +- Elwig/Helpers/Billing/Billing.cs | 2 +- Elwig/Helpers/Billing/BillingData.cs | 2 +- Elwig/Helpers/Billing/EditBillingData.cs | 2 +- Elwig/Helpers/Billing/GraphEntry.cs | 6 +- Elwig/Helpers/Billing/Varibute.cs | 2 +- .../Dtos/DeliveryConfirmationDeliveryData.cs | 6 +- Elwig/Models/Entities/DeliveryPart.cs | 3 + Elwig/Resources/Sql/43-44.sql | 11 ++++ Elwig/Services/DeliveryService.cs | 12 ++-- Elwig/ViewModels/DeliveryAdminViewModel.cs | 2 +- Elwig/Windows/ChartWindow.xaml | 4 +- Elwig/Windows/ChartWindow.xaml.cs | 28 ++++----- Elwig/Windows/DeliveryAdminWindow.xaml | 40 ++++++------ Elwig/Windows/DeliveryAdminWindow.xaml.cs | 62 +++++++++---------- .../DeliveryDepreciationListTest.cs | 6 +- .../UnitTests/HelperTests/BillingDataTest.cs | 2 +- .../ServiceTests/DeliveryServiceTest.cs | 16 ++--- Tests/fetch-resources.bat | 2 +- 24 files changed, 121 insertions(+), 107 deletions(-) rename Elwig/Documents/{DeliveryDepreciationList.cs => DeliveryDevaluationList.cs} (96%) create mode 100644 Elwig/Resources/Sql/43-44.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index b439f49..8e1aca4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -913,7 +913,7 @@ Changelog ### Neue Funktionen {#v0.13.2-features} -- Im Lieferungen-Fenster den Menüpunkt _Abwertungsliste_ (`DeliveryDepreciationList`) hinzugefügt. (3cbffdbf27) +- Im Lieferungen-Fenster den Menüpunkt _Abwertungsliste_ (`DeliveryDevaluationList`) hinzugefügt. (3cbffdbf27) ### Behobene Fehler {#v0.13.2-bugfixes} diff --git a/Elwig/Dialogs/DeliverySplittingDialog.xaml b/Elwig/Dialogs/DeliverySplittingDialog.xaml index ca02ca2..b197adf 100644 --- a/Elwig/Dialogs/DeliverySplittingDialog.xaml +++ b/Elwig/Dialogs/DeliverySplittingDialog.xaml @@ -20,7 +20,7 @@ - r.Part.Weight); InfoBlock.Text = $"Insgesamt {weight:N0} kg / {total:N0} kg ausgewählt."; ConfirmButton.IsEnabled = DeliveryParts.Any(r => r.SplitCompletely || r.SplitWeight > 0) && ( - DepreciateModeInput.IsChecked == true || + DevalueModeInput.IsChecked == true || (MemberModeInput.IsChecked == true && MemberInput.SelectedItem != null && !DeliveryParts.All(r => r.SplitCompletely)) || (DeliveryModeInput.IsChecked == true && DeliveryInput.SelectedItem != null)); } diff --git a/Elwig/Documents/DeliveryConfirmation.cs b/Elwig/Documents/DeliveryConfirmation.cs index 437dc37..65f87c3 100644 --- a/Elwig/Documents/DeliveryConfirmation.cs +++ b/Elwig/Documents/DeliveryConfirmation.cs @@ -165,7 +165,7 @@ namespace Elwig.Documents { .SetPaddingsMM(1, 1, 0, 1)) .AddCell(NewTd("Davon abgewertet:", 10, colspan: 7) .SetPaddingsMM(0, 1, 0.5f, 1)) - .AddCell(NewTd($"{data.Rows.Where(p => p.IsDepreciated).Sum(p => p.Weight):N0}", 10, colspan: 2, right: true) + .AddCell(NewTd($"{data.Rows.Where(p => p.IsDevalued).Sum(p => p.Weight):N0}", 10, colspan: 2, right: true) .SetPaddingsMM(0, 1, 0.5f, 1)) .AddCell(NewCell(colspan: 2) .SetPaddingsMM(0, 1, 0.5f, 1)); diff --git a/Elwig/Documents/DeliveryDepreciationList.cs b/Elwig/Documents/DeliveryDevaluationList.cs similarity index 96% rename from Elwig/Documents/DeliveryDepreciationList.cs rename to Elwig/Documents/DeliveryDevaluationList.cs index cdc474a..d97fcfa 100644 --- a/Elwig/Documents/DeliveryDepreciationList.cs +++ b/Elwig/Documents/DeliveryDevaluationList.cs @@ -6,20 +6,20 @@ using System.Collections.Generic; using System.Linq; namespace Elwig.Documents { - public class DeliveryDepreciationList : Document { + public class DeliveryDevaluationList : Document { public new static string Name => "Abwertungsliste"; public string Filter; public List Deliveries; - public DeliveryDepreciationList(string filter, IEnumerable deliveries) : + public DeliveryDevaluationList(string filter, IEnumerable deliveries) : base($"{Name} {filter}") { Filter = filter; Deliveries = [.. deliveries]; } - public DeliveryDepreciationList(string filter, DeliveryJournalData data) : + public DeliveryDevaluationList(string filter, DeliveryJournalData data) : this(filter, data.Rows) { } diff --git a/Elwig/Helpers/AppDbUpdater.cs b/Elwig/Helpers/AppDbUpdater.cs index e556742..2d58c7e 100644 --- a/Elwig/Helpers/AppDbUpdater.cs +++ b/Elwig/Helpers/AppDbUpdater.cs @@ -12,7 +12,7 @@ namespace Elwig.Helpers { public static class AppDbUpdater { // Don't forget to update value in Tests/fetch-resources.bat! - public static readonly int RequiredSchemaVersion = 43; + public static readonly int RequiredSchemaVersion = 44; private static int VersionOffset = 0; diff --git a/Elwig/Helpers/Billing/Billing.cs b/Elwig/Helpers/Billing/Billing.cs index 10ce46a..e639a86 100644 --- a/Elwig/Helpers/Billing/Billing.cs +++ b/Elwig/Helpers/Billing/Billing.cs @@ -99,7 +99,7 @@ namespace Elwig.Helpers.Billing { SELECT mgnr, did, dpnr, sortid, weight, kmw, qualid, attrid, modifiers, contracted FROM v_delivery WHERE year = {Year} - ORDER BY mgnr, sortid, abgewertet ASC, {(honorContracted ? "contracted IS NOT NULL DESC, contracted DESC," : "")} + ORDER BY mgnr, sortid, devalued ASC, {(honorContracted ? "contracted IS NOT NULL DESC, contracted DESC," : "")} attribute_prio DESC, COALESCE(attrid, '~'), kmw DESC, lsnr, dpnr """; using var reader = await cmd.ExecuteReaderAsync(); diff --git a/Elwig/Helpers/Billing/BillingData.cs b/Elwig/Helpers/Billing/BillingData.cs index 3c29732..ca0deb0 100644 --- a/Elwig/Helpers/Billing/BillingData.cs +++ b/Elwig/Helpers/Billing/BillingData.cs @@ -451,7 +451,7 @@ namespace Elwig.Helpers.Billing { foreach (var c in entry.Vaributes) { var v = new RawVaribute(c.Variety!.SortId, c.Attribute?.AttrId ?? "", c.Cultivation?.CultId); if (v.CultId == "") v.CultId = null; - if (entry.Abgewertet) {; + if (entry.IsDevalued) {; qualityWei[v.ToString()] = node.DeepClone(); } else { payment[v.ToString()] = node.DeepClone(); diff --git a/Elwig/Helpers/Billing/EditBillingData.cs b/Elwig/Helpers/Billing/EditBillingData.cs index 288650e..7a2c755 100644 --- a/Elwig/Helpers/Billing/EditBillingData.cs +++ b/Elwig/Helpers/Billing/EditBillingData.cs @@ -100,7 +100,7 @@ namespace Elwig.Helpers.Billing { var list = (await CreateGraphEntries(ctx, season.Precision, curves, entries)).Where(e => e.Vaributes.Count > 0); foreach (var e in list) { e.Id += idOffset; - e.Abgewertet = true; + e.IsDevalued = true; } return list; } diff --git a/Elwig/Helpers/Billing/GraphEntry.cs b/Elwig/Helpers/Billing/GraphEntry.cs index 648f2a3..8b160e3 100644 --- a/Elwig/Helpers/Billing/GraphEntry.cs +++ b/Elwig/Helpers/Billing/GraphEntry.cs @@ -12,7 +12,7 @@ namespace Elwig.Helpers.Billing { public int Id { get; set; } public BillingData.CurveMode Mode { get; set; } - public bool Abgewertet { get; set; } + public bool IsDevalued { get; set; } public Graph DataGraph { get; set; } public Graph? ContractedGraph { get; set; } @@ -38,9 +38,9 @@ namespace Elwig.Helpers.Billing { } public List Vaributes { get; set; } - public string VaributeStringSimple => (Abgewertet ? "Abgew.: " : "") + (Vaributes.Count != 0 ? (Vaributes.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Vaributes.Select(c => c.Listing))) : "-"); + public string VaributeStringSimple => (IsDevalued ? "Abgew.: " : "") + (Vaributes.Count != 0 ? (Vaributes.Count >= 25 ? "Restliche Sorten" : string.Join(", ", Vaributes.Select(c => c.Listing))) : "-"); public string VaributeString => Vaributes.Count != 0 ? string.Join("\n", Vaributes.Select(c => c.FullName)) : "-"; - public string VaributeStringChange => (Abgewertet ? "A." : "") + string.Join(",", Vaributes.Select(c => c.Listing)); + public string VaributeStringChange => (IsDevalued ? "A." : "") + string.Join(",", Vaributes.Select(c => c.Listing)); public Brush? Color => Vaributes.Select(v => v.Variety?.Color).Distinct().SingleOrDefault(); private readonly int Precision; diff --git a/Elwig/Helpers/Billing/Varibute.cs b/Elwig/Helpers/Billing/Varibute.cs index 216afbd..e9c562d 100644 --- a/Elwig/Helpers/Billing/Varibute.cs +++ b/Elwig/Helpers/Billing/Varibute.cs @@ -53,7 +53,7 @@ namespace Elwig.Helpers.Billing { public WineAttr? Attribute { get; } public WineCult? Cultivation { get; } public int? AssignedGraphId { get; set; } - public int? AssignedAbgewGraphId { get; set; } + public int? AssignedDevaluedGraphId { get; set; } public string Listing => $"{Variety?.SortId}" + (Attribute != null ? $"/{Attribute.AttrId}" : "") + diff --git a/Elwig/Models/Dtos/DeliveryConfirmationDeliveryData.cs b/Elwig/Models/Dtos/DeliveryConfirmationDeliveryData.cs index 142fdd2..440a7d7 100644 --- a/Elwig/Models/Dtos/DeliveryConfirmationDeliveryData.cs +++ b/Elwig/Models/Dtos/DeliveryConfirmationDeliveryData.cs @@ -58,7 +58,7 @@ namespace Elwig.Models.Dtos { FROM v_delivery v JOIN delivery_part p ON (p.year, p.did, p.dpnr) = (v.year, v.did, v.dpnr) WHERE (p.year = {year} OR {year} IS NULL) AND (v.mgnr = {mgnr} OR {mgnr} IS NULL) - ORDER BY p.year, v.mgnr, v.sortid, v.abgewertet ASC, v.attribute_prio DESC, COALESCE(v.attrid, '~'), v.kmw DESC, v.lsnr, v.dpnr + ORDER BY p.year, v.mgnr, v.sortid, v.devalued ASC, v.attribute_prio DESC, COALESCE(v.attrid, '~'), v.kmw DESC, v.lsnr, v.dpnr """).IgnoreAutoIncludes().ToListAsync(); } } @@ -72,7 +72,7 @@ namespace Elwig.Models.Dtos { public string? Cultivation; public string QualityLevel; public string QualId; - public bool IsDepreciated; + public bool IsDevalued; public (double Oe, double Kmw) Gradation; public string[] Modifiers; public int Weight; @@ -89,7 +89,7 @@ namespace Elwig.Models.Dtos { Cultivation = p.Cultivation?.Name; QualityLevel = p.Quality.Name; QualId = p.Quality.QualId; - IsDepreciated = p.QualId == "WEI"; + IsDevalued = p.QualId == "WEI"; Gradation = (p.Oe, p.Kmw); Modifiers = [.. p.Modifiers.Select(m => m.Name)]; Weight = p.Weight; diff --git a/Elwig/Models/Entities/DeliveryPart.cs b/Elwig/Models/Entities/DeliveryPart.cs index b5af68a..910d186 100644 --- a/Elwig/Models/Entities/DeliveryPart.cs +++ b/Elwig/Models/Entities/DeliveryPart.cs @@ -61,6 +61,9 @@ namespace Elwig.Models.Entities { [ForeignKey("QualId")] public virtual WineQualLevel Quality { get; init; } = null!; + [NotMapped] + public bool IsDevalued => QualId == "WEI"; + [Column("hkid")] public required string HkId { get; set; } diff --git a/Elwig/Resources/Sql/43-44.sql b/Elwig/Resources/Sql/43-44.sql new file mode 100644 index 0000000..f41f47a --- /dev/null +++ b/Elwig/Resources/Sql/43-44.sql @@ -0,0 +1,11 @@ +-- schema version 43 to 44 + +PRAGMA writable_schema = ON; + +UPDATE sqlite_schema SET sql = REPLACE(sql, + 'IN (SELECT l.qualid FROM wine_quality_level l WHERE NOT l.predicate AND (p.kmw >= l.min_kmw OR l.min_kmw IS NULL) ORDER BY l.min_kmw DESC LIMIT 1,100) AS abgewertet', + '= ''WEI'' AS devalued') +WHERE type = 'view' AND name = 'v_delivery'; + +PRAGMA schema_version = 4301; +PRAGMA writable_schema = OFF; diff --git a/Elwig/Services/DeliveryService.cs b/Elwig/Services/DeliveryService.cs index 69bc62e..58a4427 100644 --- a/Elwig/Services/DeliveryService.cs +++ b/Elwig/Services/DeliveryService.cs @@ -720,7 +720,7 @@ namespace Elwig.Services { }); } - public static async Task DepreciateDelivery(int year, int did, int[] weights) { + public static async Task DevalueDelivery(int year, int did, int[] weights) { await Task.Run(async () => { using var ctx = new AppDbContext(); var d = await ctx.Deliveries @@ -890,7 +890,7 @@ namespace Elwig.Services { } } - public static async Task GenerateDeliveryDepreciationList(this DeliveryAdminViewModel vm, ExportSubject subject, ExportMode mode) { + public static async Task GenerateDeliveryDevaluationList(this DeliveryAdminViewModel vm, ExportSubject subject, ExportMode mode) { using var ctx = new AppDbContext(); IQueryable query; List filterNames = []; @@ -917,17 +917,17 @@ namespace Elwig.Services { filterNames.Remove("abgewertet"); if (mode == ExportMode.SaveList) { - var filename = InteractionService.SaveFile(DeliveryDepreciationList.Name, $"{DeliveryDepreciationList.Name}-{vm.FilterSeason ?? Utils.CurrentLastSeason}", "ods"); + var filename = InteractionService.SaveFile(DeliveryDevaluationList.Name, $"{DeliveryDevaluationList.Name}-{vm.FilterSeason ?? Utils.CurrentLastSeason}", "ods"); if (filename != null) { await Utils.RunForeground(async () => { using var ods = new OdsFile(filename); var tblTotal = await DeliveryJournalData.FromQuery(query, filterNames); - tblTotal.FullName = DeliveryDepreciationList.Name; + tblTotal.FullName = DeliveryDevaluationList.Name; tblTotal.Name = "Gesamt"; await ods.AddTable(tblTotal); foreach (var branch in await ctx.FetchBranches().ToListAsync()) { var tbl = await DeliveryJournalData.FromQuery(query.Where(p => p.Delivery.ZwstId == branch.ZwstId), filterNames); - tbl.FullName = DeliveryDepreciationList.Name; + tbl.FullName = DeliveryDevaluationList.Name; tbl.Name = branch.Name; await ods.AddTable(tbl); } @@ -936,7 +936,7 @@ namespace Elwig.Services { } else { await Utils.RunForeground(async () => { var data = await DeliveryJournalData.FromQuery(query, filterNames); - using var doc = new DeliveryDepreciationList(string.Join(" / ", filterNames), data); + using var doc = new DeliveryDevaluationList(string.Join(" / ", filterNames), data); await Utils.ExportDocument(doc, mode); }); } diff --git a/Elwig/ViewModels/DeliveryAdminViewModel.cs b/Elwig/ViewModels/DeliveryAdminViewModel.cs index 3b665f0..bc452ad 100644 --- a/Elwig/ViewModels/DeliveryAdminViewModel.cs +++ b/Elwig/ViewModels/DeliveryAdminViewModel.cs @@ -117,7 +117,7 @@ namespace Elwig.ViewModels { [ObservableProperty] public partial IEnumerable WineQualityLevelSource { get; set; } = []; [ObservableProperty] - public partial bool Abgewertet { get; set; } + public partial bool IsDevalued { get; set; } [ObservableProperty] public partial string? WeightString { get; set; } diff --git a/Elwig/Windows/ChartWindow.xaml b/Elwig/Windows/ChartWindow.xaml index a69504f..86b271f 100644 --- a/Elwig/Windows/ChartWindow.xaml +++ b/Elwig/Windows/ChartWindow.xaml @@ -79,13 +79,13 @@ - + - diff --git a/Elwig/Windows/ChartWindow.xaml.cs b/Elwig/Windows/ChartWindow.xaml.cs index c36ea05..821642a 100644 --- a/Elwig/Windows/ChartWindow.xaml.cs +++ b/Elwig/Windows/ChartWindow.xaml.cs @@ -65,7 +65,7 @@ namespace Elwig.Windows { private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem; private List Vaributes = []; private bool AllVaributesAssigned => Vaributes.All(v => v.AssignedGraphId != null); - private bool AllVaributesAssignedAbgew => Vaributes.All(v => v.AssignedAbgewGraphId != null); + private bool AllVaributesAssignedDevalued => Vaributes.All(v => v.AssignedDevaluedGraphId != null); public ChartWindow(int year, int avnr) { InitializeComponent(); @@ -126,8 +126,8 @@ namespace Elwig.Windows { e.Vaributes.ForEach(v => { var found = Vaributes.Find(a => a.Variety?.SortId == v.Variety?.SortId && a.Attribute?.AttrId == v.Attribute?.AttrId && a.Cultivation?.CultId == v.Cultivation?.CultId); if (found == null) return; - if (e.Abgewertet) { - found.AssignedAbgewGraphId = e.Id; + if (e.IsDevalued) { + found.AssignedDevaluedGraphId = e.Id; } else { found.AssignedGraphId = e.Id; } @@ -153,7 +153,7 @@ namespace Elwig.Windows { ContractedTypeGraph.IsEnabled = true; ContractedTypeNone.IsEnabled = true; VaributeInput.IsEnabled = true; - AbgewertetInput.IsEnabled = true; + DevaluedInput.IsEnabled = true; EnableOptionButtons(); FillInputs(); } else { @@ -172,7 +172,7 @@ namespace Elwig.Windows { ContractedTypeGraph.IsEnabled = false; ContractedTypeNone.IsEnabled = false; VaributeInput.IsEnabled = false; - AbgewertetInput.IsEnabled = false; + DevaluedInput.IsEnabled = false; } GC.Collect(); } @@ -180,7 +180,7 @@ namespace Elwig.Windows { private void FillInputs() { FillingInputs = true; - AbgewertetInput.IsChecked = SelectedGraphEntry?.Abgewertet; + DevaluedInput.IsChecked = SelectedGraphEntry?.IsDevalued; if (SelectedGraphEntry?.ContractedFlatBonus is double bonus) { ContractedTypeFixed.IsChecked = true; ContractedFlatBonus.Text = $"{bonus}"; @@ -652,7 +652,7 @@ namespace Elwig.Windows { using var ctx = new AppDbContext(); var origData = BillingData.FromJson(PaymentVar.Data); var data = BillingData.FromGraphEntries(GraphEntries, origData, await Utils.GetVaributes(ctx, Year), - AllVaributesAssigned, AllVaributesAssignedAbgew); + AllVaributesAssigned, AllVaributesAssignedDevalued); PaymentVar.Data = data.ToJsonString(); ctx.Update(PaymentVar); @@ -747,8 +747,8 @@ namespace Elwig.Windows { foreach (var i in evt.AddedItems) { if (i is not Varibute v) continue; if (RemoveVaributeFromOthers(v.ToString())) { - if (AbgewertetInput.IsChecked == true) { - v.AssignedAbgewGraphId = SelectedGraphEntry?.Id; + if (DevaluedInput.IsChecked == true) { + v.AssignedDevaluedGraphId = SelectedGraphEntry?.Id; } else { v.AssignedGraphId = SelectedGraphEntry?.Id; } @@ -758,8 +758,8 @@ namespace Elwig.Windows { } foreach (var i in evt.RemovedItems) { if (i is not Varibute v) continue; - if (AbgewertetInput.IsChecked == true) { - v.AssignedAbgewGraphId = null; + if (DevaluedInput.IsChecked == true) { + v.AssignedDevaluedGraphId = null; } else { v.AssignedGraphId = null; } @@ -775,7 +775,7 @@ namespace Elwig.Windows { private bool RemoveVaributeFromOthers(string? varibute) { if (varibute == null) return true; foreach (var ge in GraphEntries) { - if (ge != SelectedGraphEntry && ge.Abgewertet == SelectedGraphEntry?.Abgewertet) { + if (ge != SelectedGraphEntry && ge.IsDevalued == SelectedGraphEntry?.IsDevalued) { var toRemove = ge.Vaributes.Where(c => c.Listing.Equals(varibute)).ToList(); if (toRemove.Count == 0) continue; if (!InteractionService.AskConfirmation("Entfernen bestätigen", $"Achtung: {string.Join(", ", toRemove)} ist bereits in Kurve {ge.Id} in Verwendung!\nSoll die Zuweisung dort entfernt werden?")) { @@ -787,10 +787,10 @@ namespace Elwig.Windows { return true; } - private void AbgewertetInput_Changed(object sender, RoutedEventArgs e) { + private void DevaluedInput_Changed(object sender, RoutedEventArgs e) { if (FillingInputs) return; if (SelectedGraphEntry == null) return; - SelectedGraphEntry.Abgewertet = AbgewertetInput.IsChecked == true; + SelectedGraphEntry.IsDevalued = DevaluedInput.IsChecked == true; SetHasChanged(); GraphList.Items.Refresh(); } diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml b/Elwig/Windows/DeliveryAdminWindow.xaml index b23c2f8..51cf29d 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml +++ b/Elwig/Windows/DeliveryAdminWindow.xaml @@ -109,24 +109,24 @@ - - - - - + + + + + - - - - + + + + Alt+Einfg -