


google.charts.load('current', { packages: ['corechart', 'bar'] });
google.charts.setOnLoadCallback(drawBasic);
$(function () {
  
    
    $.ajax({
        type: "POST",
        url: "InteractiveDashboard.aspx/Web_GetTotalSaleslist",
      
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess,
        failure: function (response) {
            //alert(response.d);
            alert("Error..1");

        },
        error: function (response) {


            alert("Error..2");
            alert(response);
        }
    });
});

function OnSuccess(response) {
    //  var jsonResult = JSON.stringify(response.d)
    //  alert(jsonResult);
    var jsonResult = JSON.parse(response.d);
    var jsonCount = jsonResult.length;


    for (var n = 0; n < jsonCount; n++) {
        var _Branch = jsonResult[n].Branch;
        var _TotalsalesAmt = jsonResult[n].TotalsalesAmt;

    }
    sessionStorage.setItem("JsonResult", JSON.stringify(jsonResult));
    // loop the jsonresult Here 
    drawBasic();
 



};


// Main Chat linked to the child chart 
function drawBasic() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Branch');
    data.addColumn('number', 'TotalsalesAmt');

    var Rjsonvalue = JSON.parse(sessionStorage.getItem("JsonResult"));
    Rjsonvalue.forEach(function (item) {
        data.addRow([item.Branch, item.TotalsalesAmt]);
    });

   
    var options = {
        title: 'Monthy Total Sales',
        hAxis: {
            title: 'Branch',
            // format: 'MMM yyyy',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Total Sales'
        }
    };
    
    // Calling All selectiion Methods Here  On Page Load..

    // Totoal Sales Amount Wise Total By All category In All Branches
    google.charts.setOnLoadCallback(byBranchAll());
    // Total Qty in  All category In All Branches
    google.charts.setOnLoadCallback(byQtyWiseCategoryALL());
    // Inventory Wise total in All  Branches..
    google.charts.setOnLoadCallback(byInventoryTotalALL());
    // TotalQty-InventoryWise  in All Branches
    google.charts.setOnLoadCallback(byInventoryQTYTotalALL());

    // This is 3rd Level To show the Inventory Items and Amount  
    google.charts.setOnLoadCallback(byInventoryitemsListALL3rdlvel());
    // This is to load the Total sales amount branchwise 
    google.charts.setOnLoadCallback(byAllBranchPie());

    
    // This i Table data which is topQty Categoryname 
    GetTopCategory_Default();

 

    
    
    function selectHandler() {
        var selection = chart.getSelection();
        if (selection.length > 0)
        {
            var mydata = data.getValue(selection[0].row, 0);
           // alert(selection[0].row);  This show data row index value 

            //alert(mydata);

            var Branchid = Read_BranchId(mydata);

            sessionStorage.setItem("Branchid", Branchid);
            google.charts.setOnLoadCallback(byBranch(Branchid));
            google.charts.setOnLoadCallback(byQtyWiseCategoryBranch(Branchid));
            google.charts.setOnLoadCallback(byInventoryWiseTotalByBranch(Branchid));
            google.charts.setOnLoadCallback(byInventoryQTYTotalByBranch(Branchid));
            

            
        }
        else 
        {
           

        }

    }
    

    // Loading the chart 
    var chart = new google.visualization.ColumnChart(
    document.getElementById('chart_div'));
    google.visualization.events.addListener(chart, 'select', selectHandler);
    chart.draw(data, options);
   
}

// CategoryWise Total Sales By Branch 
function byBranch(Branchid) {

  
    
    var Branchdata = new google.visualization.DataTable();
    Branchdata.addColumn('string', 'CategoryName');
    Branchdata.addColumn('number', 'Amount');

    var Branchjsonvalue = JSON.parse(GetCategorylistBranchid(Branchid));
    Branchjsonvalue.forEach(function (item) {
        Branchdata.addRow([item.CategoryName, item.Amount]);
        
    });


    

    var options = {
        title: 'Total Amount Sold By Category',
        hAxis: {
            title: 'Category',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/

            

        },
      

        vAxis: {
            title: 'Sales'
        }
    };

    function selectHandler() {
        var selection = chart.getSelection();
        if (selection.length > 0) {
            var myBranchdata = Branchdata.getValue(selection[0].row, 0);

            // Bring Branchwise & Categorywise Data By Categoryname and Branchid : Ohm
            // Get the Branchid from session..
            

            var bid = sessionStorage.getItem("Branchid");
            google.charts.setOnLoadCallback(byInventoryWiseTotalByBranchandCategory(bid, myBranchdata));
            google.charts.setOnLoadCallback(byInventoryitemsListCategorynameandBranchid(bid, myBranchdata));
            google.charts.setOnLoadCallback(byIn(myBranchdata));

         
        }
    }

    var chart = new google.visualization.PieChart(
        document.getElementById('chart_divbranch'));
    google.visualization.events.addListener(chart, 'select', selectHandler);
    chart.draw(Branchdata, options);
}


// Catgorywise Total Sale In All Branches 
function byBranchAll() {
       

    var Branchdata = new google.visualization.DataTable();
    Branchdata.addColumn('string', 'CategoryName');
    Branchdata.addColumn('number', 'Amount');

    var Branchjsonvalue = JSON.parse(GetCategorylistALL());
    Branchjsonvalue.forEach(function (item) {
        Branchdata.addRow([item.CategoryName, item.Amount]);

    });




    var options = {
        title: 'Total Amount Sold By Category',
        hAxis: {
            title: 'Category',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Sales'
        }
    };

    function selectHandler() {
        var selection = chart.getSelection();
        if (selection.length > 0) {
            var myBranchdata = Branchdata.getValue(selection[0].row, 0);

            // myBranchdata  Returns the CategoryName, Get the Categoryname
            sessionStorage.setItem("Categoryval", myBranchdata);
            google.charts.setOnLoadCallback(byInventoryitemsList3rdlvel(myBranchdata.toString()));
            google.charts.setOnLoadCallback(byIn(myBranchdata.toString()));

            // Load the 3rd Level Data on CategoryName selection
            google.charts.setOnLoadCallback(byInventoryitemsList3rdlvelOnwithoutBranch(myBranchdata.toString()));
            


        }
    }

    var chart = new google.visualization.PieChart(
        document.getElementById('chart_divbranch'));
    google.visualization.events.addListener(chart, 'select', selectHandler);
    chart.draw(Branchdata, options);
}

