public IQueryable <ComboBoxResult> GetCustomPerson(int Id, string term)
        {
            int DocTypeId  = Id;
            int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(DocTypeId, DivisionId, SiteId);

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

            string DivIdStr  = "|" + DivisionId.ToString() + "|";
            string SiteIdStr = "|" + SiteId.ToString() + "|";

            int ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.Sales).ProcessId;

            var list = (from p in db.Persons
                        join bus in db.BusinessEntity on p.PersonID equals bus.PersonID into BusinessEntityTable
                        from BusinessEntityTab in BusinessEntityTable.DefaultIfEmpty()
                        join pp in db.PersonProcess on p.PersonID equals pp.PersonId into PersonProcessTable
                        from PersonProcessTab in PersonProcessTable.DefaultIfEmpty()
                        join pr in db.PersonRole on p.PersonID equals pr.PersonId into PersonRoleTable
                        from PersonRoleTab in PersonRoleTable.DefaultIfEmpty()
                        where PersonProcessTab.ProcessId == ProcessId &&
                        (string.IsNullOrEmpty(term) ? 1 == 1 : (p.Name.ToLower().Contains(term.ToLower()) || p.Code.ToLower().Contains(term.ToLower()))) &&
                        (string.IsNullOrEmpty(settings.filterPersonRoles) ? 1 == 1 : PersonRoles.Contains(PersonRoleTab.RoleDocTypeId.ToString())) &&
                        BusinessEntityTab.DivisionIds.IndexOf(DivIdStr) != -1 &&
                        BusinessEntityTab.SiteIds.IndexOf(SiteIdStr) != -1 &&
                        (p.IsActive == null ? 1 == 1 : p.IsActive == true)
                        group new { p } by new { p.PersonID } into Result
                        orderby Result.Max(m => m.p.Name)
                        select new ComboBoxResult
            {
                id = Result.Key.PersonID.ToString(),
                text = Result.Max(m => m.p.Name + ", " + m.p.Suffix + " [" + m.p.Code + "]"),
            }
                        );

            return(list);
        }
Ejemplo n.º 2
0
        public IQueryable <ComboBoxResult> GetPendingMaterialPlanHelpList(int Id, string term)
        {
            //var PurchaseIndent = new PurchaseIndentHeaderService(_unitOfWork).Find(Id);

            //var settings = new PurchaseIndentSettingService(_unitOfWork).GetPurchaseIndentSettingForDocument(PurchaseIndent.DocTypeId, PurchaseIndent.DivisionId, PurchaseIndent.SiteId);

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

            //var list = (from p in db.ViewMaterialPlanBalance
            //            where (string.IsNullOrEmpty(term) ? 1 == 1 : p.MaterialPlanNo.ToLower().Contains(term.ToLower())) && p.BalanceQty > 0
            //           // && (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(p.DocTypeId.ToString()))
            //            group new { p } by p.MaterialPlanHeaderId into g
            //            select new MaterialPlanLineHelpListViewModel
            //            {
            //                DocNo = g.Max(m => m.p.MaterialPlanNo),
            //                MaterialPlanHeaderId = g.Key,
            //                DocumentTypeName = g.Max(m => m.p.DocType.DocumentTypeName)
            //                //    DocumentTypeName=g.Max(p=>p.p.DocumentTypeShortName)
            //            }
            //              ).Take(20);

            //return list.ToList();


            var ProdOrderHeader = new ProdOrderHeaderService(_unitOfWork).Find(Id);

            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(ProdOrderHeader.DocTypeId, ProdOrderHeader.DivisionId, ProdOrderHeader.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" };
            }

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

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

            string[] filterProductGroups = null;
            if (!string.IsNullOrEmpty(settings.filterProductGroups))
            {
                filterProductGroups = settings.filterProductGroups.Split(",".ToCharArray());
            }
            else
            {
                filterProductGroups = 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.ViewMaterialPlanBalance
                        join t in db.MaterialPlanHeader on p.MaterialPlanHeaderId equals t.MaterialPlanHeaderId
                        join Prod in db.Product on p.ProductId equals Prod.ProductId
                        where (string.IsNullOrEmpty(term) ? 1 == 1 : p.MaterialPlanNo.ToLower().Contains(term.ToLower())) && p.BalanceQty > 0 &&
                        (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(p.DocTypeId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterProducts) ? 1 == 1 : filterProducts.Contains(p.ProductId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterProductGroups) ? 1 == 1 : filterProductGroups.Contains(Prod.ProductGroupId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterProductTypes) ? 1 == 1 : filterProductTypes.Contains(Prod.ProductGroup.ProductTypeId.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()))
                        group new { p } by p.MaterialPlanHeaderId into g
                        orderby g.Max(m => m.p.MaterialPlanDate)
                        select new ComboBoxResult
            {
                text = g.Max(m => m.p.MaterialPlanNo) + " | " + g.Max(m => m.p.DocType.DocumentTypeShortName),
                id = g.Key.ToString(),
            }
                        );

            return(list);
        }
