Beispiel #1
0
        public static void IncomeLines(List <BudgetRow> retList, int selectedMonth)
        {
            PrimaryContext             db      = new PrimaryContext();
            IEnumerable <IncomeSource> Sources = db.IncomeSources.ToList();
            decimal budgetSubTotalDecimal      = Decimal.Zero;
            decimal actualSubTotalDecimal      = Decimal.Zero;

            foreach (IncomeSource source in Sources)
            {
                retList.Add(new BudgetRow("", source.Name, Enums.TableRowType.header2));
                foreach (Income income in source.Incomes)
                {
                    //Apply change events
                    decimal newAmount = General.GetAllocationWithChangeEventsByMonth(income, selectedMonth);

                    //Calculate actuals
                    decimal transactSum = GetMonthTransactionActuals(income, selectedMonth);

                    retList.Add(new BudgetRow("", "", income.Name, "", newAmount, transactSum,
                                              Enums.TableRowType.income, income.Id));
                    budgetSubTotalDecimal += newAmount;
                    actualSubTotalDecimal += transactSum;
                }
            }
            retList.Find(x => x.Column1.Contains("Income")).MoneyCol1 = budgetSubTotalDecimal;
            retList.Find(x => x.Column1.Contains("Income")).MoneyCol2 = actualSubTotalDecimal;
        }
Beispiel #2
0
        public static void LoanLines(List <BudgetRow> retList, int selectedMonth)
        {
            PrimaryContext     db    = new PrimaryContext();
            IEnumerable <Loan> Loans = db.Loans.ToList();
            decimal            budgetSubTotalDecimal = Decimal.Zero;
            decimal            actualSubTotalDecimal = Decimal.Zero;

            foreach (Loan loan in Loans)
            {
                //Apply change events
                decimal newAmount = General.GetAllocationWithChangeEventsByMonth(loan, selectedMonth);

                //Calculate Actuals
                decimal transactSum = GetMonthTransactionActuals(loan, selectedMonth);

                //Get Balance
                Account account    = db.Accounts.Find(loan.AccountId);
                decimal currentBal = EstimatedLoanBalance(loan);

                retList.Add(new BudgetRow("", "", loan.Name, "", newAmount, transactSum,
                                          Enums.TableRowType.loan, loan.Id, currentBal));
                budgetSubTotalDecimal += newAmount;
                actualSubTotalDecimal += transactSum;
            }
            retList.Find(x => x.Column1.Contains("Loan")).MoneyCol1 = budgetSubTotalDecimal;
            retList.Find(x => x.Column1.Contains("Loan")).MoneyCol2 = actualSubTotalDecimal;
        }
Beispiel #3
0
        private static decimal GetResidualToDate(Allocation allocation)
        {
            PrimaryContext db = new PrimaryContext();

            //Get List of Months
            DateTime      start = DateTime.Now.AddMonths(-3);
            SystemSetting setting;

            if (db.SystemSettings.Any(x => x.Setting == Enums.SysSetting.AllocationOverUnderCalcDate))
            {
                setting = db.SystemSettings.FirstOrDefault(x => x.Setting == Enums.SysSetting.AllocationOverUnderCalcDate);
                if (setting.SettingDate != null)
                {
                    start = (DateTime)setting.SettingDate;
                }
            }

            List <Month> Months = Utilities.General.GetMonthList(start,
                                                                 DateTime.Now);

            //calculate total spent from cut off to now and total allocated
            decimal spentSum     = decimal.Zero;
            decimal allocatedSum = decimal.Zero;

            //foreach (Month m in Months)
            //{
            //    spentSum += GetMonthTransactionActuals(allocation, m.MonthNumber, m.Year);
            //    allocatedSum += General.GetAllocationWithChangeEventsByMonth(allocation, m.MonthNumber, m.Year);
            //}
            return(allocatedSum - spentSum);
        }
