Exemplo n.º 1
0
        public ReturnModel UpdateAutomated(string manualcashflow)
        {
            CFType            type = new CFType();
            AutomatedCashFlow automatedCashFlow = getTransaction(this.ID);
            Account           account           = new Account(automatedCashFlow.AccountId);
            string            collectionsId     = account.CollectionsId;
            List <CFType>     types             = type.GetCFList(collectionsId);

            types.Add(new CFType {
                Id = "999"
            });
            if (manualcashflow != null)
            {
                ManualCashFlow mancf = new ManualCashFlow();
                mancf.updateTransaction(manualcashflow, this.ID);
            }
            if (!types.Any(x => x.Id == this.CFTypeId))
            {
                type = type.CreateCFType(collectionsId, this.CFTypeId);
                automatedCashFlow.CFTypeId = type.Id;
            }
            else
            {
                automatedCashFlow.CFTypeId = this.CFTypeId;;
            }
            automatedCashFlow.Validated       = this.Validated;
            automatedCashFlow.SourceOfExpense = this.SourceOfExpense;
            return(updateTransaction(automatedCashFlow));
        }
Exemplo n.º 2
0
 private ReportedTransaction(ManualCashFlow manual, List <CFType> types, List <CFClassification> classifications)
 {
     CFType           = types.Where(x => x.Id == manual.CFTypeId).FirstOrDefault();
     CFClassification = classifications.Where(x => x.Id == manual.CFClassificationId).FirstOrDefault();
     Amount           = manual.Amount;
     DateCaptured     = manual.DateCaptured;
     SourceOfExpense  = manual.SourceOfExpense;
     AccountId        = manual.AccountId;
     DateBooked       = manual.DateBooked;
     Validated        = true;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
 public void updateTransaction(string manId, string autoId)
 {
     try
     {
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             ManualCashFlow man = _context.ManualCashFlows.Find(manId);
             man.AutomatedCashFlowId   = autoId;
             _context.Entry(man).State = EntityState.Modified;
             _context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         ExceptionCatcher exceptionCatcher = new ExceptionCatcher();
         exceptionCatcher.Catch(e.Message);
     }
 }
Exemplo n.º 6
0
        public ManualCashFlow(ManualCashFlow flow)
        {
            AspNetUsers users = new AspNetUsers();

            CFTypeId           = flow.CFTypeId;
            CFClassificationId = flow.CFClassificationId;
            Amount             = flow.Amount;
            DateBooked         = flow.DateBooked;
            DateCaptured       = DateTime.Now;
            SourceOfExpense    = flow.SourceOfExpense;
            Expected           = flow.Expected;
            Id              = Guid.NewGuid().ToString();
            UserId          = users.getUserId(flow.UserId);
            isDeleted       = false;
            ExpenseLocation = flow.ExpenseLocation;
            AccountId       = flow.AccountId;
            Description     = flow.Description;
            ExpenseLocation = flow.ExpenseLocation;
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
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();
            }
        }
Exemplo n.º 9
0
        public List <ReportedTransaction> GetTransactions(string AccountId)
        {
            AutomatedCashFlow          automatedCashFlows   = new AutomatedCashFlow();
            ManualCashFlow             manualCashFlow       = new ManualCashFlow();
            List <ReportedTransaction> reportedTransactions = new List <ReportedTransaction>();
            List <AutomatedCashFlow>   auto = automatedCashFlows.GetAutomatedCashFlows(AccountId, 10000);
            Account account = new Account();

            account = account.GetAccount(AccountId, false);
            List <ManualCashFlow> manual = manualCashFlow.GetManualCashFlows(AccountId);

            manual = manual.Where(x => x.AutomatedCashFlowId == null).ToList();
            foreach (AutomatedCashFlow automated in auto)
            {
                reportedTransactions.Add(new ReportedTransaction(automated, account));
            }
            foreach (ManualCashFlow man in manual)
            {
                reportedTransactions.Add(new ReportedTransaction(man, account));
            }
            return(reportedTransactions);
        }
Exemplo n.º 10
0
        public ReturnModel Save()
        {
            ManualCashFlow flow        = new ManualCashFlow(this);
            ReturnModel    returnModel = new ReturnModel();

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.Add(flow);
                try
                {
                    _context.SaveChanges();
                    AccountChange change = new AccountChange();
                    change.AddAccountChange(flow);
                    returnModel.result = true;
                    return(returnModel);
                }
                catch (Exception e)
                {
                    returnModel.returnStr = e.Message;
                    returnModel.result    = false;
                    return(returnModel);
                }
            }
        }
Exemplo n.º 11
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
            });
        }
Exemplo n.º 12
0
        public AutomateReturn AddTransaction(YodleeTransactionLevel transaction, string accId, List <CFType> types, ManualCashFlow manual, List <CFClassification> classifications, Account account)
        {
            AutomateReturn automateReturn = new AutomateReturn();

            automateReturn.AutomatedCashFlow = new AutomatedCashFlow()
            {
                ID                 = Guid.NewGuid().ToString(),
                AccountId          = accId,
                Amount             = transaction.amount.amount,
                CFClassificationId = GetCFClassification(transaction, classifications),
                CFTypeId           = types.Where(x => x.YodleeId == transaction.categoryId).Select(x => x.Id).FirstOrDefault(),
                DateBooked         = transaction.transactionDate,
                DateCaptured       = transaction.createdDate,
                SourceOfExpense    = GetSource(transaction),
                YodleeId           = transaction.id
            };
            if (automateReturn.AutomatedCashFlow.DateBooked == DateTime.MinValue)
            {
                automateReturn.AutomatedCashFlow.DateBooked = automateReturn.AutomatedCashFlow.DateCaptured;
            }

            if (manual != null)
            {
                automateReturn.ManualCashFlow = manual;
                automateReturn.ManualCashFlow.AutomatedCashFlowId = automateReturn.AutomatedCashFlow.ID;
                automateReturn.AutomatedCashFlow.CFTypeId         = manual.CFTypeId;
                automateReturn.AccountChange = new AccountChange()
                {
                    AccountChangeId = ""
                };
                automateReturn.AutomatedCashFlow.Validated = true;
            }
            else
            {
                AccountChange change = new AccountChange();
                automateReturn.AccountChange  = change.AddAccountChange(automateReturn.AutomatedCashFlow, account, GetCFClassificationSign(transaction, classifications));
                automateReturn.ManualCashFlow = new ManualCashFlow()
                {
                    Id = ""
                };
                automateReturn.AutomatedCashFlow.Validated = false;
            }
            return(automateReturn);
        }
Exemplo n.º 13
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);
        }