コード例 #1
0
        /// <summary>
        /// Calculation and addition of the Automated Bank Charges field
        /// </summary>
        /// <param name="budgetId">The Id of the budget in question</param>
        /// <returns>New Budget Transaction with a completed Automated Bank Charges Calculation</returns>
        private BudgetTransaction AddAutomated(string budgetId)
        {
            double fees = 0;

            foreach (Account acc in Collections.Accounts.Where(x => x.AccountType.Transactional))
            {
                fees = fees + acc.MonthlyFee;
                double debt = acc.AccountLimit - acc.Available;
                if (debt > 0)
                {
                    fees = fees + debt * (acc.CreditRate / 12 / 100);
                }
            }
            fees = Math.Round(fees, 2);
            CFClassification classification = new CFClassification("Expense");
            CFType           typeT          = new CFType("Bank Charges");

            return(new BudgetTransaction
            {
                BudgetId = budgetId,
                Automated = true,
                BudgetTransactionId = Guid.NewGuid().ToString(),
                CFClassificationId = classification.Id,
                CFClassification = classification,
                CFType = typeT,
                CFTypeId = typeT.Id,
                Name = "Automated Bank Charges",
                Amount = fees,
            });
        }
コード例 #2
0
 /// <summary>
 /// Constuctor that returns a single CFClassification by Id	or name
 /// </summary>
 /// <param name="id">The Id or name of the CFClassification</param>
 public CFClassification(string id)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         try {
             CFClassification temp = _context.CFClassifications.Find(id);
             Id   = temp.Id;
             Name = temp.Name;
             Sign = temp.Sign;
             if (temp == null)
             {
                 temp = _context.CFClassifications.Where(x => x.Name == id).FirstOrDefault();
                 Id   = temp.Id;
                 Name = temp.Name;
                 Sign = temp.Sign;
             }
         }
         catch
         {
             try
             {
                 CFClassification temp = _context.CFClassifications.Where(x => x.Name == id).FirstOrDefault();
                 Id   = temp.Id;
                 Name = temp.Name;
                 Sign = temp.Sign;
             }
             catch
             {
                 Id   = "";
                 Name = "";
                 Sign = 0;
             }
         }
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public TransactionComparison(double spent, double budgeted, BudgetTransaction transaction)
 {
     CFClassification   = new CFClassification(transaction.CFClassificationId);
     CFType             = new CFType(transaction.CFTypeId);
     Budgeted           = budgeted;
     Spent              = spent;
     Remaining          = budgeted - spent;
     CFClassificationId = transaction.CFClassificationId;
     CFTypeId           = transaction.CFTypeId;
 }
コード例 #5
0
 private ReportedTransaction(AutomatedCashFlow auto, Account account)
 {
     CFType                     = new CFType(auto.CFTypeId);
     CFClassification           = new CFClassification(auto.CFClassificationId);
     Amount                     = auto.Amount;
     DateCaptured               = auto.DateCaptured;
     SourceOfExpense            = auto.SourceOfExpense;
     Account                    = account;
     Account.ManualCashFlows    = null;
     Account.AutomatedCashFlows = null;
     DateBooked                 = auto.DateBooked;
     Validated                  = auto.Validated;
 }
コード例 #6
0
 private ReportedTransaction(ManualCashFlow manual, Account account)
 {
     CFType                     = new CFType(manual.CFTypeId);
     CFClassification           = new CFClassification(manual.CFClassificationId);
     Amount                     = manual.Amount;
     DateCaptured               = manual.DateCaptured;
     SourceOfExpense            = manual.SourceOfExpense;
     Account                    = account;
     Account.ManualCashFlows    = null;
     Account.AutomatedCashFlows = null;
     DateBooked                 = manual.DateBooked;
     Validated                  = true;
 }