Beispiel #4
0
        public static void ExpenseLines(List <BudgetRow> retList, int selectedMonth)  //need to distinguish year
        {
            PrimaryContext db = new PrimaryContext();
            IEnumerable <ExpenseCategory> Categories = db.ExpenseCategories.ToList();
            decimal budgetSubTotalDecimal            = Decimal.Zero;
            decimal actualSubTotalDecimal            = Decimal.Zero;

            foreach (ExpenseCategory category in Categories)
            {
                retList.Add(new BudgetRow("", category.Name, Enums.TableRowType.header2));
                foreach (Expense expense in category.Expenses)
                {
                    //Apply change events
                    decimal newAmount = General.GetAllocationWithChangeEventsByMonth(expense, selectedMonth);

                    //Calculate Actuals
                    decimal transactSum = GetMonthTransactionActuals(expense, selectedMonth);

                    //Calculate Budget running total for sysSetting to date
                    decimal residual = GetResidualToDate(expense);

                    //Add budget row to retList
                    retList.Add(new BudgetRow("", "", expense.Name, "", newAmount, transactSum,
                                              Enums.TableRowType.expense, expense.Id, residual));

                    //Sub Totals
                    budgetSubTotalDecimal += newAmount;
                    actualSubTotalDecimal += transactSum;
                }
            }
            retList.Find(x => x.Column1.Contains("Expense")).MoneyCol1 = budgetSubTotalDecimal;
            retList.Find(x => x.Column1.Contains("Expense")).MoneyCol2 = actualSubTotalDecimal;
        }
Beispiel #5
0
        /// <summary>
        /// returns the sum of change amount deltas, not including the initial amount of the allocation
        /// Change events are applied once per month
        /// </summary>
        /// <param name="allocation"></param>
        /// <param name="selectedMonth"></param>
        /// <param name="selectedYear"></param>
        /// <returns></returns>
        private static decimal GetTotalChangeAmountForMonthDecimal(Allocation allocation, int selectedMonth, int selectedYear)
        {
            decimal        retVal               = decimal.Zero;
            PrimaryContext db                   = new PrimaryContext();
            decimal        summingAmount        = allocation.Amount;
            int            days                 = DateTime.DaysInMonth(selectedYear, selectedMonth);
            DateTime       endOfSelectedMonth   = new DateTime(selectedYear, selectedMonth, days, 23, 59, 59);
            DateTime       beginOfSelectedMonth = new DateTime(selectedYear, selectedMonth, 1, 00, 00, 01);

            List <AllocationChange> changeEvents = db.ChangeEvents.OfType <AllocationChange>().
                                                   Where(x => x.AllocationId == allocation.Id &&
                                                         x.EffectiveDateTime <= endOfSelectedMonth).ToList();

            //Get this working List<ChangeEvent> changeEvents = allocation.ChangeEvents.Where(x => x.EffectiveDateTime <= endOfSelectedMonth).ToList();
            if (changeEvents.Count > 0)
            {
                changeEvents = changeEvents.OrderBy(change => change.EffectiveDateTime).ToList();

                foreach (var changeEvent in changeEvents)
                {
                    decimal individualChangeAmount = GetIndividualChangeEventAmountDecimal(summingAmount, changeEvent);
                    retVal        += individualChangeAmount;
                    summingAmount += individualChangeAmount;
                }
            }
            return(retVal);
        }
 public override void EnterPrimary([NotNull] PrimaryContext context)
 {
     foreach (var rule in context.GetRuleContexts <ParserRuleContext>())
     {
         rule.EnterRule(this);
     }
 }
        public override Tree VisitExpression(ExpressionContext context)
        {
            PrimaryContext primaryCtx = context.primary();

            if (primaryCtx != null)
            {
                Expression            expr             = (Expression)VisitPrimary(primaryCtx);
                FuncInvocationContext methodInvocation = context.funcInvocation();
                if (methodInvocation != null)
                {
                    expr = makeMethodInvocation(expr, methodInvocation);
                }
                return(expr);
            }
            FuncInvocationContext invocation = context.funcInvocation();

            if (invocation != null)
            {
                return((Expression)VisitFuncInvocation(invocation));
            }
            if (context.NEW() != null)
            {
                return(context.Identifier() != null
                    ? makeNewStruct(context)
                    : makeNewArray(context));
            }
            if (context.index != null)
            {
                return(makeArrayIndex(context));
            }
            IToken postfix = context.postfix;

            if (postfix != null)
            {
                return(makeUnary(context, postfix.Type));
            }
            IToken prefix = context.prefix;

            if (prefix != null)
            {
                return(makeUnary(context, prefix.Type));
            }
            IToken binOp = context.bop;

            if (binOp != null)
            {
                if (binOp.Type == DOT)
                {
                    return(makeSelect(context));
                }
                return(context.isAssignment
                    ? makeAssignment(context)
                    : makeBinary(context));
            }
            return(makeConditional(context));
        }
