<style>
    table.dataTable tfoot th {
        font-weight: 600 !important;
    }

    .filter-form-section .form-group .bootstrap-select>.dropdown-toggle {
        padding: 9px 9px !important;
        font-size: 12px !important;
        border: 1px solid #c8c8c8 !important;
        background: #fff !important;
    }
</style>
<div class="wraper responsive-width">

    <main class="long-tbl-main" id="main">
        <!-- admin template section -->
        <div class="admin_tempblock">
            <div class="admin_tempsec">
                <div class="admin_sec">

                    <div class="subsec_sec" style="display:block">
                        <div class="subject_lsec dashboard_graph report_sec_graph">

                            <div class="report_sec_cover">
                                <div class="report_sec_left">
                                    <?php
                                    $currency_symbol =  $school_info['currency_symbol'];

                                    $theExportHeader = 'The Fee Revert Reports';
                                    if (isset($school_info) && !empty($school_info)) {
                                        $theExportHeader = $school_info['school_name'] . '\n' . $school_info['address'] . '\n Fee Revert Reports';
                                    }
                                    ?>
                                </div>


                                <div class="subject_lhead">Fee Revert Reports</div>
                                <?php
                                $f_f_types = array();
                                $f_course = array();
                                $f_from_date = '';
                                $f_to_date = '';
                                $select_particular = '';
                                if (count($_POST) > 0) {
                                    //echo '<pre>'; print_r($_POST);exit;
                                    if (isset($_POST['filter_fee_types']) && !empty($_POST['filter_fee_types']))
                                        $f_f_types = $_POST['filter_fee_types'];

                                    if (isset($_POST['filter_course']) && !empty($_POST['filter_course']))
                                        $f_course = $_POST['filter_course'];

                                    $f_from_date = $_POST['filter_from_date'];
                                    $f_to_date = $_POST['filter_to_date'];

                                    $select_particular = $_POST['select_particular'];

                                    if ($select_particular == 'today')
                                        $theExportHeader .= ' For Today';

                                    if ($f_from_date != '')
                                        $theExportHeader .= ' From ' . $f_from_date;
                                    if ($f_to_date != '')
                                        $theExportHeader .= ' To ' . $f_to_date;
                                }
                                ?>
                                <form action="<?= base_url(); ?>admin/fee-revert-reports" method="POST" id='feeRevertReportsSearchForm'>
                                    <div class="row filter-form-section">
                                        <div class="col-md-2">
                                            <div class="subject-filter">
                                                <div class="form-group assign_fee_toall">
                                                    <label>Select Fees Type</label>
                                                    <select name="filter_fee_types[]" id="filter_fee_types" class=" form-control selectpicker" multiple data-live-search="true">
                                                        <option value="" disabled="">Select Fees Type</option>
                                                        <?php
                                                        if (!empty($all_fee_types)) {
                                                            foreach ($all_fee_types as $ftypes) {
                                                        ?>
                                                                <option value="<?php echo $ftypes['id'] ?>" <?php if (in_array($ftypes['id'], $f_f_types)) { ?> selected <?php } ?>> <?php echo $ftypes['feetype_name'] ?> </option>
                                                        <?php
                                                            }
                                                        }
                                                        ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-2">
                                            <div class="subject-filter">
                                                <div class="form-group assign_fee_toall">
                                                    <label>Select Course</label>
                                                    <select name="filter_course[]" id="filter_course" class=" form-control selectpicker" multiple data-live-search="true">
                                                        <option value="" disabled="">Select Course</option>
                                                        <?php
                                                        if (!empty($course_list)) {
                                                            foreach ($course_list as $crs) {
                                                        ?>
                                                                <option value="<?php echo $crs['id'] ?>" <?php if (in_array($crs['id'], $f_course)) { ?> selected <?php } ?>> <?php echo $crs['course_name'] ?> </option>
                                                        <?php
                                                            }
                                                        }
                                                        ?>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-2">
                                            <div class="subject-filter">
                                                <div class="form-group assign_fee_toall">
                                                    <label>Select Particular</label>
                                                    <select name="select_particular" id="select_particular" class="form-control selectpicker" onchange='manage_select_particular()'>
                                                        <option value=''>Select</option>
                                                        <option value='today' <?php if ($select_particular == 'today') { ?> selected <?php } ?>>Today</option>
                                                        <option value='select_date_range' <?php if ($select_particular == 'select_date_range') { ?> selected <?php } ?>>Select Date Range</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-2 the-dates" style='display:none;'>
                                            <div class="date-filter">
                                                <div class="date-fil-row">
                                                    <label>Start Date</label>
                                                    <input type="text" name="filter_from_date" id="filter_from_date" class="form-control nepal-date" value="<?php echo $f_from_date; ?>" placeholder='yyyy-mm-dd'>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-2 the-dates" style='display:none;'>
                                            <div class="date-filter">
                                                <div class="date-fil-row">
                                                    <label>End Date</label>
                                                    <input type="text" name="filter_to_date" id="filter_to_date" class="form-control nepal-date" value="<?php echo $f_to_date; ?>" placeholder='yyyy-mm-dd'>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="col-md-2">
                                            <div class="filter-reset">
                                                <input type="button" name="filtersubmit" id="filter_reset1" class="btn btn-success" value="Filter" onclick="search_fee_revert_reports()">

                                                <a href="<?php echo base_url() ?>admin/fee-revert-reports">
                                                    <button type="button" name="reset_filter" id="reset_filter" value="reset_filter" class="subject_addbtn subject_addbtn_nobg">
                                                        <i class="fas fa-redo"></i>Reset
                                                    </button>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <!-- tab added -->
                                <!-- new divs added -->
                                <div class="tab-content">
                                    <!-- new divs added -->
                                    <div class="applicnts-list-wrap ">
                                        <div class=" ">
                                            <!-- changed ID -->
                                            <table id="tbl1" class="display table-responsive">
                                                <thead>
                                                    <tr>
                                                        <th>S.No</th>
                                                        <th>StudentID</th>
                                                        <th>Student Name</th>
                                                        <th>Course</th>

                                                        <th>Inovice No</th>
                                                        <th>Payment Type</th>

                                                        <th>Amount</th>
                                                        <th>Done By</th>
                                                        <th>Date & Time</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php

                                                    $rowscount = (isset($the_results) && !empty($the_results)) ? count($the_results) : 0;
                                                    if (isset($the_results) && !empty($the_results)) {
                                                        $sno = 1;
                                                        foreach ($the_results as $res) {
                                                            $invoiceNo = $res['invoice_no'];
                                                            if ($school_info['invoice_prefix_status'] == 1)
                                                                $invoiceNo = $school_info['invoice_prefix'] . $invoiceNo;

                                                            $d_by = '-';
                                                            if ($res['done_by'] != '') {
                                                                $dby_arr = explode(' - ', $res['done_by']);
                                                                if (isset($dby_arr[1]) && $dby_arr[1] != '')
                                                                    $d_by = $dby_arr[1];
                                                            }
                                                    ?>
                                                            <tr>
                                                                <td><?= $sno; ?></td>
                                                                <td><?php echo $res['studentId']; ?></td>
                                                                <td><?php echo $res['std_name']; ?></td>
                                                                <td><?php echo $res['course_name']; ?></td>

                                                                <td><?php echo $invoiceNo; ?></td>

                                                                <td>
                                                                    <?php echo $res['fee_name'] . '<br> (' . $res['feetype_name'] . ')'; ?>
                                                                </td>

                                                                <td><?php echo $res['payment_amt']; ?></td>
                                                                <td><?php echo $d_by; ?></td>
                                                                <td><?php echo date('Y-m-d h:iA', strtotime($res['c_date'])); ?></td>
                                                            </tr>
                                                    <?php
                                                            $sno++;
                                                        }
                                                    }  ?>
                                                <tfoot>
                                                    <tr>
                                                        <!--<th style="text-align:left"></th>
                                                        <th style="text-align:left"></th>
                                                        <th style="text-align:left"></th>
                                                        <th style="text-align:left"></th>
                                                        <th style="text-align:right">Total Fee Revert Amount:</th>
                                                        <th style="text-align:left"></th>
                                                        <th style="text-align:left"></th>
                                                        <th style="text-align:left"></th>
                                                        <th style="text-align:left"></th>-->
                                                        <th colspan="6" style="text-align:right">Total Fee Revert Amount:</th>
                                                        <th style="text-align:left"></th>
                                                        <th colspan="2" style="text-align:left"></th>
                                                    </tr>
                                                </tfoot>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>




                    </div>
                </div>

            </div>
            <!-- admin template section end -->
    </main>
    <!--End right-top side-->

