Esempio n. 1
0
        public IEnumerable <SaleDeliveryLineViewModel> GetSaleInvoicesForFilters(SaleDeliveryFilterViewModel vm)
        {
            var SaleDeliveryHeader = new SaleDeliveryHeaderService(_unitOfWork).Find(vm.SaleDeliveryHeaderId);

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

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

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

            string[] SaleInvoiceIdArr = null;
            if (!string.IsNullOrEmpty(vm.SaleInvoiceHeaderId))
            {
                SaleInvoiceIdArr = vm.SaleInvoiceHeaderId.Split(",".ToCharArray());
            }
            else
            {
                SaleInvoiceIdArr = 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.ViewSaleInvoiceBalanceForDelivery
                        join t in db.SaleInvoiceHeader on p.SaleInvoiceHeaderId equals t.SaleInvoiceHeaderId into table
                        from tab in table.DefaultIfEmpty()
                        join t1 in db.SaleInvoiceLine on p.SaleInvoiceLineId equals t1.SaleInvoiceLineId into table1
                        from tab1 in table1.DefaultIfEmpty()
                        join product in db.Product on p.ProductId equals product.ProductId into table2
                        from tab2 in table2.DefaultIfEmpty()
                        where p.SaleToBuyerId == SaleDeliveryHeader.SaleToBuyerId &&
                        (string.IsNullOrEmpty(vm.ProductId) ? 1 == 1 : ProductIdArr.Contains(p.ProductId.ToString())) &&
                        (string.IsNullOrEmpty(vm.SaleInvoiceHeaderId) ? 1 == 1 : SaleInvoiceIdArr.Contains(p.SaleInvoiceHeaderId.ToString())) &&
                        (string.IsNullOrEmpty(vm.ProductGroupId) ? 1 == 1 : ProductGroupIdArr.Contains(tab2.ProductGroupId.ToString())) &&
                        (string.IsNullOrEmpty(vm.Dimension1Id) ? 1 == 1 : Dimension1IdArr.Contains(p.Dimension1Id.ToString())) &&
                        (string.IsNullOrEmpty(vm.Dimension2Id) ? 1 == 1 : Dimension2IdArr.Contains(p.Dimension2Id.ToString())) &&
                        p.BalanceQty > 0
                        orderby p.SaleInvoiceLineId
                        select new SaleDeliveryLineViewModel
            {
                //ProductUidIdName = tab1.ProductUid != null ? tab1.ProductUid.ProductUidName : "",
                Dimension1Name = tab1.Dimension1.Dimension1Name,
                Dimension2Name = tab1.Dimension2.Dimension2Name,
                BalanceQty = p.BalanceQty,
                Qty = p.BalanceQty,
                SaleInvoiceHeaderDocNo = tab.DocNo,
                ProductName = tab2.ProductName,
                ProductId = p.ProductId,
                Dimension1Id = p.Dimension1Id,
                Dimension2Id = p.Dimension2Id,
                SaleDeliveryHeaderId = vm.SaleDeliveryHeaderId,
                SaleInvoiceLineId = p.SaleInvoiceLineId,
                UnitId = tab2.UnitId,
                UnitName = tab2.Unit.UnitName,
                DealUnitId = tab1.DealUnitId,
                DealUnitName = tab1.DealUnit.UnitName,
                unitDecimalPlaces = tab2.Unit.DecimalPlaces,
                DealUnitDecimalPlaces = tab1.DealUnit.DecimalPlaces,
                DealQty = (!tab1.UnitConversionMultiplier.HasValue || tab1.UnitConversionMultiplier <= 0) ? p.BalanceQty : p.BalanceQty * tab1.UnitConversionMultiplier.Value,
                UnitConversionMultiplier = tab1.UnitConversionMultiplier,
            }

                        );

            return(temp);
        }
