diff --git a/src/Savings.SPA/Pages/Projection.razor b/src/Savings.SPA/Pages/Projection.razor index 470e2d3..73a704b 100644 --- a/src/Savings.SPA/Pages/Projection.razor +++ b/src/Savings.SPA/Pages/Projection.razor @@ -14,12 +14,12 @@ else
-
- +
+
-
- +
+

diff --git a/src/Savings.SPA/Pages/Projection.razor.cs b/src/Savings.SPA/Pages/Projection.razor.cs index b817742..afd1e86 100644 --- a/src/Savings.SPA/Pages/Projection.razor.cs +++ b/src/Savings.SPA/Pages/Projection.razor.cs @@ -1,122 +1,122 @@ -using Microsoft.AspNetCore.Components; -using Savings.Model; -using Savings.SPA.Services; -using System; -using System.Threading.Tasks; -using Radzen; -using System.Collections.Generic; -using Microsoft.AspNetCore.Components.WebAssembly.Authentication; - -namespace Savings.SPA.Pages -{ - public partial class Projection : ComponentBase - { - [Inject] - public ISavingsApi savingsAPI { get; set; } - - private MaterializedMoneyItem[] materializedMoneyItems; - - [Inject] - public DialogService dialogService { get; set; } - - public bool HidePastItems { get; set; } = true; - - public bool HideZero { get; set; } = true; - - public DateTime? FilterDateTo { get; set; } - - public Configuration CurrentConfiguration { get; set; } - - protected override async Task OnInitializedAsync() - { - FilterDateTo = DateTime.Now.Date.AddYears(1); - await InitializeList(); - CurrentConfiguration = (await savingsAPI.GetConfigurations()).FirstOrDefault(); - } - - - async void HidePastItems_Changed() +using Microsoft.AspNetCore.Components; +using Savings.Model; +using Savings.SPA.Services; +using System; +using System.Threading.Tasks; +using Radzen; +using System.Collections.Generic; +using Microsoft.AspNetCore.Components.WebAssembly.Authentication; + +namespace Savings.SPA.Pages +{ + public partial class Projection : ComponentBase + { + [Inject] + public ISavingsApi savingsAPI { get; set; } + + private MaterializedMoneyItem[] materializedMoneyItems; + + [Inject] + public DialogService dialogService { get; set; } + + public bool ShowPastItems { get; set; } = false; + + public bool ShowZero { get; set; } = false; + + public DateTime? FilterDateTo { get; set; } + + public Configuration CurrentConfiguration { get; set; } + + protected override async Task OnInitializedAsync() + { + FilterDateTo = DateTime.Now.Date.AddYears(1); + await InitializeList(); + CurrentConfiguration = (await savingsAPI.GetConfigurations()).FirstOrDefault(); + } + + + async void PastItems_Changed() + { + await InitializeList(); + StateHasChanged(); + } + + async void Zero_Changed() { await InitializeList(); StateHasChanged(); } - async void HideZero_Changed() + async void Change(DateTime? value, string name) { await InitializeList(); StateHasChanged(); - } - - async void Change(DateTime? value, string name) - { - await InitializeList(); - StateHasChanged(); - } - - - async Task InitializeList() - { + } + + + async Task InitializeList() + { materializedMoneyItems = await savingsAPI.GetSavings(null, FilterDateTo); - if (HidePastItems) + if (!ShowPastItems) { var lastBeforeToday = materializedMoneyItems.LastOrDefault(x => x.Date <= DateTime.Now.Date); if (lastBeforeToday != null) { materializedMoneyItems = materializedMoneyItems[Array.IndexOf(materializedMoneyItems, lastBeforeToday)..]; } - } - if(HideZero) + } + if(!ShowZero) { materializedMoneyItems = materializedMoneyItems.Where(x => x.Amount != 0).ToArray(); - } - } - - async Task AdjustRecurrency(MaterializedMoneyItem item) - { - if (item.EndPeriod) return; - var res = await dialogService.OpenAsync($"Recurrency Adjustment", - new Dictionary() { { "materializedItem", item } }, - new DialogOptions() { Width = "600px", Height = "300px" }); - await InitializeList(); - StateHasChanged(); - } - - async Task AdjustFixedItem(MaterializedMoneyItem item) - { - if (item.EndPeriod) return; - if (!item.FixedMoneyItemID.HasValue) return; - var itemToEdit = await savingsAPI.GetixedMoneyItem(item.FixedMoneyItemID.Value); - bool? res = await dialogService.OpenAsync($"Edit item", - new Dictionary() { { "fixedItemToEdit", itemToEdit }, { "isNew", false } }, - new DialogOptions() { Width = "600px" }); - if (res.HasValue && res.Value) - { - await InitializeList(); - StateHasChanged(); - } - } - - async Task SaveMaterializedHistory(DateTime date) - { - var res = await dialogService.Confirm($"Do you want to save the projection to the history until {date:dd/MM/yyyy}?", "Save the history", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }); - if (res.HasValue && res.Value) - { - await savingsAPI.PostSavingsToHistory(date); - await InitializeList(); - } - } - - async Task AddNew() - { - bool? res = await dialogService.OpenAsync($"Add new", - new Dictionary() { { "fixedItemToEdit", new Savings.Model.FixedMoneyItem() }, { "isNew", true } }, - new DialogOptions() { Width = "700px" }); - if (res.HasValue && res.Value) - { - await InitializeList(); - StateHasChanged(); - } - } - } -} + } + } + + async Task AdjustRecurrency(MaterializedMoneyItem item) + { + if (item.EndPeriod) return; + var res = await dialogService.OpenAsync($"Recurrency Adjustment", + new Dictionary() { { "materializedItem", item } }, + new DialogOptions() { Width = "600px", Height = "300px" }); + await InitializeList(); + StateHasChanged(); + } + + async Task AdjustFixedItem(MaterializedMoneyItem item) + { + if (item.EndPeriod) return; + if (!item.FixedMoneyItemID.HasValue) return; + var itemToEdit = await savingsAPI.GetixedMoneyItem(item.FixedMoneyItemID.Value); + bool? res = await dialogService.OpenAsync($"Edit item", + new Dictionary() { { "fixedItemToEdit", itemToEdit }, { "isNew", false } }, + new DialogOptions() { Width = "600px" }); + if (res.HasValue && res.Value) + { + await InitializeList(); + StateHasChanged(); + } + } + + async Task SaveMaterializedHistory(DateTime date) + { + var res = await dialogService.Confirm($"Do you want to save the projection to the history until {date:dd/MM/yyyy}?", "Save the history", new ConfirmOptions() { OkButtonText = "Yes", CancelButtonText = "No" }); + if (res.HasValue && res.Value) + { + await savingsAPI.PostSavingsToHistory(date); + await InitializeList(); + } + } + + async Task AddNew() + { + bool? res = await dialogService.OpenAsync($"Add new", + new Dictionary() { { "fixedItemToEdit", new Savings.Model.FixedMoneyItem() }, { "isNew", true } }, + new DialogOptions() { Width = "700px" }); + if (res.HasValue && res.Value) + { + await InitializeList(); + StateHasChanged(); + } + } + } +}