// CategoryWise Qty Total By Branchid 
function byQtyWiseCategoryBranch(Branchid) {

    //Get the BrancDetails By BranchId




    var QtywiseBranchdata = new google.visualization.DataTable();
    QtywiseBranchdata.addColumn('string', 'CategoryName');
    QtywiseBranchdata.addColumn('number', 'Qty');

    var QtyBranchjsonvalue = JSON.parse(GetQtywiseCategorylistBranchid(Branchid));
    QtyBranchjsonvalue.forEach(function (itemss) {
        QtywiseBranchdata.addRow([itemss.CategoryName, itemss.Qty]);

    });


    

    var options = {
        title: 'Total Qty Sold By Category',
        hAxis: {
            title: 'Category',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Qty'
        }
    };

    function selectHandler() {
        var selection = chart2.getSelection();
        if (selection.length > 0) {
            var myQtyBranchdata = QtywiseBranchdata.getValue(selection[0].row, 0);

            // myQtyBranchdata Returns the CategoryName
            var bid = sessionStorage.getItem("Branchid");
            google.charts.setOnLoadCallback(byProductQTYTotalByBranchandCategoryName(bid, myQtyBranchdata));
           
            google.charts.setOnLoadCallback(byIn(myQtyBranchdata));

            google.charts.setOnLoadCallback(byInventoryitemsQTY(bid,myQtyBranchdata));



            
            
        }
    }

    var chart2 = new google.visualization.PieChart(
        document.getElementById('chart_divQtyWiseCategory'));
    google.visualization.events.addListener(chart2, 'select', selectHandler);
    chart2.draw(QtywiseBranchdata, options);
}

// InventoryList By Category


// Qty wise CategoryList in All Branches
function byQtyWiseCategoryALL() {

    

    var QtywiseBranchdata = new google.visualization.DataTable();
    QtywiseBranchdata.addColumn('string', 'CategoryName');
    QtywiseBranchdata.addColumn('number', 'Qty');

    var QtyBranchjsonvalue = JSON.parse(GetQtywiseCategorylistALL());
    QtyBranchjsonvalue.forEach(function (itemss) {
        QtywiseBranchdata.addRow([itemss.CategoryName, itemss.Qty]);

    });




    var options = {
        title: 'Total Qty Sold By Category',
        hAxis: {
            title: 'Category',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Qty'
        }
    };

    function selectHandler3() {
        var selection = chart3.getSelection();
        if (selection.length > 0) {
            var myQtyBranchdata = QtywiseBranchdata.getValue(selection[0].row, 0);    
            // myQtyBranchdata  Returns the CategoryName   
            sessionStorage.setItem("Categoryval", myQtyBranchdata);
            google.charts.setOnLoadCallback(byInventoryitemsList3rdlvel(myQtyBranchdata.toString()));     // Consider this evt
            google.charts.setOnLoadCallback(byIn(myQtyBranchdata.toString()));     // Consider this evt
            // Load the 3rd Level Data on CategoryName selection
            google.charts.setOnLoadCallback(byInventoryitemsList3rdlvelOnwithoutBranch(myQtyBranchdata.toString()));
            
        }
    }

    var chart3 = new google.visualization.PieChart(
    document.getElementById('chart_divQtyWiseCategory'));
    google.visualization.events.addListener(chart3, 'select', selectHandler3);
    chart3.draw(QtywiseBranchdata, options);
}


// InventoryWise Total Specific Branch 
function byInventoryWiseTotalByBranch(Branchid) {

    //Get the BrancDetails By BranchId




    var InventoryWiseBranchdata = new google.visualization.DataTable();
    InventoryWiseBranchdata.addColumn('string', 'InventoryName');
    InventoryWiseBranchdata.addColumn('number', 'Amount');

    var InventoryBranchjsonvalue = JSON.parse(GetInventoryAmountWiseBranchid(Branchid));
    InventoryBranchjsonvalue.forEach(function (itemss) {
        InventoryWiseBranchdata.addRow([itemss.InventoryName, itemss.Amount]);

    });




    var options = {
        title: 'Total Amount Sold By Products',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Amount'
        }
    };

    function selectHandler() {
        var selection = chart.getSelection();
        if (selection.length > 0) {
            var myInventoryBranchdata = InventoryWiseBranchdata.getValue(selection[0].row, 0);
            //google.charts.setOnLoadCallback(byCategory(myInventoryBranchdata));


        }
    }

    var chart3 = new google.visualization.PieChart(
        document.getElementById('chart_InventoryAmount'));
    google.visualization.events.addListener(chart3, 'select', selectHandler);
    chart3.draw(InventoryWiseBranchdata, options);
}


