public EditBillViewModel(int id)
        {
            this.CustomBills = new List <CustomBillViewModel>();
            this.DOTM        = new List <BootstrapLI>();

            PBProxy p = new PBProxy();
            Bill    b = p.GetBill(id);

            this.Bill = Mapper.Map <Bill, BillViewModel>(b);
            this.Bill.DueDaySuffix = Utility.IntSuffix(this.Bill.DueDay);
            for (int i = 1; i < 32; i++)
            {
                this.DOTM.Add(new BootstrapLI()
                {
                    Text = i.ToString() + Utility.IntSuffix(i), Value = i.ToString(), Selected = (i == b.DueDay)
                });
            }

            IEnumerable <CustomBill> cbills = p.GetCustomBills(b.Id);

            if (cbills != null)
            {
                this.Bill.CustomBillCount = cbills.Count();
                //this.CustomBills = Mapper.Map<List<CustomBillViewModel>>(cbills);
            }

            p = null;
        }
        public PaycheckViewModel(Guid userid, string type)
        {
            Type   = type;
            UserID = userid;
            var p = new PBProxy();

            PayCheck = p.GetPaycheck(userid.ToString(), type);
            Exists   = this.PayCheck != null;
        }
        public static SettingsViewModel GetSettings(Guid userid)
        {
            PBProxy  p    = new PBProxy();
            Setting  temp = p.GetSettings(userid);
            Paycheck pc   = p.GetPaychecks(userid).FirstOrDefault();

            p = null;

            SettingsViewModel Return = Mapper.Map <SettingsViewModel>(temp);

            Return.PaycheckAmount = pc == null ? 0 : pc.Amount;

            return(Return);
        }
        public CustomBillsViewModel(int id)
        {
            this.CustomBills = new List <CustomBillViewModel>();

            PBProxy p = new PBProxy();
            Bill    b = p.GetBill(id);

            this.Bill = Mapper.Map <Bill, BillViewModel>(b);
            this.Bill.DueDaySuffix = Utility.IntSuffix(this.Bill.DueDay);

            IEnumerable <CustomBill> cbills = p.GetCustomBills(b.Id);

            if (cbills != null)
            {
                this.CustomBills = Mapper.Map <List <CustomBillViewModel> >(cbills);
            }

            p = null;
        }
        public ListBillsViewModel(Guid userid)
        {
            this.Bills = new List <BillViewModel>();

            PBProxy p = new PBProxy();

            foreach (Bill b in p.GetBills(userid).OrderBy(a => a.DueDay))
            {
                BillViewModel bill = Mapper.Map <BillViewModel>(b);
                bill.DueDaySuffix = Utility.IntSuffix(bill.DueDay);

                IEnumerable <CustomBill> cbills = p.GetCustomBills(b.Id).OrderBy(a => a.BillDate);
                if (cbills != null)
                {
                    bill.CustomBillCount = cbills.Count();
                }

                this.Bills.Add(bill);
            }
            p = null;
        }
        public IncomeViewModel(Guid userid)
        {
            this.Paychecks = new List <PaycheckViewModel>();

            PBProxy p = new PBProxy();

            this.Paychecks = Mapper.Map <List <PaycheckViewModel> >(p.GetPaychecks(userid).OrderBy(a => a.Type));

            int index = 0;

            foreach (string type in "A,B,C,D".Split(','))
            {
                if (this.Paychecks.All(a => a.Type != type))
                {
                    this.Paychecks.Insert(index, new PaycheckViewModel()
                    {
                        Type = type, Exists = false, UserID = userid, PayCheck = null
                    });
                }
                index++;
            }

            this.PayDay = p.GetPaydays(userid).FirstOrDefault();
        }
Beispiel #7
0
        public IActionResult Get()
        {
            try
            {
                PBProxy pb       = new PBProxy();
                Guid    userGuid = new Guid(_userManager.GetUserId(HttpContext.User));
                //get Settings
                var settings = _repository.GetSettingsByUser(userGuid);

                //get list of all bills
                var bills    = _repository.GetBillsByUser(userGuid);
                var AllBills = _repository.GetListBillsViewModelByUser(userGuid);

                //get payday seed
                var paydayseed = _repository.GetPaydaySeedByUser(userGuid);
                SetSeed(ref paydayseed, settings.PreviousPeriodsToShow);

                //get paycheck list
                var payChecks = GetPaydays(paydayseed.Paydate);

                //get firstday based on payday seed
                var firstDay = FindFirstDay(paydayseed);

                //prepare for foreach day
                var      currentMonth      = -1;
                var      currentCheckIndex = 0;
                var      currentMonthIndex = -1;
                string[] monthColors       = { "C4FFEA", "D1D7FF", "FFCCF9", "FFF6D8" };
                var      CurrentMonth      = 0;
                var      daysShowing       = (settings.ChecksToShow + 1) * 14;
                var      showData          = false;

                PaycheckSummaryViewModel summary = null;
                var paycheckdetails = new PaycheckDetailsViewModel();
                var home            = new HomePageViewModel();



                //foreach day
                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, DayOfWeek = (int)tempdate.DayOfWeek, Index = dayIndex, MonthColor = monthColors[currentMonthIndex]
                    };
                    var paycheckType = tempdate.Day <= 14 ? "A" : "B";

                    if (payChecks.Any(a => a == tempdate))
                    {
                        home.DayIndexOfCurrentPeriod = tempdate > DateTime.Now ? home.DayIndexOfCurrentPeriod : dayIndex;
                        var inLastPaycheck = (daysShowing - dayIndex) < 13;
                        showData = !inLastPaycheck;
                        if (currentCheckIndex > 0)
                        {
                            paycheckdetails = new PaycheckDetailsViewModel {
                                Summary = summary
                            };
                            home.Days.FirstOrDefault(a => a.Index == currentCheckIndex).Paycheck = paycheckdetails;
                            summary = new PaycheckSummaryViewModel();
                        }
                        currentCheckIndex = dayIndex;
                        summary           = new PaycheckSummaryViewModel
                        {
                            Payday  = tempdate,
                            Credits = _repository.GetPaycheck(userGuid, paycheckType).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    = _repository.GetCustomBills(todaysbill.Id);
                                var thiscustombill =
                                    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    = _repository.GetCustomBills(todaysbill.Id);
                                        var thiscustombill = 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
                    }
                    home.Days.Add(day);
                    #endregion
                }



                return(Ok(Mapper.Map <HomePageViewModel>(home)));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error: " + ex.Message);
                return(BadRequest("Error happened: " + ex.Message));
            }
        }
        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;
        }
        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;
        }