public async Task ShowPastReportsAsync()
 {
     await this.ViewService.ExecuteBusyActionAsync(
         async () =>
         {
             ExpenseReportsViewModel expenseReportsViewModel = new ExpenseReportsViewModel();
             await expenseReportsViewModel.LoadApprovedExpenseReportsAsync();
             this.CurrentViewModel = expenseReportsViewModel;
         });
 }
 internal ExpenseReportViewModel(ExpenseReportsViewModel expenseReportsViewModel, ExpenseReport expenseReport)
     : this()
 {
     ExpenseReportsViewModel = expenseReportsViewModel;
     this.Load(expenseReport);
 }
        public async Task <ObservableCollection <SummaryItemViewModel> > GetSummaryItems()
        {
            List <SummaryItem> items = await this._repository.GetSummaryItemsAsync(this._employeeViewModel.EmployeeId);

            var summaryItems = from item in items
                               select new SummaryItemViewModel()
            {
                Id          = item.Id,
                Amount      = item.Amount,
                Date        = Convert.ToDateTime(item.Date),
                Description = item.Description,
                Submitter   = item.Submitter,
                ItemType    = item.ItemType,
            };

            this.SummaryItems = new ObservableCollection <SummaryItemViewModel>(summaryItems);

            this.NumberOfCharges =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge
                 select item).Count();
            this.AmountOfCharges =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge
                 select Convert.ToDecimal(item.Amount)).Sum();
            this.NumberOfChargesLT30Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days < 30
                 select item).Count();
            this.AmountOfChargesLT30Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days < 30
                 select Convert.ToDecimal(item.Amount)).Sum();
            this.NumberOfCharges30To44Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 30 &&
                 DateTime.Today.Subtract(item.Date).Days < 45
                 select item).Count();
            this.AmountOfCharges30To44Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 30 &&
                 DateTime.Today.Subtract(item.Date).Days < 45
                 select Convert.ToDecimal(item.Amount)).Sum();
            this.NumberOfChargesGT45Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 45
                 select item).Count();
            this.AmountOfChargesGT45Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 45
                 select Convert.ToDecimal(item.Amount)).Sum();

            if (this.NumberOfCharges > 0)
            {
                this.BeginDateOfCharges = (from item in this.SummaryItems
                                           where item.ItemType == ItemType.Charge
                                           select item.Date).Min();
                this.EndDateOfCharges = (from item in this.SummaryItems
                                         where item.ItemType == ItemType.Charge
                                         select item.Date).Max();
            }

            this.NumberOfSavedReports = (from item in this.SummaryItems
                                         where item.ItemType == ItemType.SavedReport
                                         select item).Count();
            this.AmountOfSavedReports = Convert.ToDecimal(
                (from item in summaryItems
                 where item.ItemType == ItemType.SavedReport
                 select item.Amount).Sum());

            this.NumberOfPendingReports = (from item in this.SummaryItems
                                           where item.ItemType == ItemType.PendingReport
                                           select item).Count();
            this.AmountOfPendingReports = Convert.ToDecimal(
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.PendingReport
                 select item.Amount).Sum());

            var expenseReportsViewModel = new ExpenseReportsViewModel();

            this._amountOwedToCreditCard = await this._repository.GetAmountOwedToCreditCardAsync(this._employeeViewModel.EmployeeId);

            this._amountOwedToEmployee = await this._repository.GetAmountOwedToEmployeeAsync(this._employeeViewModel.EmployeeId);

            this.NumberOfReportsNeedingApproval = (from item in this.SummaryItems
                                                   where item.ItemType == ItemType.UnresolvedReport
                                                   select item).Count();
            this.AmountOfReportsNeedingApproval = Convert.ToDecimal(
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.UnresolvedReport
                 select item.Amount).Sum());

            GroupItems();

            if (this.NumberOfReportsNeedingApproval > 0)
            {
                this.MyApprovalsBackgroundColor =
                    new Tuple <byte, byte, byte>(255, 127, 127);
            }
            else
            {
                this.MyApprovalsBackgroundColor =
                    new Tuple <byte, byte, byte>(0, 255, 127);
            }


            return(this.SummaryItems);
        }
        public async Task<ObservableCollection<SummaryItemViewModel>> GetSummaryItems()
        {
            List<SummaryItem> items = await this._repository.GetSummaryItemsAsync(this._employeeViewModel.EmployeeId);

            var summaryItems = from item in items
                               select new SummaryItemViewModel()
                               {
                                   Id = item.Id,
                                   Amount = item.Amount,
                                   Date = Convert.ToDateTime(item.Date),
                                   Description = item.Description,
                                   Submitter = item.Submitter,
                                   ItemType = item.ItemType,
                               };
            this.SummaryItems = new ObservableCollection<SummaryItemViewModel>(summaryItems);

            this.NumberOfCharges =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge
                 select item).Count();
            this.AmountOfCharges =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge
                 select Convert.ToDecimal(item.Amount)).Sum();
            this.NumberOfChargesLT30Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days < 30
                 select item).Count();
            this.AmountOfChargesLT30Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days < 30
                 select Convert.ToDecimal(item.Amount)).Sum();
            this.NumberOfCharges30To44Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 30
                 && DateTime.Today.Subtract(item.Date).Days < 45
                 select item).Count();
            this.AmountOfCharges30To44Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 30
                 && DateTime.Today.Subtract(item.Date).Days < 45
                 select Convert.ToDecimal(item.Amount)).Sum();
            this.NumberOfChargesGT45Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 45
                 select item).Count();
            this.AmountOfChargesGT45Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 45
                 select Convert.ToDecimal(item.Amount)).Sum();

            if (this.NumberOfCharges > 0)
            {
                this.BeginDateOfCharges = (from item in this.SummaryItems
                                      where item.ItemType == ItemType.Charge
                                      select item.Date).Min();
                this.EndDateOfCharges = (from item in this.SummaryItems
                                    where item.ItemType == ItemType.Charge
                                    select item.Date).Max();
            }

            this.NumberOfSavedReports = (from item in this.SummaryItems
                                    where item.ItemType == ItemType.SavedReport
                                    select item).Count();
            this.AmountOfSavedReports = Convert.ToDecimal(
                (from item in summaryItems
                 where item.ItemType == ItemType.SavedReport
                 select item.Amount).Sum());

            this.NumberOfPendingReports = (from item in this.SummaryItems
                                      where item.ItemType == ItemType.PendingReport
                                      select item).Count();
            this.AmountOfPendingReports = Convert.ToDecimal(
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.PendingReport
                 select item.Amount).Sum());

            var expenseReportsViewModel = new ExpenseReportsViewModel();
            this._amountOwedToCreditCard = await this._repository.GetAmountOwedToCreditCardAsync(this._employeeViewModel.EmployeeId);
            this._amountOwedToEmployee = await this._repository.GetAmountOwedToEmployeeAsync(this._employeeViewModel.EmployeeId);

            this.NumberOfReportsNeedingApproval = (from item in this.SummaryItems
                                              where item.ItemType == ItemType.UnresolvedReport
                                              select item).Count();
            this.AmountOfReportsNeedingApproval = Convert.ToDecimal(
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.UnresolvedReport
                 select item.Amount).Sum());

            GroupItems();

            if (this.NumberOfReportsNeedingApproval > 0)
            {
              this.MyApprovalsBackgroundColor = 
                new Tuple<byte, byte, byte>(255, 127, 127);
            }
            else
            {
              this.MyApprovalsBackgroundColor = 
                new Tuple<byte, byte, byte>(0, 255, 127);
            }


            return this.SummaryItems;
        }