コード例 #7
0
 public void BankCharges(Collections collection)
 {
     try
     {
         Budget budget = collection.Budgets.Where(x => x.Simulation == false).OrderByDescending(x => x.EndDate).First();
         double fees   = 0;
         foreach (Account acc in collection.Accounts.Where(x => x.AccountType.Transactional == true))
         {
             fees = fees + acc.MonthlyFee;
             double debt = acc.AccountLimit - acc.Available;
             if (debt > 0)
             {
                 fees = fees + debt * (acc.CreditRate / 12 / 100);
             }
         }
         fees = Math.Round(fees, 2);
         budget.GetBudgetTransacions();
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             if (budget.BudgetTransactions.Where(x => x.CFType.Name == "Bank Charges" && x.Automated == true).Any())
             {
                 BudgetTransaction transaction = budget.BudgetTransactions.Where(x => x.CFType.Name == "Bank Charges" && x.Automated == true).FirstOrDefault();
                 transaction.Amount = fees;
                 _context.Entry(transaction).State = EntityState.Modified;
             }
             else
             {
                 CFClassification  classification = new CFClassification("Expense");
                 CFType            type           = new CFType("Bank Charges");
                 BudgetTransaction transaction    = new BudgetTransaction()
                 {
                     BudgetId            = budget.BudgetId,
                     Automated           = true,
                     BudgetTransactionId = Guid.NewGuid().ToString(),
                     CFClassificationId  = classification.Id,
                     CFTypeId            = type.Id,
                     Name   = "Automated Bank Charges",
                     Amount = fees,
                 };
                 _context.Add(transaction);
             }
             _context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         ExceptionCatcher catcher = new ExceptionCatcher();
         catcher.Catch(e.Message);
     }
 }
コード例 #8
0
 public ManualCashFlow(CFType cfId, CFClassification cfClass, double amount, DateTime dateBooked, string source, string userID, bool exp, string el)
 {
     CFType           = cfId;
     CFClassification = cfClass;
     Amount           = amount;
     DateBooked       = dateBooked;
     DateCaptured     = DateTime.Now;
     SourceOfExpense  = source;
     Expected         = exp;
     Id              = Guid.NewGuid().ToString();
     UserId          = userID;
     isDeleted       = false;
     ExpenseLocation = el;
 }
コード例 #9
0
        public void GetBudgetTransacions()
        {
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                BudgetTransactions = _context.BudgetTransactions.Where(x => x.BudgetId == this.BudgetId).ToList();
            }
            CFClassification        classification  = new CFClassification();
            List <CFClassification> classifications = classification.GetList();
            CFType        type  = new CFType();
            List <CFType> types = type.GetCFList(this.CollectionId);

            foreach (BudgetTransaction item in BudgetTransactions)
            {
                item.CFClassification = classifications.Where(x => x.Id == item.CFClassificationId).FirstOrDefault();
                item.CFType           = types.Where(x => x.Id == item.CFTypeId).FirstOrDefault();
            }
        }
コード例 #10
0
        public void AddAccountChange(ManualCashFlow flow)
        {
            AccountChange change = new AccountChange();

            change.AccountChangeId = Guid.NewGuid().ToString();
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                Account          account        = _context.Account.Find(flow.AccountId);
                CFClassification classification = _context.CFClassifications.Find(flow.CFClassificationId);
                change.UpdatedBalance         = Math.Round(account.Available + (flow.Amount * classification.Sign), 2);
                account.Available             = change.UpdatedBalance;
                change.DateAdded              = DateTime.Now;
                change.ManualCashFlowId       = flow.Id;
                _context.Entry(account).State = EntityState.Modified;
                _context.AccountChange.Add(change);
                _context.SaveChanges();
            }
        }
