public IQueryable <PackingHeaderViewModel> GetPackingHeaderList(string Uname)
        {
            var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            var SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

            IQueryable <PackingHeaderViewModel> packingheaderlist = from H in db.PackingHeader
                                                                    join B in db.Persons on H.BuyerId equals B.PersonID into BuyerTable
                                                                    from BuyerTab in BuyerTable.DefaultIfEmpty()
                                                                    orderby H.DocDate descending, H.DocNo descending
            where H.SiteId == SiteId && H.DivisionId == DivisionId
                                                select new PackingHeaderViewModel
            {
                PackingHeaderId = H.PackingHeaderId,
                DocTypeId       = H.DocTypeId,
                DocDate         = H.DocDate,
                DocNo           = H.DocNo,
                BuyerName       = BuyerTab.Name,
                Remark          = H.Remark,
                Status          = H.Status,
                ModifiedBy      = H.ModifiedBy,
                ReviewCount     = H.ReviewCount,
                ReviewBy        = H.ReviewBy,
                Reviewed        = (SqlFunctions.CharIndex(Uname, H.ReviewBy) > 0),
                TotalQty        = H.PackingLines.Sum(m => m.Qty),
                DecimalPlaces   = (from o in H.PackingLines
                                   join prod in db.Product on o.ProductId equals prod.ProductId
                                   join u in db.Units on prod.UnitId equals u.UnitId
                                   select u.DecimalPlaces).Max(),
            };


            return(packingheaderlist);
        }
        //New Functions

        public IQueryable <PackingHeaderIndexViewModel> GetPackingHeaderList(int id, string Uname)
        {
            var DivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
            var SiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

            IQueryable <PackingHeaderIndexViewModel> packingheaderlist = from H in db.PackingHeader
                                                                         join B in db.Persons on H.BuyerId equals B.PersonID into BuyerTable
                                                                         from BuyerTab in BuyerTable.DefaultIfEmpty()
                                                                         orderby H.DocDate descending, H.DocNo descending
            where H.SiteId == SiteId && H.DivisionId == DivisionId && H.DocTypeId == id
                                                     select new PackingHeaderIndexViewModel
            {
                PackingHeaderId = H.PackingHeaderId,
                DocTypeId       = H.DocTypeId,
                DocDate         = H.DocDate,
                DocNo           = H.DocNo,
                BuyerName       = BuyerTab.Name,
                Remark          = H.Remark,
                Status          = H.Status,
                ModifiedBy      = H.ModifiedBy,
                ReviewCount     = H.ReviewCount,
                ReviewBy        = H.ReviewBy,
                Reviewed        = (SqlFunctions.CharIndex(Uname, H.ReviewBy) > 0),
            };


            return(packingheaderlist);
        }
        public PackingHeaderViewModel GetPackingHeaderViewModel(int id)
        {
            PackingHeaderViewModel packingheader = (from H in db.PackingHeader
                                                    join B in db.Persons on H.BuyerId equals B.PersonID into BuyerTable from BuyerTab in BuyerTable.DefaultIfEmpty()
                                                    join B in db.Persons on H.JobWorkerId equals B.PersonID into JobWorkerTable from JobWorkerTab in JobWorkerTable.DefaultIfEmpty()
                                                    join D in db.DocumentType on H.DocTypeId equals D.DocumentTypeId into DocumentTypeTable from DocumentTypeTab in DocumentTypeTable.DefaultIfEmpty()
                                                    join Div in db.Divisions on H.DivisionId equals Div.DivisionId into DivisionTable from DivisionTab in DivisionTable.DefaultIfEmpty()
                                                    join S in db.Site on H.SiteId equals S.SiteId into SiteTable from SiteTab in SiteTable.DefaultIfEmpty()
                                                    join G in db.Godown on H.GodownId equals G.GodownId into GodownTable from GodownTab in GodownTable.DefaultIfEmpty()
                                                    join Du in db.Units on H.DealUnitId equals Du.UnitId into DeliveryUnitTable
                                                    from DeliveryUnitTab in DeliveryUnitTable.DefaultIfEmpty()
                                                    where H.PackingHeaderId == id
                                                    select new PackingHeaderViewModel
            {
                PackingHeaderId = H.PackingHeaderId,
                DocTypeName = DocumentTypeTab.DocumentTypeName,
                DocDate = H.DocDate,
                DocNo = H.DocNo,
                BuyerId = H.BuyerId,
                DocTypeId = H.DocTypeId,
                BuyerName = BuyerTab.Name,
                JobWorkerId = H.JobWorkerId.Value,
                JobWorkerName = JobWorkerTab.Name,
                DivisionId = H.DivisionId,
                DivisionName = DivisionTab.DivisionName,
                SiteId = H.SiteId,
                SiteName = SiteTab.SiteName,
                GodownId = H.GodownId,
                GodownName = GodownTab.GodownName,
                DealUnitId = H.DealUnitId,
                DealUnitName = DeliveryUnitTab.UnitName,
                BaleNoPattern = H.BaleNoPattern,
                ShipMethodId = H.ShipMethodId,
                Remark = H.Remark,
                Status = H.Status,
                CreatedBy = H.CreatedBy,
                CreatedDate = H.CreatedDate,
                ModifiedBy = H.ModifiedBy,
                ModifiedDate = H.ModifiedDate,
                LockReason = H.LockReason,
                TotalQty = H.PackingLines.Sum(m => m.Qty),
                DecimalPlaces = (from o in H.PackingLines
                                 join prod in db.Product on o.ProductId equals prod.ProductId
                                 join u in db.Units on prod.UnitId equals u.UnitId
                                 select u.DecimalPlaces).Max(),
            }).FirstOrDefault();

            return(packingheader);
        }