예제 #1
0
        public ActionResult UpdateBalance(UpdateBalanceViewModel ubvm)
        {
            using (var fo = new FinancialOperations())
                using (var fq = new FinancialQueries())
                {
                    var fundBal = fq.GetBalance(ubvm.Date, User.Identity.Name, ubvm.SelectedFundId);
                    fo.UpdateBalance(ubvm.Value - fundBal, ubvm.SelectedFundId, ubvm.Date, User.Identity.Name);
                }

            return(SavingsAccountPartial());
        }
예제 #2
0
        public ActionResult GetProjection(string[] checkedRes)
        {
            using (var q = new FinancialQueries())
            {
                var user     = User.Identity.Name;
                var funds    = q.GetFunds(user);
                var reserves = q.GetReserves(user).Where(r => checkedRes.Any(c => c == r.ID.ToString())).OrderByDescending(r => r.DateToWithdraw);
                var today    = DateTime.Today;

                var      labels    = new List <string>();
                DateTime end       = reserves.Max(r => r.DateToWithdraw);
                DateTime currDate1 = today;

                int incr = (int)Math.Ceiling(end.Subtract(today).TotalDays / 1095);

                while (currDate1.Year < end.Year || (currDate1.Year == end.Year && currDate1.Month <= end.Month))
                {
                    labels.Add(GetMonth(currDate1.Month) + "-" + GetYear(currDate1.Year));
                    currDate1 = currDate1.AddMonths(incr);
                }

                var     datasets        = new List <dataset>();
                int     x               = 0;
                decimal totalMonthlyDep = 0;
                foreach (var res in reserves)
                {
                    x++;
                    int monthsToAchieve = 0;
                    var currDate        = today;
                    while (currDate <= res.DateToWithdraw)
                    {
                        monthsToAchieve++;
                        currDate = currDate.AddMonths(1);
                    }

                    // escolhendo fundo
                    decimal?percIncome = null;
                    if (monthsToAchieve < 24)
                    {
                        percIncome = 1.0015m;
                    }
                    else if (monthsToAchieve < 84)
                    {
                        percIncome = 1.002875m;
                    }
                    else
                    {
                        percIncome = 1.0063125m;
                    }

                    var resBal = q.GetBalance(today, user, null, res.ID);

                    decimal monthlyDep = Math.Max(0, res.FinalExpectedValue - resBal);
                    decimal div        = 0;
                    for (int i = 0; i < monthsToAchieve; i++)
                    {
                        div += (decimal)Math.Pow((double)percIncome, i);
                    }
                    monthlyDep /= Math.Max(1, div);

                    var     data    = new List <decimal>();
                    decimal currBal = q.GetBalance(today, user, reserveId: res.ID);
                    int     currIt  = 0;
                    for (int i = 0; i < monthsToAchieve; i++)
                    {
                        currIt++;
                        if (currIt == 1)
                        {
                            data.Add(currBal);
                        }

                        if (currIt == incr)
                        {
                            currIt = 0;
                        }

                        currBal *= percIncome.Value;
                        currBal += monthlyDep;
                    }
                    currIt++;
                    while (currIt != 1)
                    {
                        if (currIt == incr)
                        {
                            currIt = 0;
                        }

                        currBal *= percIncome.Value;
                        currBal += monthlyDep;

                        currIt++;
                    }
                    data.Add(currBal);

                    totalMonthlyDep += monthlyDep;

                    var dataset = new dataset()
                    {
                        reserveId        = res.ID,
                        monthlyDep       = monthlyDep.ToString("0.00"),
                        data             = data,
                        fillColor        = "rgba(151,187,205,0)",
                        strokeColor      = GetColor(x),
                        pointColor       = "rgba(151,187,205,1)",
                        pointStrokeColor = "#fff"
                    };
                    datasets.Add(dataset);
                }

                var simularRes = new simulatorResult()
                {
                    totalMonthlyDep = totalMonthlyDep.ToString("0.00"),
                    labels          = labels,
                    datasets        = datasets
                };
                return(Json(simularRes));
            }
        }
예제 #3
0
        //
        // GET: /Manager/
        public PartialViewResult SavingsAccountPartial()
        {
            var tvm = new TransactionViewModel();

            using (FinancialQueries queries = new FinancialQueries())
            {
                List <Fund>           fundList              = queries.GetFunds(User.Identity.Name);
                List <Reserve>        reserveList           = queries.GetReserves(User.Identity.Name);
                List <SelectListItem> distributionRuleItems = Helper.GetListItem(queries.GetDistributionRules(User.Identity.Name));

                tvm.TransactionList = queries.GetTransactions(null, null, DateTime.Today, User.Identity.Name);

                var ops     = tvm.TransactionList.GroupBy(t => t.Operation);
                var opsList = new List <OperationVM>();

                foreach (var op in ops)
                {
                    var opVW = new OperationVM()
                    {
                        Date        = op.Key.Date,
                        Description = op.Key.Type != EOperationType.BalanceUpdate ? op.Key.Description : "Rendimento",
                        Value       = op.Key.TotalValue,
                        Reserves    = op.Select(o => o.ReserveID).Distinct().Count() == 1
                            ? op.FirstOrDefault().Reserve.Name
                            : String.Concat(op.Select(o => o.Reserve.NameAbbreviation + "/").Distinct()).Trim('/'),
                        Funds = op.Select(o => o.FundID).Distinct().Count() == 1
                            ? op.FirstOrDefault().Fund.Name
                            : String.Concat(op.Select(o => o.Fund.NameAbbreviation + "/").Distinct()).Trim('/')
                    };
                    opsList.Add(opVW);
                }
                tvm.OperationList = opsList;
                tvm.FundList      = Helper.GetListItem(fundList, "TODOS");
                tvm.ReserveList   = Helper.GetListItem(reserveList, "TODOS");
                tvm.Balance       = tvm.TransactionList.Sum(t => t.Value);

                List <UpdateFundToDepositViewModel> fundsBalanceList = new List <UpdateFundToDepositViewModel>();
                fundsBalanceList.AddRange(
                    fundList.Select(
                        f => new UpdateFundToDepositViewModel()
                {
                    FundId = f.ID, FundName = f.Name, CurrentBalance = queries.GetBalance(DateTime.Today, User.Identity.Name, f.ID).ToString("0.00")
                }
                        )
                    );

                DepositViewModel dvm = new DepositViewModel()
                {
                    FundList             = Helper.GetListItem(fundList, "NENHUM"),
                    ReserveList          = Helper.GetListItem(reserveList, "NENHUM"),
                    DistributionRuleList = distributionRuleItems,
                    Date             = DateTime.Today,
                    fundsBalanceList = fundsBalanceList
                };
                tvm.DepositViewModel = dvm;

                WithdrawViewModel wvm = new WithdrawViewModel()
                {
                    FundList    = Helper.GetListItem(fundList),
                    ReserveList = Helper.GetListItem(reserveList),
                    Date        = DateTime.Today
                };
                tvm.WithdrawViewModel = wvm;

                UpdateBalanceViewModel ubvm = new UpdateBalanceViewModel()
                {
                    FundList = Helper.GetListItem(fundList),
                    Date     = DateTime.Today
                };
                tvm.UpdateBalanceViewModel = ubvm;
            }
            ModelState.Clear();
            return(PartialView("SavingsAccountPartial", tvm));
        }