コード例 #11
0
ファイル: Account.cs プロジェクト: kylesaffy/DailyForecaster
        public List <Account> GetAccountsWithCF(string collectionsId, int count)
        {
            CFClassification        classification  = new CFClassification();
            List <CFClassification> classifications = classification.GetList();
            List <Account>          accounts        = GetAccountsEmpty(collectionsId);
            Institution             institution     = new Institution();
            List <Institution>      institutions    = institution.GetInstitutions();
            AccountType             type            = new AccountType();
            List <AccountType>      types           = type.GetAccountTypes();
            ManualCashFlow          manual          = new ManualCashFlow();
            AutomatedCashFlow       automated       = new AutomatedCashFlow();
            Collections             collection      = new Collections();

            foreach (Account item in accounts)
            {
                item.Institution = institutions
                                   .Where(x => x.Id == item.InstitutionId)
                                   .FirstOrDefault();
                item.AccountType = types
                                   .Where(x => x.AccountTypeId == item.AccountTypeId)
                                   .FirstOrDefault();
                item.AccountType.Accounts = null;
                item.ManualCashFlows      = manual.GetManualCashFlows(item.Id, count);
                item.AutomatedCashFlows   = automated.GetAutomatedCashFlows(item.Id, count);
                foreach (ManualCashFlow flow in item.ManualCashFlows)
                {
                    flow.CFClassification = classifications.Where(x => x.Id == flow.CFClassificationId).FirstOrDefault();;
                    flow.CFClassification.ManualCashFlows = null;
                }
                foreach (AutomatedCashFlow flow in item.AutomatedCashFlows)
                {
                    flow.CFClassification = classifications.Where(x => x.Id == flow.CFClassificationId).FirstOrDefault();;
                    flow.CFClassification.ManualCashFlows = null;
                }
                item.Collections = collection.GetCollections(collectionsId);
                //foreach(ManualCashFlow flow in item.ManualCashFlows)
                //{
                //	flow.Account.ManualCashFlows = null;
                //}
            }
            return(accounts);
        }
コード例 #12
0
        public UnseenModel(string userId)
        {
            AspNetUsers users = new AspNetUsers();
            string      id    = users.getUserId(userId);

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                List <string> collections = _context
                                            .UserCollectionMapping
                                            .Where(x => x.Id == id)
                                            .Select(x => x.CollectionsId)
                                            .ToList();
                List <string> accountsStr = _context
                                            .Account
                                            .Where(Acc => collections.Contains(Acc.CollectionsId))
                                            .Select(x => x.Id)
                                            .ToList();
                Account account = new Account();
                Accounts = new List <Account>();
                foreach (string item in collections)
                {
                    Accounts
                    .AddRange(account.GetAccounts(item));
                }
                AutomatedCashFlow automatedCash  = new AutomatedCashFlow();
                ManualCashFlow    manualCash     = new ManualCashFlow();
                CFType            type           = new CFType();
                CFClassification  classification = new CFClassification();
                AutomatedCashFlows = automatedCash
                                     .GetAutomatedCashFlowsUnseen(accountsStr);
                ManualCashFlows = manualCash
                                  .GetManualCahFlowsUnseen(accountsStr);
                CFTypes = type
                          .GetCFList(collections)
                          .GroupBy(x => x.Id)
                          .Select(x => x.First())
                          .ToList();
                CFClassifications = classification
                                    .GetList();
            }
        }
コード例 #13
0
        public List <ReportedTransaction> GetTransactions(List <string> accountIds, int count, List <string> collectionsIds)
        {
            //get transaction
            List <ManualCashFlow>    manualCashFlows    = new List <ManualCashFlow>();
            List <AutomatedCashFlow> automatedCashFlows = new List <AutomatedCashFlow>();

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                manualCashFlows = _context
                                  .ManualCashFlows
                                  .Where(cf => accountIds.Contains(cf.AccountId))
                                  .Where(x => x.AutomatedCashFlow == null)
                                  .OrderByDescending(x => x.DateBooked)
                                  .Take(count)
                                  .ToList();
                automatedCashFlows = _context
                                     .AutomatedCashFlows
                                     .Where(cf => accountIds.Contains(cf.AccountId))
                                     .OrderByDescending(x => x.DateBooked)
                                     .Take(count)
                                     .ToList();
            }
            //get type and classification lists
            CFType                  type            = new CFType();
            CFClassification        classification  = new CFClassification();
            List <CFType>           types           = type.GetCFList(collectionsIds);
            List <CFClassification> classifications = classification.GetList();
            //reconfigure cash flows
            List <ReportedTransaction> transactions = new List <ReportedTransaction>();

            foreach (AutomatedCashFlow item in automatedCashFlows)
            {
                transactions.Add(new ReportedTransaction(item, types, classifications));
            }
            foreach (ManualCashFlow item in manualCashFlows)
            {
                transactions.Add(new ReportedTransaction(item, types, classifications));
            }
            return(transactions);
        }        /// <summary>