Esempio n. 2
0
        public IEnumerable <RequisitionCancelLineViewModel> GetRequisitionLineForOrders(RequisitionCancelFilterViewModel svm)
        {
            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.RequisitionId))
            {
                SaleOrderIdArr = svm.RequisitionId.Split(",".ToCharArray());
            }
            else
            {
                SaleOrderIdArr = new string[] { "NA" };
            }

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

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

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

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


            var Query = (from p in db.ViewRequisitionBalance
                         join product in db.Product on p.ProductId equals product.ProductId into table2
                         from tab2 in table2.DefaultIfEmpty()
                         join t in db.RequisitionLine on p.RequisitionLineId equals t.RequisitionLineId into table1
                         from tab1 in table1.DefaultIfEmpty()
                         join t2 in db.RequisitionHeader on tab1.RequisitionHeaderId equals t2.RequisitionHeaderId
                         where p.BalanceQty > 0 && p.PersonId == svm.PersonId
                         orderby t2.DocDate, t2.DocNo
                         select new
            {
                BalanceQty = p.BalanceQty,
                Qty = 0,
                RequisitionDocNo = p.RequisitionNo,
                ProductName = tab2.ProductName,
                ProductId = p.ProductId,
                RequisitionCancelHeaderId = svm.RequisitionCancelHeaderId,
                RequisitionLineId = p.RequisitionLineId,
                unitDecimalPlaces = tab2.Unit.DecimalPlaces,
                UnitId = tab2.UnitId,
                UnitName = tab2.Unit.UnitName,
                Dimension1Name = tab1.Dimension1.Dimension1Name,
                Dimension2Name = tab1.Dimension2.Dimension2Name,
                Specification = tab1.Specification,

                //ForFilters
                PersonId = p.PersonId,
                RequisitionHeaderId = p.RequisitionHeaderId,
                CostCenterId = p.CostCenterId,
                ProductGorupId = tab2.ProductGroupId,
                Dimension1Id = tab1.Dimension1Id,
                Dimension2Id = tab1.Dimension2Id,
            }
                         );

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

            if (svm.PersonId != 0)
            {
                Query = Query.Where(m => m.PersonId == svm.PersonId);
            }

            if (!string.IsNullOrEmpty(svm.RequisitionId))
            {
                Query = Query.Where(m => SaleOrderIdArr.Contains(m.RequisitionHeaderId.ToString()));
            }

            if (!string.IsNullOrEmpty(svm.CostCenterId))
            {
                Query = Query.Where(m => CostCenterIdArr.Contains(m.CostCenterId.ToString()));
            }

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

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

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

            return(Query.Select(m => new RequisitionCancelLineViewModel
            {
                BalanceQty = m.BalanceQty,
                Qty = 0,
                RequisitionDocNo = m.RequisitionDocNo,
                ProductName = m.ProductName,
                ProductId = m.ProductId,
                RequisitionCancelHeaderId = m.RequisitionCancelHeaderId,
                RequisitionLineId = m.RequisitionLineId,
                unitDecimalPlaces = m.unitDecimalPlaces,
                UnitId = m.UnitId,
                UnitName = m.UnitName,
                Dimension1Name = m.Dimension1Name,
                Dimension2Name = m.Dimension2Name,
                Specification = m.Specification,
            }));
        }