Beispiel #8
0
        public static int GetFirstTransactionYear()
        {
            int            retVal = DateTime.Now.Year;
            PrimaryContext db     = new PrimaryContext();

            if (db.Transactions.Any())
            {
                retVal = db.Transactions.Min(x => x.TransactionDate).Year;
            }
            return(retVal);
        }
Beispiel #9
0
        public static int YearsToDisplay()
        {
            PrimaryContext db = new PrimaryContext();
            int            futureYearsDisplay = 2;

            if (db.SystemSettings.Any(x => x.Setting == Enums.SysSetting.NumYearsToDisplay))
            {
                futureYearsDisplay = Convert.ToInt16(db.SystemSettings.FirstOrDefault(x => x.Setting == Enums.SysSetting.NumYearsToDisplay).SettingValue);
            }
            return(System.DateTime.Now.Year - GetFirstTransactionYear() + futureYearsDisplay);
        }
Beispiel #10
0
        /// <summary>
        /// Returns the number of weeks in a given month using the WeekEnd/Start system setting
        /// if system setting = Friday, returns # of fridays in the given month
        /// </summary>
        /// <param name="selectedMonth"></param>
        /// <param name="selectedYear"></param>
        /// <returns></returns>
        public static int WeeksInMonth(int selectedMonth, int selectedYear)
        {
            PrimaryContext db      = new PrimaryContext();
            SystemSetting  setting = db.SystemSettings.FirstOrDefault(x => x.Setting == Enums.SysSetting.WeekStartDay);
            int            days    = DateTime.DaysInMonth(selectedYear, selectedMonth);

            DateTime[] datesInMonth =
            {
                new DateTime(selectedYear, selectedMonth, 1),
                new DateTime(selectedYear, selectedMonth, days)
            };
            return(datesInMonth.Count(x => x.DayOfWeek == setting.SettingDay));
        }
Beispiel #11
0
        internal static decimal GetAllocationWithChangeEventsByMonth(Allocation allocation, int selectedMonth, int selectedYear = 0)
        {
            PrimaryContext db = new PrimaryContext();

            if (selectedYear == 0)
            {
                selectedYear = System.DateTime.Now.Year;
            }
            decimal retVal       = allocation.Amount;
            decimal changeAmount = GetTotalChangeAmountForMonthDecimal(allocation, selectedMonth, selectedYear);

            switch (allocation.Recurrence.RecurrenceFrequencyEnum)
            {
            case RecurrenceEnum.None:         //None
                if ((allocation.Recurrence.RecuranceStartDate.Month == selectedMonth &&
                     allocation.Recurrence.RecuranceStartDate.Year == selectedYear))
                {
                    retVal = retVal + changeAmount;
                }
                else
                {
                    retVal = decimal.Zero;
                }
                break;

            case RecurrenceEnum.Weekly:         //Weekly
                DateTime date  = new DateTime(selectedYear, selectedMonth, 1);
                int      weeks = date.GetWeeksInMonth();
                retVal = (retVal + changeAmount) * weeks;
                break;

            case RecurrenceEnum.Monthly:         //Monthly
                retVal = retVal + changeAmount;
                break;

            case RecurrenceEnum.Yearly:         //Yearly
                if ((allocation.Recurrence.RecuranceStartDate.Month == selectedMonth))
                {
                    retVal = retVal + changeAmount;
                }
                else
                {
                    retVal = decimal.Zero;
                }
                break;
            }

            return(retVal);
        }
        //Move to general?
        public static decimal GetCurrentBalance(Account account)
        {
            PrimaryContext db     = new PrimaryContext();
            decimal        retVal = decimal.Zero;

            if (db.AccountBalanceEntries.Any(x => x.AccountId == account.Id))
            {
                AccountBalanceEntry lastEntry = db.AccountBalanceEntries.Where(x => x.AccountId == account.Id)
                                                .OrderByDescending(x => x.Date).First();
                retVal = lastEntry.Amount;
            }


            // AccountBalanceEntry lastEntry = db.AccountBalanceEntries.Where(x => x.AccountId == account.Id).Last();
            return(retVal);
        }
