Пример #1
0
        public HomePageViewModel(Guid userid)
        {
            SettingsViewModel settings = SettingsViewModel.GetSettings(userid);

            this.Paychecks = new List <PaycheckDetailsViewModel>();

            DayViewModel             day     = null;
            PaycheckSummaryViewModel summary = null;

            PBProxy p          = new PBProxy();
            Payday  PayDaySeed = p.GetPaydays(userid).FirstOrDefault();

            SetSeed(ref PayDaySeed, settings.PreviousPeriodsToShow);

            ListBillsViewModel AllBills = new ListBillsViewModel(userid);

            int  CurrentMonth    = 0;
            bool WillMonthChange = false;

            for (int checkIndex = 0; checkIndex < settings.ChecksToShow; checkIndex++)
            {
                DateTime thisdate     = PayDaySeed.Paydate.AddDays(checkIndex * 14);
                string   PaycheckType = thisdate.Day <= 14 ? "A" : "B";

                PaycheckDetailsViewModel paycheckdetails = new PaycheckDetailsViewModel();
                PaycheckViewModel        Paycheck        = new PaycheckViewModel(userid, PaycheckType);

                summary         = new PaycheckSummaryViewModel();
                summary.Payday  = thisdate;
                summary.Credits = Paycheck.PayCheck.Amount;

                #region For Each Day In Pay Period

                for (int dayIndex = 0; dayIndex < 14; dayIndex++)
                {
                    DateTime tempdate = thisdate.AddDays(dayIndex);
                    if (CurrentMonth == 0 | tempdate.Day == 31 | tempdate.Day < 28)
                    {
                        WillMonthChange = false;
                    }
                    else
                    {
                        WillMonthChange = tempdate.AddDays(1).Month != CurrentMonth;
                    }
                    CurrentMonth = tempdate.Month;

                    day      = new DayViewModel();
                    day.Date = tempdate;

                    #region Tithe

                    if (dayIndex == 0)
                    {
                        if (settings.AddTithe)
                        {
                            BillViewModel Tithe = new BillViewModel();
                            Tithe.Name            = "Tithe";
                            Tithe.Amount          = Paycheck.PayCheck.Amount * settings.TitheMultiplier;
                            Tithe.BackgroundColor = settings.TitheBGColor;
                            Tithe.ForeColor       = settings.TitheForeColor;
                            summary.Debits       += Tithe.Amount;
                            Tithe.DueDay          = tempdate.Day;
                            day.Bills.Add(Tithe);
                        }
                    }

                    #endregion

                    if (tempdate.ToShortDateString() == DateTime.Now.ToShortDateString())
                    {
                        summary.CurrentClass = "list-group-item-info";
                    }
                    if (AllBills.Bills.Any(b => b.DueDay == tempdate.Day))
                    {
                        List <BillViewModel> todaysbills = AllBills.Bills.Where(b => b.DueDay == tempdate.Day).ToList();
                        foreach (BillViewModel todaysbill in todaysbills)
                        {
                            CustomBillsViewModel CustomBills    = new CustomBillsViewModel(todaysbill.Id);
                            CustomBillViewModel  thiscustombill =
                                CustomBills.CustomBills.FirstOrDefault(
                                    cb => cb.BillDate.Year == tempdate.Year && cb.BillDate.Month == tempdate.Month);

                            if (thiscustombill != null)
                            {
                                BillViewModel billcopy = new BillViewModel(todaysbill);
                                //billcopy.Name = "* " + billcopy.Name;
                                billcopy.Amount = thiscustombill.Amount;
                                day.Bills.Add(billcopy);
                                summary.Debits += billcopy.Amount;
                            }
                            else
                            {
                                day.Bills.Add(todaysbill);
                                summary.Debits += todaysbill.Amount;
                            }
                        }
                    }

                    #region Month Changed

                    if (WillMonthChange)
                    {
                        for (int d = tempdate.Day + 1; d < 32; d++)
                        {
                            if (AllBills.Bills.Any(b => b.DueDay == d))
                            {
                                List <BillViewModel> todaysbills = AllBills.Bills.Where(b => b.DueDay == d).ToList();
                                foreach (BillViewModel todaysbill in todaysbills)
                                {
                                    CustomBillsViewModel CustomBills    = new CustomBillsViewModel(todaysbill.Id);
                                    CustomBillViewModel  thiscustombill =
                                        CustomBills.CustomBills.FirstOrDefault(cb => cb.BillDate.Month == CurrentMonth);

                                    if (thiscustombill != null)
                                    {
                                        BillViewModel billcopy = new BillViewModel(todaysbill);
                                        //billcopy.Name = "* " + billcopy.Name + " (" + d.ToString() + ")";
                                        billcopy.Amount = thiscustombill.Amount;
                                        day.Bills.Add(billcopy);
                                        summary.Debits += billcopy.Amount;
                                    }
                                    else
                                    {
                                        //todaysbill.Name = todaysbill.Name + " (" + d.ToString() + ")";
                                        day.Bills.Add(todaysbill);
                                        summary.Debits += todaysbill.Amount;
                                    }
                                }
                            }
                        }
                    }

                    #endregion

                    paycheckdetails.Days.Add(day);
                }

                #endregion

                paycheckdetails.Summary = summary;
                summary = null;

                this.Paychecks.Add(paycheckdetails);
                paycheckdetails = null;
            }

            p = null;
        }