// Inventorywise Total Specific Branch and Specific Category -Ohm
function byInventoryWiseTotalByBranchandCategory(Branchid,CategoryName)
{

    var ProudctsBranchCategorydata = new google.visualization.DataTable();
    ProudctsBranchCategorydata.addColumn('string', 'InventoryName');
    ProudctsBranchCategorydata.addColumn('number', 'Amount');

    var ProductBranchCategoryjsonvalue = JSON.parse(GetInventoryAmountWiseBranchidandCategoryName(Branchid, CategoryName));
    ProductBranchCategoryjsonvalue.forEach(function (itemss) {
        ProudctsBranchCategorydata.addRow([itemss.InventoryName, itemss.Amount]);

    });




    var options = {
        title: 'Total Amount Sold By Product',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Amount'
        }
    };

    function selectHandler30() {
        var selection = chart30.getSelection();
        if (selection.length > 0) {
            var myProductBranchCategoryhdata = ProudctsBranchCategorydata.getValue(selection[0].row, 0);
            //google.charts.setOnLoadCallback(byCategory(myProductBranchCategoryhdata));

            google.charts.setOnLoadCallback(byIn(myProductBranchCategoryhdata));

            google.charts.setOnLoadCallback(byInventoryitemsList4thlevelWithBranch(myProductBranchCategoryhdata));

            // Call Webgrid
            CallitbackBrachProductData(Branchid, myProductBranchCategoryhdata);

        }
    }

    var chart30 = new google.visualization.PieChart(
        document.getElementById('chart_InventoryAmount'));
    google.visualization.events.addListener(chart30, 'select', selectHandler30);
    chart30.draw(ProudctsBranchCategorydata, options);
}

// InventoryWise Total ALL Branch 
function byInventoryTotalALL() {

   
    var InventoryWiseALL = new google.visualization.DataTable();
    InventoryWiseALL.addColumn('string', 'InventoryName');
    InventoryWiseALL.addColumn('number', 'Amount');

    var InventoryALLjsonvalue = JSON.parse(GetInventoryAmountWiseALL());
    InventoryALLjsonvalue.forEach(function (itemss) {
        InventoryWiseALL.addRow([itemss.InventoryName, itemss.Amount]);

    });




    var options = {
        title: 'Total Amount Sold By Products',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Amount'
        }
    };


    // Later Point to the redirect Chart with this chart..
    function selectHandler7() {
        var selection = chart7.getSelection();
        if (selection.length > 0) {
            var myInventoryALL = InventoryWiseALL.getValue(selection[0].row, 0);
            google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryALL));
        }
    }

    var chart7 = new google.visualization.PieChart(
        document.getElementById('chart_InventoryAmount'));
    google.visualization.events.addListener(chart7, 'select', selectHandler7);
    chart7.draw(InventoryWiseALL, options);
}


// Get the Inventorywise Total Qty By Branch 
function byInventoryQTYTotalByBranch(Branchid) {

    //Get the BrancDetails By BranchId

    var InventoryQTYBranchdata = new google.visualization.DataTable();
    InventoryQTYBranchdata.addColumn('string', 'InventoryName');
    InventoryQTYBranchdata.addColumn('number', 'Qty');

    var InventoryQTYBranchjsonvalue = JSON.parse(GetInventoryQtyWiseBranchid(Branchid));
    InventoryQTYBranchjsonvalue.forEach(function (itemss) {
        InventoryQTYBranchdata.addRow([itemss.InventoryName, itemss.Qty]);

    });




    var options = {
        title: 'Total Qty Sold By Products',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Qty'
        }
    };

    function selectHandler() {
        var selection = chart.getSelection();
        if (selection.length > 0) {
            var myInventoryQtyBranchdata = InventoryQTYBranchdata.getValue(selection[0].row, 0);
            //google.charts.setOnLoadCallback(byCategory(myInventoryQtyBranchdata));
            google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryQtyBranchdata));

        }
    }

    var chart4 = new google.visualization.PieChart(
        document.getElementById('chart_InventoryQty'));
    google.visualization.events.addListener(chart4, 'select', selectHandler);
    chart4.draw(InventoryQTYBranchdata, options);
}

// Get The ProductList QtyWise By Category and Brnachid 
function byProductQTYTotalByBranchandCategoryName(Branchid,CategoryName) {

    //Get the BrancDetails By BranchId

    var ProductQTYBranchdata = new google.visualization.DataTable();
    ProductQTYBranchdata.addColumn('string', 'InventoryName');
    ProductQTYBranchdata.addColumn('number', 'Qty');

    var ProductQTYBranchjsonvalue = JSON.parse(GetProductListByBranchidAndCategoryName(Branchid, CategoryName));
    ProductQTYBranchjsonvalue.forEach(function (itemss) {
        ProductQTYBranchdata.addRow([itemss.InventoryName, itemss.Qty]);

    });




    var options = {
        title: 'Total Qty Sold By Products',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Qty'
        }
    };  

    function selectHandler() {
        var selection = chart30.getSelection();
        if (selection.length > 0) {
            var myProductQtyBranchdata = ProductQTYBranchdata.getValue(selection[0].row, 0);

            // CREATE EVENT For -> Load the Top Qty Pie Chat and load webgrid with that InventoryName

            google.charts.setOnLoadCallback(byInBranchPie(myProductQtyBranchdata));
            CallitbackBrachProductData(Branchid, myProductQtyBranchdata);


        }
    }

    var chart30 = new google.visualization.BarChart(
        document.getElementById('chartInventoryListByCategory'));
    google.visualization.events.addListener(chart30, 'select', selectHandler);
    chart30.draw(ProductQTYBranchdata, options);
}

// Get Inventory TotalQty-All 
function byInventoryQTYTotalALL() {

    //Get the BrancDetails By BranchId

    var InventoryQTYALL = new google.visualization.DataTable();
    InventoryQTYALL.addColumn('string', 'InventoryName');
    InventoryQTYALL.addColumn('number', 'Qty');

    var InventoryQTYALLjsonvalue = JSON.parse(GetInventoryQtyWiseALL());
    InventoryQTYALLjsonvalue.forEach(function (itemss) {
        InventoryQTYALL.addRow([itemss.InventoryName, itemss.Qty]);

    });




    var options = {
        title: 'Total Qty Sold By Products',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Qty'
        }
    };

    function selectHandler10() {
        var selection = chart10.getSelection();
        if (selection.length > 0) {
            var myInventoryQtyALLdata = InventoryQTYALL.getValue(selection[0].row, 0);
            google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryQtyALLdata));
        }
    }

  var chart10 = new google.visualization.PieChart
        (
        document.getElementById('chart_InventoryQty'));
        google.visualization.events.addListener(chart10, 'select', selectHandler10);
        chart10.draw(InventoryQTYALL, options);
        }