Esempio n. 3
0
        public IEnumerable <MaterialPlanCancelLineViewModel> GetOrderPlanForFilters(MaterialPlanCancelFilterViewModel vm)
        {
            var Header = new MaterialPlanCancelHeaderService(_unitOfWork).Find(vm.MaterialPlanCancelHeaderId);

            var Settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(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[] 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" };
            }

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

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

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

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

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

            var Query = db.ViewMaterialPlanBalance.AsQueryable()
                        .Join(db.MaterialPlanLine,
                              m => m.MaterialPlanLineId,
                              om => om.MaterialPlanLineId,
                              (m, p) => new { m, p })
                        .Join(db.Product, m => m.m.ProductId, t => t.ProductId,
                              (m, j) => new
            {
                MaterialPlanLineId   = m.m.MaterialPlanLineId,
                BalanceQty           = m.m.BalanceQty,
                MaterialPlanHeaderId = m.m.MaterialPlanHeaderId,
                MaterialPlanNo       = m.m.MaterialPlanNo,
                ProductId            = m.m.ProductId,
                MaterialPlanDate     = m.m.MaterialPlanDate,
                DocTypeId            = m.m.DocTypeId,
                DocTypeName          = m.m.DocType.DocumentTypeName,
                ProductGroupId       = j.ProductGroupId,
                Dimension1Name       = m.p.Dimension1.Dimension1Name,
                Dimenstion2Name      = m.p.Dimension2.Dimension2Name,
                ProcessName          = m.p.Process.ProcessName,
                ProductName          = j.ProductName,
                Specification        = m.p.Specification,
                unitDecimalPlaces    = j.Unit.DecimalPlaces,
                UnitId            = j.UnitId,
                MaterialPlanDocNo = m.m.MaterialPlanNo,
                UnitName          = j.Unit.UnitName,
                BuyerId           = m.p.MaterialPlanHeader.BuyerId,
                Dimension1Id      = m.p.Dimension1Id,
                Dimension2Id      = m.p.Dimension2Id,
                Dimension3Id      = m.p.Dimension3Id,
                Dimension4Id      = m.p.Dimension4Id,
                ProcessId         = m.p.ProcessId,
            });

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

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

            if (!string.IsNullOrEmpty(vm.MaterialPlanHeaderId))
            {
                Query = Query.Where(m => SaleOrderIdArr.Contains(m.MaterialPlanHeaderId.ToString()));
            }

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

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

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

            if (!string.IsNullOrEmpty(vm.Dimension3Id))
            {
                Query = Query.Where(m => Dimension3IdArr.Contains(m.Dimension3Id.ToString()));
            }

            if (!string.IsNullOrEmpty(vm.Dimension4Id))
            {
                Query = Query.Where(m => Dimension4IdArr.Contains(m.Dimension4Id.ToString()));
            }

            if (!string.IsNullOrEmpty(vm.ProcessId))
            {
                Query = Query.Where(m => ProcessIdArr.Contains(m.ProcessId.ToString()));
            }

            var Result = Query.Where(m => m.BuyerId == Header.BuyerId).Select(m => new MaterialPlanCancelLineViewModel
            {
                BalanceQty     = m.BalanceQty,
                Dimension1Name = m.Dimension1Name,
                Dimension2Name = m.Dimenstion2Name,
                MaterialPlanCancelHeaderDocNo = Header.DocNo,
                MaterialPlanDocNo             = m.MaterialPlanDocNo,
                MaterialPlanCancelHeaderId    = Header.MaterialPlanCancelHeaderId,
                MaterialPlanLineId            = m.MaterialPlanLineId,
                ProcessName       = m.ProcessName,
                ProductName       = m.ProductName,
                Qty               = m.BalanceQty,
                Specification     = m.Specification,
                unitDecimalPlaces = m.unitDecimalPlaces,
                UnitId            = m.UnitId,
                UnitName          = m.UnitName
            });

            return(Result);
        }