</div>


<script defer src="<?php echo base_url(); ?>assets_admin/js/bootstrap-select.min.js"></script>



<script>
    var jsSdate = '<?php echo $f_from_date; ?>';
    var jsTdate = '<?php echo $f_to_date; ?>';

    var jsTheExportHeader = '<?php echo $theExportHeader; ?>';

    $(document).ready(function() {
        $('.user-drpdown').click(function() {
            $('.drpdown-items').toggle();
        });

        manage_select_particular();

        var currency_symbol = "<?php echo $currency_symbol; ?>";

        //table js
        $('#tbl1').DataTable({
            "lengthMenu": [
                [100, -1],
                [100, "All"]
            ],
            "dom": 'lBfrtip',
            "buttons": [{
                    extend: 'pdfHtml5',
                    header: true,
                    footer: true,
                    title: jsTheExportHeader,
                    //messageTop: 'the address will come here',
                    customize: function(doc) {
                        var rowCount = document.getElementById("tbl1").rows.length;
                        for (i = 0; i < rowCount; i++) {
                            for (j = 0; j <= 8; j++) {
                                doc.content[1].table.body[i][j].alignment = 'center';

                                /*if(i>0 && j==6)
                                    doc.content[1].table.body[i][j].color = 'red'; */
                            }
                        }
                    },
                    exportOptions: {
                        columns: [0, 1, 2, 3, 4, 5, 6, 7, 8],
                        modifier: {
                            page: 'current'
                        }

                    },
                    orientation: 'portrait',
                    pageSize: 'A3'
                },
                {
                    extend: 'csvHtml5',
                    exportOptions: {
                        columns: [0, 1, 2, 3, 4, 5, 6, 7, 8]
                    }
                }
            ],
            "footerCallback": function(row, data, start, end, display) {
                var api = this.api(),
                    data;

                // Remove the formatting to get integer data for summation
                var intVal = function(i) {
                    return typeof i === 'string' ?
                        i.replace(/[\$,]/g, '') * 1 :
                        typeof i === 'number' ?
                        i : 0;
                };

                // Total over all pages
                total = api
                    .column(6)
                    .data()
                    .reduce(function(a, b) {
                        return intVal(a) + intVal(b);
                    }, 0);

                // Total over this page
                pageTotal = api
                    .column(6, {
                        page: 'current'
                    })
                    .data()
                    .reduce(function(a, b) {
                        return intVal(a) + intVal(b);
                    }, 0);

                // Update footer
                $(api.column(0).footer()).html(
                    ''
                );
                $(api.column(6).footer()).html(
                    currency_symbol + ' ' + pageTotal + ' ( ' + currency_symbol + ' ' + total + ' total )'
                );
            }
        });
        $('#tbl2').DataTable({
            "lengthMenu": [
                [5, 10, 25, 50, -1],
                [5, 10, 25, 50, "All"]
            ]
        });
        $('#tbl3').DataTable({
            "lengthMenu": [
                [5, 10, 25, 50, -1],
                [5, 10, 25, 50, "All"]
            ]
        });
        //table js end
        //multiple select js start
        $('select').selectpicker();
        //multiple select js end       
    });

    function manage_select_particular() {
        if ($('#select_particular').val() == 'select_date_range') {
            $('#filter_from_date').val(jsSdate);
            $('#filter_to_date').val(jsTdate);
            $('.the-dates').show();
        } else {
            $('#filter_from_date').val('');
            $('#filter_to_date').val('');
            $('.the-dates').hide();
        }
    }

    function search_fee_revert_reports() {
        $('#feeRevertReportsSearchForm').submit();
    }
</script>


</body>

</html>