예제 #1
0
 public DashboardItem(BillHistory history)
 {
     Id = history.BillId;
     Name = history.Bill.Name;
     Date = history.DatePaid;
     Amount = history.Amount;
     IsPastDue = false;
     IsShared = history.Bill.Shared;
     Type = "Bill";
     IsPaid = true;
 }
예제 #2
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);
                }
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
        public ActionResult EditPayment(BillHistory collection)
        {
            using (LinkToDBDataContext context = new LinkToDBDataContext())
            {
                BillHistory history = context.GetBillHistoryItem(collection.Id);

                try
                {
                    history.ModifyDate = DateTime.Now;
                    history.Version += 1;
                    history.DatePaid = collection.DatePaid;
                    history.Amount = collection.Amount;
                    history.Payee = collection.Payee;
                    history.IssueDate = collection.IssueDate;

                    context.SubmitChanges();

                    return RedirectToAction("Edit", new { id = history.BillId });
                }
                catch
                {
                    return View(history);
                }
            }
        }
예제 #5
0
		private void detach_BillHistories(BillHistory entity)
		{
			this.SendPropertyChanging();
			entity.Bill = null;
		}
예제 #6
0
		private void attach_BillHistories(BillHistory entity)
		{
			this.SendPropertyChanging();
			entity.Bill = this;
		}
예제 #7
0
 partial void DeleteBillHistory(BillHistory instance);
예제 #8
0
 partial void UpdateBillHistory(BillHistory instance);
예제 #9
0
 partial void InsertBillHistory(BillHistory instance);
예제 #10
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);
            }
        }