Пример #2
0
        public NewHomePageViewModel(Guid userid)
        {
            var currentMonth      = -1;
            var currentMonthIndex = -1;

            string[] monthColors = { "C4FFEA", "D1D7FF", "FFCCF9", "FFF6D8" };
            Days = new List <DayViewModel>();
            var db       = new PBProxy();
            var settings = SettingsViewModel.GetSettings(userid);
            var AllBills = new ListBillsViewModel(userid);

            var PayDaySeed   = db.GetPaydays(userid).FirstOrDefault();
            var CurrentMonth = 0;

            SetSeed(ref PayDaySeed, settings.PreviousPeriodsToShow);
            var payChecks = GetPaydays(PayDaySeed.Paydate);

            var firstDay = FindFirstDay(PayDaySeed);

            var currentCheckIndex            = 0;
            PaycheckSummaryViewModel summary = null;
            var paycheckdetails = new PaycheckDetailsViewModel();

            var daysShowing = (settings.ChecksToShow + 1) * 14;
            var showData    = false;

            for (var dayIndex = 0; dayIndex < daysShowing; dayIndex++)
            {
                #region For Each Day In Pay Period
                var tempdate = firstDay.AddDays(dayIndex);
                if (tempdate.Month != currentMonth)
                {
                    currentMonth = tempdate.Month;
                    currentMonthIndex++;
                }
                var day = new DayViewModel {
                    Date = tempdate, Index = dayIndex, MonthColor = monthColors[currentMonthIndex]
                };
                var paycheckType = tempdate.Day <= 14 ? "A" : "B";

                if (payChecks.Any(a => a == tempdate))
                {
                    DayIndexOfCurrentPeriod = tempdate > DateTime.Now ? DayIndexOfCurrentPeriod : dayIndex;
                    var inLastPaycheck = (daysShowing - dayIndex) < 13;
                    showData = !inLastPaycheck;
                    if (currentCheckIndex > 0)
                    {
                        paycheckdetails = new PaycheckDetailsViewModel {
                            Summary = summary
                        };
                        Days.FirstOrDefault(a => a.Index == currentCheckIndex).Paycheck = paycheckdetails;
                        summary = new PaycheckSummaryViewModel();
                    }
                    currentCheckIndex = dayIndex;
                    summary           = new PaycheckSummaryViewModel
                    {
                        Payday  = tempdate,
                        Credits = new PaycheckViewModel(userid, paycheckType).PayCheck.Amount
                    };

                    #region Tithe

                    if (showData && settings.AddTithe)
                    {
                        var tithe = new BillViewModel
                        {
                            Name            = "",
                            Icon            = "fa-heart-o",
                            Amount          = summary.Credits * settings.TitheMultiplier,
                            BackgroundColor = settings.TitheBGColor,
                            ForeColor       = settings.TitheForeColor,
                            DueDay          = tempdate.Day
                        };
                        day.Bills.Add(tithe);

                        #endregion
                    }
                }
                day.PaydayIndex = currentCheckIndex;
                //day.Bills.Add(new BillViewModel() { Amount = 0, Name = dayIndex.ToString()});

                var WillMonthChange = false;
                if (CurrentMonth == 0 | tempdate.Day == 31 | tempdate.Day < 28)
                {
                    WillMonthChange = false;
                }
                else
                {
                    WillMonthChange = tempdate.AddDays(1).Month != CurrentMonth;
                }
                CurrentMonth = tempdate.Month;

                if (showData)
                {
                    if (tempdate.ToShortDateString() == DateTime.Now.ToShortDateString())
                    {
                        if (summary != null)
                        {
                            summary.CurrentClass = "list-group-item-info";
                        }
                    }
                    if (AllBills.Bills.Any(b => b.DueDay == tempdate.Day))
                    {
                        var todaysbills = AllBills.Bills.Where(b => b.DueDay == tempdate.Day).ToList();
                        foreach (var todaysbill in todaysbills)
                        {
                            var CustomBills    = new CustomBillsViewModel(todaysbill.Id);
                            var thiscustombill =
                                CustomBills.CustomBills.FirstOrDefault(
                                    cb => cb.BillDate.Year == tempdate.Year && cb.BillDate.Month == tempdate.Month);

                            if (thiscustombill != null)
                            {
                                var billcopy = new BillViewModel(todaysbill);
                                billcopy.Amount = thiscustombill.Amount;
                                day.Bills.Add(billcopy);
                                if (summary != null)
                                {
                                    summary.Debits += billcopy.Amount;
                                }
                            }
                            else
                            {
                                day.Bills.Add(todaysbill);
                                if (summary != null)
                                {
                                    summary.Debits += todaysbill.Amount;
                                }
                            }
                        }
                    }

                    #region Month Changed

                    if (WillMonthChange)
                    {
                        for (var d = tempdate.Day + 1; d < 32; d++)
                        {
                            if (AllBills.Bills.Any(b => b.DueDay == d))
                            {
                                var todaysbills = AllBills.Bills.Where(b => b.DueDay == d).ToList();
                                foreach (BillViewModel todaysbill in todaysbills)
                                {
                                    var CustomBills    = new CustomBillsViewModel(todaysbill.Id);
                                    var thiscustombill = CustomBills.CustomBills.FirstOrDefault(cb => cb.BillDate.Month == CurrentMonth);

                                    if (thiscustombill != null)
                                    {
                                        var billcopy = new BillViewModel(todaysbill);
                                        billcopy.Amount = thiscustombill.Amount;
                                        day.Bills.Add(billcopy);
                                    }
                                    else
                                    {
                                        day.Bills.Add(todaysbill);
                                    }
                                }
                            }
                        }
                    }

                    #endregion
                }
                this.Days.Add(day);
            }
            summary.Debits  = 0;
            paycheckdetails = new PaycheckDetailsViewModel {
                Summary = summary
            };
            Days.FirstOrDefault(a => a.Index == currentCheckIndex).Paycheck = paycheckdetails;
            #endregion

            db = null;
        }