Beispiel #13
0
        //Run once after upgrading to object based recurrence
        public static void SetAllNullRecurrenceToValue()
        {
            PrimaryContext db = new PrimaryContext();

            foreach (var allocation in db.Allocations.ToList())
            {
                if (allocation.Recurrence == null)
                {
                    allocation.Recurrence = new Recurrence()
                    {
                        RecuranceStartDate      = System.DateTime.Today,
                        RecurrenceFrequencyEnum = Models.Enums.RecurrenceEnum.Monthly
                    };
                    db.SaveChanges();
                }
            }
        }
        private bool VisitPrimaryContext(PrimaryContext ctx)
        {
            var nodeText = ctx.GetText();

            if (PaintCodeColorClassMembers.Contains(nodeText))
            {
                _rewriter.Replace(ctx.Start, ctx.Stop, nodeText.Pascalize());
            }
            else if (ColorClassMethods.ContainsKey(nodeText))
            {
                _rewriter.Replace(ctx.Start, ctx.Stop, $"Color.{ColorClassMethods[nodeText]}");
            }
            else if (JavaConstantConventionRegex.IsMatch(nodeText))
            {
                _rewriter.Replace(ctx.Start, ctx.Stop, $"Color.{nodeText.ToLowerInvariant().Pascalize()}");
            }

            return(true);
        }
Beispiel #15
0
        public static decimal EstimatedLoanBalance(Loan loan)
        {
            PrimaryContext db     = new PrimaryContext();
            decimal        retVal = decimal.Zero;

            //if(db.LoanBalanceEntries.Any(x => x.LoanId == loan.Id))
            //{
            //    List<LoanBalanceEntry> loanBalList = db.LoanBalanceEntries.Where(x => x.LoanId == loan.Id).OrderBy(x => x.Date).ToList();
            //    LoanBalanceEntry entry = loanBalList.Last();
            //    decimal lastKnown = entry.Amount;
            //    TimeSpan span = DateTime.Now - entry.Date;
            //    int months = span.GetMonths();
            //    decimal allocatedPayments = loan.Amount * months ;
            //    //decimal interest = ((lastKnown - allocatedPayments / 2) * loan.Apr / 1200) * months;
            //    retVal = lastKnown - allocatedPayments + interest;
            //}


            return(retVal);
        }
Beispiel #16
0
        public static void SaveInvestLines(List <BudgetRow> retList, int selectedMonth)
        {
            PrimaryContext db = new PrimaryContext();
            IEnumerable <SavingsInvestment> siEnumerable = db.SavingsInvestments.ToList();
            decimal subTotalDecimal       = decimal.Zero;
            decimal actualSubTotalDecimal = decimal.Zero;

            foreach (var si in siEnumerable)
            {
                //Apply change events
                decimal newAmount   = General.GetAllocationWithChangeEventsByMonth(si, selectedMonth);
                decimal transactSum = GetMonthTransactionActuals(si, selectedMonth);

                retList.Add(new BudgetRow("", "", si.Name, "", newAmount, transactSum,
                                          Enums.TableRowType.si, si.Id));
                subTotalDecimal       += newAmount;
                actualSubTotalDecimal += transactSum;
            }
            retList.Find(x => x.Column1.Contains("Save")).MoneyCol1 = subTotalDecimal;
            retList.Find(x => x.Column1.Contains("Save")).MoneyCol2 = actualSubTotalDecimal;
        }
