HOME


Mini Shell 1.0
DIR: /home/islapiiu/sites/magnoliya/control-panel/js/
Upload File :
Current File : /home/islapiiu/sites/magnoliya/control-panel/js/report-of-delivered-orders.js
$(document).ready(function () {
    $('.form-line').addClass('focused');
    $.ajax({
        type: 'POST',
        url: 'ajax/reports.php',
        dataType: "json",
        data: {
            option: 'GETSTARTANDENDDATE'
        },
        success: function (result) {
            $("#from").val(result.start_date);
            $("#to").val(result.end_date);
            var status = $("#status").val();
            $.ajax({
                type: 'POST',
                url: 'ajax/reports.php',
                dataType: "json",
                data: {
                    from: result.start_date,
                    to: result.end_date,
                    status: 1,
                    option: 'GETDELIVEREDORDERSBYSTARTANDENDDATE'
                },
                success: function (orders) {
                    var table = $('#delivered-orders').DataTable();
                    $("#delivered-orders tbody").empty();
                    table.clear();

//                    callLoader();
                    var html = '';
                    var sum = 0;
                    if (orders) {
                        $.each(orders, function (key, order) {

                            key++;
                            sum += parseFloat(order.amount);
                            table.row.add([
                                key,
                                order.orderId,
                                order.orderedAt,
                                order.deliveredAt,
                                order.fullName,
                                order.address,
                                order.product,
                                order.qty,
                                order.amount
                            ]).draw();
                        });
                    } else {
                        html = 'No any orders in database';
                        $("#delivered-orders tbody").empty();
                        $("#delivered-orders tbody").append(html);
                    }
                    $("#amount-total").empty();
                    $("#amount-total").html(sum);
                }

            });
        }
    });

    $("#from").change(function () {
        var from = $("#from").val();
        var to = $("#to").val();
        var status = $("#status").val();
//        callLoader();
        $.ajax({
            type: 'POST',
            url: 'ajax/reports.php',
            dataType: "json",
            data: {
                from: from,
                to: to,
                status: 1,
                option: 'GETDELIVEREDORDERSBYSTARTANDENDDATE'
            },
            success: function (orders) {
                var table = $('#delivered-orders').DataTable();
                $("#delivered-orders tbody").empty();
                table.clear();
//                    callLoader();
                var html = '';
                var sum = 0;
                if (orders) {
                    $.each(orders, function (key, order) {

                        key++;
                        sum += parseFloat(order.amount);
                        table.row.add([
                            key,
                            order.orderId,
                            order.orderedAt,
                            order.deliveredAt,
                            order.fullName,
                            order.address,
                            order.product,
                            order.qty,
                            order.amount
                        ]).draw();



                    });
                } else {
                    html = 'No any orders in database';
                    $("#delivered-orders tbody").empty();
                    $("#delivered-orders tbody").append(html);
                }
                $("#amount-total").empty();
                $("#amount-total").html(sum);
            }

        });
    });

    $("#to").change(function () {
        var from = $("#from").val();
        var to = $("#to").val();
        var status = $("#status").val();
//        callLoader();
        $.ajax({
            type: 'POST',
            url: 'ajax/reports.php',
            dataType: "json",
            data: {
                from: from,
                to: to,
                status: 1,
                option: 'GETDELIVEREDORDERSBYSTARTANDENDDATE'
            },
            success: function (orders) {
                var table = $('#delivered-orders').DataTable();
                $("#delivered-orders tbody").empty();
                table.clear();
//                    callLoader();
                var html = '';
                var sum = 0;
                if (orders) {

                    $.each(orders, function (key, order) {

                        key++;
                        sum += parseFloat(order.amount);
                        table.row.add([
                            key,
                            order.orderId,
                            order.orderedAt,
                            order.deliveredAt,
                            order.fullName,
                            order.address,
                            order.product,
                            order.qty,
                            order.amount
                        ]).draw();



                    });
                } else {
                    html = 'No any orders in database';
                    $("#delivered-orders tbody").empty();
                    $("#delivered-orders tbody").append(html);
                }
                $("#amount-total").empty();
                $("#amount-total").html(sum);
            }

        });
    });

//    function callLoader() {
//        $.loadingBlockShow({
//            imgPath: 'plugins/loader/img/default.svg',
//            style: {
//                position: 'fixed',
//                width: '100%',
//                height: '100%',
//                background: 'rgba(0, 0, 0, .6)',
//                left: 0,
//                top: 0,
//                zIndex: 10000
//            }
//        });
//
//        setTimeout($.loadingBlockHide, 5000);
//    }
//    ;

});