public IEnumerable <PurchaseIndentLineListViewModel> GetPendingIndentsForQuotation(int id, int PurchaseQuotationHeaderId)
        {
            var PurchaseQuotationHeader = db.PurchaseQuotationHeader.Find(PurchaseQuotationHeaderId);

            var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(PurchaseQuotationHeader.DocTypeId, PurchaseQuotationHeader.DivisionId, PurchaseQuotationHeader.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"];


            return(from p in db.ViewPurchaseIndentBalance
                   join t1 in db.PurchaseIndentLine on p.PurchaseIndentLineId equals t1.PurchaseIndentLineId into table1
                   from tab1 in table1.DefaultIfEmpty()
                   where p.ProductId == id && p.BalanceQty > 0 &&
                   (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(p.DocTypeId.ToString())) &&
                   (string.IsNullOrEmpty(settings.filterContraSites) ? p.SiteId == CurrentSiteId : contraSites.Contains(p.SiteId.ToString())) &&
                   (string.IsNullOrEmpty(settings.filterContraDivisions) ? p.DivisionId == CurrentDivisionId : contraDivisions.Contains(p.DivisionId.ToString()))
                   select new PurchaseIndentLineListViewModel
            {
                PurchaseIndentLineId = p.PurchaseIndentLineId,
                PurchaseIndentHeaderId = p.PurchaseIndentHeaderId,
                DocNo = p.PurchaseIndentNo,
                Dimension1Name = tab1.Dimension1.Dimension1Name,
                Dimension2Name = tab1.Dimension2.Dimension2Name,
            }
                   );
        }
        public IEnumerable <PurchaseOrderLineListViewModel> GetPendingPurchaseIndentHelpList(int Id, string term)
        {
            var PurchaseQuotation = db.PurchaseQuotationHeader.Find(Id);

            var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(PurchaseQuotation.DocTypeId, PurchaseQuotation.DivisionId, PurchaseQuotation.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.ViewPurchaseIndentBalance
                        where (string.IsNullOrEmpty(term) ? 1 == 1 : p.PurchaseIndentNo.ToLower().Contains(term.ToLower())) && p.BalanceQty > 0 &&
                        (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(p.DocTypeId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterContraSites) ? p.SiteId == CurrentSiteId : contraSites.Contains(p.SiteId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterContraDivisions) ? p.DivisionId == CurrentDivisionId : contraDivisions.Contains(p.DivisionId.ToString()))
                        group new { p } by p.PurchaseIndentHeaderId into g
                        select new PurchaseOrderLineListViewModel
            {
                DocNo = g.Max(m => m.p.PurchaseIndentNo),
                PurchaseIndentHeaderId = g.Key,
            }
                        ).Take(20);

            return(list.ToList());
        }
        public IQueryable <ComboBoxResult> GetProductHelpList(int Id, string term)
        {
            var PurchaseQuotation = db.PurchaseQuotationHeader.Find(Id);

            var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(PurchaseQuotation.DocTypeId, PurchaseQuotation.DivisionId, PurchaseQuotation.SiteId);

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

            var query = (from p in db.Product
                         join pg in db.ProductGroups on p.ProductGroupId equals pg.ProductGroupId
                         //t.Status == (int)StatusConstants.Submitted
                         orderby p.ProductName
                         select new
            {
                ProductName = p.ProductName,
                ProductId = p.ProductId,
                ProductType = pg.ProductTypeId,
            });

            if (!string.IsNullOrEmpty(settings.filterProductTypes))
            {
                query = query.Where(m => ProductTypes.Contains(m.ProductType.ToString()));
            }

            if (!string.IsNullOrEmpty(term))
            {
                query = query.Where(m => m.ProductName.ToLower().Contains(term.ToLower()));
            }

            return(from p in query
                   select new ComboBoxResult
            {
                text = p.ProductName,
                id = p.ProductId.ToString(),
            });
        }
        public dynamic GetProductHelpListforAC(int Id, string term, int Limit)
        {
            var PurchaseQuotation = db.PurchaseQuotationHeader.Find(Id);

            var settings = new PurchaseQuotationSettingService(_unitOfWork).GetPurchaseQuotationSettingForDocument(PurchaseQuotation.DocTypeId, PurchaseQuotation.DivisionId, PurchaseQuotation.SiteId);

            //var list = (from p in db.Product
            //            where (string.IsNullOrEmpty(term) ? 1 == 1 : p.ProductName.ToLower().Contains(term.ToLower()))
            //            && (string.IsNullOrEmpty(settings.filterProductTypes) ? 1 == 1 : ProductTypes.Contains(p.ProductGroup.ProductTypeId.ToString()))
            //            group new { p } by p.ProductId into g
            //            select new ComboBoxList
            //            {
            //                PropFirst = g.Max(m => m.p.ProductName),
            //                Id = g.Key,

            //                //    DocumentTypeName=g.Max(p=>p.p.DocumentTypeShortName)
            //            }
            //              ).Take(20);

            //return list.ToList();


            string[] ProductTypes = null;
            if (!string.IsNullOrEmpty(settings.filterProductTypes))
            {
                ProductTypes = settings.filterProductTypes.Split(",".ToCharArray());
            }
            else
            {
                ProductTypes = 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" };
            }

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

            var query = (from p in db.ViewPurchaseIndentBalance
                         join t in db.PurchaseIndentHeader on p.PurchaseIndentHeaderId equals t.PurchaseIndentHeaderId
                         join rl in db.PurchaseIndentLine on p.PurchaseIndentLineId equals rl.PurchaseIndentLineId
                         join prod in db.Product on p.ProductId equals prod.ProductId
                         join pg in db.ProductGroups on prod.ProductGroupId equals pg.ProductGroupId
                         where p.BalanceQty > 0
                         //t.Status == (int)StatusConstants.Submitted
                         orderby t.DocDate, t.DocNo
                         select new
            {
                ProductName = rl.Product.ProductName,
                ProductId = p.ProductId,
                Specification = rl.Specification,
                Dimension1Name = rl.Dimension1.Dimension1Name,
                Dimension2Name = rl.Dimension2.Dimension2Name,
                PurchaseIndentNo = p.PurchaseIndentNo,
                PurchaseIndentLineId = p.PurchaseIndentLineId,
                Qty = p.BalanceQty,
                ProductType = pg.ProductTypeId,
                SiteId = p.SiteId,
                DivisionId = p.DivisionId,
                DocTypeId = p.DocTypeId,
            });

            if (!string.IsNullOrEmpty(settings.filterProductTypes))
            {
                query = query.Where(m => ProductTypes.Contains(m.ProductType.ToString()));
            }

            if (!string.IsNullOrEmpty(settings.filterContraSites))
            {
                query = query.Where(m => ContraSites.Contains(m.SiteId.ToString()));
            }
            else
            {
                query = query.Where(m => m.SiteId == PurchaseQuotation.SiteId);
            }

            if (!string.IsNullOrEmpty(settings.filterContraDivisions))
            {
                query = query.Where(m => ContraDivisions.Contains(m.DivisionId.ToString()));
            }
            else
            {
                query = query.Where(m => m.DivisionId == PurchaseQuotation.DivisionId);
            }

            if (!string.IsNullOrEmpty(settings.filterContraDocTypes))
            {
                query = query.Where(m => ContraDocTypes.Contains(m.DocTypeId.ToString()));
            }

            if (!string.IsNullOrEmpty(term))
            {
                query = query.Where(m => m.ProductName.ToLower().Contains(term.ToLower()) ||
                                    m.Specification.ToLower().Contains(term.ToLower()) ||
                                    m.Dimension1Name.ToLower().Contains(term.ToLower()) ||
                                    m.Dimension2Name.ToLower().Contains(term.ToLower()) ||
                                    m.PurchaseIndentNo.ToLower().Contains(term.ToLower())
                                    );
            }

            return((from p in query
                    select new
            {
                ProductName = p.ProductName,
                ProductId = p.ProductId,
                Specification = p.Specification,
                Dimension1Name = p.Dimension1Name,
                Dimension2Name = p.Dimension2Name,
                PurchaseIndentNo = p.PurchaseIndentNo,
                PurchaseIndentLineId = p.PurchaseIndentLineId,
                Qty = p.Qty,
            }).Take(Limit).ToList());
        }