public DashboardItem(LoanPayment payment, ApplicationUser user)
 {
     Id       = payment.Loan.ID;
     Name     = payment.Loan.Name;
     Date     = payment.DatePaid;
     Amount   = payment.Payment;
     YouPay   = payment.YouPay;
     IsShared = payment.Loan.IsShared;
     NotOwner = payment.User.Id != user.Id;
     if (payment.SharedWith.Any())
     {
         SharedWith = payment.SharedWith.Select(x => x.SharedWithUser).ToList();
     }
     Type   = "Loan";
     IsPaid = true;
 }
Esempio n. 2
0
 public SharedLoanPayment(LoanPayment loanPayment, ApplicationUser user, SharedPercentage percentage)
 {
     LoanPayment      = loanPayment;
     SharedWithUser   = user;
     SharedPercentage = percentage;
 }
Esempio n. 3
0
 public SharedLoanPayment()
 {
     LoanPayment = new LoanPayment();
 }
Esempio n. 4
0
        public static Loan Populate(this Loan loan, ApplicationUser user)
        {
            loan.NotOwner  = loan.User.Id != user.Id;
            loan.DueDate   = loan.FirstPaymentDate;
            loan.Principal = loan.LoanAmount;
            loan.OwnerPays = loan.MonthlyPayment - ((loan.SharedWith == null) ? 0 : loan.SharedWith.Sum(x => x.Amount));
            if (loan.NotOwner)
            {
                loan.YouPay = loan.SharedWith.Where(x => x.SharedWithUser.Id == user.Id).FirstOrDefault().Amount;
            }
            else
            {
                loan.YouPay = loan.OwnerPays;
            }
            DateTime lastPaymentDate = loan.FirstPaymentDate.AddMonths(-1);

            if (loan.LoanPayments != null && loan.LoanPayments.Any())
            {
                LoanPayment lastPayment = loan.LoanPayments.OrderBy(x => x.DatePaid).LastOrDefault();
                if (lastPayment != null)
                {
                    lastPaymentDate        = lastPayment.DatePaid;
                    loan.LastPaymentDate   = lastPayment.DatePaid;
                    loan.LastPaymentAmount = lastPayment.Payment;
                    loan.Principal         = lastPayment.Principal;
                    loan.DueDate           = loan.GetNextDueDate(loan.LastPaymentDate, user);
                }
                if (loan.NotOwner)
                {
                    loan.NotOwnerLoanPayments = loan.LoanPayments.Where(x => x.SharedWith.Where(y => y.SharedWithUser.Id == user.Id).Any()).OrderBy(x => x.DatePaid).ToList();
                    if (loan.NotOwnerLoanPayments != null && loan.NotOwnerLoanPayments.Any())
                    {
                        lastPayment = loan.NotOwnerLoanPayments.LastOrDefault();
                        if (lastPayment != null)
                        {
                            loan.LastPaymentDate   = lastPayment.DatePaid;
                            loan.LastPaymentAmount = lastPayment.Payment;
                        }
                        loan.PaymentMinYear = loan.NotOwnerLoanPayments.Min(x => x.DatePaid.Year);
                        loan.PaymentMaxYear = loan.NotOwnerLoanPayments.Max(x => x.DatePaid.Year);
                    }
                }
                else
                {
                    loan.PaymentMinYear = loan.LoanPayments.Min(x => x.DatePaid.Year);
                    loan.PaymentMaxYear = loan.LoanPayments.Max(x => x.DatePaid.Year);
                }
            }

            loan.LoanOutlook = loan.GetLoanOutlook(lastPaymentDate);
            if (loan.LoanOutlook.Any())
            {
                loan.PaymentsRemaining = loan.LoanOutlook.Count();
                loan.OutlookMinYear    = loan.LoanOutlook.Min(x => x.Date.Year);
                loan.OutlookMaxYear    = loan.LoanOutlook.Max(x => x.Date.Year);
                loan.NextPayment       = loan.LoanOutlook.FirstOrDefault();
            }

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

            loan.DueIn   = GetDueIn(loan.IsActive, isPastDue, dueInDays);
            loan.Classes = GetClasses(loan.IsActive, isPastDue, dueInDays);
            return(loan);
        }