コード例 #14
0
 /// <summary>
 /// Return a specific instance of the object
 /// </summary>
 /// <param name="Id">Id of the instance</param>
 public SimulationAssumptions(string Id)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         SimulationAssumptions a = _context.SimulationAssumptions.Find(Id);
         SimulationAssumptionsId = a.SimulationAssumptionsId;
         NumberOfMonths          = a.NumberOfMonths;
         Bonus              = a.Bonus;
         BonusMonth         = a.BonusMonth;
         BonusAmount        = a.BonusAmount;
         Increase           = a.Increase;
         IncreaseMonth      = a.IncreaseMonth;
         IncreasePercentage = a.IncreasePercentage;
         Recurring          = a.Recurring;
         ChangeDate         = a.ChangeDate;
         CFClassification   = new CFClassification(a.CFClassificationId);
         CFClassificationId = a.CFClassificationId;
         CFType             = new CFType(a.CFTypeId);
         CFTypeId           = a.CFTypeId;
         Type           = a.Type;
         SimualtionName = a.SimualtionName;
     }
 }
コード例 #15
0
        public ReturnModel AddTransfer(TransferObject obj)
        {
            CFClassification        classification  = new CFClassification();
            List <CFClassification> classifications = classification.GetList();
            ManualCashFlow          to = new ManualCashFlow()
            {
                Id = Guid.NewGuid().ToString(),
                CFClassificationId = classifications.Where(x => x.Sign == 1).Select(x => x.Id).FirstOrDefault(),
                CFTypeId           = "999",
                Amount             = obj.Amount,
                SourceOfExpense    = "Transfer",
                Description        = "Transfer",
                DateBooked         = obj.DateBooked,
                DateCaptured       = DateTime.Now,
                AccountId          = obj.TransferTo,
            };
            ManualCashFlow from = new ManualCashFlow()
            {
                Id = Guid.NewGuid().ToString(),
                CFClassificationId = classifications.Where(x => x.Sign == -1).Select(x => x.Id).FirstOrDefault(),
                CFTypeId           = "999",
                SourceOfExpense    = "Transfer",
                Description        = "Transfer",
                Amount             = obj.Amount,
                DateBooked         = obj.DateBooked,
                DateCaptured       = DateTime.Now,
                AccountId          = obj.TransferFrom,
            };

            to.Save();
            from.Save();
            return(new ReturnModel()
            {
                result = true
            });
        }
