private int GenerateLoanFromBank(BankAccountDoc account, LoanOverviewDto loanOverview) { decimal principal = 0; decimal interest = 0; foreach (var loan in account.Loans) { principal += loan.DeptAmount; interest += loan.DeptAmount * loan.InterestRate / 100 * (loan.NumberOfInterestPayments - loan.NextInterestPayment + 1) / 12; } loanOverview.Principal += principal; loanOverview.Interest += interest; return(account.Loans.Count()); }
private int GenerateMortgageFromBank(BankAccountDoc account, LoanOverviewDto mortgageOverview) { decimal principal = 0; decimal interest = 0; decimal commission = 0; foreach (var mortgage in account.Mortgages) { principal += mortgage.DeptAmount; interest += mortgage.InterestAmount; commission += mortgage.PrepaymentCommission; } mortgageOverview.Principal += principal; mortgageOverview.Interest += interest; mortgageOverview.Commission += commission; return(account.Mortgages.Count()); }
public async Task <OverviewDto> GetOverview(String userId) { if (!_validationHelper.ValidateUserPermissions(User, userId)) { throw new AuthenticationException(); } var expenses = new Dictionary <String, Decimal>(); //institution vs amount last 30 days var incomes = new Dictionary <String, Decimal>(); //institution vs amount last 30 days var cashFlowExpenses = new Dictionary <String, Decimal>(); //month vs amount last 6 months var cashFlowIncomes = new Dictionary <String, Decimal>(); //month vs amount last 6 months var institutions = new List <InstitutionOverviewDto>(); var mortgageOverview = new LoanOverviewDto(); var loanOverview = new LoanOverviewDto(); int numberOfMortgages = 0; int numberOfLoans = 0; Decimal netWorth = 0; InitCashFlowDictionary(cashFlowExpenses); InitCashFlowDictionary(cashFlowIncomes); var bankAccounts = await _bankAccountRepository.GetAccountsByUserId(userId); foreach (var account in bankAccounts) { GenerateNetWorthFromBank(account, incomes, expenses); GenerateCashFlowFromBank(account, cashFlowIncomes, cashFlowExpenses); numberOfMortgages += GenerateMortgageFromBank(account, mortgageOverview); numberOfLoans += GenerateLoanFromBank(account, loanOverview); netWorth += account.Balance; institutions.Add(new InstitutionOverviewDto { Label = account.Label, ProviderName = account.ProviderName, Balance = account.Balance }); } var creditCards = await _creditAccountRepository.GetCardsByUserId(userId); foreach (var account in creditCards) { GenerateNetWorthFromCredit(account, incomes, expenses); netWorth += incomes[account.LastDigits] - expenses[account.LastDigits]; institutions.Add(new InstitutionOverviewDto { Label = account.LastDigits, ProviderName = account.ProviderName, Balance = incomes[account.LastDigits] - expenses[account.LastDigits] }); } return(new OverviewDto { NetWorth = netWorth, ListOfInstitutions = institutions, NetWorthIncomes = incomes, NetWorthExpenses = expenses, CashFlowIncomes = cashFlowIncomes, CashFlowExpenses = cashFlowExpenses, MortgageOverview = mortgageOverview, LoanOverview = loanOverview, NumberOfMortgages = numberOfMortgages, NumberOfLoans = numberOfLoans, Loans = new List <Decimal[]>(), Mortgages = new List <Decimal[]>() }); }