Beispiel #17
0
        private static decimal GetMonthTransactionActuals(Allocation allocation, int selectedMonth, int selectedYear = 0)
        {
            PrimaryContext db = new PrimaryContext();

            if (selectedYear == 0)
            {
                selectedYear = System.DateTime.Now.Year;
            }
            var transactions =
                db.Transactions.Where(x => x.AllocationId == allocation.Id &&
                                      x.TransactionDate.Month == selectedMonth &&
                                      x.TransactionDate.Year == System.DateTime.Now.Year);
            //need to make year selectable and assign variable
            decimal transactSum = decimal.Zero;

            if (transactions.Any())
            {
                transactSum = transactions.Sum(x => x.Amount);
            }
            return(transactSum);
        }
        public static List <ForecastRow> BuildForecastRows()
        {
            PrimaryContext                 db = new PrimaryContext();
            IEnumerable <Account>          checkingAccounts   = db.Accounts.Where(x => x.AccountType == Enums.AccountType.Checking).ToList();
            IEnumerable <Account>          loanAccounts       = db.Accounts.Where(x => x.AccountType == Enums.AccountType.Loan).ToList();
            IEnumerable <Account>          creditCards        = db.Accounts.Where(x => x.AccountType == Enums.AccountType.CreditCard).ToList();
            IEnumerable <Account>          savingsAccounts    = db.Accounts.Where(x => x.AccountType == Enums.AccountType.Savings).ToList();
            IEnumerable <Account>          investmentAccounts = db.Accounts.Where(x => x.AccountType == Enums.AccountType.Investment).ToList();
            IEnumerable <PayrollDeduction> deductions         = db.PayrollDeductions.ToList();
            List <ForecastRow>             retList            = new List <ForecastRow>();

            BuildAccountRows(checkingAccounts, retList, Enums.AccountType.Checking);
            BuildAccountRows(loanAccounts, retList, Enums.AccountType.Loan);
            BuildAccountRows(creditCards, retList, Enums.AccountType.CreditCard);
            BuildAccountRows(savingsAccounts, retList, Enums.AccountType.Savings);
            BuildAccountRows(investmentAccounts, retList, Enums.AccountType.Investment);
            //BuildPayrollDeductions(deductions, retList);


            return(retList);
        }
Beispiel #19
0
        public static void PayrollDeductionLines(List <BudgetRow> retList, int selectedMonth)
        {
            PrimaryContext db = new PrimaryContext();
            IEnumerable <PayrollDeduction> PdEnumerable = db.PayrollDeductions.ToList();
            decimal subTotalDecimal       = decimal.Zero;
            decimal actualSubTotalDecimal = decimal.Zero;

            foreach (var pd in PdEnumerable)
            {
                //Apply change events Later
                //decimal newAmount = General.GetAllocationWithChangeEventsByMonth(si, selectedMonth);
                //decimal transactSum = GetMonthTransactionActuals(si, selectedMonth);

                //Need to add current Bal in place of 100.00m
                decimal bal = 100.00m;
                retList.Add(new BudgetRow("", "", pd.Name, "", pd.Amount, bal, Enums.TableRowType.payrollDeduction, pd.Id));
                subTotalDecimal       += pd.Amount;
                actualSubTotalDecimal += bal;
            }
            retList.Find(x => x.Column1.Contains("Pay")).MoneyCol1 = subTotalDecimal;
            retList.Find(x => x.Column1.Contains("Pay")).MoneyCol2 = actualSubTotalDecimal;
        }
        public override Tree VisitPrimary(PrimaryContext primary)
        {
            var expressionContext = primary.parenthesized;

            if (expressionContext != null)
            {
                return((Expression)VisitExpression(expressionContext));
            }
            LiteralContext literal = primary.literal();

            if (literal != null)
            {
                return((Expression)VisitLiteral(literal));
            }
            ITerminalNode identifier = primary.Identifier();

            if (identifier != null)
            {
                return(makeIdentifier(identifier));
            }
            return(new This(primary.start.Line, primary.start.Column, primary.stop.Line, primary.stop.Column));
        }