function byCategory(branch) {
    var data;
    switch (branch) {
        case 'Branch A':
            data = google.visualization.arrayToDataTable([
                ['Task', 'Hours per Day'],
                ['Work', 15],
                ['Eat', 2],
                ['Commute', 2],
                ['Watch TV', 2],
                ['Sleep', 7]
            ]);
            break;
        case 'Branch B':
            data = google.visualization.arrayToDataTable([
                ['Task', 'Hours per Day'],
                ['Work', 10],
                ['Eat', 2],
                ['Commute', 2],
                ['Watch TV', 4],
                ['Sleep', 7]
            ]);
            break;
        case 'Branch C':
            data = google.visualization.arrayToDataTable([
                ['Task', 'Hours per Day'],
                ['Work', 10],
                ['Eat', 40],
                ['Commute', 22],
                ['Watch TV', 4],
                ['Sleep', 7]
            ]);
            break;
        default:
        // code block
    }

    var options = {
        title: 'My Daily Activities'
    };



    var chart = new google.visualization.PieChart(
        document.getElementById('chart_divbranchCat'));

    chart.draw(data, options);

}

// Supporting Functions :

// Read Branchid 
function Read_BranchId(BranchFullName)
{

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/GetBranchId",
        data: "{BranchFullName:'" + BranchFullName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data)
            {
                ret = Data
            }
            else
            {
              ret = "";
            }
        }
    });
    return (ret);
}

// Get CategoryList By Branchid 
function GetCategorylistBranchid(BranchID) {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebCategoryListByBranchid",
        data: "{BranchID:" + BranchID + "}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}

// Get CategoryList ALL  
function GetCategorylistALL() {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebCategoryListAll",
        data: "{ }",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}

// Get Qty wise CategoryList  
function GetQtywiseCategorylistBranchid(BranchID) {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebCategoryListQuantitywiseByBranchid",
        data: "{BranchID:" + BranchID + "}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}





function GetProductListByBranchidAndCategoryName(BranchID, CategoryName) {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/QTYWiseProductListByCategoryNameAndBranch",
        data: "{BranchID:" + BranchID + ",CategoryName:'" + CategoryName + "' }",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data

                CallitbackBrachData(CategoryName, BranchID);

            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}












// Get Qty wise CategoryListAll 
function GetQtywiseCategorylistALL() {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebCategoryListQuantitywiseALL",
        data: "{}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data

               

            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}

// Inventory wise Total-Amount
function GetInventoryAmountWiseBranchid(BranchID) {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryByAmountBranchid",
        data: "{BranchID:" + BranchID + "}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}

// Get Inventory-Amountwise By Branchid and CategoryName - Ohm 
function GetInventoryAmountWiseBranchidandCategoryName(BranchID, CategoryName) {

    
    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryByAmountBranchidAndCategory",
        data: "{BranchID:" + BranchID + ",CategoryName:'" + CategoryName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
                CallitbackBrachData(CategoryName, BranchID);
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}


function GetInventoryQTYWiseBranchidandCategoryName(BranchID, CategoryName) {


    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryByQtyBranchidAndCategory",
        data: "{BranchID:" + BranchID + ",CategoryName:'" + CategoryName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
                CallitbackBrachProductData(CategoryName, BranchID);
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}



// Get BranchPie On inventoryName  : Return Branchwise qty Top of Particular Product
function GetBranchPieDataByProductName(Name) {


    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/BranchDat_Pie",
        data: "{Name:'" + Name + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
                var bid = sessionStorage.getItem("Branchid");
                
                CallitbackBrachProductData(bid, Name);
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}







// Inventory wise Total-Amount By All 
function GetInventoryAmountWiseALL() {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryByAmountALL",
        data: "{}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}

// Inventory wise Total-Qty  
function GetInventoryQtyWiseBranchid(BranchID) {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebQtyInventoryWiseBranchid",
        data: "{BranchID:" + BranchID + "}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}

// Inventory wise Total-Qty ALL
function GetInventoryQtyWiseALL() {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebQtyInventoryALL",
        data: "{}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data




            }
            else {
                ret = "";
            }
        }
    });
    return (ret);
}


// 3rd Level Chart Methods 
// Inventoryitems and Amount By  CategoryName
function GetInventory1(CategoryName)
{

    var returnval = "";
    
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryItemsAndAmountByCategoryName",
        data: "{CategoryName:'" + CategoryName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {

           
            var Data = result.d.toString();
            if (Data)
            {
                ret = Data

                CallitbackTest(CategoryName);
                

            }
            else
            {
              ret = "";
            }
        }
    });
    return (ret);
      
}
// Function for load the InventoryList By category Chart Function 
function byInventoryitemsList3rdlvel(CategoryName)
{

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");



    if (_selectedchart == "chart_divbranch") {

        //Get the BrancDetails By BranchId
        var InventoryItemsdata = new google.visualization.DataTable();
        InventoryItemsdata.addColumn('string', 'InventoryName');
        InventoryItemsdata.addColumn('number', 'Amount');

        var InventoryitemsJSON = JSON.parse(GetInventory1(CategoryName));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        InventoryitemsJSON.forEach(function (iitem) {
            InventoryItemsdata.addRow([iitem.InventoryName, iitem.Amount]);

        });

        var options = {
            title: 'Total Amount Sold By Products',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart21.getSelection();
            if (selection.length > 0) {
                var myInventoryItems = InventoryItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryItems));
            }
        }

        var chart21 = new google.visualization.BarChart(
            document.getElementById('chartInventoryListByCategory'));
        google.visualization.events.addListener(chart21, 'select', selectHandler);
        chart21.draw(InventoryItemsdata, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory")
    {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'InventoryName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.InventoryName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Products',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.BarChart(
            document.getElementById('chartInventoryListByCategory'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);



    }

   
}

function byInventoryitemsList3rdlvelOnwithoutBranch(CategoryName) {

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");



    if (_selectedchart == "chart_divbranch") {

        //Get the BrancDetails By BranchId
        var InventoryItemsdata = new google.visualization.DataTable();
        InventoryItemsdata.addColumn('string', 'InventoryName');
        InventoryItemsdata.addColumn('number', 'Amount');

        var InventoryitemsJSON = JSON.parse(GetInventory1(CategoryName));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        InventoryitemsJSON.forEach(function (iitem) {
            InventoryItemsdata.addRow([iitem.InventoryName, iitem.Amount]);

        });

        var options = {
            title: 'Total Amount Sold By Products',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart21.getSelection();
            if (selection.length > 0) {
                var myInventoryItems = InventoryItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryItems));
            }
        }

        var chart21 = new google.visualization.PieChart(
            document.getElementById('chart_InventoryAmount'));
        google.visualization.events.addListener(chart21, 'select', selectHandler);
        chart21.draw(InventoryItemsdata, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'InventoryName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.InventoryName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Products',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('chart_InventoryQty'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);



    }


}