Example #5
0
        public ObservableCollection <SummaryItemViewModel> GetSummaryItems()
        {
            List <SummaryItem> items = this._repository.GetSummaryItems(this.EmployeeViewModel.EmployeeId);

            var summaryItems = from item in items
                               select new SummaryItemViewModel()
            {
                Id          = item.Id,
                Amount      = item.Amount,
                Date        = Convert.ToDateTime(item.Date),
                Description = item.Description,
                Submitter   = item.Submitter,
                ItemType    = item.ItemType,
            };

            this.SummaryItems          = new ObservableCollection <SummaryItemViewModel>(summaryItems);
            this.ListOfAmountOfCharges = new ObservableCollection <SummaryItemViewModel>();
            _numberOfCharges           =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge
                 select item).Count();
            _amountOfCharges =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge
                 select Convert.ToDecimal(item.Amount)).Sum();
            _numberOfChargesLT30Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days < 30
                 select item).Count();
            _amountOfChargesLT30Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days < 30
                 select Convert.ToDecimal(item.Amount)).Sum();
            _numberOfCharges30To44Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 30 &&
                 DateTime.Today.Subtract(item.Date).Days < 45
                 select item).Count();
            _amountOfCharges30To44Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 30 &&
                 DateTime.Today.Subtract(item.Date).Days < 45
                 select Convert.ToDecimal(item.Amount)).Sum();
            _numberOfChargesGT45Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 45
                 select item).Count();
            _amountOfChargesGT45Days =
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.Charge &&
                 DateTime.Today.Subtract(item.Date).Days >= 45
                 select Convert.ToDecimal(item.Amount)).Sum();

            ListOfAmountOfCharges.Add(new SummaryItemViewModel()
            {
                Amount = _amountOfChargesLT30Days, Description = "Less than 30 days"
            });
            ListOfAmountOfCharges.Add(new SummaryItemViewModel()
            {
                Amount = _amountOfCharges30To44Days, Description = "30-45 days"
            });
            ListOfAmountOfCharges.Add(new SummaryItemViewModel()
            {
                Amount = _amountOfChargesGT45Days, Description = "Over 35 days"
            });

            if (_numberOfCharges > 0)
            {
                _beginDateOfCharges = (from item in this.SummaryItems
                                       where item.ItemType == ItemType.Charge
                                       select item.Date).Min();
                _endDateOfCharges = (from item in this.SummaryItems
                                     where item.ItemType == ItemType.Charge
                                     select item.Date).Max();
            }

            numberOfSavedReports = (from item in this.SummaryItems
                                    where item.ItemType == ItemType.SavedReport
                                    select item).Count();
            amountOfSavedReports = Convert.ToDecimal(
                (from item in summaryItems
                 where item.ItemType == ItemType.SavedReport
                 select item.Amount).Sum());

            numberOfPendingReports = (from item in this.SummaryItems
                                      where item.ItemType == ItemType.PendingReport
                                      select item).Count();
            amountOfPendingReports = Convert.ToDecimal(
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.PendingReport
                 select item.Amount).Sum());

            var expenseReportsViewModel = new ExpenseReportsViewModel();

            amountOwedToCreditCard = this._repository.GetAmountOwedToCreditCard(this.EmployeeViewModel.EmployeeId);
            amountOwedToEmployee   = this._repository.GetAmountOwedToEmployee(this.EmployeeViewModel.EmployeeId);

            numberOfReportsNeedingApproval = (from item in this.SummaryItems
                                              where item.ItemType == ItemType.UnresolvedReport
                                              select item).Count();
            amountOfReportsNeedingApproval = Convert.ToDecimal(
                (from item in this.SummaryItems
                 where item.ItemType == ItemType.UnresolvedReport
                 select item.Amount).Sum());

            List <ExpenseReport> expenseReports = this._repository.GetExpenseReports(this.EmployeeViewModel.EmployeeId);

            SavedReportsMonthlyHistory   = GetSavedReportsMonthlyHistory(expenseReports);
            PendingReportsMonthlyHistory = GetPendingReportsMonthlyHistory(expenseReports);
            PastReportsMonthlyHistory    = GetPastReportsMonthlyHistory(expenseReports);
            AmountMonthlyHistory         = GetAmountMonthlyHistory(expenseReports);
            DateTime minDate = DateTime.Now.AddYears(-1);
            var      a       = expenseReports.GroupBy(i => i.Status).ToList();

            if (SavedReportsMonthlyHistory.Count != 0)
            {
                DateTime min = SavedReportsMonthlyHistory.Min(x => x.Date);
                if (min < minDate)
                {
                    minDate = min;
                }
            }
            if (PendingReportsMonthlyHistory.Count != 0)
            {
                DateTime min = PendingReportsMonthlyHistory.Min(x => x.Date);
                if (min < minDate)
                {
                    minDate = min;
                }
            }
            if (PastReportsMonthlyHistory.Count != 0)
            {
                DateTime min = PastReportsMonthlyHistory.Min(x => x.Date);
                if (min < minDate)
                {
                    minDate = min;
                }
            }
            BeginDateOfHistory        = minDate;
            EndDateOfHistory          = DateTime.Now;
            HistorySelectionStartDate = EndDateOfHistory.AddYears(-1);
            HistorySelectionEndDate   = EndDateOfHistory;
            GroupItems();

            return(this.SummaryItems);
        }