Beispiel #21
0
        public PrimaryContext primary()
        {
            PrimaryContext _localctx = new PrimaryContext(Context, State);

            EnterRule(_localctx, 6, RULE_primary);
            int _la;

            try {
                EnterOuterAlt(_localctx, 1);
                {
                    State = 24; expression();
                    State = 30;
                    ErrorHandler.Sync(this);
                    _la = TokenStream.LA(1);
                    while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__5) | (1L << T__6) | (1L << T__7) | (1L << T__8) | (1L << T__9))) != 0))
                    {
                        {
                            {
                                State = 25; gate();
                                State = 26; expression();
                            }
                        }
                        State = 32;
                        ErrorHandler.Sync(this);
                        _la = TokenStream.LA(1);
                    }
                }
            }
            catch (RecognitionException re) {
                _localctx.exception = re;
                ErrorHandler.ReportError(this, re);
                ErrorHandler.Recover(this, re);
            }
            finally {
                ExitRule();
            }
            return(_localctx);
        }
Beispiel #22
0
        public static int GetWeeksInMonth(this DateTime time)
        {
            PrimaryContext db = new PrimaryContext();
            DayOfWeek      settingDay;

            if (db.SystemSettings.Any(x => x.Setting == Enums.SysSetting.WeekStartDay))
            {
                settingDay = (DayOfWeek)Convert.ToInt16(db.SystemSettings.FirstOrDefault(x => x.Setting == Enums.SysSetting.WeekStartDay).SettingValue);
            }
            else
            {
                db.SystemSettings.Add(new SystemSetting()
                {
                    Setting = Enums.SysSetting.WeekStartDay, SettingInt = (int)DayOfWeek.Monday
                });
                db.SaveChanges();
                settingDay = DayOfWeek.Monday;
            }

            int       daysInMonth   = _gc.GetDaysInMonth(time.Year, time.Month);
            DayOfWeek firstDay      = _gc.GetDayOfWeek(new DateTime(time.Year, time.Month, 1));
            DateTime  lastDay       = new DateTime(time.Year, time.Month, daysInMonth);
            int       count         = (int)Math.Floor((decimal)(daysInMonth / 7));
            int       remainder     = (int)(daysInMonth % 7);
            int       daysToLastDay = (int)(lastDay.DayOfWeek - settingDay);    //index setting day to last day of the month

            if (daysToLastDay < 0)
            {
                daysToLastDay += 7;                                             //account for setting Day after last day of week
            }
            if (remainder >= daysToLastDay)
            {
                count++;
            }

            return(count);
        }
        private static decimal GetMonthAccountProjection(Account account, DateTime targetMonth)
        {
            PrimaryContext    db = new PrimaryContext();
            List <Allocation> accountAllocations;
            decimal?          retVal = decimal.Zero;

            if (db.Allocations.Any(x => x.AccountId == account.Id))
            {
                accountAllocations = db.Allocations.Where(x => x.AccountId == account.Id).ToList();
                foreach (var allocation in accountAllocations)
                {
                    allocation.TempAmountDecimal = General.GetAllocationWithChangeEventsByMonth(allocation, targetMonth.Month, targetMonth.Year);
                }
                retVal += accountAllocations.OfType <Income>().Sum(x => x.TempAmountDecimal);
                retVal -= accountAllocations.OfType <Expense>().Sum(x => x.TempAmountDecimal);
                retVal -= accountAllocations.OfType <Loan>().Sum(x => x.TempAmountDecimal);
                retVal -= accountAllocations.OfType <SavingsInvestment>().Sum(x => x.Amount);
                if (account.AccountType != Enums.AccountType.Checking)
                {
                    retVal += GetMonthInterest(account, retVal);
                }
            }
            return((decimal)retVal);
        }
