public List <DataSerie> GetSubClassExpensesPerMonth() { var subclasses = subclassRepository.GetSubClassList(); var transactions = viewService.GetTransactionViewList().Where(a => a.TargetAccount.Class == ClassIds.Expenses).ToList(); var list = new List <DataSerie>(); var newestTransaction = transactions.OrderByDescending(t => t.ValueDate).FirstOrDefault(); var maxMonth = newestTransaction?.ValueDate.Month ?? 12; // Group by subclass foreach (var grp in transactions.GroupBy(a => a.TargetAccount.SubClass).Select(a => new { Key = a.Key, List = a.ToList() })) { // Sum subclass transactions per month var groupedByMonth = grp.List.GroupBy(g => g.ValueDate.Month).ToDictionary(g => g.Key, g => g.ToList().Sum(s => s.Value)); EnsureEntryForEveryMonth(groupedByMonth, maxMonth); var subClass = subclasses.FirstOrDefault(s => s.Number == grp.List.First().TargetAccount.SubClass); list.Add( new DataSerie( subClass.Name, groupedByMonth.OrderBy(o => o.Key).Select(o => o.Value).ToList(), grp.List.First().TargetAccount.SubClass.ToString() ) ); } return(list); }
public IActionResult Expenses() { ViewData["Title"] = "Ausgaben"; var subclassNumber = ClassIds.Expenses * 10; var expenses = subclassRepository.GetSubClassList().Where(s => s.Number >= subclassNumber); if (expenses.Count() == 1) { return(Redirect("ExpensesDetail/" + expenses.First().Number)); } else { return(View()); } }
/// <summary> /// Load accounts and calculates their balances /// </summary> public List <AccountDataset> GetAccountViewList() { var accounts = accountRepository.GetAccountList(); var transactionList = GetTransactionViewList(); var subClassNameByNumber = subclassRepository.GetSubClassList().ToDictionary(s => s.Number, s => s.Name); var settings = settingsService.GetSettings(); var accountList = accounts.Select( a => new AccountDataset( account: a, balance: GetBalanceInAccountCurrency(a, transactionList), balanceCHF: GetCurrentBalanceInCHF(a, transactionList), startBalanceCHF: fxService.ConvertCurrency(a.StartBalance, a.Currency, "CHF", settings.FixerIoApiKey), className: subclassRepository.GetClass(a.Class), subClassName: subClassNameByNumber[a.SubClass] ) ) .ToList(); return(accountList.OrderBy(a => a.Number).ToList()); }