using System; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Markup.Xaml; using PolyTrader.App.Avalonia.ViewModels; using PolyTrader.Core.Modularity; using PolyTrader.Modules.Accounting.Logic; using PolyTrader.Modules.Accounting.Models; using PolyTrader.Modules.Accounting.Persistence; using PolyTrader.Modules.Accounting.Services; using PolyTraderSharp; using PolyTraderSharp.Services; namespace PolyTrader.App.Avalonia.Views.Modules { /// /// Accounting: Periodenabrechnung mit KPI-Kacheln und Monatsübersicht, Ledger-Ansicht und /// Abruf-/Status-Tab. Layout vollständig in AccountingWindow.axaml. /// public partial class AccountingWindow : Window { private readonly ObservableCollection _monthly = new(); private readonly ObservableCollection _ledger = new(); private readonly ObservableCollection _runs = new(); private readonly TradingState _state = null!; private readonly AccountingReportService _reports = null!; private readonly ILedgerRepository _ledgerRepo = null!; private readonly IIngestRunRepository _runRepo = null!; private readonly AccountingIngestService _ingest = null!; private readonly TerminalLogger _logger = null!; private PeriodStatement? _statement; private CurrencyContext _currency = new("USDC", 1m, true, string.Empty); public AccountingWindow() => AvaloniaXamlLoader.Load(this); public AccountingWindow(IModuleUiHost host, TradingState state, AccountingReportService reports, ILedgerRepository ledgerRepo, IIngestRunRepository runRepo, AccountingIngestService ingest, TerminalLogger logger) : this() { this.FindControl("menuBar")!.Attach(host, "accounting.main", this); _state = state; _reports = reports; _ledgerRepo = ledgerRepo; _runRepo = runRepo; _ingest = ingest; _logger = logger; this.FindControl("gridMonthly")!.ItemsSource = _monthly; this.FindControl("gridLedger")!.ItemsSource = _ledger; this.FindControl("gridRuns")!.ItemsSource = _runs; var cbCurrency = this.FindControl("cbCurrency")!; cbCurrency.ItemsSource = new[] { "USDC", "USD", "EUR" }; cbCurrency.SelectedIndex = 0; // Vorbelegung wie bisher: laufender Monat. var now = DateTime.Now; this.FindControl("dtFrom")!.SelectedDate = new DateTime(now.Year, now.Month, 1); this.FindControl("dtTo")!.SelectedDate = now.Date; FillAccountCombos(); this.FindControl