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 IQueryable <ComboBoxResult> GetPendingProductHelpList(int Id, string term)
        {
            int CurrentSiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int CurrentDivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

            var settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(Id, CurrentDivisionId, CurrentSiteId);

            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 list = (from p in db.ViewJobOrderBalanceForInvoice
                        join t in db.JobOrderHeader on p.JobOrderHeaderId equals t.JobOrderHeaderId
                        where (string.IsNullOrEmpty(term) ? 1 == 1 : p.Product.ProductName.ToLower().Contains(term.ToLower())) && p.BalanceQty > 0 && t.ProcessId == settings.ProcessId &&
                        (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()))
                        group new { p, t } by p.ProductId into g
                        orderby g.Max(m => m.p.OrderDate)
                        select new ComboBoxResult
            {
                text = g.Max(m => m.p.Product.ProductName),
                id = g.Key.ToString(),
            }
                        );

            return(list);
        }
        public JobOrderLineViewModel GetOrderLineForUidMain(int Uid, int JobOrderCancelHeaderId)
        {
            JobOrderCancelHeader header = new JobOrderCancelHeaderService(_unitOfWork).Find(JobOrderCancelHeaderId);

            var Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(header.DocTypeId, header.DivisionId, header.SiteId);

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

            var temp = (from p in db.ProductUid
                        where p.ProductUIDId == Uid
                        select new
            {
                Rec = (from t in db.JobOrderLine
                       join R in db.JobReceiveLine on new { A = t.JobOrderLineId, B = (int?)Uid } equals new { A = R.JobOrderLineId ?? 0, B = R.ProductUidId } into Rtable
                       from Rtab in Rtable.DefaultIfEmpty()
                       join RT in db.JobReturnLine on Rtab.JobReceiveLineId equals RT.JobReceiveLineId into RTtable
                       from RTtab in RTtable.DefaultIfEmpty()
                       join JOH in db.JobOrderHeader on t.JobOrderHeaderId equals JOH.JobOrderHeaderId into JOHtable
                       from JOHtab in JOHtable.DefaultIfEmpty()
                       where t.JobOrderHeaderId == p.GenDocId && t.JobOrderHeader.DocTypeId == p.GenDocTypeId && t.ProductUidHeaderId == p.ProductUidHeaderId &&
                       (string.IsNullOrEmpty(Settings.filterContraDocTypes) ? 1 == 1 : ContraDocTypeIdArr.Contains(JOHtab.DocTypeId.ToString())) &&
                       Rtab == null
                       select new JobOrderLineViewModel
                {
                    JobOrderLineId = t.JobOrderLineId,
                    JobOrderHeaderDocNo = t.JobOrderHeader.DocNo,
                    Specification = t.Specification,
                    Dimension1Name = t.Dimension1.Dimension1Name,
                    Dimension2Name = t.Dimension2.Dimension2Name,
                    Dimension3Name = t.Dimension3.Dimension3Name,
                    Dimension4Name = t.Dimension4.Dimension4Name,
                    ProdOrderBalanceQty = 1,
                    LotNo = p.LotNo,
                    UnitName = p.Product.Unit.UnitName,
                }).FirstOrDefault()
            }
                        ).FirstOrDefault();

            return(temp.Rec);
        }
        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 JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(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() + "|";

            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 == settings.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);
        }
        public string ValidateCostCenter(int DocTypeId, int HeaderId, int JobWorkerId, string CostCenterName)
        {
            int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

            var Settings        = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(DocTypeId, DivisionId, SiteId);
            var LedgerAccountId = new LedgerAccountService(_unitOfWork).GetLedgerAccountByPersondId(JobWorkerId).LedgerAccountId;

            string ValidationMsg = "";

            if (Settings.PersonWiseCostCenter == true)
            {
                var CostCenter = (db.CostCenter.AsNoTracking().Where(m => m.CostCenterName == CostCenterName &&
                                                                     m.ReferenceDocTypeId == DocTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId).FirstOrDefault());
                if (CostCenter != null)
                {
                    if (CostCenter.LedgerAccountId != LedgerAccountId)
                    {
                        ValidationMsg += "CostCenter belongs to a different person. ";
                    }
                }
            }

            if (Settings.isUniqueCostCenter == true)
            {
                var CostCenter = db.CostCenter.AsNoTracking().Where(m => m.CostCenterName == CostCenterName &&
                                                                    m.ReferenceDocTypeId == DocTypeId && m.SiteId == SiteId && m.DivisionId == DivisionId).FirstOrDefault();
                if (CostCenter != null)
                {
                    var UniqueCostCenter = (from p in db.JobOrderHeader
                                            where p.CostCenterId == CostCenter.CostCenterId && p.JobOrderHeaderId != HeaderId && p.DocTypeId == DocTypeId &&
                                            p.SiteId == SiteId && p.DivisionId == DivisionId
                                            select p
                                            ).FirstOrDefault();
                    if (UniqueCostCenter != null)
                    {
                        ValidationMsg += "CostCenter Already exists";
                    }
                }
            }

            return(ValidationMsg);
        }
        public IEnumerable <ProcGetBomForWeavingViewModel> GetBomPostingDataForCancel(int ProductId, int?Dimension1Id, int?Dimension2Id, int?Dimension3Id, int?Dimension4Id, int ProcessId, decimal Qty, int DocTypeId)
        {
            SqlParameter SQLDocTypeID = new SqlParameter("@DocTypeId", DocTypeId);
            SqlParameter SQLProductID = new SqlParameter("@ProductId", ProductId);
            SqlParameter SQLProcessId = new SqlParameter("@ProcessId", ProcessId);
            SqlParameter SQLQty       = new SqlParameter("@Qty", Qty);
            SqlParameter SQLDime1     = new SqlParameter("@Dimension1Id", Dimension1Id);
            SqlParameter SQLDime2     = new SqlParameter("@Dimension2Id", Dimension2Id);

            List <ProcGetBomForWeavingViewModel> PendingOrderQtyForPacking = new List <ProcGetBomForWeavingViewModel>();

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

            string ProcName = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(DocTypeId, DivisionId, SiteId).SqlProcConsumption;

            //PendingOrderQtyForPacking = db.Database.SqlQuery<ProcGetBomForWeavingViewModel>("" + ConfigurationManager.AppSettings["DataBaseSchema"] + ".ProcGetBomForWeaving @DocTypeId, @ProductId, @ProcessId,@Qty"+(Dimension1Id==null?"":",@Dimension1Id")+(Dimension2Id==null?"":",@Dimension2Id"), SQLDocTypeID, SQLProductID, SQLProcessId, SQLQty, (Dimension1Id==null? "" : Dimension1Id), (Dimension2Id)).ToList();

            if (ProcName != null && ProcName != "")
            {
                if (Dimension1Id == null && Dimension2Id == null)
                {
                    PendingOrderQtyForPacking = db.Database.SqlQuery <ProcGetBomForWeavingViewModel>("" + ProcName + " @DocTypeId, @ProductId, @ProcessId,@Qty", SQLDocTypeID, SQLProductID, SQLProcessId, SQLQty).ToList();
                }
                else if (Dimension1Id == null && Dimension2Id != null)
                {
                    PendingOrderQtyForPacking = db.Database.SqlQuery <ProcGetBomForWeavingViewModel>("" + ProcName + " @DocTypeId, @ProductId, @ProcessId,@Qty,@Dimension2Id", SQLDocTypeID, SQLProductID, SQLProcessId, SQLQty, Dimension2Id).ToList();
                }
                else if (Dimension1Id != null && Dimension2Id == null)
                {
                    PendingOrderQtyForPacking = db.Database.SqlQuery <ProcGetBomForWeavingViewModel>("" + ProcName + " @DocTypeId, @ProductId, @ProcessId,@Qty,@Dimension1Id", SQLDocTypeID, SQLProductID, SQLProcessId, SQLQty, Dimension1Id).ToList();
                }
                else
                {
                    PendingOrderQtyForPacking = db.Database.SqlQuery <ProcGetBomForWeavingViewModel>("" + ProcName + " @DocTypeId, @ProductId, @ProcessId,@Qty,@Dimension1Id, @Dimension2Id", SQLDocTypeID, SQLProductID, SQLProcessId, SQLQty, SQLDime1, SQLDime2).ToList();
                }
            }

            return(PendingOrderQtyForPacking);
        }
        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());
        }
        public IEnumerable <JobOrderCancelLineViewModel> GetJobOrderLineForMultiSelect(JobOrderCancelFilterViewModel svm)
        {
            JobOrderCancelHeader Header = db.JobOrderCancelHeader.Find(svm.JobOrderCancelHeaderId);

            var Settings = new JobOrderSettingsService(_unitOfWork).GetJobOrderSettingsForDocument(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[] SaleOrderIdArr = null;
            if (!string.IsNullOrEmpty(svm.JobOrderId))
            {
                SaleOrderIdArr = svm.JobOrderId.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[] Dime1IdArr = null;
            if (!string.IsNullOrEmpty(svm.Dimension1Id))
            {
                Dime1IdArr = svm.Dimension1Id.Split(",".ToCharArray());
            }
            else
            {
                Dime1IdArr = new string[] { "NA" };
            }

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

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

            string[] Dime4IdArr = null;
            if (!string.IsNullOrEmpty(svm.Dimension4Id))
            {
                Dime4IdArr = svm.Dimension4Id.Split(",".ToCharArray());
            }
            else
            {
                Dime4IdArr = 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.ViewJobOrderBalance
                        join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId into table
                        from tab in table.DefaultIfEmpty()
                        join product in db.Product on p.ProductId equals product.ProductId into table2
                        from tab2 in table2.DefaultIfEmpty()
                        where (string.IsNullOrEmpty(svm.ProductId) ? 1 == 1 : ProductIdArr.Contains(p.ProductId.ToString())) &&
                        (svm.JobWorkerId == 0 ? 1 == 1 : p.JobWorkerId == svm.JobWorkerId) &&
                        (string.IsNullOrEmpty(svm.JobOrderId) ? 1 == 1 : SaleOrderIdArr.Contains(p.JobOrderHeaderId.ToString())) &&
                        (string.IsNullOrEmpty(svm.ProductGroupId) ? 1 == 1 : ProductGroupIdArr.Contains(tab2.ProductGroupId.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension1Id) ? 1 == 1 : Dime1IdArr.Contains(p.Dimension1Id.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension2Id) ? 1 == 1 : Dime2IdArr.Contains(p.Dimension2Id.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension3Id) ? 3 == 3 : Dime3IdArr.Contains(p.Dimension3Id.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension4Id) ? 3 == 3 : Dime4IdArr.Contains(p.Dimension4Id.ToString())) &&
                        (string.IsNullOrEmpty(Settings.filterContraSites) ? p.SiteId == Header.SiteId : ContraSites.Contains(p.SiteId.ToString())) &&
                        (string.IsNullOrEmpty(Settings.filterContraDivisions) ? p.DivisionId == Header.DivisionId : ContraDivisions.Contains(p.DivisionId.ToString())) &&
                        p.BalanceQty > 0 && p.JobWorkerId == svm.JobWorkerId
                        orderby p.OrderDate, p.JobOrderNo, tab.Sr
                        select new JobOrderCancelLineViewModel
            {
                BalanceQty = p.BalanceQty,
                Qty = p.BalanceQty,
                JobOrderDocNo = p.JobOrderNo,
                ProductName = tab2.ProductName,
                ProductId = p.ProductId,
                JobOrderCancelHeaderId = svm.JobOrderCancelHeaderId,
                JobOrderLineId = p.JobOrderLineId,
                Dimension1Id = p.Dimension1Id,
                Dimension2Id = p.Dimension2Id,
                Dimension3Id = p.Dimension3Id,
                Dimension4Id = p.Dimension4Id,
                Dimension1Name = p.Dimension1.Dimension1Name,
                Dimension2Name = p.Dimension2.Dimension2Name,
                Dimension3Name = p.Dimension3.Dimension3Name,
                Dimension4Name = p.Dimension4.Dimension4Name,
                Specification = tab.Specification,
                UnitId = tab2.UnitId,
                UnitName = tab2.Unit.UnitName,
                unitDecimalPlaces = tab2.Unit.DecimalPlaces,
                DealunitDecimalPlaces = tab.DealUnit.DecimalPlaces,
                ProductUidName = (tab.ProductUidHeaderId == null ? tab.ProductUid.ProductUidName : "")
            });

            return(temp);
        }
        public IEnumerable <WeavingOrderWizardViewModel> GetProdOrdersForWeavingWizard(int DocTypeId)//DocTypeId
        {
            int SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];
            int DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];

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

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

            SqlParameter SqlParameterSiteId     = new SqlParameter("@SiteId", SiteId);
            SqlParameter SqlParameterDivisionId = new SqlParameter("@DivisionId", DivisionId);
            SqlParameter SqlParameterDocTypeId  = new SqlParameter("@DocumentTypeId", DocTypeId);

            IEnumerable <WeavingOrderWizardViewModel> PendingProdOrderList = db.Database.SqlQuery <WeavingOrderWizardViewModel>("Web.ProcWeavingOrderWizard @SiteId, @DivisionId, @DocumentTypeId", SqlParameterSiteId, SqlParameterDivisionId, SqlParameterDocTypeId).ToList();

            IEnumerable <WeavingOrderWizardViewModel> temp = (from p in PendingProdOrderList
                                                              where (string.IsNullOrEmpty(settings.filterProductCategories) ? 1 == 1 : ProductCategories.Contains(p.ProductCategoryId.ToString()))
                                                              orderby p.ProdOrderLineId
                                                              select p).ToList();



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

            //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 temp = from p in db.ViewProdOrderBalance
            //           where (string.IsNullOrEmpty(settings.filterContraSites) ? p.SiteId == SiteId : ContraSites.Contains(p.SiteId.ToString()))
            //           && (string.IsNullOrEmpty(settings.filterContraDivisions) ? p.DivisionId== DivisionId : ContraDivisions.Contains(p.DivisionId.ToString()))
            //           && (string.IsNullOrEmpty(settings.filterContraDocTypes) ? 1 == 1 : ContraDocTypes.Contains(p.DocTypeId.ToString()))
            //           join t in db.FinishedProduct on p.ProductId equals t.ProductId into table
            //           from tab in table.DefaultIfEmpty()
            //           join t2 in db.ViewRugSize on p.ProductId equals t2.ProductId into table2
            //           from tab2 in table2.DefaultIfEmpty()
            //           join t3 in db.ProdOrderHeader on p.ProdOrderHeaderId equals t3.ProdOrderHeaderId into table3
            //           from tab3 in table3.DefaultIfEmpty()
            //           select new WeavingOrderWizardViewModel
            //           {
            //               Area = tab2.ManufaturingSizeArea * p.BalanceQty,
            //               BalanceQty = p.BalanceQty,
            //               BuyerId = tab3.BuyerId,
            //               BuyerName = tab3.Buyer.Person.Name,
            //               DesignName = tab.ProductGroup.ProductGroupName,
            //               Date = p.IndentDate.ToString(),
            //               DocNo = p.ProdOrderNo,
            //               DueDate = tab3.DueDate.ToString(),
            //               Qty = p.BalanceQty,
            //               Quality = tab.ProductQuality.ProductQualityName,
            //               Size = tab2.ManufaturingSizeName,
            //               ProdOrderLineId=p.ProdOrderLineId,
            //               RefDocLineId=p.ReferenceDocLineId,
            //               RefDocTypeId=p.ReferenceDocTypeId,
            //               DesignPatternName=tab.ProductDesign.ProductDesignName,
            //           };
            return(temp);
        }