// Function to load the InvetoryList-Amount  Categoryname and Branchid 
function byInventoryitemsListCategorynameandBranchid(BranchID, CategoryName) {

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");



    if (_selectedchart == "chart_divbranch") {

        //Get the BrancDetails By BranchId
        var InventoryItemsdata = new google.visualization.DataTable();
        InventoryItemsdata.addColumn('string', 'InventoryName');
        InventoryItemsdata.addColumn('number', 'Amount');

        var InventoryitemsJSON = JSON.parse(GetInventoryAmountWiseBranchidandCategoryName(BranchID, CategoryName ));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        InventoryitemsJSON.forEach(function (iitem) {
            InventoryItemsdata.addRow([iitem.InventoryName, iitem.Amount]);

        });

        var options = {
            title: 'Total Amount Sold By Products',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart21.getSelection();
            if (selection.length > 0) {
                // Here  myInventoryItems  return the Barchart's ProductNane or InventoryName 
                var myInventoryItems = InventoryItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevelWithBranch(myInventoryItems));

                // CAll the SubGrid
                var bid = sessionStorage.getItem("Branchid");
                CallitbackBrachProductData(bid, myInventoryItems);


            }
        }

        var chart21 = new google.visualization.BarChart(
            document.getElementById('chartInventoryListByCategory'));
        google.visualization.events.addListener(chart21, 'select', selectHandler);
        chart21.draw(InventoryItemsdata, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'InventoryName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(categoryname));
        var InventoryQtyitemsJSON = JSON.parse(GetInventoryQTYWiseBranchidandCategoryName(BranchID, CategoryName));
        
        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.InventoryName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Product',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.BarChart(
            document.getElementById('chartInventoryListByCategory'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);



    }


}


function byInventoryitemsQTY(BranchID, CategoryName)
{

   
  

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'InventoryName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(categoryname));
        var InventoryQtyitemsJSON = JSON.parse(GetInventoryQTYWiseBranchidandCategoryName(BranchID, CategoryName));

        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.InventoryName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Product',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart40.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
                google.charts.setOnLoadCallback(byInventoryitemsList4thlevelWithBranch(myInventoryQtyItems));
            }
        }

        var chart40 = new google.visualization.PieChart(
            document.getElementById('chart_InventoryQty'));
        google.visualization.events.addListener(chart40, 'select', selectHandler);
        chart40.draw(InventoryQtyItemsdata, options);



    


}






// Inventoryitems and Amount All
function GetInventory2() {

    var returnval = "";
    
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryItemsAndAmountALL",
        data: "{ }",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {

            
            var Data = result.d.toString();
            if (Data) {
                ret = Data
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}

// Get the InventoryList ALL 
function byInventoryitemsListALL3rdlvel() {
    //Get the BrancDetails By BranchId
    var InventoryItemsdata = new google.visualization.DataTable();
    InventoryItemsdata.addColumn('string', 'InventoryName');
    InventoryItemsdata.addColumn('number', 'Amount');

    var InventoryitemsJSON = JSON.parse(GetInventory2());
    // TEST PORUPOSE 
   
    InventoryitemsJSON.forEach(function (iitem) {
        InventoryItemsdata.addRow([iitem.InventoryName, iitem.Amount]);

    });

    var options = {
        title: 'Total Amount Sold By Products',
        hAxis: {
            title: 'Inventory',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Amount'
        }
    };

    function selectHandler() {
        var selection = chart22.getSelection();
        if (selection.length > 0) {
            var myInventoryItems = InventoryItemsdata.getValue(selection[0].row, 0);
            google.charts.setOnLoadCallback(byInventoryitemsList4thlevel(myInventoryItems));
        }
    }

    var chart22 = new google.visualization.BarChart(
        document.getElementById('chartInventoryListByCategory'));
    google.visualization.events.addListener(chart22, 'select', selectHandler);
    chart22.draw(InventoryItemsdata, options);
}


// Get the InventoryList Qty wise
function GetInventory3(CategoryName) {

    var returnval = "";
    
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebInventoryQtyWiseItemsAndAmountByCategoryName",
        data: "{CategoryName:'" + CategoryName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data) {
                ret = Data
                CallitbackTest(CategoryName);
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}





function GetInventory4(Name) {

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/Fourth_WebBranchAmountData",
        data: "{Name:'" + Name + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data) {
                ret = Data

                // Call the Indiduval data .. For Webgrid by Inventoryname

                //var bid = sessionStorage.getItem("Branchid");
                CallitbackProductData(Name);
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}


function GetInventory4_2(Name) {

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/Fourth_WebBranchAmountData",
        data: "{Name:'" + Name + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data) {
                ret = Data

                // Call the Indiduval data .. For Webgrid by Inventoryname

                var bid = sessionStorage.getItem("Branchid");
                CallitbackBrachProductData(bid, Name);
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}






function GetInventory5(Name)
{

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/Fourth_WebBranchQtyData",
        data: "{Name:'" + Name + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data) {
                ret = Data

                var bid = sessionStorage.getItem("Branchid");
                CallitbackBrachProductData(bid, Name);
                

            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}


function GetInventory5_2(Name) {

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/Fourth_WebBranchQtyData",
        data: "{Name:'" + Name + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data) {
                ret = Data

                
                CallitbackProductData(Name);


            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}

// This is for Load the Branch Pie chart : On GTotal amount on page Load 
function GetInventory7() {

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/AllBranchWiseGrandTotalAmount",
        data: "{}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data) {
                ret = Data
                
            }
            else {
                ret = "";
            }
        }
    });
    return (ret);

}







