AccountingNext/Schaad.Accounting.UI/Components/Pages/PendingBookings.razor.cs
Claudio Schaad 5b19972762 Pending bookings: hide a row once it is booked
Booking or splitting a pending bank transaction now removes its row from the
list instead of leaving it read-only. The list is not reloaded, so the booking
rules are not re-evaluated and edits on other rows are kept. The now unused
Transaction.ReadOnly flag is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 11:04:49 +01:00

83 lines
2.8 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.FluentUI.AspNetCore.Components;
using Schaad.Accounting.Interfaces;
using Schaad.Accounting.Models;
using Schaad.Accounting.UI.Components.Pages.Dialogs;
namespace Schaad.Accounting.UI.Components.Pages;
public partial class PendingBookings : ComponentBase
{
[Inject]
private IViewService viewService { get; set; } = null!;
[Inject]
private ITransactionRepository transactionRepository { get; set; } = null!;
[Inject]
private IBookingTextRepository bookingTextRepository { get; set; } = null!;
[Inject]
private IDialogService dialogService { get; set; } = null!;
[Inject]
private IToastService toastService { get; set; } = null!;
private List<Transaction>? matchingBankTransactions;
private IReadOnlyList<Account> accounts = [];
private IReadOnlyList<string> bookingTexts = [];
protected override async Task OnInitializedAsync()
{
await LoadDataAsync();
await base.OnInitializedAsync();
}
/// <summary>
/// Re-run the auto-matcher and reload accounts / booking texts. Called from
/// the parent (Home) after a statement import completes.
/// </summary>
public async Task RefreshAsync()
{
await LoadDataAsync();
StateHasChanged();
}
private async Task LoadDataAsync()
{
matchingBankTransactions = await viewService.MatchOpenBankTransactionsAsync();
accounts = await viewService.GetAccountViewListAsync();
bookingTexts = (await bookingTextRepository.GetBookingTextListAsync()).Select(b => b.Text).ToArray();
}
private async Task BookBankTransactionAsync(Transaction transaction)
{
if (string.IsNullOrEmpty(transaction.Text) || string.IsNullOrEmpty(transaction.TargetAccountId))
{
toastService.ShowToast(ToastIntent.Error, "Transaktion kann wegen fehlenden Daten nicht gespeichert werden!", 3000);
return;
}
await transactionRepository.SaveTransactionAsync(transaction);
// Only drop the booked row: reloading would re-run the booking rules and
// discard edits on the other rows.
matchingBankTransactions?.Remove(transaction);
}
private async Task SplitBankTransactionAsync(Transaction transaction)
{
var dialog = await dialogService.ShowDialogAsync<TransactionSplitDialog>(transaction, new DialogParameters()
{
Height = "500px",
Width = "800px",
Title = "Split Transaktion",
PreventDismissOnOverlayClick = true,
PreventScroll = true,
});
var result = await dialog.Result;
if (!result.Cancelled && result.Data != null)
{
matchingBankTransactions?.Remove(transaction);
}
}
}