
function chkboxcolorrow(result) {

    if (result.checked){
        result.parentNode.parentNode.style.backgroundColor = "#fdd6cf";
    }
    else{
        result.parentNode.parentNode.style.backgroundColor = "";
    }

}



$('#parent').click(function() {
    if ($(this).is(':checked')) {
        $('#checkboxlist input').attr('checked', true);
    } else {
        $('#checkboxlist input').attr('checked', false);
    }
});


// var chkall = $("#chkall").val();
//
// localStorage["mydatas"] = chkall;
// var datas = JSON.parse(localStorage["mydatas"]);






$("input[name='productBuyPrice']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox1", $(this).val());
    } else {
        localStorage.removeItem("checkbox1");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox1");
    if (data !== null) {
        $("input[name='productBuyPrice']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////

$("input[name='productSellAllPrice']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox2", $(this).val());
    } else {
        localStorage.removeItem("checkbox2");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox2");
    if (data !== null) {
        $("input[name='productSellAllPrice']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////

$("input[name='productSellHalfPrice']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox3", $(this).val());
    } else {
        localStorage.removeItem("checkbox3");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox3");
    if (data !== null) {
        $("input[name='productSellHalfPrice']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////
$("input[name='productSellUnitPrice']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox4", $(this).val());
    } else {
        localStorage.removeItem("checkbox4");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox4");
    if (data !== null) {
        $("input[name='productSellUnitPrice']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////

$("input[name='storename']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox5", $(this).val());
    } else {
        localStorage.removeItem("checkbox5");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox5");
    if (data !== null) {
        $("input[name='storename']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////

$("input[name='amount']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox6", $(this).val());
    } else {
        localStorage.removeItem("checkbox6");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox6");
    if (data !== null) {
        $("input[name='amount']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////

$("input[name='lastProcessDate']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox7", $(this).val());
    } else {
        localStorage.removeItem("checkbox7");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox7");
    if (data !== null) {
        $("input[name='lastProcessDate']").attr("checked", "checked");
    }
});


////////////////////////////////////////////////
$("input[name='selldiscount']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox8", $(this).val());
    } else {
        localStorage.removeItem("checkbox8");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox8");
    if (data !== null) {
        $("input[name='selldiscount']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////
$("input[name='image']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox9", $(this).val());
    } else {
        localStorage.removeItem("checkbox9");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox9");
    if (data !== null) {
        $("input[name='image']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////
$("input[name='hideZeroQuantity']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox10", $(this).val());
    } else {
        localStorage.removeItem("checkbox10");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox10");
    if (data !== null) {
        $("input[name='hideZeroQuantity']").attr("checked", "checked");
    }
});


////////////////////////////////////////////////
$("input[name='description']").click(function() {
    if ($(this).is(":checked")) {
        localStorage.setItem("checkbox11", $(this).val());
    } else {
        localStorage.removeItem("checkbox11");
    }
});

$(function() {
    var data = localStorage.getItem("checkbox11");
    if (data !== null) {
        $("input[name='description']").attr("checked", "checked");
    }
});

////////////////////////////////////////////////



//تصنيفات
$(document).ready(function(){

    $.ajax({
        type: "POST",
        url: 'sellbillAjaxController.php?do=chartsCats',
        async: false,
        success: function (data) {
            // alert(data[0])
            var obj = jQuery.parseJSON(data);
            var dataPoints = [];
            for (var i = 0; i < obj.length; i++) {
                dataPoints.push({
                    label: obj[i].productCatName,
                    y: obj[i].netNo
                });


                renderPieChart(dataPoints);

                function renderPieChart(values) {

                    var chart = new CanvasJS.Chart("pieChart", {

                        title: {
                            text: "اكثر التصنيفات مبيعا - عدد",
                        },
                        animationEnabled: true,
                        data: [{
                            type: "pie",
                            startAngle: 90,
                            dataPoints: values
                        }]
                    });
                    chart.render();
                }
            }


        }
    });

});

//تصنيفات
$(document).ready(function(){

    $.ajax({
        type: "POST",
        url: 'sellbillAjaxController.php?do=chartsCats',
        async: false,
        success: function (data) {
            // alert(data[0])
            var obj = jQuery.parseJSON(data);
            var dataPoints = [];
            for (var i = 0; i < obj.length; i++) {
                dataPoints.push({
                    label: obj[i].productCatName,
                    y: obj[i].netVal
                });


                renderPieChart(dataPoints);

                function renderPieChart(values) {

                    var chart = new CanvasJS.Chart("pieChart1", {

                        title: {
                            text: "اكثر التصنيفات مبيعا - قيمه",
                        },
                        animationEnabled: true,
                        data: [{
                            type: "pie",
                            startAngle: 90,
                            dataPoints: values
                        }]
                    });
                    chart.render();
                }
            }


        }
    });

});


//المنتجات ربحا ومبيعا
$('document').ready(function() {

    $.ajax({
        type: "POST",
        url: 'sellbillAjaxController.php?do=chartsProducts',
        async: false,
        success: function (res) {
            var obje = jQuery.parseJSON(res);
            var dataProductsbe3 = [];
            var dataProductsrab7 = [];
            for (var x = 0; x < obje.length; x++) {
                dataProductsbe3.push({
                    y: Number(obje[x].netVal),
                    label: obje[x].productName,
                });

                dataProductsrab7.push({
                    y: Number(obje[x].netProfit),
                    label: obje[x].productName,
                });
            }

            // console.log(dataProductsbe3,dataProductsrab7);
            renderPieChart(dataProductsbe3,dataProductsrab7);

            function renderPieChart(dataProductsbe3,dataProductsrab7) {

                var chart = new CanvasJS.Chart("chartContainer2", {
                    animationEnabled: true,
                    title:{
                        text: "اكثر المنتجات بيعا وربحا"
                    },
                    axisY: {
                        title: "اكثر المنتجات مبيعا",
                        titleFontColor: "#4F81BC",
                        lineColor: "#4F81BC",
                        labelFontColor: "#4F81BC",
                        tickColor: "#4F81BC"
                    },
                    axisY2: {
                        title: "اكثر المنتحات ربحا",
                        titleFontColor: "#C0504E",
                        lineColor: "#C0504E",
                        labelFontColor: "#C0504E",
                        tickColor: "#C0504E"
                    },
                    toolTip: {
                        shared: true
                    },
                    legend: {
                        cursor:"pointer",
                        itemclick: toggleDataSeries
                    },
                    data: [{
                        type: "column",
                        name: "اكثر المنتحات مبيعا",
                        legendText: "اكثر المنتحات مبيعا",
                        showInLegend: true,
                        dataPoints:dataProductsbe3
                    },
                        {
                            type: "column",
                            name: "اكثر المنتجات ربحا",
                            legendText: "اكثر المنتجات ربحا",
                            axisYType: "secondary",
                            showInLegend: true,
                            dataPoints:dataProductsrab7
                        }]
                });
                chart.render();

            }

        }

    });

    function toggleDataSeries(e) {
        if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
            e.dataSeries.visible = false;
        }
        else {
            e.dataSeries.visible = true;
        }
        chart.render();
    }

});

//العملاء مبيعا
$(document).ready(function(){

    $.ajax({
        type: "POST",
        url: 'sellbillAjaxController.php?do=chartsClients',
        async: false,
        success: function (data) {
            // alert(data[0])
            var obj = jQuery.parseJSON(data);
            var dataPoints = [];
            for (var i = 0; i < obj.length; i++) {
                dataPoints.push({
                    label: obj[i].clientName,
                    y: obj[i].netVal
                });

                renderPieChart(dataPoints);

                function renderPieChart(values) {

                    var chart = new CanvasJS.Chart("chartContainer", {
                        animationEnabled: true,
                        theme: "light2", // "light1", "light2", "dark1", "dark2"
                        title:{
                            text: "اكثر العملاء مبيعا"
                        },

                        data: [{
                            type: "column",

                            dataPoints: values,
                        }]
                    });
                    chart.render();
                }
            }


        }
    });

});


//العملاء ربحا
$(document).ready(function(){

    $.ajax({
        type: "POST",
        url: 'sellbillAjaxController.php?do=chartsClients',
        async: false,
        success: function (data) {
            // alert(data[0])
            var obj = jQuery.parseJSON(data);
            var dataPoints = [];
            for (var i = 0; i < obj.length; i++) {
                dataPoints.push({
                    label: obj[i].clientName,
                    y: obj[i].netProfit
                });

                renderPieChart(dataPoints);

                function renderPieChart(values) {

                    var chart = new CanvasJS.Chart("chartContainer3", {
                        animationEnabled: true,
                        theme: "light2", // "light1", "light2", "dark1", "dark2"
                        title:{
                            text: "اكثر العملاء ربحا"
                        },

                        data: [{
                            type: "column",

                            dataPoints: values,
                        }]
                    });
                    chart.render();
                }
            }


        }
    });

});
$(document).ready(function(){

    $.ajax({
        type: "POST",
        url: 'sellbillAjaxController.php?do=chartsExpenses',
        async: false,
        success: function (data) {
            // alert(data[0])
            var obj = jQuery.parseJSON(data);
            var dataPoints = [];
            for (var i = 0; i < obj.length; i++) {
                dataPoints.push({
                    label: obj[i].expensestypename,
                    y: Number(obj[i].sumExpensesValue)
                });

                renderPieChart(dataPoints);

                function renderPieChart(values) {


                    var options = {
                        animationEnabled: true,
                        title: {
                            text: "تصنيفات المصروفات"
                        },
                        data: [{
                            type: "doughnut",
                            innerRadius: "40%",
                            showInLegend: true,
                            legendText: "{label}",
                            indexLabel: "{label}: #percent%",
                            dataPoints: values
                        }]
                    };

                    $("#chartsExpenses").CanvasJSChart(options);



                }
            }


        }
    });

});