function byInventoryitemsList4thlevelWithBranch(Name) {

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");

    if (_selectedchart == "chart_divbranch") {

        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');

        var Inventory4JSON = JSON.parse(GetInventory4_2(Name));


        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale by Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart23.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
                //google.charts.setOnLoadCallback(byCategory(myInventory4Items));


            }
        }

        var chart23 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart23, 'select', selectHandler);
        chart23.draw(Inventory4data, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'BranchFullName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        var InventoryQtyitemsJSON = JSON.parse(GetInventory5_2(Name));


        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.BranchFullName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Products',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
               // google.charts.setOnLoadCallback(byCategory(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);



    }
    else if (_selectedchart == "chart_InventoryAmount") {


        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');

        var Inventory4JSON = JSON.parse(GetInventory4(Name));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart23.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
               // google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart23 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart23, 'select', selectHandler);
        chart23.draw(Inventory4data, options);


    }
    else if (_selectedchart == "chart_InventoryQty") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'BranchFullName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');
        var InventoryQtyitemsJSON = JSON.parse(GetInventory5(Name));
        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.BranchFullName, iitem.Qty]);

        });

        var options = {
            title: 'Product Sales Qty By Branch',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
              //  google.charts.setOnLoadCallback(byCategory(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);


    }
    else {
        // This is defalt chart at the page load.

        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');
        var Inventory4JSON = JSON.parse(GetInventory2(Name));

        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart25.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
               // google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart25 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart25, 'select', selectHandler);
        chart25.draw(Inventory4data, options);

    }


}



function byInventoryitemsList4thlevel(Name)
{

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");

    if (_selectedchart == "chart_divbranch") {

        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');

        var Inventory4JSON = JSON.parse(GetInventory4(Name));

        
        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale by Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart23.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
              //  google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart23 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart23, 'select', selectHandler);
        chart23.draw(Inventory4data, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'BranchFullName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        var InventoryQtyitemsJSON = JSON.parse(GetInventory5_2(Name));


        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.BranchFullName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Products',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
                //google.charts.setOnLoadCallback(byCategory(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);



    }
    else if (_selectedchart == "chart_InventoryAmount") {


        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');

        var Inventory4JSON = JSON.parse(GetInventory4(Name));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart23.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
               // google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart23 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart23, 'select', selectHandler);
        chart23.draw(Inventory4data, options);


    }
    else if (_selectedchart == "chart_InventoryQty") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'BranchFullName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');
        var InventoryQtyitemsJSON = JSON.parse(GetInventory5_2(Name));
        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.BranchFullName, iitem.Qty]);

        });

        var options = {
            title: 'Product Sales Qty By Branch',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
              // google.charts.setOnLoadCallback(byCategory(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);


    }
    else
    {
        // This is defalt chart at the page load.

        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');
        var Inventory4JSON = JSON.parse(GetInventory2(Name));
        
        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart25.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
               // google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart25 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart25, 'select', selectHandler);
        chart25.draw(Inventory4data, options);

    }


}


function byInventoryitemsList4thlevel_2(Name) {

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");

    if (_selectedchart == "chart_divbranch") {

        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');

        var Inventory4JSON = JSON.parse(GetInventory4(Name));


        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale by Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart23.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
                //  google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart23 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart23, 'select', selectHandler);
        chart23.draw(Inventory4data, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'BranchFullName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');

        var InventoryQtyitemsJSON = JSON.parse(GetInventory4(Name));


        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.BranchFullName, iitem.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Products',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
                //google.charts.setOnLoadCallback(byCategory(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);



    }
    else if (_selectedchart == "chart_InventoryAmount") {


        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');

        var Inventory4JSON = JSON.parse(GetInventory4_2(Name));

        // var InventoryQtyitemsJSON = JSON.parse(GetInventory3(CategoryName));
        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart23.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
                // google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart23 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart23, 'select', selectHandler);
        chart23.draw(Inventory4data, options);


    }
    else if (_selectedchart == "chart_InventoryQty") {

        //Get the BrancDetails By BranchId
        var InventoryQtyItemsdata = new google.visualization.DataTable();
        InventoryQtyItemsdata.addColumn('string', 'BranchFullName');
        InventoryQtyItemsdata.addColumn('number', 'Qty');
        var InventoryQtyitemsJSON = JSON.parse(GetInventory4(Name));
        InventoryQtyitemsJSON.forEach(function (iitem) {
            InventoryQtyItemsdata.addRow([iitem.BranchFullName, iitem.Qty]);

        });

        var options = {
            title: 'Product Sales Qty By Branch',
            hAxis: {
                title: 'Inventory',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler() {
            var selection = chart22.getSelection();
            if (selection.length > 0) {
                var myInventoryQtyItems = InventoryQtyItemsdata.getValue(selection[0].row, 0);
              //  google.charts.setOnLoadCallback(byCategory(myInventoryQtyItems));
            }
        }

        var chart22 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart22, 'select', selectHandler);
        chart22.draw(InventoryQtyItemsdata, options);


    }
    else {
        // This is defalt chart at the page load.

        //Get the BrancDetails By BranchId
        var Inventory4data = new google.visualization.DataTable();
        Inventory4data.addColumn('string', 'BranchFullName');
        Inventory4data.addColumn('number', 'Amount');
        var Inventory4JSON = JSON.parse(GetInventory2(Name));

        Inventory4JSON.forEach(function (iitem) {
            Inventory4data.addRow([iitem.BranchFullName, iitem.Amount]);

        });

        var options = {
            title: 'Product Sale By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler() {
            var selection = chart25.getSelection();
            if (selection.length > 0) {
                var myInventory4Items = Inventory4data.getValue(selection[0].row, 0);
                // google.charts.setOnLoadCallback(byCategory(myInventory4Items));
            }
        }

        var chart25 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart25, 'select', selectHandler);
        chart25.draw(Inventory4data, options);

    }


}