コード例 #16
0
        private void Build()
        {
            this.Collections = new Collections(this.CollectionsId);
            // Get base information
            Budget budget = Collections.Budgets.Where(x => x.Simulation == false).OrderByDescending(x => x.StartDate).FirstOrDefault();

            this.Collections.Budgets = null;
            Account account = new Account();

            this.Collections.Accounts = account.GetAccounts(this.CollectionsId);
            foreach (Account acc in Collections.Accounts)
            {
                acc.ReportedTransactions = null;
                acc.AutomatedCashFlows   = null;
                acc.ManualCashFlows      = null;
                acc.Institution          = null;
            }
            //this.SimulationAssumptions = new SimulationAssumptions(SimulationAssumptionsId);
            this.Budgets = new List <Budget>();
            CFClassification        cf     = new CFClassification();
            List <CFClassification> cfList = cf.GetList();
            CFType        type             = new CFType();
            List <CFType> typeList         = type.GetCFList(CollectionsId);

            switch (this.Collections.DurationType)
            {
            case "Month":
                // Get Date of starting
                DateTime date = DateTime.Now;
                date = new DateTime(date.Year, date.Month, this.Collections.ResetDay);
                if (date > DateTime.Now)
                {
                    date.AddMonths(1);
                }
                // Set Simulation Object
                Simulation simulation = new Simulation();
                // Loop for the number of Months
                for (int i = 0; i < SimulationAssumptions.NumberOfMonths; i++)
                {
                    Budget sim = new Budget(CollectionsId, date.AddMonths(i), date.AddMonths(i + 1), true);
                    sim.AccountStates = new List <AccountState>();
                    // If first month, then pull BudgetTransactions from actual BudgetTransactions ELSE pull from previous month
                    if (i == 0)
                    {
                        sim.BudgetTransactions = budget.BudgetTransactions.Where(x => x.Automated == false).ToList();
                        foreach (BudgetTransaction item in sim.BudgetTransactions)
                        {
                            item.CFClassification = cfList.Where(x => x.Id == item.CFClassificationId).FirstOrDefault();
                            item.CFType           = typeList.Where(x => x.Id == item.CFTypeId).FirstOrDefault();
                        }
                        foreach (Account item in Collections.Accounts)
                        {
                            sim.AccountStates.Add(new AccountState(item, sim.BudgetId));
                        }
                    }
                    else
                    {
                        sim.BudgetTransactions = this.Budgets[i - 1].BudgetTransactions.Where(x => x.Automated == false).ToList();
                        foreach (BudgetTransaction item in sim.BudgetTransactions)
                        {
                            item.CFClassification = cfList.Where(x => x.Id == item.CFClassificationId).FirstOrDefault();
                        }
                        foreach (Account item in this.Collections.Accounts)
                        {
                            sim.AccountStates.Add(new AccountState(item, sim.BudgetId, this
                                                                   .Budgets[i - 1]
                                                                   .AccountStates
                                                                   .Where(x => x.AccountId == item.Id)
                                                                   .FirstOrDefault()));
                        }
                    }
                    //=======================================================================================================================================================
                    // Bonus Handling
                    //=======================================================================================================================================================
                    // Add Bonus multiple if the correct month
                    if (SimulationAssumptions.Bonus && SimulationAssumptions.BonusMonth == date.AddMonths(i).Month)
                    {
                        foreach (BudgetTransaction transaction in sim.BudgetTransactions.Where(x => x.CFType.Name == "Salary"))
                        {
                            transaction.Amount = transaction.Amount * SimulationAssumptions.BonusAmount;
                        }
                    }
                    // Strip Bonus Amount out if following Month
                    if (SimulationAssumptions.Bonus && SimulationAssumptions.BonusMonth == date.AddMonths(i + 1).Month)
                    {
                        foreach (BudgetTransaction transaction in sim.BudgetTransactions.Where(x => x.CFType.Name == "Salary"))
                        {
                            transaction.Amount = this.Budgets[i - 1].BudgetTransactions.Where(x => x.Name == transaction.Name).Select(x => x.Amount).FirstOrDefault();
                        }
                    }
                    //=======================================================================================================================================================
                    // Increase Handling
                    //=======================================================================================================================================================
                    // Add Increase if correct month (only add apportionment of previous month if not bonus month)
                    if (SimulationAssumptions.Increase && SimulationAssumptions.IncreaseMonth == date.AddMonths(i).Month)
                    {
                        // if Bonus month == Increase month then use previous month
                        if (SimulationAssumptions.IncreaseMonth == SimulationAssumptions.BonusMonth)
                        {
                            foreach (BudgetTransaction transaction in sim.BudgetTransactions.Where(x => x.CFType.Name == "Salary"))
                            {
                                transaction.Amount = this
                                                     .Budgets[i - 1]
                                                     .BudgetTransactions.Where(x => x.Name == transaction.Name)
                                                     .Select(x => x.Amount)
                                                     .FirstOrDefault()
                                                     * (1 + SimulationAssumptions.IncreasePercentage);
                            }
                        }
                        else
                        {
                            foreach (BudgetTransaction transaction in sim.BudgetTransactions.Where(x => x.CFType.Name == "Salary"))
                            {
                                transaction.Amount = transaction.Amount * (1 + SimulationAssumptions.IncreasePercentage);
                            }
                        }
                    }
                    //=======================================================================================================================================================
                    // Inflation Handling
                    //=======================================================================================================================================================
                    if (date.AddMonths(i).Month == 1)
                    {
                        foreach (BudgetTransaction item in sim.BudgetTransactions.Where(x => x.CFType.Infaltion))
                        {
                            item.Amount = item.Amount * 1.06;
                        }
                    }
                    //=======================================================================================================================================================
                    // Cashflow Handling
                    //=======================================================================================================================================================
                    if (i > 0)
                    {
                        //double fees = 0;
                        //foreach(Account acc in Collections.Accounts.Where(x=>x.AccountType.Transactional))
                        //{
                        //	fees = fees + acc.MonthlyFee;
                        //	double debt = acc.AccountLimit - acc.Available;
                        //	if (debt > 0)
                        //	{
                        //		fees = fees + debt * (acc.CreditRate / 12 / 100);
                        //	}
                        //}
                        //fees = Math.Round(fees, 2);
                        //CFClassification classification = new CFClassification("Expense");
                        //CFType typeT = new CFType("Bank Charges");
                        //sim.BudgetTransactions.Add(new BudgetTransaction
                        //{
                        //	BudgetId = sim.BudgetId,
                        //	Automated = true,
                        //	BudgetTransactionId = Guid.NewGuid().ToString(),
                        //	CFClassificationId = classification.Id,
                        //	CFClassification = classification,
                        //	CFType = typeT,
                        //	CFTypeId = typeT.Id,
                        //	Name = "Automated Bank Charges",
                        //	Amount = fees,
                        //});
                        sim.BudgetTransactions.Add(AddAutomated(sim.BudgetId));
                        sim.AccountStates
                        .Where(x => x.Amount < 0 && x.Account.AccountType.Transactional)
                        .OrderByDescending(x => x.Account.CreditRate)
                        .FirstOrDefault()
                        .Update(sim.BudgetTransactions.Sum(x => x.Amount * x.CFClassification.Sign));
                    }
                    this.Budgets.Add(sim);
                }
                break;
            }
        }
