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)); }
public async Task <IActionResult> Create(InvoiceConstructorSearchViewModel model) { try { if (ModelState.IsValid) { var item = await _businessManager.CreateInvoiceConstructorSearchCriterias(_mapper.Map <InvoiceConstructorSearchDto>(model)); if (item == null) { return(NotFound()); } //model = _mapper.Map<CustomerViewModel>(item); return(RedirectToAction(nameof(Edit), new { id = item.Id })); } } catch (Exception er) { _logger.LogError(er, er.Message); } // ReportSearchCriteriaViewModel model = new ReportSearchCriteriaViewModel(); var customerTags = await _businessManager.GetCustomerTags(); ViewBag.CustomerTags = customerTags.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); var customerTypes = await _customerBusinessManager.GetCustomerTypes(); ViewBag.CustomerTypes = customerTypes.Select(x => new SelectListItem() { Text = x.Name, Value = x.Id.ToString() }).ToList(); var rechecks = model.Recheck; if (rechecks == null || rechecks.Count() == 0) { rechecks.Add(0); } ViewBag.CustomerRechecks = rechecks.Select(x => new SelectListItem() { Text = x.ToString(), Value = x.ToString() }).ToList(); return(View("Create", model)); }
public async Task <IActionResult> GenerateSavedReportPlan(ReportFilterViewModel model) { try { if (!ModelState.IsValid) { throw new Exception("Form is not valid!"); } var userId = new Guid(User.FindFirstValue(ClaimTypes.NameIdentifier)); var item = await _reportBusinessManager.GetSavedPlanReport(userId, model.CompanyId, model.Date); var customerTypes = await _customerBusinessManager.GetCustomerTypes(); SavedReportPlanViewModel result; if (item != null) { result = _mapper.Map <SavedReportPlanViewModel>(item); result.Fields.ForEach(x => { if (x.Name.Equals("Total Customers")) { x.CountReadOnly = true; x.AmountDisplay = false; } else if (x.Name.Equals("Balance") || x.Name.Equals("No Balance")) { x.CountReadOnly = true; x.AmountDisplay = false; } else if (x.Name.Equals("Total Late") || x.Name.Equals("Total")) { x.AmountReadOnly = true; x.CountReadOnly = true; } else if (customerTypes.Any(y => y.Name.Equals(x.Name))) { x.AmountDisplay = false; } }); } else { var fields = new List <SavedReportPlanFieldViewModel>(); fields.Add(new SavedReportPlanFieldViewModel() { Name = "Total Customers", CountReadOnly = true, AmountDisplay = false, }); //Add customer types foreach (var ctype in customerTypes) { fields.Add(new SavedReportPlanFieldViewModel() { Name = ctype.Name, AmountDisplay = false }); } fields.Add(new SavedReportPlanFieldViewModel() { Name = "Balance", CountReadOnly = true, AmountDisplay = false }); fields.Add(new SavedReportPlanFieldViewModel() { Name = "No Balance", CountReadOnly = true, AmountDisplay = false }); //Add Balance #region CREATE HEADERS var daysPerPeriod = 30; for (int i = -1; i < model.NumberOfPeriods; i++) { var from = (i < 0 ? -1 : 1) + i * daysPerPeriod; var to = (i + 1) * daysPerPeriod; fields.Add(new SavedReportPlanFieldViewModel() { Name = $"{from}-{to}" }); } fields.Add(new SavedReportPlanFieldViewModel() { Name = $"{1 + model.NumberOfPeriods * daysPerPeriod}+", }); fields.Add(new SavedReportPlanFieldViewModel() { Name = "Total Late", CountDisplay = true, AmountReadOnly = true, CountReadOnly = true }); fields.Add(new SavedReportPlanFieldViewModel() { Name = "Total", CountDisplay = true, AmountReadOnly = true, CountReadOnly = true }); #endregion result = new SavedReportPlanViewModel() { CompanyId = model.CompanyId, Date = model.Date, Fields = fields, NumberOfPeriods = model.NumberOfPeriods, }; } string html = await _viewRenderService.RenderToStringAsync("_SavedReportPlanPartial", result); return(Ok(html)); } catch (Exception er) { return(BadRequest(er.Message ?? er.StackTrace)); } }
public async Task <IActionResult> CreateSavedReport([FromBody] SavedReportViewModel model) { try { if (!ModelState.IsValid) { throw new Exception("Form is not valid!"); } var report = await _reportBusinessManager.GetAgingReport(model.CompanyId, model.Date, 30, model.NumberOfPeriods, false); var customerTypes = await _customerBusinessManager.GetCustomerTypes(); var fields = new List <SavedReportFieldDto>(); #region CUSTOMERS foreach (var field in report.CustomerTotal.Keys) { fields.Add(new SavedReportFieldDto() { Name = field, Count = report.CustomerTotal[field], }); } #endregion #region CUSTOMER TYPES foreach (var ctype in customerTypes) { fields.Add(new SavedReportFieldDto() { Name = ctype.Name, Count = report.CustomerTypes.ContainsKey(ctype.Name) ? report.CustomerTypes[ctype.Name] : 0 }); } #endregion #region BALANCE TOTAL foreach (var column in report.Cols) { fields.Add(new SavedReportFieldDto() { Name = column.Name, Count = report.BalanceTotal[column.Name].Count, Amount = report.BalanceTotal[column.Name].Sum }); } #endregion #region FILES var files = new List <SavedReportFileDto>(); if (model.ExportSettings != null) { foreach (var settingId in model.ExportSettings) { var settings = await _companyBusinessManager.GetExportSettings(settingId); if (settings != null) { var file = await GetExportData(model.CompanyId, model.Date, model.NumberOfPeriods, settings); if (file != null) { var fileName = settings.Title; var match = Regex.Match(fileName, @"(?:\$)?\{.*?\}", RegexOptions.IgnoreCase); if (match.Success) { string template = match.Value.Trim(new char[] { '{', '}', '$' }); var date = model.Date.ToString(template, DateTimeFormatInfo.InvariantInfo); fileName = Regex.Replace(fileName, @"(?:\$)?\{.*?\}", match.Value.Contains('$') ? date.ToUpper() : date, RegexOptions.IgnoreCase); } // var fileDate = Regex.Replace(model.Date.ToString("d", DateTimeFormatInfo.InvariantInfo), @"\b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b", settings.Title, RegexOptions.IgnoreCase); files.Add(new SavedReportFileDto() { Name = fileName, File = file }); } } } } #endregion var dto = _mapper.Map <SavedReportDto>(model); dto.ApplicationUserId = new Guid(User.FindFirstValue(ClaimTypes.NameIdentifier)); dto.Fields = fields; dto.Files = files; var result = await _reportBusinessManager.CreateSavedFactReport(dto); return(Ok(result)); } catch (Exception er) { return(BadRequest(er.Message ?? er.StackTrace)); } }