// This is for Load the Branchwise Amount , Qty ohm2
function byIn(CategoryName) {

    var _selectedchart = sessionStorage.getItem("CurrentChartSelection");

    if (_selectedchart == "chart_divbranch")
    {

        //Get the BrancDetails By BranchId
        var   BranchwiseAmountdata = new google.visualization.DataTable();
        BranchwiseAmountdata.addColumn('string', 'BranchFullName');
        BranchwiseAmountdata.addColumn('number', 'Amount');

        var BranhwiseAmountJSON = JSON.parse(GetBranchwiseAmountonLoad(CategoryName));

        
        BranhwiseAmountJSON.forEach(function (itm) {
            BranchwiseAmountdata.addRow([itm.BranchFullName, itm.Amount]);

        });

        var options = {
            title: 'Product Sale by Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler32() {
            var selection = chart32.getSelection();
            if (selection.length > 0) {
                var myBranhwiseAmountItems = BranchwiseAmountdata.getValue(selection[0].row, 0);
              //  google.charts.setOnLoadCallback(byCategory(myBranhwiseAmountItems));
            }
        }

        var chart32 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart32, 'select', selectHandler32);
        chart32.draw(BranchwiseAmountdata, options);



    }
    else if (_selectedchart == "chart_divQtyWiseCategory")
    {

        //Get the BrancDetails By BranchId
        var BranchwiseQtyItemsdata = new google.visualization.DataTable();
        BranchwiseQtyItemsdata.addColumn('string', 'BranchFullName');
        BranchwiseQtyItemsdata.addColumn('number', 'Qty');

        var BranchwiseQtyitemsJSON = JSON.parse(GetBranchwiseQTYonLoad(CategoryName));


        BranchwiseQtyitemsJSON.forEach(function (itemss) {
            BranchwiseQtyItemsdata.addRow([itemss.BranchFullName, itemss.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler33() {
            var selection = chart33.getSelection();
            if (selection.length > 0) {
                var myBranchwiseQtyItems = BranchwiseQtyItemsdata.getValue(selection[0].row, 0);
               // google.charts.setOnLoadCallback(byCategory(myBranchwiseQtyItems));
            }
        }

        var chart33 = new google.visualization.PieChart(
        document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart33, 'select', selectHandler33);
        chart33.draw(BranchwiseQtyItemsdata, options);



    }

}


// This is shown the chart without select any category : loads the default category
function byInBranchPie(CategoryName)
{

   

        //Get the BrancDetails By BranchId
        var BranchwiseAmountdata = new google.visualization.DataTable();
        BranchwiseAmountdata.addColumn('string', 'BranchFullName');
        BranchwiseAmountdata.addColumn('number', 'Amount');

        var BranhwiseAmountJSON = JSON.parse(GetBranchwiseAmountonLoad(CategoryName));


        BranhwiseAmountJSON.forEach(function (itm) {
            BranchwiseAmountdata.addRow([itm.BranchFullName, itm.Amount]);

        });

        var options = {
            title: 'Product Sale by Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Amount'
            }
        };

        function selectHandler32() {
            var selection = chart32.getSelection();
            if (selection.length > 0) {
                var myBranhwiseAmountItems = BranchwiseAmountdata.getValue(selection[0].row, 0);
                //  google.charts.setOnLoadCallback(byCategory(myBranhwiseAmountItems));
            }
        }

        var chart32 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart32, 'select', selectHandler32);
        chart32.draw(BranchwiseAmountdata, options);



    
    
}



function byInBranchPie(Name)
{

        //Get the BrancDetails By BranchId
        var BranchwiseQtyItemsdata = new google.visualization.DataTable();
        BranchwiseQtyItemsdata.addColumn('string', 'BranchFullName');
        BranchwiseQtyItemsdata.addColumn('number', 'Qty');

         var BranchwiseQtyitemsJSON = JSON.parse(GetBranchPieDataByProductName(Name));


        BranchwiseQtyitemsJSON.forEach(function (itemss) {
            BranchwiseQtyItemsdata.addRow([itemss.BranchFullName, itemss.Qty]);

        });

        var options = {
            title: 'Total Qty Sold By Branch',
            hAxis: {
                title: 'Branch',
                format: '',
                /*viewWindow: {
                  min: [7, 30, 0],
                  max: [19, 30, 0]
                }*/
            },
            vAxis: {
                title: 'Qty'
            }
        };

        function selectHandler33() {
            var selection = chart33.getSelection();
            if (selection.length > 0) {
                var myBranchwiseQtyItems = BranchwiseQtyItemsdata.getValue(selection[0].row, 0);
               //  google.charts.setOnLoadCallback(byCategory(myBranchwiseQtyItems));   // Later Remove it 

            }
        }

        var chart33 = new google.visualization.PieChart(
            document.getElementById('CommonchartFourthLevel'));
        google.visualization.events.addListener(chart33, 'select', selectHandler33);
        chart33.draw(BranchwiseQtyItemsdata, options);



    

}




// This Pie For load the G.Total amount on Page Load 
function byAllBranchPie() {



    //Get the BrancDetails By BranchId
    var BranchwiseAmountdata = new google.visualization.DataTable();
    BranchwiseAmountdata.addColumn('string', 'BranchFullName');
    BranchwiseAmountdata.addColumn('number', 'Amount');

    var BranhwiseAmountJSON = JSON.parse(GetInventory7());


    BranhwiseAmountJSON.forEach(function (itm) {
        BranchwiseAmountdata.addRow([itm.BranchFullName, itm.Amount]);

    });

    var options = {
        title: 'Product Sale by Branch',
        hAxis: {
            title: 'Branch',
            format: '',
            /*viewWindow: {
              min: [7, 30, 0],
              max: [19, 30, 0]
            }*/
        },
        vAxis: {
            title: 'Amount'
        }
    };

    function selectHandler40() {
        var selection = chart40.getSelection();
        if (selection.length > 0) {
            var myBranhwiseAmountItems = BranchwiseAmountdata.getValue(selection[0].row, 0);
            //  google.charts.setOnLoadCallback(byCategory(myBranhwiseAmountItems));
        }
    }

    var chart40 = new google.visualization.PieChart(
        document.getElementById('CommonchartFourthLevel'));
    google.visualization.events.addListener(chart40, 'select', selectHandler40);
    chart40.draw(BranchwiseAmountdata, options);





}




// This is for Grid  -  CategoryName
function CallitbackTest(CategoryName) {

    // This is category Session


  
    $.ajax({
        type: "POST",
        url: "InteractiveDashboard.aspx/WebGrid1",
        data: "{CategoryName:'" + CategoryName + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (data) {

            OnSuccessT(data.d.toString());
        },

        failure: function (r) {

        },
        error: function (response) {

        }
    });
} 

// This is for Grid -  CategoryName with Branchid 
function CallitbackBrachData(CategoryName, BranchID) {

    // This is category Session

    $.ajax({
        type: "POST",
        url: "InteractiveDashboard.aspx/WebGridwithBranchid",
        // data: "{Branchid=" + Branchid +", CategoryName:'" + CategoryName + "'}",
        data: "{CategoryName:'" + CategoryName + "',BranchID:" + BranchID +"}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (data)
        {

            OnSuccessT(data.d.toString());
        },

        failure: function (r) {

        },
        error: function (response) {

        }
    });
}



function CallitbackBrachProductData(BranchID, Name) {

    // This is category Session

    $.ajax({
        type: "POST",
        url: "InteractiveDashboard.aspx/WebGridByBranchAndProducts",
        data: "{BranchID:" + BranchID + ",Name:'" + Name + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (data) {

            OnSuccessT(data.d.toString());
        },

        failure: function (r) {

        },
        error: function (response) {

        }
    });
}


function CallitbackProductData(Name) {

    // This is category Session

    $.ajax({
        type: "POST",
        url: "InteractiveDashboard.aspx/WebGridByProductsAlone",      // this webmethod validate with without Branchid
        data: "{Name:'" + Name + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",

        success: function (data) {

            OnSuccessT(data.d.toString());
        },

        failure: function (r) {

        },
        error: function (response) {

        }
    });
}




function OnSuccessT(r) {

    $("#tablex").empty();
    //$("#tablex").remove()
    var jsonvalue = JSON.parse(r);


    var html = '';

    html += '<tr>';
    html += '<th>Branch</th>' 
    html += '<th>BusinessDate</th>' 
    html += '<th>Barcode</th>'
    html += '<th>Name</th>'
    html += '<th>InventoryDesc</th>'
    html += '<th>CategoryName </th>'
    html += '<th>Amount <br>(S$)</th>'
    html += '<th>Qty</th>'
    html += '</tr>';
    
    $.each(jsonvalue, function (key, item) {
      

        html += '<tr>';
        html += '<td>' + item.Branch + '</td>'
        html += '<td>' + item.BusinessDate + '</td>'
        html += '<td>' + item.Barcode + '</td>'
        html += '<td>' + item.Name + '</td>'
        html += '<td>' + item.InventoryDesc + '</td>'
        html += '<td>' + item.CategoryName + '</td>'
        html += '<td>' + item.Amount.toFixed(2) + '</td>'
        html += '<td>' + item.Qty + '</td>'
        html += '</tr>';

       
    });
     

    $('#tablex').append(html);

  

}


function GetTopCategory_Default() {

    var returnval = "";
    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/WebGetTopCategory",
        data: "{}",
       /* async: false,*/
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {
            var Data = result.d.toString();
            if (Data) {
                ret = Data


                var jsonvalue = JSON.parse(Data);
                
                jsonvalue.forEach(function (item)
                {
                    returnval = item.CategoryName;
                    sessionStorage.setItem("DefaultCategory", returnval);
                  
                    
                    CallitbackTest(returnval);
                    
                  
                });

             

            }
            else {
                returnval = "";
            }
        }
    });
    return (returnval);
}



// This  is for Branchise Amount on Load 
function GetBranchwiseAmountonLoad(CategoryName) {

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/BranchwiseAmount",
        data: "{CategoryName:'" + CategoryName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data)
            {
                ret = Data
               
            }
            else
            {
               ret = "";
            }
        }
    });
    return (ret);

}


function GetBranchwiseQTYonLoad(CategoryName) {

    var returnval = "";

    $.ajax({

        type: "POST",
        url: "InteractiveDashboard.aspx/BranchwiseQty",
        data: "{CategoryName:'" + CategoryName + "'}",
        async: false,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        error: function (XMLHttpRequest, textStatus, errorThrown) {

            alert("Error occured..");

        },
        success: function (result) {


            var Data = result.d.toString();
            if (Data)
            {
                ret = Data
                // any subgrid data 

            }
            else
            {
                ret = "";
            }
        }
    });
    return (ret);

}