Beispiel #24
0
 public BaseConnection()
 {
     dbcontext = new PrimaryContext();
     dbset     = dbcontext.Set <TEntity>();
 }
        private static Dictionary <int, decimal> GetLoanProjections(Loan loan)
        {
            PrimaryContext            db            = new PrimaryContext();
            Dictionary <int, decimal> retDictionary = new Dictionary <int, decimal>();

            //Check that loan entry is valid
            //bool valid = true;
            LoanBalanceEntry   balEntry = new LoanBalanceEntry();
            decimal            payment  = decimal.Zero;
            List <Transaction> transactionsResult;
            decimal            transactionsAmount = decimal.Zero;

            //Still need to select most recent entry
            if (db.LoanBalanceEntries.Any(x => x.LoanId == loan.Id))
            {
                balEntry = db.LoanBalanceEntries.First(x => x.LoanId == loan.Id);
            }
            if (db.Allocations.Any(x => x.Id == loan.Id))
            {
                payment = db.Allocations.First(x => x.Id == loan.Id).Amount;
            }
            if (db.Transactions.Any(x => x.AllocationId == loan.Id &&
                                    x.TransactionDate > balEntry.Date))
            {
                transactionsResult = db.Transactions.Where(x => x.AllocationId == loan.Id &&
                                                           x.TransactionDate > balEntry.Date).ToList();
                transactionsAmount = transactionsResult.AsQueryable().Sum(x => x.Amount);
            }

            //TODO: This section needs cleaned up
            //try
            //{
            //    balEntry = db.LoanBalanceEntries.First(x => x.LoanId == loan.Id);
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("Invalid balance entry for loan:" + loan.Name + Environment.NewLine+ e.Message);
            //}
            //try
            //{
            //    payment = db.Allocations.First(x => x.Id == loan.Id).Amount;
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("Invalid payment entry for loan:" + loan.Name + Environment.NewLine + e.Message);
            //}
            //try
            //{
            //    transactionsResult = db.Transactions.Where(x => x.AllocationId == loan.Id &&
            //                                                    x.TransactionDate > balEntry.Date).ToList();
            //    if(transactionsResult.Any()) transactionsAmount = transactionsResult.AsQueryable().Sum(x => x.Amount);
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("Invalid transactions result for loan:" + loan.Name + Environment.NewLine + e.Message);
            //}
            //in future log exception and continue, use NoBalEntry method


            //Correct for time passed since entry = workingBal
            //________Diferent way of getting APR
            //TimeSpan span = new TimeSpan(System.DateTime.Now.Ticks - balEntry.Date.Ticks);
            //decimal interest = Decimal.Zero;
            //if(balEntry != null) Financial.GetMonthlyLoanInterest(balEntry.Amount, loan.Apr, (int)(span.Days / 30));

            //decimal initialBal = balEntry.Amount - transactionsAmount + interest;
            //decimal workingBal = initialBal;

            ////Current Month
            //retDictionary.Add(0,workingBal);

            ////For 6 months
            //for (int i = 1; i <= 6; i++)
            //{
            //    interest = Financial.GetMonthlyLoanInterest(workingBal, loan.Apr);
            //    //TODO: Change Events
            //    workingBal = workingBal - payment + interest;
            //    if (workingBal < 1) workingBal = 0;
            //    retDictionary.Add(i,workingBal);
            //}

            ////For 3 Years
            //workingBal = initialBal;
            //for (int i = 7; i <= 10; i++)
            //{
            //    interest = Financial.GetYearlyLoanInterest(workingBal, loan.Apr, payment);
            //    //TODO: Change Events
            //    workingBal = workingBal - payment * 12 + interest;
            //    if (workingBal < 1) workingBal = 0;
            //    retDictionary.Add(i, workingBal);
            //}

            return(retDictionary);
        }
Beispiel #26
0
 public TransactionService(PrimaryContext context)
 {
     _context = context;
 }
Beispiel #27
0
 public BaseRepository(PrimaryContext context)
 {
     _context = context;
 }
 public ValuesController()
 {
     _primaryContext   = new PrimaryContext();
     _secondaryContext = new SecondaryContext();
 }
Beispiel #29
0
 public UserService(IOptions <AppSettings> appSettings, PrimaryContext context)
 {
     _context     = context;
     _appSettings = appSettings.Value;
 }
Beispiel #30
0
 public AccountService(PrimaryContext context)
 {
     _context = context;
 }