public async Task <Pager <CustomerListViewModel> > GetDraftCustomers([FromQuery] InvoiceDraftFilterViewModel model)
        {
            var constructor = await _businessManager.GetConstructorInvoice(model.ConstructorId ?? 0);

            var constructors = await _businessManager.GetConstructorInvoices(constructor.CompanyId, constructor.Date);

            constructors = constructors.Where(x => x.SearchCriteriaId == constructor.SearchCriteriaId).ToList();

            var invoices = await _businessManager.GetInvoiceDraft(constructors.Select(x => x.Id).ToArray());

            var customers = await _businessManager.GetCustomers(constructor);

            customers = customers.Where(x => !invoices.Any(y => y.CustomerId == x.Id)).ToList();
            var count = customers.Count();

            customers = customers.Skip(model.Offset).Take(model.Limit).ToList();

            if (customers.Count == 0)
            {
                return(new Pager <CustomerListViewModel>(new List <CustomerListViewModel>(), 0, model.Offset, model.Limit));
            }

            var page = (model.Offset + model.Limit) / model.Limit;

            var result = _mapper.Map <List <CustomerListViewModel> >(customers);

            return(new Pager <CustomerListViewModel>(result, count, page, model.Limit));
        }
        public async Task <IActionResult> View(long id)
        {
            var constructor = await _businessManager.GetConstructorInvoice(id);

            var summaryRange = await _companyBusinessManager.GetSummaryRange(constructor.SummaryRangeId);

            ViewBag.SummaryRange = $"{summaryRange.From} - {summaryRange.To}";

            var searchCriteria = await _businessManager.GetInvoiceConstructorSearchCriteria(constructor.SearchCriteriaId);

            ViewBag.SearchCriteria = _mapper.Map <InvoiceConstructorSearchViewModel>(searchCriteria);

            if (searchCriteria.Group == CustomerGroupType.OnlyNew)
            {
                ViewBag.CreatedDate = $"{constructor.Date.FirstDayOfMonth().ToString("MM/dd/yyyy")} - {constructor.Date.LastDayOfMonth().ToString("MM/dd/yyyy")}";
            }
            else if (searchCriteria.Group == CustomerGroupType.ExcludeNew)
            {
                ViewBag.CreatedDate = $"None - {constructor.Date.AddMonths(-1).LastDayOfMonth().ToString("MM/dd/yyyy")}";
            }
            else if (searchCriteria.Group == CustomerGroupType.All)
            {
                ViewBag.CreatedDate = $"None - {constructor.Date.LastDayOfMonth().ToString("MM/dd/yyyy")}";
            }

            var tags = await _businessManager.GetCustomerTags();

            ViewBag.Tags = string.Join(',', tags.Where(x => searchCriteria.TagsIds.Contains(x.Id)).Select(x => x.Name));

            var types = await _businessManager.GetCustomerTypes();

            ViewBag.Types = string.Join(',', types.Where(x => searchCriteria.TypeIds.Contains(x.Id)).Select(x => x.Name));

            var constructors = await _businessManager.GetConstructorInvoices(constructor.CompanyId, constructor.Date);

            constructors = constructors.Where(x => x.SearchCriteriaId == constructor.SearchCriteriaId).ToList();

            var invoices = await _businessManager.GetInvoiceDraft(constructors.Select(x => x.Id).ToArray());

            ViewBag.Invoices = invoices.Count();

            var customers = await _businessManager.GetCustomers(constructor);

            ViewBag.Customers = customers.Count();

            var model = _mapper.Map <InvoiceConstructorViewModel>(constructor);

            if (IsAjaxRequest)
            {
                return(PartialView(model));
            }
            else
            {
                return(View(model));
            }
        }