From d1c9818f27fa319bff11c808b8e0f550e6bc8953 Mon Sep 17 00:00:00 2001 From: Gianluigi Liguori Date: Tue, 5 Mar 2024 10:19:38 +0100 Subject: [PATCH] Fix zero and last item --- src/Savings.SPA/Pages/Projection.razor.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Savings.SPA/Pages/Projection.razor.cs b/src/Savings.SPA/Pages/Projection.razor.cs index 5b6f329..a9fb1ed 100644 --- a/src/Savings.SPA/Pages/Projection.razor.cs +++ b/src/Savings.SPA/Pages/Projection.razor.cs @@ -58,19 +58,22 @@ async Task InitializeList() { materializedMoneyItems = await savingsAPI.GetSavings(null, FilterDateTo); - MaterializedMoneyItem? lastBeforeToday = null; + //Remove first zero + if (!ShowZero) + { + materializedMoneyItems = materializedMoneyItems.Where(x => x.Amount != 0).ToArray(); + } + + //The decide to remove past items (when zero is already excluded) if (!ShowPastItems) { - lastBeforeToday = materializedMoneyItems.LastOrDefault(x => x.Date <= DateTime.Now.Date); + var lastBeforeToday = materializedMoneyItems.LastOrDefault(x => x.Date <= DateTime.Now.Date); if (lastBeforeToday != null) { materializedMoneyItems = materializedMoneyItems[Array.IndexOf(materializedMoneyItems, lastBeforeToday)..]; } } - if(!ShowZero) - { - materializedMoneyItems = materializedMoneyItems.Where(x => x.Amount != 0 || x.ID == lastBeforeToday?.ID).ToArray(); - } + } async Task AdjustRecurrency(MaterializedMoneyItem item)