public async Task <List <SavedReportListViewModel> > GetSavedReportPlanList([FromQuery] ReportFilterViewModel model)
        {
            var companies = await _companyBusinessManager.GetCompanies();

            var userId = new Guid(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var list = await _reportBusinessManager.GetSavedPlanReport(userId);

            var result = list.GroupBy(x => x.CompanyId, x => x.Name, (companyId, names) => new {
                Key   = companyId ?? 0,
                Count = names.Count(),
                Name  = names.First()
            }).Select(x => new SavedReportListViewModel()
            {
                Name      = x.Name,
                CompanyId = x.Key,
                Count     = x.Count
            }).ToList();

            var planCompanies = companies.Where(x => !result.Any(y => y.CompanyId == x.Id)).ToList();

            if (planCompanies.Count > 0)
            {
                result.AddRange(planCompanies.Select(x => new SavedReportListViewModel()
                {
                    Name      = x.Name,
                    CompanyId = x.Id,
                    Count     = 0
                }));
            }

            return(result);
        }
        public async Task <IActionResult> DetailsPlan(long id)
        {
            var company = await _companyBusinessManager.GetCompany(id);

            if (company == null)
            {
                return(BadRequest());
            }
            ViewBag.CompanyId   = company.Id;
            ViewBag.CompanyName = company.Name;

            var userId = new Guid(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var report = await _reportBusinessManager.GetSavedPlanReport(userId, id);

            var customerTypes = await _customerBusinessManager.GetCustomerTypes();

            var rows = new Dictionary <string, List <SavedReportFieldViewModel> >();

            rows.Add("Name", new List <SavedReportFieldViewModel>());
            rows.Add("Total Customers", new List <SavedReportFieldViewModel>());
            foreach (var ctype in customerTypes)
            {
                rows.Add(ctype.Name, new List <SavedReportFieldViewModel>());
            }

            foreach (var item in report)
            {
                if (rows.ContainsKey("Name"))
                {
                    rows["Name"].Add(new SavedReportFieldViewModel()
                    {
                        Id   = item.Id,
                        Name = item.Date.ToString("MMM/dd/yyyy"),
                    });
                }

                foreach (var field in item.Fields)
                {
                    if (rows.ContainsKey(field.Name))
                    {
                        rows[field.Name].Add(_mapper.Map <SavedReportFieldViewModel>(field));
                    }
                    else
                    {
                        rows.Add(field.Name, new List <SavedReportFieldViewModel>()
                        {
                            _mapper.Map <SavedReportFieldViewModel>(field)
                        });
                    }
                }
            }

            return(View(rows));
        }
Example #3
0
        public async Task <IActionResult> GenerateAgingReport(ReportFilterViewModel model)
        {
            try {
                if (!ModelState.IsValid)
                {
                    throw new Exception("Form is not valid!");
                }

                var userId = new Guid(User.FindFirstValue(ClaimTypes.NameIdentifier));

                var result = await _reportBusinessManager.GetAgingReport(model.CompanyId, model.Date, 30, model.NumberOfPeriods, false);

                var plan = await _reportBusinessManager.GetSavedPlanReport(userId, model.CompanyId, model.Date);

                var viewDataDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
                {
                    { "Plan", _mapper.Map <SavedReportPlanViewModel>(plan) }
                };

                string html = await _viewRenderService.RenderToStringAsync("_AgingReportPartial", result, viewDataDictionary);

                return(Ok(html));
            } catch (Exception er) {
                return(BadRequest(er.Message ?? er.StackTrace));
            }
        }