예제 #1
0
        public static List <DashboardItem> GetDashboardItems(this IEnumerable <Loan> loans, DashboardDateRange range, ApplicationUser user)
        {
            List <DashboardItem> items = new List <DashboardItem>();

            foreach (Loan loan in loans)
            {
                foreach (LoanOutlook outlook in loan.LoanOutlook.Where(x => x.Date >= range.StartDate && x.Date <= range.EndDate))
                {
                    items.Add(new DashboardItem(outlook));
                }

                if (loan.LoanPayments.Any())
                {
                    items.AddRange(loan.LoanPayments.Where(x => x.DatePaid >= range.StartDate && x.DatePaid <= range.EndDate).Select(x => new DashboardItem(x, user)));
                }
            }

            return(items);
        }
예제 #2
0
        public static List <DashboardIncomeItem> GetDashboardItems(this IEnumerable <Income> incomes, DashboardDateRange range)
        {
            List <DashboardIncomeItem> items = new List <DashboardIncomeItem>();

            foreach (Income income in incomes)
            {
                DateTime date   = income.Date;
                Decimal  amount = income.Amount;
                if (income.Date >= range.StartDate && income.Date <= range.EndDate)
                {
                    items.Add(new DashboardIncomeItem(income));
                }

                if (income.PaymentFrequency == PaymentFrequency.SemiMonthly && income.SecondDate >= range.StartDate && income.SecondDate <= range.EndDate)
                {
                    date = income.SecondDate;
                    DashboardIncomeItem item = new DashboardIncomeItem(income)
                    {
                        Date   = income.SecondDate,
                        Amount = income.SecondAmount
                    };
                    items.Add(item);
                }

                while (date <= range.EndDate)
                {
                    if (income.PaymentFrequency != PaymentFrequency.SemiMonthly)
                    {
                        date = income.GetNextDate(date);
                    }
                    else
                    {
                        if (date.Date.Day == income.Date.Day)
                        {
                            date   = new DateTime(date.Year, date.Month, income.SecondDate.Day);
                            amount = income.SecondAmount;
                        }
                        else
                        {
                            date   = date.AddMonths(1);
                            date   = new DateTime(date.Year, date.Month, income.Date.Day);
                            amount = income.Amount;
                        }
                    }
                    if (date >= range.StartDate && date <= range.EndDate)
                    {
                        DashboardIncomeItem item = new DashboardIncomeItem(income)
                        {
                            Date   = date,
                            Amount = amount
                        };
                        items.Add(item);
                    }
                }

                if (income.IncomePayments.Any())
                {
                    items.AddRange(income.IncomePayments.Where(x => x.Date >= range.StartDate && x.Date <= range.EndDate)
                                   .Select(x => new DashboardIncomeItem(x)));
                }
            }

            return(items);
        }
예제 #3
0
        public static List <DashboardItem> GetDashboardItems(this IEnumerable <Bill> bills, DashboardDateRange range, ApplicationUser user)
        {
            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));
                }

                DateTime date = bill.DueDate;
                while (date <= range.EndDate)
                {
                    Tuple <DateTime, decimal> newDateAmount = bill.GetDateAmount(bill.GetNextDate(date, user), bill.Amount);
                    date = newDateAmount.Item1;
                    if (newDateAmount.Item1 >= range.StartDate && date <= range.EndDate)
                    {
                        DashboardItem item = new DashboardItem(bill)
                        {
                            Date   = date,
                            Amount = newDateAmount.Item2
                        };
                        if (bill.NotOwner)
                        {
                            item.YouPay = bill.SharedWith.Where(x => x.SharedWithUser.Id == user.Id).FirstOrDefault().Amount;
                        }
                        else
                        {
                            item.YouPay = item.Amount - bill.SharedWith.Sum(x => x.Amount);
                        }
                        items.Add(item);
                    }
                }

                if (bill.BillPayments.Any())
                {
                    items.AddRange(bill.BillPayments.Where(x => x.DatePaid >= range.StartDate && x.DatePaid <= range.EndDate)
                                   .Where(x => x.User.Id == user.Id || (x.Bill.IsShared && x.SharedWith.Any() && x.SharedWith.Where(y => y.SharedWithUser.Id == user.Id).Any()))
                                   .Select(x => new DashboardItem(x, user)));
                }
            }

            return(items);
        }