public async Task <IActionResult> CustomerCreditUtilizedSettingsView([FromQuery] ReportFilterViewModel model) { try { if (!ModelState.IsValid) { throw new Exception("Form is not valid!"); } var company = await _companyBusinessManager.GetCompany(model.CompanyId); var creditUtilizedSettings = await _businessManager.GetCustomerCreditUtilizedSettings(model.CompanyId, model.Date); model.RoundType = creditUtilizedSettings == null ? company.Settings.RoundType : creditUtilizedSettings.RoundType; var report = await _reportBusinessManager.GetAgingReport(model.CompanyId, model.Date, 30, model.NumberOfPeriods, false); var creditUtilizedList = new List <CustomerCreditUtilizedViewModel>(); foreach (var data in report.Rows) { var customer = data.Customer; var creditUtilizeds = await _businessManager.GetCustomerCreditUtilizeds(customer.Id); var creditUtilized = creditUtilizeds .OrderByDescending(x => x.CreatedDate) .Where(x => x.CreatedDate <= model.Date).FirstOrDefault(); if (creditUtilized != null && creditUtilized.IsIgnored) { var value = data.Data["Total"]; if (model.RoundType == Core.Data.Enum.RoundType.RoundUp) { value = Math.Ceiling(value); } else if (model.RoundType == Core.Data.Enum.RoundType.RoundDown) { value = Math.Floor(value); } if (creditUtilized.Value < value) { creditUtilizedList.Add(_mapper.Map <CustomerCreditUtilizedViewModel>(creditUtilized)); } } } creditUtilizedList = creditUtilizedList.OrderBy(x => x.CreatedDate == model.Date).ToList(); var viewDataDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { { "CreditUtilizedList", _mapper.Map <List <CustomerCreditUtilizedViewModel> >(creditUtilizedList) } }; string html = await _viewRenderService.RenderToStringAsync("_CreateCustomerCreditsPartial", model, viewDataDictionary); return(Ok(html)); } catch (Exception er) { return(BadRequest(er.Message ?? er.StackTrace)); } }
public async Task <Pager <CustomerCreditUtilizedDto> > GetCustomerCreditUtilizedComparedReport(ReportFilterDto filter) { var company = await _companyManager.FindInclude(filter.CompanyId); if (company.Settings == null || !company.Settings.SaveCreditValues) { return(new Pager <CustomerCreditUtilizedDto>(new List <CustomerCreditUtilizedDto>(), 0, filter.Offset, filter.Limit)); } var creditUtilizedSettings = await _businessManager.GetCustomerCreditUtilizedSettings(filter.CompanyId, filter.Date); if (creditUtilizedSettings == null) { creditUtilizedSettings = new CustomerCreditUtilizedSettingsDto() { RoundType = company.Settings.RoundType, CompanyId = company.Id }; } var creditUtilizedList = new List <CustomerCreditUtilizedDto>(); var report = await GetAgingReport(filter.CompanyId, filter.Date, 30, 4, false); foreach (var data in report.Rows) { var customer = data.Customer; var value = data.Data["Total"];//new height credit if (creditUtilizedSettings.RoundType == RoundType.RoundUp) { value = Math.Ceiling(value); } else if (creditUtilizedSettings.RoundType == RoundType.RoundDown) { value = Math.Floor(value); } var creditUtilized = customer.CreditUtilizeds.FirstOrDefault(); if (creditUtilized == null || (creditUtilized.CreatedDate != filter.Date && creditUtilized.Value < value)) { if (creditUtilized == null) { creditUtilized = new CustomerCreditUtilizedDto() { CreatedDate = DateTime.Now }; } creditUtilized.CustomerId = customer.Id; creditUtilized.Customer = customer; creditUtilized.IsNew = true; creditUtilized.NewValue = value; creditUtilized.NewCreatedDate = filter.Date; creditUtilizedList.Add(creditUtilized); } else if (creditUtilized.Value < value) { creditUtilized.CustomerId = customer.Id; creditUtilized.Customer = customer; creditUtilized.NewValue = value; creditUtilized.NewCreatedDate = filter.Date; creditUtilizedList.Add(creditUtilized); } } var count = creditUtilizedList.Count(); if (count == 0) { return(new Pager <CustomerCreditUtilizedDto>(new List <CustomerCreditUtilizedDto>(), 0, filter.Offset, filter.Limit)); } var page = (filter.Offset + filter.Limit) / filter.Limit; var pager = new Pager <CustomerCreditUtilizedDto>(creditUtilizedList.Skip(filter.Offset).Take(filter.Limit), count, page, filter.Limit); return(pager); }