public JsonResult GetSaleOrderDetailJson(int SaleOrderLineId)
        {
            var temp = (from L in db.ViewSaleOrderBalance
                        join Dl in db.SaleOrderLine on L.SaleOrderLineId equals Dl.SaleOrderLineId into SaleOrderLineTable
                        from SaleOrderLineTab in SaleOrderLineTable.DefaultIfEmpty()
                        join P in db.Product on L.ProductId equals P.ProductId into ProductTable
                        from ProductTab in ProductTable.DefaultIfEmpty()
                        join U in db.Units on ProductTab.UnitId equals U.UnitId into UnitTable
                        from UnitTab in UnitTable.DefaultIfEmpty()
                        join D1 in db.Dimension1 on L.Dimension1Id equals D1.Dimension1Id into Dimension1Table
                        from Dimension1Tab in Dimension1Table.DefaultIfEmpty()
                        join D2 in db.Dimension2 on L.Dimension2Id equals D2.Dimension2Id into Dimension2Table
                        from Dimension2Tab in Dimension2Table.DefaultIfEmpty()
                        where L.SaleOrderLineId == SaleOrderLineId
                        select new
            {
                SaleOrderHeaderDocNo = L.SaleOrderNo,
                UnitId = UnitTab.UnitId,
                UnitName = UnitTab.UnitName,
                DealUnitId = SaleOrderLineTab.DealUnitId,
                Specification = SaleOrderLineTab.Specification,
                UnitConversionMultiplier = SaleOrderLineTab.UnitConversionMultiplier,
                ProductId = L.ProductId,
                Dimension1Id = L.Dimension1Id,
                Dimension1Name = Dimension1Tab.Dimension1Name,
                Dimension2Id = L.Dimension2Id,
                Dimension2Name = Dimension2Tab.Dimension2Name,
                Rate = L.Rate,
                BalanceQty = L.BalanceQty
            }).FirstOrDefault();

            if (temp != null)
            {
                return(Json(temp));
            }
            else
            {
                return(null);
            }
        }
        public SaleDispatchLineViewModel GetSaleDispatchDetailForInvoice(int id)
        {
            return((from t in db.ViewSaleDispatchBalance
                    join p in db.SaleDispatchLine on t.SaleDispatchLineId equals p.SaleDispatchLineId into SaleDispatchLineTable from SaleDispatchLineTab in SaleDispatchLineTable.DefaultIfEmpty()
                    join pl in db.PackingLine on SaleDispatchLineTab.PackingLineId equals pl.PackingLineId into PackingLineTable from PackingLineTab in PackingLineTable.DefaultIfEmpty()
                    join sol in db.SaleOrderLine on t.SaleOrderLineId equals sol.SaleOrderLineId into SaleOrderLineTable from SaleOrderLineTab in SaleOrderLineTable.DefaultIfEmpty()
                    where t.SaleDispatchLineId == id
                    select new SaleDispatchLineViewModel
            {
                DealQty = PackingLineTab.DealQty,
                DealUnitId = PackingLineTab.DealUnitId,
                ProductId = PackingLineTab.ProductId,
                Qty = t.BalanceQty,
                Rate = SaleOrderLineTab.Rate,
                Remark = PackingLineTab.Remark,
                Dimension1Id = PackingLineTab.Dimension1Id,
                Dimension2Id = PackingLineTab.Dimension2Id,
                Dimension1Name = PackingLineTab.Dimension1.Dimension1Name,
                Dimension2Name = PackingLineTab.Dimension2.Dimension2Name,
                SaleOrderLineId = PackingLineTab.SaleOrderLineId,
                Specification = PackingLineTab.Specification,
                UnitConversionMultiplier = PackingLineTab.UnitConversionMultiplier,
                UnitId = PackingLineTab.Product.UnitId,
                UnitName = PackingLineTab.Product.Unit.UnitName,
            }

                    ).FirstOrDefault());
        }