Пример #1
0
        public static Bill Populate(this Bill bill, ApplicationUser user)
        {
            bill.NotOwner  = bill.User.Id != user.Id;
            bill.OwnerPays = bill.Amount - bill.SharedWith.Sum(x => x.Amount);
            if (bill.NotOwner)
            {
                bill.YouPay = bill.SharedWith.Where(x => x.SharedWithUser.Id == user.Id).FirstOrDefault().Amount;
            }
            else
            {
                bill.YouPay = bill.OwnerPays;
            }

            if (bill.BillPayments != null && bill.BillPayments.Any())
            {
                if (bill.NotOwner)
                {
                    bill.NotOwnerBillPayments = bill.BillPayments.Where(x => x.SharedWith.Where(y => y.SharedWithUser.Id == user.Id).Any()).OrderBy(x => x.DatePaid).ToList();
                    if (bill.NotOwnerBillPayments != null && bill.NotOwnerBillPayments.Any())
                    {
                        BillPayment lastPayment = bill.NotOwnerBillPayments.LastOrDefault();
                        if (lastPayment != null)
                        {
                            bill.LastPaymentDate   = lastPayment.DatePaid;
                            bill.LastPaymentAmount = lastPayment.Amount;
                        }
                        bill.MinYear = bill.NotOwnerBillPayments.Min(x => x.DatePaid.Year);
                        bill.MaxYear = bill.NotOwnerBillPayments.Max(x => x.DatePaid.Year);
                    }
                }
                else
                {
                    BillPayment lastPayment = bill.BillPayments.OrderBy(x => x.DatePaid).LastOrDefault();
                    if (lastPayment != null)
                    {
                        bill.LastPaymentDate   = lastPayment.DatePaid;
                        bill.LastPaymentAmount = lastPayment.Amount;
                    }
                    bill.MinYear = bill.BillPayments.Min(x => x.DatePaid.Year);
                    bill.MaxYear = bill.BillPayments.Max(x => x.DatePaid.Year);
                }
                bill.MinPaid     = bill.BillPayments.Min(x => x.Amount);
                bill.MaxPaid     = bill.BillPayments.Max(x => x.Amount);
                bill.AveragePaid = bill.BillPayments.Average(x => x.Amount);
            }

            double dueInDays = (bill.DueDate - new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)).TotalDays;
            bool   isPastDue = dueInDays < 0;

            bill.DueIn   = GetDueIn(bill.IsActive, isPastDue, dueInDays);
            bill.Classes = GetClasses(bill.IsActive, isPastDue, dueInDays);

            return(bill);
        }
Пример #2
0
 public DashboardItem(BillPayment payment, ApplicationUser user)
 {
     Id       = payment.Bill.ID;
     Name     = payment.Bill.Name;
     Date     = payment.DatePaid;
     Amount   = payment.Amount;
     IsShared = payment.Bill.IsShared;
     YouPay   = payment.YouPay;
     NotOwner = payment.User.Id != user.Id;
     if (payment.SharedWith.Any())
     {
         SharedWith = payment.SharedWith.Select(x => x.SharedWithUser).ToList();
     }
     Type   = "Bill";
     IsPaid = true;
 }
Пример #3
0
 public SharedBillPayment(BillPayment billPayment, ApplicationUser user, SharedPercentage percentage)
 {
     BillPayment      = billPayment;
     SharedWithUser   = user;
     SharedPercentage = percentage;
 }
Пример #4
0
 public SharedBillPayment()
 {
     BillPayment = new BillPayment();
 }