feat(accounts): preview and confirm cross-year balance corrections (U12)
This commit is contained in:
@@ -1,39 +1,36 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
using Duempelkas.App.Services;
|
||||
namespace Duempelkas.App.Components.Dialogs;
|
||||
|
||||
public partial class EditCarryoverDialog
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
[Parameter]
|
||||
public decimal CurrentAmount { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<decimal> OnSave { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public EventCallback OnCancel { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private decimal amount;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Lifecycle
|
||||
|
||||
protected override void OnParametersSet() => amount = CurrentAmount;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Actions
|
||||
|
||||
private async Task Save() => await OnSave.InvokeAsync(amount);
|
||||
|
||||
private async Task Cancel() { if (modal != null) await modal.RequestCloseAsync(); else await OnCancel.InvokeAsync(); }
|
||||
|
||||
#endregion
|
||||
[Parameter] public decimal CurrentAmount { get; set; }
|
||||
[Parameter] public decimal InitialBalance { get; set; }
|
||||
[Parameter] public decimal CurrentEndBalance { get; set; }
|
||||
[Parameter] public int? Year { get; set; }
|
||||
[Parameter] public string AccountName { get; set; } = "Konto";
|
||||
[Parameter] public EventCallback<decimal> OnSave { get; set; }
|
||||
[Parameter] public EventCallback OnCancel { get; set; }
|
||||
private string amountText = string.Empty;
|
||||
private bool acknowledged;
|
||||
private bool initialized;
|
||||
private bool saving;
|
||||
private bool ValidAmount => BookingInput.TryBalance(amountText, out _);
|
||||
private decimal amount => BookingInput.TryBalance(amountText, out var value) ? value : CurrentAmount;
|
||||
private decimal Delta => amount - CurrentAmount;
|
||||
private static string Money(decimal value) => value.ToString("N2", System.Globalization.CultureInfo.GetCultureInfo("de-DE")) + " €";
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
if (!initialized) { amountText = CurrentAmount.ToString("0.00", System.Globalization.CultureInfo.GetCultureInfo("de-DE")); initialized = true; }
|
||||
}
|
||||
private void ChangeAmount(string value) { amountText = value; acknowledged = false; }
|
||||
private async Task Save()
|
||||
{
|
||||
if (saving || !ValidAmount || !acknowledged || Delta == 0m) return;
|
||||
saving = true;
|
||||
try { await OnSave.InvokeAsync(amount); }
|
||||
catch (Exception ex) { Toasts.Show("Die Korrektur konnte nicht gespeichert werden. Bitte den aktuellen Bestand prüfen.", ToastKind.Error, ex.Message); }
|
||||
finally { saving = false; }
|
||||
}
|
||||
private Task Cancel() => modal?.RequestCloseAsync() ?? Task.CompletedTask;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user