From 03b09ca3b07d17d9591330847250256a271829db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Erbsh=C3=A4u=C3=9Fer?= Date: Fri, 19 Jun 2020 08:10:29 +0200 Subject: [PATCH] Implemented missing dumping of cost entry details model to billing. --- ucalc/BillingWindow.xaml.cs | 2 +- ucalc/Data/BillingLoader.cs | 10 +++++----- ucalc/MainWindow.xaml.cs | 2 +- ucalc/Models/Model.cs | 16 ++++++++++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ucalc/BillingWindow.xaml.cs b/ucalc/BillingWindow.xaml.cs index 7dd6643..09b1f2e 100644 --- a/ucalc/BillingWindow.xaml.cs +++ b/ucalc/BillingWindow.xaml.cs @@ -162,7 +162,7 @@ namespace UCalc var billing = Model.Dump(); try { - new BillingLoader().Store(FilePath, billing); + BillingLoader.Store(FilePath, billing); Model.ResetModified(); return true; } diff --git a/ucalc/Data/BillingLoader.cs b/ucalc/Data/BillingLoader.cs index a14c7e7..7553604 100644 --- a/ucalc/Data/BillingLoader.cs +++ b/ucalc/Data/BillingLoader.cs @@ -69,7 +69,7 @@ namespace UCalc.Data } } - public class BillingLoader + public static class BillingLoader { private static string AsString(JObject parent, string name, bool optional = false) { @@ -171,7 +171,7 @@ namespace UCalc.Data target.BankName = AsString(bankAccount, "bank_name"); } - private Billing LoadFormat1(string path) + private static Billing LoadFormat1(string path) { var content = File.ReadAllText(path); try @@ -289,7 +289,7 @@ namespace UCalc.Data } [SuppressMessage("ReSharper", "PossibleNullReferenceException")] - private Billing LoadFormat2(string path) + private static Billing LoadFormat2(string path) { var content = File.ReadAllText(path); try @@ -337,7 +337,7 @@ namespace UCalc.Data } } - public Billing Load(string path) + public static Billing Load(string path) { try { @@ -349,7 +349,7 @@ namespace UCalc.Data } } - public void Store(string path, Billing billing) + public static void Store(string path, Billing billing) { File.WriteAllText(path, JsonConvert.SerializeObject(billing, Formatting.Indented)); } diff --git a/ucalc/MainWindow.xaml.cs b/ucalc/MainWindow.xaml.cs index b88c5e0..b7ec7c8 100644 --- a/ucalc/MainWindow.xaml.cs +++ b/ucalc/MainWindow.xaml.cs @@ -71,7 +71,7 @@ namespace UCalc { try { - var billing = new BillingLoader().Load(path); + var billing = BillingLoader.Load(path); App.RecentlyOpenedList.Add(new RecentlyOpenedItem(path)); new BillingWindow(path, billing).Show(); diff --git a/ucalc/Models/Model.cs b/ucalc/Models/Model.cs index a15d0b4..d24bdb6 100644 --- a/ucalc/Models/Model.cs +++ b/ucalc/Models/Model.cs @@ -240,7 +240,7 @@ namespace UCalc.Models DepartureDate = tenant.DepartureDate.Value, RentedFlats = new HashSet(tenant.RentedFlats.Select(rentedFlat => flatPropertyToFlat[rentedFlat])), - PaidRent = decimal.TryParse(tenant.PaidRent.Value, out var d) ? d : 0, + PaidRent = tenant.PaidRent.ConvertedValue ?? 0, CustomMessage1 = tenant.CustomMessage1.Value, CustomMessage2 = tenant.CustomMessage2.Value }).ToList(); @@ -253,7 +253,19 @@ namespace UCalc.Models IncludeUnrented = cost.IncludeUnrented.Value, AffectedFlats = new HashSet(cost.AffectedFlats.Select(rentedFlat => flatPropertyToFlat[rentedFlat])), - // TODO: Entries = {}, + Entries = cost.Entries.Select(entry => new CostEntry + { + StartDate = entry.StartDate.Value ?? StartDate, + EndDate = entry.EndDate.Value ?? EndDate, + Amount = entry.Amount.ConvertedValue ?? 0, + Details = new CostEntryDetails + { + TotalAmount = entry.Details.TotalAmount.ConvertedValue ?? 0, + UnitCount = entry.Details.UnitCount.ConvertedValue ?? 0, + DiscountsInUnits = entry.Details.DiscountsInUnits + .Select(discount => discount.ConvertedValue ?? 0).ToList() + } + }).ToList(), DisplayInBill = cost.DisplayInBill.Value }).ToList();