Exemplo n.º 1
0
        /* =========================
         * Bill History Functions
         * ========================= */
        public ActionResult AddPayment(int id)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                Bill bill = context.GetBill(id);

                BillHistory history = new BillHistory();
                history.Amount = bill.Amount;
                history.DatePaid = bill.DueDate;
                history.Payee = bill.Payee;
                history.PaymentTypeId = bill.PaymentTypeId;
                history.IssueDate = bill.IssueDate;
                history.Bill = bill;

                return View(history);
            }
        }
Exemplo n.º 2
0
 public ActionResult EditPayment(int id)
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         BillHistory history = context.GetBillHistoryItem(id);
         history.Bill = context.GetBill(history.BillId);
         return View(history);
     }
 }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                DashboardViewModel viewModel = new DashboardViewModel();
                IEnumerable<Bill> bills = context.GetBills();
                IEnumerable<Loan> loans = context.GetLoans();

                DateTime startDate = DateTime.Now;
                foreach (Bill bill in bills) { startDate = (bill.DueDate <= startDate) ? bill.DueDate : startDate; }
                foreach (Loan loan in loans) { startDate = (loan.DueDate <= startDate) ? loan.DueDate : startDate; }
                if (startDate.Day > 1)
                {
                    //startDate = startDate.AddMonths(-1);
                    startDate = new DateTime(startDate.Year, startDate.Month, 1);
                }

                viewModel.DateRanges = InitiateDateRanges(startDate);

                foreach (DashboardDateRange range in viewModel.DateRanges)
                {
                    List<DashboardItem> items = new List<DashboardItem>();

                    foreach (Bill bill in bills) {
                        if (bill.DueDate >= range.StartDate && bill.DueDate <= range.EndDate) {
                            items.Add(new DashboardItem(bill));
                        }
                        if (bill.StaysSame || !bill.BillHistories.Any())
                        {
                            for (int i = 1; i <= 3; i++)
                            {
                                DateTime date = bill.DueDate.AddMonths(i);
                                if (date >= range.StartDate && date <= range.EndDate)
                                {
                                    DashboardItem item = new DashboardItem(bill);
                                    item.Date = date;
                                    item.IsPastDue = item.DueInDays < 0;
                                    items.Add(item);
                                }
                            }
                        }
                        else
                        {
                            Bill difBill = context.GetBill(bill.Id);
                            foreach (BillHistoryAverage bha in difBill.BillHistoryAverage)
                            {
                                if (bha.Month >= range.StartDate && bha.Month <= range.EndDate && bha.Month.Month != bill.DueDate.Month)
                                {
                                    DashboardItem item = new DashboardItem(bha);
                                    item.Id = bill.Id;
                                    item.Name = bill.Name;
                                    items.Add(item);
                                }
                            }
                        }

                        if (bill.BillHistories.Any())
                        {
                            foreach (BillHistory history in bill.BillHistory)
                            {
                                if (history.DatePaid >= range.StartDate && history.DatePaid <= range.EndDate)
                                {
                                    items.Add(new DashboardItem(history));
                                }
                            }
                        }
                    }

                    foreach (Loan loan in loans)
                    {
                        foreach (LoanOutlook outlook in loan.LoanOutlook)
                        {
                            if (outlook.Date >= range.StartDate && outlook.Date <= range.EndDate)
                            {
                                DashboardItem dbItem = new DashboardItem(outlook);
                                dbItem.Name = loan.Name;
                                dbItem.Id = loan.Id;
                                items.Add(dbItem);
                            }
                        }
                        foreach (LoanHistory history in loan.LoanHistory)
                        {
                            if (history.DatePaid >= range.StartDate && history.DatePaid <= range.EndDate)
                            {
                                items.Add(new DashboardItem(history));
                            }
                        }
                    }

                    range.Items = items.OrderBy(x => x.Date);
                }

                return View(viewModel);
            }
        }
Exemplo n.º 4
0
        public ActionResult AddPayment(BillHistory collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                try
                {
                    BillHistory history = new BillHistory();
                    history.CreationDate = DateTime.Now;
                    history.ModifyDate = DateTime.Now;
                    history.Version = 1;
                    history.BillId = collection.Id;

                    Bill bill = context.GetBill(history.BillId);
                    history.Bill = bill;

                    history.Amount = collection.Amount;
                    history.DatePaid = collection.DatePaid;
                    history.Payee = collection.Payee;
                    history.PaymentTypeId = collection.PaymentTypeId;
                    history.IssueDate = collection.IssueDate;

                    bill.BillHistories.Add(history);

                    if (bill.StaysSame || bill.BillHistoryAverage == null)
                    {
                        bill.DueDate = bill.DueDate.AddMonths(1);
                    }
                    else
                    {
                        IEnumerable<BillHistoryAverage> bha = bill.BillHistoryAverage.Where(x => x.Month.Month == bill.DueDate.AddMonths(1).Month);
                        if (bha.Any())
                        {
                            bill.DueDate = bha.FirstOrDefault().Month;
                            bill.Amount = bha.FirstOrDefault().Average;
                        }
                        else
                        {
                            bill.DueDate = bill.DueDate.AddMonths(1);
                        }
                    }

                    context.SubmitChanges();

                    return RedirectToAction("Edit", new { id = history.BillId });
                }
                catch
                {
                    return View(collection);
                }
            }
        }
Exemplo n.º 5
0
 public ActionResult View(int id)
 {
     using (LinkToDBDataContext context = new LinkToDBDataContext())
     {
         return View(context.GetBill(id));
     }
 }
Exemplo n.º 6
0
        public ActionResult Paid(int id)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                BillHistory history = new BillHistory();
                history.CreationDate = DateTime.Now;
                history.ModifyDate = DateTime.Now;
                history.Version = 1;
                history.BillId = id;

                Bill bill = context.GetBill(id);

                history.Amount = bill.Amount;
                history.DatePaid = bill.DueDate;
                history.Payee = bill.Payee;
                history.PaymentTypeId = bill.PaymentTypeId;
                history.IssueDate = bill.IssueDate;
                history.Bill = bill;

                if (bill.StaysSame || bill.BillHistoryAverage == null)
                {
                    bill.DueDate = bill.DueDate.AddMonths(1);
                }
                else
                {
                    IEnumerable<BillHistoryAverage> bha = bill.BillHistoryAverage.Where(x => x.Month.Month == bill.DueDate.AddMonths(1).Month);
                    if (bha.Any())
                    {
                        bill.DueDate = bha.FirstOrDefault().Month;
                        bill.Amount = bha.FirstOrDefault().Average;
                    }
                    else
                    {
                        bill.DueDate = bill.DueDate.AddMonths(1);
                    }
                }

                context.SubmitChanges();
                return RedirectToAction("Index", "Home", null);
            }
        }
Exemplo n.º 7
0
        public ActionResult Edit(int id, Bill collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                Bill bill = context.GetBill(id);

                try
                {
                    bill.ModifyDate = DateTime.Now;
                    bill.Version += 1;
                    bill.Name = collection.Name;
                    bill.Payee = collection.Payee;
                    bill.DueDate = collection.DueDate;
                    bill.Amount = collection.Amount;
                    bill.IssueDate = collection.IssueDate;
                    bill.StaysSame = collection.StaysSame;
                    bill.Shared = collection.Shared;

                    context.SubmitChanges();

                    return RedirectToAction("Index");
                }
                catch
                {
                    return View(bill);
                }
            }
        }