示例#1
0
        public decimal GetSalesTax(Billing billing, TaxYear taxYear)
        {
            decimal subtotal = decimal.Round(decimal.Divide(decimal.Multiply(billing.Total, (taxYear.TaxablePercent / 100)), (decimal)(1 + (taxYear.TaxRate / 100))), 2);
            decimal salesTax = decimal.Round(decimal.Subtract(decimal.Multiply(billing.Total, (taxYear.TaxablePercent / 100)), subtotal), 2);

            return salesTax;
        }
        public ActionResult Index()
        {
            HomeData data = new HomeData();

            string user = User.Identity.Name;

            foreach (Event evnt in db.Events.Where(e => e.Username == user))
            {
                if (evnt.EventDate >= DateTime.Now && evnt.EventDate < DateTime.Now.AddDays(30))
                {
                    data.UpcomingEvents.Add(evnt);
                }
            }

            foreach (TodoList todo in db.TodoList.Where(e => e.Username == user))
            {
                //if (!todo.IsCompleted)
                //{
                    data.TodoListItems.Add(todo);
                //}
            }

            TaxYear taxYear = new TaxYear();

            foreach (TaxYear year in db.TaxYears.Where(e => e.Username == user))
            {
                if (year.Year == DateTime.Now.Year)
                {
                    taxYear = year;
                }
            }

            data.TotalSalesTax = taxYear.TotalTax;
            data.TotalExpenses = taxYear.TotalExpenses;
            data.TotalGrossIncome = taxYear.TotalGrossIncome;
            data.TotalNetIncome = data.TotalGrossIncome - data.TotalExpenses;
            data.MilesDriven = (int)taxYear.TotalMiles;
            data.UpcomingEvents =  data.UpcomingEvents.OrderBy(x => x.EventDate).ToList();
            data.TodoListItems = data.TodoListItems.OrderBy(x => x.DueDate).ToList();

            VerifyActiveStatus(db, user);

            return View(data);
        }
        private TaxYear RecalculateBilling(TaxYear taxYear)
        {
            taxYear.TotalTax = 0;
            taxYear.TotalExpenses = 0;
            taxYear.TotalGrossIncome = 0;

            foreach (Billing billing in db.Billing)
            {
                if (billing.BillingType == "Payment")
                {
                    billing.SalesTax = billing.GetSalesTax(billing, taxYear);
                    billing.Subtotal = billing.Total - billing.SalesTax;

                    taxYear.TotalTax += billing.SalesTax;
                    taxYear.TotalGrossIncome += billing.Subtotal;
                }
                else if (billing.BillingType == "Expense")
                {
                    taxYear.TotalExpenses += billing.Total;
                }
            }

            taxYear.TotalNetIncome = taxYear.TotalGrossIncome - taxYear.TotalExpenses;

            return taxYear;
        }