
$(document).ready(function() {

    $.ajax({
        url: base_url + "dashboard/get/",
        type: "GET",
        dataType: "json",
        success: function(data){
            $('#activeStudents').val(code);
            $('#name').val(name);
        },
        error:function(){
            //alert('Unable to load data');
        }
    });
});

$(document).ready(function () {
    $('#pendingPaymentTable').DataTable({
        processing: true,
        ajax: {
            url: base_url + 'dashboard/getPendingPayments',
            dataSrc: 'data'
        },
        columns: [
            { data: 'student_name' },
            { data: 'class_name' },
            { data: 'class_dates' },

            {
                data: 'pending_amount',
                render: function(data){
                    return 'LKR. '+parseFloat(data).toLocaleString();
                }
            }
        ],
        order: [[3, 'desc']]
    });

    $.ajax({
        url: base_url + "dashboard/getMonthlyIncome",
        type: 'GET',
        dataType: 'json',
        success: function(response) {
            let labels = [];
            let values = [];
            $.each(response, function(index, item) {
                labels.push(item.month_name);
                values.push(Number(item.total_income));
            });
            new Chartist.Bar('#income-chart', {
                labels: labels,
                series: [
                    values
                ]
            },
                {
                    plugins: [
                        Chartist.plugins.tooltip({
                            transformTooltipTextFnc: function(value) {
                                return 'LKR. '+Number(value).toLocaleString();
                            }
                        })
                    ]
                });
        }
    });
});




