AccountingNext/Schaad.Accounting.UI/Components/Pages/PendingBookings.razor.cs
Claudio Schaad 97bf85d6a8 PR U-10: split Home into StatementImport and PendingBookings
Home shrinks from ~200-line codebehind + 100-line markup to a
10-line orchestrator holding a @ref to <PendingBookings/> and
wiring <StatementImport OnImported="RefreshPendingAsync"/> to it.

Also renames IsCanceled -> cancelRequested and clears the Files
dictionary after each import batch.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-06 16:29:51 +02:00

81 lines
2.6 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);
transaction.ReadOnly = true;
}
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)
{
await LoadDataAsync();
}
}
}