コード例 #17
0
        private void Payment()
        {
            CFClassification        cf     = new CFClassification();
            List <CFClassification> cfList = cf.GetList();
            CFType        type             = new CFType();
            List <CFType> typeList         = type.GetCFList(CollectionsId);

            if (SimulationAssumptions.Recurring)
            {
                for (int i = 0; i < SimulationAssumptions.NumberOfMonths; i++)
                {
                    Budgets[i].BudgetTransactions.Add(new BudgetTransaction
                    {
                        Amount              = SimulationAssumptions.Amount,
                        Automated           = true,
                        BudgetId            = Budgets[i].BudgetId,
                        BudgetTransactionId = Guid.NewGuid().ToString(),
                        CFClassificationId  = cfList.Where(x => x.Sign == 1).FirstOrDefault().Id,
                        CFClassification    = cfList.Where(x => x.Sign == 1).FirstOrDefault(),
                        CFTypeId            = "999",
                        CFType              = typeList.Where(x => x.Id == "999").FirstOrDefault(),
                        Name = "Recurring Payment",
                    });
                    Budgets[i].BudgetTransactions.Add(new BudgetTransaction
                    {
                        Amount              = SimulationAssumptions.Amount,
                        Automated           = true,
                        BudgetId            = Budgets[i].BudgetId,
                        BudgetTransactionId = Guid.NewGuid().ToString(),
                        CFClassificationId  = cfList.Where(x => x.Sign == 1).FirstOrDefault().Id,
                        CFClassification    = cfList.Where(x => x.Sign == -1).FirstOrDefault(),
                        CFTypeId            = "999",
                        CFType              = typeList.Where(x => x.Id == "999").FirstOrDefault(),
                        Name = "Recurring Payment",
                    });
                    Budgets[i].AccountStates
                    .Where(x => x.Amount < 0 && x.Account.AccountType.Transactional)
                    .OrderByDescending(x => x.Account.CreditRate)
                    .FirstOrDefault()
                    .Update(-SimulationAssumptions.Amount);
                    Budgets[i].AccountStates
                    .Where(x => x.AccountId == SimulationAssumptions.AccountId)
                    .FirstOrDefault()
                    .Update(SimulationAssumptions.Amount);
                }
            }
            else
            {
                for (int i = 0; i < SimulationAssumptions.NumberOfMonths; i++)
                {
                    if (SimulationAssumptions.ChangeDate == Budgets[i].StartDate)
                    {
                        Budgets[i].BudgetTransactions.Add(new BudgetTransaction
                        {
                            Amount              = SimulationAssumptions.Amount,
                            Automated           = true,
                            BudgetId            = Budgets[i].BudgetId,
                            BudgetTransactionId = Guid.NewGuid().ToString(),
                            CFClassificationId  = cfList.Where(x => x.Sign == 1).FirstOrDefault().Id,
                            CFClassification    = cfList.Where(x => x.Sign == 1).FirstOrDefault(),
                            CFTypeId            = "999",
                            CFType              = typeList.Where(x => x.Id == "999").FirstOrDefault(),
                            Name = "Recurring Payment",
                        });
                        Budgets[i].BudgetTransactions.Add(new BudgetTransaction
                        {
                            Amount              = SimulationAssumptions.Amount,
                            Automated           = true,
                            BudgetId            = Budgets[i].BudgetId,
                            BudgetTransactionId = Guid.NewGuid().ToString(),
                            CFClassificationId  = cfList.Where(x => x.Sign == 1).FirstOrDefault().Id,
                            CFClassification    = cfList.Where(x => x.Sign == -1).FirstOrDefault(),
                            CFTypeId            = "999",
                            CFType              = typeList.Where(x => x.Id == "999").FirstOrDefault(),
                            Name = "Recurring Payment",
                        });
                        Budgets[i].AccountStates
                        .Where(x => x.Amount < 0 && x.Account.AccountType.Transactional)
                        .OrderByDescending(x => x.Account.CreditRate)
                        .FirstOrDefault()
                        .Update(-SimulationAssumptions.Amount);
                        Budgets[i].AccountStates
                        .Where(x => x.AccountId == SimulationAssumptions.AccountId)
                        .FirstOrDefault()
                        .Update(SimulationAssumptions.Amount);
                    }
                }
            }
        }