Esempio n. 4
0
        public IEnumerable <MaterialPlanForSaleOrderViewModel> GetSaleOrdersForFilters(MaterialPlanForLineFilterViewModel svm)
        {
            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.SaleOrderHeaderId))
            {
                SaleOrderIdArr = svm.SaleOrderHeaderId.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[] Dimension1IdArr = null;
            if (!string.IsNullOrEmpty(svm.Dimension1Id))
            {
                Dimension1IdArr = svm.Dimension1Id.Split(",".ToCharArray());
            }
            else
            {
                Dimension1IdArr = new string[] { "NA" };
            }

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

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


            var Header = new MaterialPlanHeaderService(_unitOfWork).Find(svm.MaterialPlanHeaderId);

            var    settings = new MaterialPlanSettingsService(_unitOfWork).GetMaterialPlanSettingsForDocument(Header.DocTypeId, Header.DivisionId, Header.SiteId);
            string ProcName = settings.PendingProdOrderList;

            if (string.IsNullOrEmpty(ProcName))
            {
                throw new Exception("Pending ProdOrders Not Configured");
            }

            SqlParameter SqlParameterDocType  = new SqlParameter("@PlanningDocumentType", svm.DocTypeId);
            SqlParameter SqlParameterSite     = new SqlParameter("@Site", Header.SiteId);
            SqlParameter SqlParameterDivision = new SqlParameter("@Division", Header.DivisionId);
            SqlParameter SqlParameterBuyer    = new SqlParameter("@BuyerId", (Header.BuyerId.HasValue ? Header.BuyerId : (object)DBNull.Value));

            IEnumerable <PendingSaleOrderFromProc> PendingSaleOrders = db.Database.SqlQuery <PendingSaleOrderFromProc>(" " + ProcName + " @PlanningDocumentType, @Site, @Division, @BuyerId", SqlParameterDocType, SqlParameterSite, SqlParameterDivision, SqlParameterBuyer).ToList();

            //var ProductIds=(PendingSaleOrders.Select(m=>m.ProductId)).ToArray();

            //var ProductGroupIds = (from p in db.Product.Where(m => ProductIdArr.Contains(m.ProductId.ToString()))
            //                       select p.ProductGroupId).ToArray();


            var resu = (from p in PendingSaleOrders
                        where (string.IsNullOrEmpty(svm.ProductId) ? 1 == 1 : ProductIdArr.Contains(p.ProductId.ToString())) &&
                        (string.IsNullOrEmpty(svm.SaleOrderHeaderId) ? 1 == 1 : SaleOrderIdArr.Contains(p.SaleOrderHeaderId.ToString())) &&
                        (string.IsNullOrEmpty(svm.ProductGroupId) ? 1 == 1 : ProductGroupIdArr.Contains(p.ProductGroupId.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension1Id) ? 1 == 1 : Dimension1IdArr.Contains(p.Dimension1Id.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension2Id) ? 1 == 1 : Dimension2IdArr.Contains(p.Dimension2Id.ToString())) &&
                        (string.IsNullOrEmpty(svm.BuyerId) ? 1 == 1 : BuyerIdArr.Contains(p.BuyerId.ToString())) &&
                        p.BalanceQty > 0
                        orderby p.Sr
                        select new MaterialPlanForSaleOrderViewModel
            {
                BalanceQtyForPlan = p.BalanceQty,
                Qty = p.BalanceQty,
                SaleOrderDocNo = p.SaleOrderNo,
                ProductId = p.ProductId,
                ProductName = p.ProductName,
                Dimension1Id = p.Dimension1Id,
                Dimension1Name = p.Dimension1Name,
                Dimension2Id = p.Dimension2Id,
                Dimension2Name = p.Dimension2Name,
                MaterialPlanHeaderId = svm.MaterialPlanHeaderId,
                SaleOrderLineId = p.SaleOrderLineId,
                Specification = p.Specification,
                UnitName = p.UnitName,
                BomDetailExists = p.BomDetailExists,
            }).ToList();

            return(resu);
        }
        public IEnumerable <SaleOrderCancelLineViewModel> GetSaleOrderLineForMultiSelect(SaleOrderCancelFilterViewModel svm)
        {
            string[] ProductIdArr = null;
            if (!string.IsNullOrEmpty(svm.ProductId))
            {
                ProductIdArr = svm.ProductId.Split(",".ToCharArray());
            }
            else
            {
                ProductIdArr = new string[] { "NA" };
            }

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

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

            string[] SaleOrderIdArr = null;
            if (!string.IsNullOrEmpty(svm.SaleOrderId))
            {
                SaleOrderIdArr = svm.SaleOrderId.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" };
            }

            var temp = (from p in db.ViewSaleOrderBalanceForCancellation
                        join product in db.Product on p.ProductId equals product.ProductId into table2
                        from tab2 in table2.DefaultIfEmpty()
                        join D1 in db.Dimension1 on p.Dimension1Id equals D1.Dimension1Id into Dimension1Table from Dimension1Tab in Dimension1Table.DefaultIfEmpty()
                        join D2 in db.Dimension2 on p.Dimension2Id equals D2.Dimension2Id into Dimension2Table
                        from Dimension2Tab in Dimension2Table.DefaultIfEmpty()
                        where (string.IsNullOrEmpty(svm.ProductId) ? 1 == 1 : ProductIdArr.Contains(p.ProductId.ToString())) &&
                        (svm.BuyerId == 0? 1 == 1 : p.BuyerId == svm.BuyerId) &&
                        (string.IsNullOrEmpty(svm.SaleOrderId) ? 1 == 1 : SaleOrderIdArr.Contains(p.SaleOrderHeaderId.ToString())) &&
                        (string.IsNullOrEmpty(svm.ProductGroupId) ? 1 == 1 : ProductGroupIdArr.Contains(tab2.ProductGroupId.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension1Id) ? 1 == 1 : Dimension1IdArr.Contains(p.Dimension1Id.ToString())) &&
                        (string.IsNullOrEmpty(svm.Dimension2Id) ? 1 == 1 : Dimension2IdArr.Contains(p.Dimension2Id.ToString())) &&
                        p.BalanceQty > 0
                        select new SaleOrderCancelLineViewModel
            {
                BalanceQty = p.BalanceQty,
                Qty = p.BalanceQty,
                DocNo = p.SaleOrderNo,
                ProductName = tab2.ProductName,
                ProductId = p.ProductId,
                Dimension1Name = Dimension1Tab.Dimension1Name,
                Dimension1Id = p.Dimension1Id,
                Dimension2Name = Dimension2Tab.Dimension2Name,
                Dimension2Id = p.Dimension2Id,
                SaleOrderCancelHeaderId = svm.SaleOrderCancelHeaderId,
                SaleOrderLineId = p.SaleOrderLineId
            });

            return(temp);
        }
        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,
            });
        }