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? matchingBankTransactions; private IReadOnlyList accounts = []; private IReadOnlyList bookingTexts = []; private IEnumerable sortedBookingTexts => bookingTexts.OrderBy(t => t); protected override async Task OnInitializedAsync() { await LoadDataAsync(); await base.OnInitializedAsync(); } /// /// Re-run the auto-matcher and reload accounts / booking texts. Called from /// the parent (Home) after a statement import completes. /// 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(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(); } } }