/// <summary> /// Returns a list of accounts associated with a list of collection /// </summary> /// <param name="collectionsIds">The list collections that is being requested</param> /// <param name="count">The number of transactions that is requested</param> /// <returns>A List of Account objects</returns> public List <Account> GetAccountIndex(List <string> collectionsIds, int count) { //get accounts List <Account> accounts = new List <Account>(); //get accountTypes AccountType type = new AccountType(); List <AccountType> accountTypes = type.GetAccountTypes(); foreach (string item in collectionsIds) { accounts.AddRange(GetAccountsEmpty(item)); } if (count > 0) { //get transactions ReportedTransaction reportedTransaction = new ReportedTransaction(); List <ReportedTransaction> transactions = reportedTransaction.GetTransactions(accounts.Select(x => x.Id).ToList(), count, collectionsIds); //assign transactions foreach (Account item in accounts) { item.ReportedTransactions = transactions.Where(x => x.AccountId == item.Id).ToList(); item.AccountType = accountTypes.Where(x => x.AccountTypeId == item.AccountTypeId).FirstOrDefault(); item.AccountType.Accounts = null; } } return(accounts); }
public List <ReportedTransaction> CleanNonTransactional(List <ReportedTransaction> reportedTransactions) { List <Account> accounts = reportedTransactions.Select(x => x.Account).Distinct().ToList(); List <ReportedTransaction> copy = new List <ReportedTransaction>(reportedTransactions.ToArray()); CFType type = new CFType(); List <CFType> types = new List <CFType>(); types.Add(new CFType("Loans")); types.Add(new CFType("Car Loan")); //4 phases //Convert interst on transactional account to bank charges CFType tempType = reportedTransactions.Select(x => x.CFType).Where(x => x.Name == "Bank Charges").FirstOrDefault(); foreach (ReportedTransaction item in copy.Where(x => x.Account.AccountType.Transactional == true && x.CFType.Name == "Interest")) { item.CFType = tempType; } //change bank charges and interest to the same CF Classification CFClassification tempClassification = reportedTransactions.Select(x => x.CFClassification).Where(x => x.Sign == -1).FirstOrDefault(); foreach (ReportedTransaction item in copy.Where(x => x.Account.AccountType.Transactional == true && x.CFType.Name == "Bank Charges" && x.CFClassification.Sign == 1)) { item.CFClassification = tempClassification; item.Amount = item.Amount * -1; } // convert transfer to non tranasactional items to payments foreach (ReportedTransaction item in copy.Where(x => x.Account.AccountType.Transactional && x.CFType.Id == "999")) { if (reportedTransactions.Where(x => x.Account.AccountType.Transactional == false && x.CFType.Id == "999" && x.Amount == item.Amount).Any()) { ReportedTransaction transaction = reportedTransactions.Where(x => x.Account.AccountType.Transactional == false && x.CFType.Id == "999" && x.Amount == item.Amount).FirstOrDefault(); switch (transaction.Account.AccountType.Name) { case "Personal Loan": item.CFType = types.Where(x => x.Name == "Loans").FirstOrDefault(); break; case "Car Loan": item.CFType = types.Where(x => x.Name == "Car Loan").FirstOrDefault(); break; } } } // strip out the non tranasactional accounts foreach (Account item in accounts.Where(x => x.AccountType.Transactional == false)) { foreach (ReportedTransaction t in reportedTransactions.Where(x => x.AccountId == item.Id)) { copy.Remove(t); } } foreach (ReportedTransaction item in copy) { item.Account = null; } return(copy); }
public TransactionComparison(double spent, double budgeted, ReportedTransaction transaction) { CFClassification = transaction.CFClassification; CFType = transaction.CFType; Budgeted = budgeted; Spent = spent; Remaining = budgeted - spent; CFClassificationId = transaction.CFClassification.Id; CFTypeId = transaction.CFType.Id; }
public BudgetTransactionComparison(string collectionsId) { Budget budget = new Budget(); BudgetItem = budget.GetBudget(collectionsId); ReportedTransaction reportedTransaction = new ReportedTransaction(); ReportedTransactions = CleanNonTransactional(reportedTransaction.GetTransactions(BudgetItem)); List <ReportedTransaction> reportedTransactions = CleanNonTransactional(reportedTransaction.GetTransactions(BudgetItem)); List <BudgetTransaction> budgetTransactions = BudgetItem.BudgetTransactions.ToList(); List <TransactionComparison> transactionList = new List <TransactionComparison>(); foreach (BudgetTransaction item in BudgetItem.BudgetTransactions) { item.CFType = new CFType(item.CFTypeId); item.CFClassification = new CFClassification(item.CFClassificationId); double spent = ReportedTransactions .Where(x => x.CFType.Id == item.CFTypeId && x.CFClassification.Id == item.CFClassificationId) .Select(x => x.Amount) .Sum(); ReportedTransaction transaction = reportedTransactions.Where(x => x.CFType.Id == item.CFTypeId && x.CFClassification.Id == item.CFClassificationId).FirstOrDefault(); reportedTransactions.Remove(transaction); double budgeted = budgetTransactions .Where(x => x.CFClassificationId == item.CFClassificationId && x.CFTypeId == item.CFTypeId) .Select(x => x.Amount) .Sum(); transactionList .Add(new TransactionComparison(spent, budgeted, item)); } foreach (ReportedTransaction item in reportedTransactions) { item.CFType = item.CFType; item.CFClassification = item.CFClassification; double spent = ReportedTransactions .Where(x => x.CFType.Id == item.CFType.Id && x.CFClassification.Id == item.CFClassification.Id) .Select(x => x.Amount) .Sum(); transactionList .Add(new TransactionComparison(spent, 0, item)); } TransactionComparisons = transactionList .GroupBy(p => new { p.CFClassificationId, p.CFTypeId }) .Select(g => g.First()) .ToList(); }
/// <summary> /// Amount that has actually been spent under the current period for a given collection /// </summary> /// <param name="collectionsId">Unique Id of a collection</param> /// <returns>The amount that has been spent in the current budgeting period (Total Actual Expenses)</returns> public double GetSpentAmount(string collectionsId) { try { Budget budget = GetBudgetNew(collectionsId); ReportedTransaction transaction = new ReportedTransaction(); //CFType type = new CFType(); //type = type.GetCFList(collectionsId).Where(x => x.Id == "999").FirstOrDefault(); List <ReportedTransaction> transactions = transaction.GetTransactions(budget); return(transactions .Where(x => x.CFClassification.Sign == -1) .Where(x => x.CFType.Id != "999") .Select(x => x.Amount) .Sum()); } catch { return(0); } }
public void GetTransactions() { ReportedTransaction reportedTransaction = new ReportedTransaction(); this.ReportedTransactions = reportedTransaction.GetTransactions(this.Id); }