コード例 #18
0
        public async Task <bool> UpdateTransactions()
        {
            //Invoke Classes
            CFClassification       classification    = new CFClassification();
            YodleeTransactionModel transactionModel  = new YodleeTransactionModel();
            Collections            collection        = new Collections();
            YodleeTransactionType  transactionType   = new YodleeTransactionType();
            ManualCashFlow         manualCash        = new ManualCashFlow();
            AutomatedCashFlow      automatedCashFlow = new AutomatedCashFlow();
            //Get Static Lists
            List <Collections>      collections     = collection.GetCollections("", "");
            List <CFClassification> classifications = classification.GetList();

            foreach (Collections item in collections.Where(x => x.Accounts.Any()))
            {
                AutomateReturnList returnList = new AutomateReturnList();
                returnList.automateReturns = new List <AutomateReturn>();
                if (item.Accounts.Where(x => x.AccountIdentifier != null).Any())
                {
                    YodleeModel yodlee = new YodleeModel();
                    string      token  = await yodlee.getToken(item.CollectionsId, "");

                    List <YodleeTransactionLevel> transactions = await transactionModel.GetYodleeTransactions(item.CollectionsId, token);

                    if (transactions != null)
                    {
                        DateTime smallest = transactions.Select(x => x.transactionDate).Min();
                        if (smallest > DateTime.MinValue)
                        {
                            smallest = smallest.AddDays(-3);
                        }
                        List <CFType> yodleeTypes = await transactionType.YodleeTransform(token, item.CollectionsId);

                        foreach (Account account in item.Accounts.Where(x => x.YodleeId != 0))
                        {
                            Account tempAccount = account;
                            List <ManualCashFlow> manualFlows = manualCash.GetManualCashFlows(account.Id);
                            foreach (ManualCashFlow m in manualFlows)
                            {
                                m.CFClassification = classifications.Where(x => x.Id == m.CFClassificationId).FirstOrDefault();
                            }
                            account.AutomatedCashFlows = automatedCashFlow.GetAutomatedCashFlows(account.Id, smallest, DateTime.Now.AddDays(1));
                            foreach (YodleeTransactionLevel transaction in transactions.Where(x => x.accountId == account.YodleeId))
                            {
                                if (!account.AutomatedCashFlows.Where(x => x.YodleeId == transaction.id).Any())
                                {
                                    ManualCashFlow manualCashFlow = manualFlows
                                                                    .Where(x => x.AutomatedCashFlowId == null)
                                                                    .Where(x => x.Amount == transaction.amount.amount && x.CFClassification.Name.ToLower() == transaction.categoryType.ToLower() && x.DateBooked > transaction.transactionDate.AddDays(-2) && x.DateBooked < transaction.transactionDate.AddDays(5))
                                                                    .FirstOrDefault();
                                    try
                                    {
                                        returnList.automateReturns.Add(AddTransaction(transaction, account.Id, yodleeTypes, manualCashFlow, classifications, tempAccount));
                                    }
                                    catch (Exception e)
                                    {
                                        ExceptionCatcher catcher = new ExceptionCatcher();
                                        catcher.Catch(e.Message + ";" + JsonConvert.SerializeObject(transaction) + ";" + JsonConvert.SerializeObject(manualCashFlow) + "");
                                    }
                                    if (manualCashFlow != null)
                                    {
                                        manualFlows.Remove(manualCashFlow);
                                    }
                                }
                            }
                            //item.Accounts.Where(x=>x.Id == account.Id).FirstOrDefault() = tempAccount;
                        }
                        try
                        {
                            List <AccountChange>     accChangeList   = new List <AccountChange>();
                            List <AutomatedCashFlow> cashFlows       = new List <AutomatedCashFlow>();
                            List <ManualCashFlow>    manualCashFlows = new List <ManualCashFlow>();
                            //ac
                            foreach (AutomateReturn returnItem in returnList.automateReturns)
                            {
                                if (returnItem.AccountChange.AccountChangeId != "")
                                {
                                    returnItem.AccountChange.Account           = null;
                                    returnItem.AccountChange.AutomatedCashFlow = null;
                                    accChangeList.Add(returnItem.AccountChange);
                                }
                                returnItem.AutomatedCashFlow.Account          = null;
                                returnItem.AutomatedCashFlow.CFClassification = null;
                                cashFlows.Add(returnItem.AutomatedCashFlow);
                                if (returnItem.ManualCashFlow.Id != "")
                                {
                                    manualCashFlows.Add(returnItem.ManualCashFlow);
                                }
                            }
                            using (FinPlannerContext _context = new FinPlannerContext())
                            {
                                _context.AccountChange.AddRange(accChangeList);
                                _context.AutomatedCashFlows.AddRange(cashFlows);
                                foreach (ManualCashFlow manual in manualCashFlows)
                                {
                                    _context.Entry(manual).State = EntityState.Modified;
                                }
                                _context.SaveChanges();
                            }
                        }
                        catch (Exception e)
                        {
                            ExceptionCatcher catcher = new ExceptionCatcher();
                            catcher.Catch(e.Message);
                        }
                    }
                }
            }
            return(true);
        }