Ejemplo n.º 3
0
        public IEnumerable <ProdOrderLineViewModel> GetProdOrderForFilters(ProdOrderLineFilterViewModel vm)
        {
            var ProdOrderHeader = new ProdOrderHeaderService(_unitOfWork).Find(vm.ProdOrderHeaderId);

            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(ProdOrderHeader.DocTypeId, ProdOrderHeader.DivisionId, ProdOrderHeader.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" };
            }

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

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

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

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

            string[] ProductIdArr = null;
            if (!string.IsNullOrEmpty(vm.ProductId))
            {
                ProductIdArr = vm.ProductId.Split(",".ToCharArray());
            }
            else
            {
                ProductIdArr = new string[] { "NA" };
            }

            string[] SaleOrderIdArr = null;
            if (!string.IsNullOrEmpty(vm.MaterialPlanHeaderId))
            {
                SaleOrderIdArr = vm.MaterialPlanHeaderId.Split(",".ToCharArray());
            }
            else
            {
                SaleOrderIdArr = new string[] { "NA" };
            }

            string[] ProductGroupIdArr = null;
            if (!string.IsNullOrEmpty(vm.ProductGroupId))
            {
                ProductGroupIdArr = vm.ProductGroupId.Split(",".ToCharArray());
            }
            else
            {
                ProductGroupIdArr = new string[] { "NA" };
            }

            var temp = (from p in db.ViewMaterialPlanBalance
                        join t in db.MaterialPlanHeader on p.MaterialPlanHeaderId equals t.MaterialPlanHeaderId into table
                        from tab in table.DefaultIfEmpty()
                        join product in db.Product on p.ProductId equals product.ProductId into table2
                        join t1 in db.MaterialPlanLine on p.MaterialPlanLineId equals t1.MaterialPlanLineId into table1
                        from tab1 in table1.DefaultIfEmpty()
                        from tab2 in table2.DefaultIfEmpty()
                        where (string.IsNullOrEmpty(vm.ProductId) ? 1 == 1 : ProductIdArr.Contains(p.ProductId.ToString())) &&
                        (string.IsNullOrEmpty(vm.MaterialPlanHeaderId) ? 1 == 1 : SaleOrderIdArr.Contains(p.MaterialPlanHeaderId.ToString())) &&
                        (string.IsNullOrEmpty(vm.ProductGroupId) ? 1 == 1 : ProductGroupIdArr.Contains(tab2.ProductGroupId.ToString())) &&
                        p.BalanceQty > 0 &&
                        (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(p.DocTypeId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterProducts) ? 1 == 1 : filterProducts.Contains(p.ProductId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterProductGroups) ? 1 == 1 : filterProductGroups.Contains(tab2.ProductGroupId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterProductTypes) ? 1 == 1 : filterProductTypes.Contains(tab2.ProductGroup.ProductTypeId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterContraSites) ? tab.SiteId == CurrentSiteId : contraSites.Contains(tab.SiteId.ToString())) &&
                        (string.IsNullOrEmpty(settings.filterContraDivisions) ? tab.DivisionId == CurrentDivisionId : contraDivisions.Contains(tab.DivisionId.ToString()))
                        select new ProdOrderLineViewModel
            {
                Dimension1Name = tab1.Dimension1.Dimension1Name,
                Dimension2Name = tab1.Dimension2.Dimension2Name,
                Dimension3Name = tab1.Dimension3.Dimension3Name,
                Dimension4Name = tab1.Dimension4.Dimension4Name,
                Specification = tab1.Specification,
                Dimension1Id = tab1.Dimension1Id,
                Dimension2Id = tab1.Dimension2Id,
                Dimension3Id = tab1.Dimension3Id,
                Dimension4Id = tab1.Dimension4Id,
                PlanBalanceQty = p.BalanceQty,
                Qty = p.BalanceQty,
                MaterialPlanHeaderDocNo = tab.DocNo,
                ProductName = tab2.ProductName,
                ProductId = p.ProductId,
                ProdOrderHeaderId = vm.ProdOrderHeaderId,
                MaterialPlanLineId = p.MaterialPlanLineId,
                //UnitId = tab2.UnitId,
            }

                        );

            return(temp);
        }
        public IEnumerable <ProdOrderLineBalance> GetPendingProdOrdersWithPatternMatch(int HeaderId, string term, int Limiter)
        {
            var ProdordercancelHeader = new ProdOrderCancelHeaderService(_unitOfWork).Find(HeaderId);

            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(ProdordercancelHeader.DocTypeId, ProdordercancelHeader.DivisionId, ProdordercancelHeader.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" };
            }

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

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

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

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

            var Qry = (from p in db.ViewProdOrderBalance
                       join t in db.ProdOrderLine on p.ProdOrderLineId equals t.ProdOrderLineId into table
                       from tab in table.DefaultIfEmpty()
                       join t1 in db.MaterialPlanLine on tab.MaterialPlanLineId equals t1.MaterialPlanLineId into table1
                       from tab1 in table1.DefaultIfEmpty()
                       join t2 in db.MaterialPlanHeader on tab1.MaterialPlanHeaderId equals t2.MaterialPlanHeaderId into table2
                       from tab2 in table2.DefaultIfEmpty()
                       join ProTab in db.ProdOrderHeader on p.ProdOrderHeaderId equals ProTab.ProdOrderHeaderId
                       join Prod in db.Product on p.ProductId equals Prod.ProductId
                       where p.BalanceQty > 0 && ((string.IsNullOrEmpty(term) ? 1 == 1 : p.ProdOrderNo.ToLower().Contains(term.ToLower())) ||
                                                  (string.IsNullOrEmpty(term) ? 1 == 1 : p.Dimension1.Dimension1Name.ToLower().Contains(term.ToLower())) ||
                                                  (string.IsNullOrEmpty(term) ? 1 == 1 : p.Dimension2.Dimension2Name.ToLower().Contains(term.ToLower())) ||
                                                  (string.IsNullOrEmpty(term) ? 1 == 1 : p.Product.ProductName.ToLower().Contains(term.ToLower()))) &&
                       (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : contraDocTypes.Contains(p.DocTypeId.ToString())) &&
                       (string.IsNullOrEmpty(settings.filterProducts) ? 1 == 1 : filterProducts.Contains(p.ProductId.ToString())) &&
                       (string.IsNullOrEmpty(settings.filterProductGroups) ? 1 == 1 : filterProductGroups.Contains(Prod.ProductGroupId.ToString())) &&
                       (string.IsNullOrEmpty(settings.filterProductTypes) ? 1 == 1 : filterProductTypes.Contains(Prod.ProductGroup.ProductTypeId.ToString())) &&
                       (string.IsNullOrEmpty(settings.filterContraSites) ? ProTab.SiteId == CurrentSiteId : contraSites.Contains(ProTab.SiteId.ToString())) &&
                       (string.IsNullOrEmpty(settings.filterContraDivisions) ? ProTab.DivisionId == CurrentDivisionId : contraDivisions.Contains(ProTab.DivisionId.ToString()))
                       select new ProdOrderLineBalance
            {
                ProdOrderDocNo = p.ProdOrderNo,
                ProdOrderLineId = p.ProdOrderLineId,
                MaterialPlanDocNo = tab2.DocNo,
                ProductId = p.ProductId,
                ProductName = p.Product.ProductName,
                Dimension1Name = p.Dimension1.Dimension1Name,
                Dimension2Name = p.Dimension2.Dimension2Name,
                BalanceQty = p.BalanceQty
            }).Take(Limiter);

            return(Qry);
        }
        public IQueryable <ComboBoxResult> GetPendingProductsForProdOrderCancel(int filter, string term)//DocTypeId
        {
            var HEader = new ProdOrderCancelHeaderService(_unitOfWork).Find(filter);

            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(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" };
            }

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

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

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

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


            var Query = from p in db.ViewProdOrderBalance
                        join t in db.ProdOrderHeader on p.ProdOrderHeaderId equals t.ProdOrderHeaderId into ProdTable
                        from ProTab in ProdTable.DefaultIfEmpty()
                        join Prod in db.Product on p.ProductId equals Prod.ProductId
                        where p.BalanceQty > 0
                        select new
            {
                ProductName    = Prod.ProductName,
                DocTypeId      = p.DocTypeId,
                ProductId      = p.ProductId,
                ProductGroupId = Prod.ProductGroupId,
                ProductTypeId  = Prod.ProductGroup.ProductTypeId,
                SiteId         = ProTab.SiteId,
                DivisionId     = ProTab.DivisionId,
            };

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

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

            if (!string.IsNullOrEmpty(settings.filterProducts))
            {
                Query = Query.Where(m => filterProducts.Contains(m.ProductId.ToString()));
            }

            if (!string.IsNullOrEmpty(settings.filterProductGroups))
            {
                Query = Query.Where(m => filterProductGroups.Contains(m.ProductGroupId.ToString()));
            }

            if (!string.IsNullOrEmpty(settings.filterProductTypes))
            {
                Query = Query.Where(m => filterProductTypes.Contains(m.ProductTypeId.ToString()));
            }

            if (!string.IsNullOrEmpty(settings.filterContraSites))
            {
                Query = Query.Where(m => contraSites.Contains(m.SiteId.ToString()));
            }
            else
            {
                Query = Query.Where(m => m.SiteId == CurrentSiteId);
            }
            if (!string.IsNullOrEmpty(settings.filterContraDivisions))
            {
                Query = Query.Where(m => contraDivisions.Contains(m.DivisionId.ToString()));
            }
            else
            {
                Query = Query.Where(m => m.DivisionId == CurrentDivisionId);
            }


            return(from p in Query
                   group p by p.ProductId into g
                   orderby g.Max(m => m.ProductName)
                   select new ComboBoxResult
            {
                id = g.Key.ToString(),
                text = g.Max(m => m.ProductName),
            });
        }
        public IEnumerable <ProdOrderCancelLineViewModel> GetProdOrderLineForMultiSelect(ProdOrderCancelFilterViewModel svm)
        {
            var Header = new ProdOrderCancelHeaderService(_unitOfWork).Find(svm.ProdOrderCancelHeaderId);

            var settings = new ProdOrderSettingsService(_unitOfWork).GetProdOrderSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId);

            string[] ProductIdArr = null;
            if (!string.IsNullOrEmpty(svm.ProductId))
            {
                ProductIdArr = svm.ProductId.Split(",".ToCharArray());
            }
            else
            {
                ProductIdArr = new string[] { "NA" };
            }

            string[] Dimension2IdArr = null;
            if (!string.IsNullOrEmpty(svm.Dimension2Id))
            {
                Dimension2IdArr = svm.Dimension2Id.Split(",".ToCharArray());
            }
            else
            {
                Dimension2IdArr = new string[] { "NA" };
            }

            string[] Dimension1IdArr = null;
            if (!string.IsNullOrEmpty(svm.Dimension1Id))
            {
                Dimension1IdArr = svm.Dimension1Id.Split(",".ToCharArray());
            }
            else
            {
                Dimension1IdArr = new string[] { "NA" };
            }

            string[] SaleOrderIdArr = null;
            if (!string.IsNullOrEmpty(svm.ProdOrderId))
            {
                SaleOrderIdArr = svm.ProdOrderId.Split(",".ToCharArray());
            }
            else
            {
                SaleOrderIdArr = new string[] { "NA" };
            }

            string[] ProductGroupIdArr = null;
            if (!string.IsNullOrEmpty(svm.ProductGroupId))
            {
                ProductGroupIdArr = svm.ProductGroupId.Split(",".ToCharArray());
            }
            else
            {
                ProductGroupIdArr = new string[] { "NA" };
            }

            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" };
            }

            var temp = (from p in db.ViewProdOrderBalance
                        join product in db.Product on p.ProductId equals product.ProductId into table2
                        from tab2 in table2.DefaultIfEmpty()
                        join t3 in db.Units on tab2.UnitId equals t3.UnitId into table3
                        from tab3 in table3.DefaultIfEmpty()
                        join t2 in db.ProdOrderLine on p.ProdOrderLineId equals t2.ProdOrderLineId
                        where p.BalanceQty > 0
                        select new
            {
                BalanceQty = p.BalanceQty,
                Qty = p.BalanceQty,
                ProdOrderNo = p.ProdOrderNo,
                ProductName = tab2.ProductName,
                ProductId = p.ProductId,
                ProdOrderCancelHeaderId = svm.ProdOrderCancelHeaderId,
                ProdOrderLineId = p.ProdOrderLineId,
                unitDecimalPlaces = (tab3 == null ? 0 : tab3.DecimalPlaces),
                Dimension1Name = t2.Dimension1.Dimension1Name,
                Dimension2Name = t2.Dimension2.Dimension2Name,
                Specification = t2.Specification,
                UnitName = tab2.Unit.UnitName,
                ProdOrderHeaderId = p.ProdOrderHeaderId,
                ProductGroupId = tab2.ProductGroupId,
                OrderDocDate = p.IndentDate,
                DocTypeId = p.DocTypeId,
                SiteId = p.SiteId,
                DivisionId = p.DivisionId,
                Dimension1Id = p.Dimension1Id,
                Dimension2Id = p.Dimension2Id,
            });

            if (!string.IsNullOrEmpty(svm.ProductId))
            {
                temp = temp.Where(m => ProductIdArr.Contains(m.ProductId.ToString()));
            }

            if (!string.IsNullOrEmpty(svm.Dimension2Id))
            {
                temp = temp.Where(m => Dimension2IdArr.Contains(m.Dimension2Id.ToString()));
            }

            if (!string.IsNullOrEmpty(svm.Dimension1Id))
            {
                temp = temp.Where(m => Dimension1IdArr.Contains(m.Dimension1Id.ToString()));
            }

            if (!string.IsNullOrEmpty(svm.ProdOrderId))
            {
                temp = temp.Where(m => SaleOrderIdArr.Contains(m.ProdOrderHeaderId.ToString()));
            }

            if (!string.IsNullOrEmpty(svm.ProductGroupId))
            {
                temp = temp.Where(m => ProductGroupIdArr.Contains(m.ProductGroupId.ToString()));
            }

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

            if (!string.IsNullOrEmpty(settings.filterContraSites))
            {
                temp = temp.Where(m => contraSites.Contains(m.SiteId.ToString()));
            }
            else
            {
                temp = temp.Where(m => m.SiteId == Header.SiteId);
            }

            if (!string.IsNullOrEmpty(settings.filterContraDivisions))
            {
                temp = temp.Where(m => contraDivisions.Contains(m.DivisionId.ToString()));
            }
            else
            {
                temp = temp.Where(m => m.DivisionId == Header.DivisionId);
            }

            if (svm.UpToDate.HasValue)
            {
                temp = temp.Where(m => m.OrderDocDate <= svm.UpToDate);
            }

            return(from p in temp
                   orderby p.OrderDocDate descending, p.ProdOrderNo descending
                   select new ProdOrderCancelLineViewModel
            {
                BalanceQty = p.BalanceQty,
                Qty = p.BalanceQty,
                ProdOrderNo = p.ProdOrderNo,
                ProductName = p.ProductName,
                ProductId = p.ProductId,
                ProdOrderCancelHeaderId = svm.ProdOrderCancelHeaderId,
                ProdOrderLineId = p.ProdOrderLineId,
                unitDecimalPlaces = p.unitDecimalPlaces,
                Dimension1Name = p.Dimension1Name,
                Dimension2Name = p.Dimension2Name,
                Specification = p.Specification,
                UnitName = p.UnitName,
                ProdOrderHeaderId = p.ProdOrderHeaderId,
                ProductGroupId = p.ProductGroupId,
                OrderDocDate = p.OrderDocDate,
            });
        }