public IQueryable <ComboBoxResult> GetPendingProductsForRateAmndmt(int id, string term)//DocTypeId
        {
            var JobOrderAmendmentHeader = new JobOrderAmendmentHeaderService(_unitOfWork).Find(id);

            var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(JobOrderAmendmentHeader.DocTypeId, JobOrderAmendmentHeader.DivisionId, JobOrderAmendmentHeader.SiteId);

            string[] contraDocTypes = null;
            if (!string.IsNullOrEmpty(settings.filterContraDocTypes))
            {
                contraDocTypes = settings.filterContraDocTypes.Split(",".ToCharArray());
            }
            else
            {
                contraDocTypes = new string[] { "NA" };
            }

            string[] contraSites = null;
            if (!string.IsNullOrEmpty(settings.filterContraSites))
            {
                contraSites = settings.filterContraSites.Split(",".ToCharArray());
            }
            else
            {
                contraSites = new string[] { "NA" };
            }

            string[] contraDivisions = null;
            if (!string.IsNullOrEmpty(settings.filterContraDivisions))
            {
                contraDivisions = settings.filterContraDivisions.Split(",".ToCharArray());
            }
            else
            {
                contraDivisions = new string[] { "NA" };
            }

            int CurrentSiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int CurrentDivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

            var list = (from p in db.ViewJobOrderBalanceForInvoice
                        join t in db.JobOrderHeader on p.JobOrderHeaderId equals t.JobOrderHeaderId
                        join t2 in db.Product on p.ProductId equals t2.ProductId
                        where (string.IsNullOrEmpty(term) ? 1 == 1 : t2.ProductName.ToLower().Contains(term.ToLower())) && p.BalanceQty > 0 &&
                        (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(t.DocTypeId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterContraSites) ? t.SiteId == CurrentSiteId : contraSites.Contains(t.SiteId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterContraDivisions) ? t.DivisionId == CurrentDivisionId : contraDivisions.Contains(t.DivisionId.ToString())) &&
                        (JobOrderAmendmentHeader.JobWorkerId.HasValue && JobOrderAmendmentHeader.JobWorkerId.Value > 0 ? t.JobWorkerId == JobOrderAmendmentHeader.JobWorkerId : 1 == 1)
                        group new { p, t2 } by p.ProductId into g
                        orderby g.Max(m => m.t2.ProductName)
                        select new ComboBoxResult
            {
                text = g.Max(m => m.t2.ProductName),
                id = g.Key.ToString(),
            }
                        );

            return(list);
        }
        public IEnumerable <JobOrderHeaderListViewModel> GetPendingJobOrdersForRateAmndmt(int HeaderId, string term, int Limit)//Product Id
        {
            var Header = new JobOrderAmendmentHeaderService(_unitOfWork).Find(HeaderId);

            var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId);

            string[] contraDocTypes = null;
            if (!string.IsNullOrEmpty(settings.filterContraDocTypes))
            {
                contraDocTypes = settings.filterContraDocTypes.Split(",".ToCharArray());
            }
            else
            {
                contraDocTypes = new string[] { "NA" };
            }

            string[] contraSites = null;
            if (!string.IsNullOrEmpty(settings.filterContraSites))
            {
                contraSites = settings.filterContraSites.Split(",".ToCharArray());
            }
            else
            {
                contraSites = new string[] { "NA" };
            }

            string[] contraDivisions = null;
            if (!string.IsNullOrEmpty(settings.filterContraDivisions))
            {
                contraDivisions = settings.filterContraDivisions.Split(",".ToCharArray());
            }
            else
            {
                contraDivisions = new string[] { "NA" };
            }

            int CurrentSiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int CurrentDivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

            var tem = from p in db.ViewJobOrderBalanceForInvoice
                      join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                      join t2 in db.Product on p.ProductId equals t2.ProductId
                      join t3 in db.JobOrderHeader on p.JobOrderHeaderId equals t3.JobOrderHeaderId
                      where p.BalanceQty > 0 && (Header.JobWorkerId.HasValue && Header.JobWorkerId.Value > 0 ? p.JobWorkerId == Header.JobWorkerId : 1 == 1) &&
                      (string.IsNullOrEmpty(term) ? 1 == 1 : (p.JobOrderNo.ToLower().Contains(term.ToLower()) || t2.ProductName.ToLower().Contains(term.ToLower()) ||
                                                              t.Dimension1.Dimension1Name.ToLower().Contains(term.ToLower()) ||
                                                              t.Dimension2.Dimension2Name.ToLower().Contains(term.ToLower()) ||
                                                              t.Dimension3.Dimension3Name.ToLower().Contains(term.ToLower()) ||
                                                              t.Dimension4.Dimension4Name.ToLower().Contains(term.ToLower())
                                                              )) &&
                      (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(t3.DocTypeId.ToString())) &&
                      (string.IsNullOrEmpty(settings.filterContraSites) ? t3.SiteId == CurrentSiteId : contraSites.Contains(t3.SiteId.ToString())) &&
                      (string.IsNullOrEmpty(settings.filterContraDivisions) ? t3.DivisionId == CurrentDivisionId : contraDivisions.Contains(t3.DivisionId.ToString()))
                      orderby p.JobOrderNo
                      select new JobOrderHeaderListViewModel
            {
                DocNo          = p.JobOrderNo,
                JobOrderLineId = p.JobOrderLineId,
                Dimension1Name = t.Dimension1.Dimension1Name,
                Dimension2Name = t.Dimension2.Dimension2Name,
                Dimension3Name = t.Dimension3.Dimension3Name,
                Dimension4Name = t.Dimension4.Dimension4Name,
                ProductName    = t2.ProductName,
                BalanceQty     = p.BalanceQty,
            };

            return(tem.Take(Limit).ToList());
        }