<?php
namespace App\Controllers;
SESSION_START();
use \Core\View;
use \Core\Inputs;
use \Core\Userlog;
use \Core\Menu;
use \Core\Form;
use App\Models\Homem;
use App\Email\Emails;
class Admin extends \Core\Controller
{
    private static function css()
    {
        $css = 
        '<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
            <title>Hindu College of Engineering & Technology || Guntur</title>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
            <title>Hindu College of Engineering & Technology || Guntur</title>
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/bootstrap.min.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/style.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/sweetalert2/dist/sweetalert2.min.css" >
            <style>
                @media print
                {
                    body * {
                        visibility: hidden;
                    }
                    .print-this, .print-this * {
                        visibility: visible;
                    }
                }
            </style>
            <script>
                function exportTableToExcel(tableID, filename = "")
                {
                    var downloadLink;
                    var dataType = "application/vnd.ms-excel";
                    var tableSelect = document.getElementById(tableID);
                    var tableHTML = tableSelect.outerHTML.replace(/ /g, "%20");
                    
                    // Specify file name
                    filename = filename?filename+".xls":"excel_data.xls";
                    
                    // Create download link element
                    downloadLink = document.createElement("a");
                    
                    document.body.appendChild(downloadLink);
                    
                    if(navigator.msSaveOrOpenBlob){
                        var blob = new Blob(["\ufeff", tableHTML], {
                            type: dataType
                        });
                        navigator.msSaveOrOpenBlob( blob, filename);
                    }else{
                        // Create a link to the file
                        downloadLink.href = "data:" + dataType + ", " + tableHTML;
                    
                        // Setting the file name
                        downloadLink.download = filename;
                        
                        //triggering the function
                        downloadLink.click();
                    }
                }
            </script>
        </head>';
        return $css;  
    }
    private static function script()
    {
        $script =
                '
                <div class="footer navbar-fixed-bottom text-center">        
                    <span class="text-muted text-center">Copyright &#169 2020. Hindu College of Engineering & Technology, Guntur</span>
                </div>
                <script src="https://assets.hinduengg.com/hindu/assets/word/jquery.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/vendor/sweetalert2/dist/sweetalert2.min.js" ></script>';
        return $script;  
    }
    public static function home()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:20px;">
                            <div class="col-xl-12">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
        }
    }
    private static function course($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'Diploma';
            }
            if($id == 2)
            {
                return 'B.Tech.';
            }
        }
    }
    private static function dept($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'Civil';
            }
            else if($id == 2)
            {
                return 'E.E.E';
            }
            else if($id == 3)
            {
                return 'Mech.';
            }
            else if($id == 4)
            {
                return 'E.C.E.';
            }
            else if($id == 5)
            {
                return 'C.S.E.';
            }
            else
            {
                return '';
            }
        }
    }
    private static function feetype($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'Tution Fee';
            }
            if($id == 2)
            {
                return 'Bus Fee';
            }
        }
    }
    public static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
    public static function dailyreport()
    {
        if($_SESSION['user_role'] == 6)
        {
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON sn.entry_id=um.id");
            if(sizeof($data) > 0)
            {
                $a = '';
                $head = '<thead><tr><th>Date</th><th>Name</th><th>No of Reciepts Entered</th><th>Total Amount</th></tr></thead>';
                $dates = array();
                $id = array();
                foreach ($data as $h) 
                {
                    $dates[] = $h['entry_date'];
                    $id[] = $h['entry_id'];
                }
                $edate = array_values(array_unique($dates));
                sort($edate);
                $uid = array_values(array_unique($id));
                sort($uid);
                for($j=0; $j<sizeof($uid); $j++)
                {
                    for($k=0; $k<sizeof($data); $k++)
                    {
                        if($uid[$j] == $data[$k]['id'])
                        {
                            $name[$uid[$j]] = $data[$k]['name'];
                        }
                    }
                }
                $tamount = 0;
                $tcount = 0;
                for($i=0; $i<sizeof($edate); $i++)
                {
                    for($j=0; $j<sizeof($uid); $j++)
                    {
                        $amount = 0;
                        $count = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($data[$k]['entry_date'] == $edate[$i] && $data[$k]['entry_id'] == $uid[$j])
                            {
                                $count++;
                                $amount = $amount+$data[$k]['amount'];
                                $tcount++;
                                $tamount = $tamount+$data[$k]['amount'];
                            }
                            if($k == sizeof($data)-1)
                            {
                                $details[$edate[$i]][$uid[$j]]['count'] = $count;
                                $details[$edate[$i]][$uid[$j]]['amount'] = $amount;
                            }
                        }
                    }
                }
                for($i=0; $i<sizeof($edate); $i++)
                {
                    for($j=0; $j<sizeof($uid); $j++)
                    {
                        if($j == 0)
                        {
                            $a .= '<tr>';
                            $a .= '<td rowspan="'.sizeof($uid).'">';
                            $a .= $edate[$i];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $name[$uid[$j]];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['count'];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['amount'];
                            $a .= '</td>';
                        }
                        else
                        {
                            $a .= '<tr>';
                            $a .= '<td>';
                            $a .= $name[$uid[$j]];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['count'];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['amount'];
                            $a .= '</td>';
                        }
                        $a .= '</tr>';
                    }
                }
                $a .= '<tr><td>Total Days: '.sizeof($edate).'</td><td>Total Users: '.sizeof($uid).'</td><td>Total Recipts: '.$tcount.'</td><td>Total Amount: '.$tamount.'</td></tr>';
                $body = $a;
                $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-3">
                            </div>
                            <div class="col-lg-6"> 
                                <form action="" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <header class="panel_header">
                                                    <h5 class="title pull-left">Daily Accounts Report (By Entry Date)</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                '.$table.'
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <!--
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    -->
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="col-lg-3">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function datewisecon()
    {
        if($_SESSION['user_role'] == 6)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['date']))
            {
                $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE sn.paid_date='$_POST[date]' order by sn.no ASC");
                if(sizeof($data) > 0)
                {
                    $total = 0;
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.static::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                </tr>';
                        $total = $total+$data[$i]['amount'];
                        if($i == sizeof($data)-1)
                        {
                            $a .= '<tr>
                                    <td colspan="3"><b>Total Amount Collected</b></td>
                                    <td><b>'.$total.'</b></td>
                                    <td colspan="4"></td>
                                </tr>';
                        }
                    }
                    $head = '<thead>
                                <tr>
                                    <th>S. No.</th>
                                    
                                    <th>Hallticket Number</th>
                                    <th>Name of the Student</th>
                                    <th>Amount</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Branch</th>
                                    <th>Fee Type</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Date Wise Fee Collection Report</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="Select Date" class="form-control" name="date" id="date" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function reportbwndates()
    {
        // Month & Year
        // $date = '2021-03-';
        // $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `paid_date` LIKE '%$date%'");
        if($_SESSION['user_role'] == 6)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['fromdate']))
            {
                $date1 = $_POST['fromdate'];
                $date2 = $_POST['todate'];
                // $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2'");
                $data = Homem::getdata("SELECT * FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2') a JOIN user_master um ON um.id=a.no ORDER BY a.paid_date ASC");

                if(sizeof($data) > 0)
                {
                    $tot = 0;
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.static::datem($data[$i]['paid_date']).'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.static::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                </tr>';
                        $tot = $tot+$data[$i]['amount'];
                    }
                    $head = '<thead>
                                <tr><th colspan="3">Date wise Fee Collection Report</th><th colspan="3">From: '.static::datem($_POST['fromdate']).'</th><th colspan="3">To: '.static::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Hallticket Number</th>
                                    <th>Name</th>
                                    <th>Amount</th>
                                    <th>Paid Date</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Department</th>
                                    <th>Fee Type</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$tot.'</b></td></tr>';
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Date Wise Fee Collection Report</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="From Date" class="form-control" name="fromdate" id="fromdate" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">             
                                                        <input placeholder="To Date" class="form-control" name="todate" id="todate" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">                               
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function reportbybook()
    {
        // Month & Year
        // $date = '2021-03-';
        // $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `paid_date` LIKE '%$date%'");
        if($_SESSION['user_role'] == 6)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['bookno']))
            {
                $bookno = '/'.$_POST['bookno'];
                $data = Homem::getdata("SELECT * FROM (SELECT * FROM `stdnt_normalfee` WHERE `recieptno`LIKE '%$bookno%') a JOIN user_master um ON um.id=a.no ORDER BY a.paid_date ASC");

                if(sizeof($data) > 0)
                {
                    $tot = 0;
                    $r = array();
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $rno = explode("/", $data[$i]['recieptno']);
                        $r[] = $rno[0];
                    }
                    sort($r);
                    $m = 0;
                    for($j=0; $j<sizeof($r); $j++)
                    {
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            $finalr = $r[$j].'/'.$_POST['bookno'];
                            if($finalr == $data[$i]['recieptno'])
                            {
                                $m++;
                                $a .= '<tr>
                                            <td>'.$m.'</td>
                                            <td>'.$data[$i]['no'].'</td>
                                            <td>'.$data[$i]['name'].'</td>
                                            <td>'.$data[$i]['amount'].'</td>
                                            <td>'.static::datem($data[$i]['paid_date']).'</td>
                                            <td>'.$data[$i]['recieptno'].'</td>
                                            <td>'.$data[$i]['year'].'</td>
                                            <td>'.static::dept($data[$i]['fk_dept_id']).'</td>
                                            <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                        </tr>';
                                $tot = $tot+$data[$i]['amount'];
                            }
                        }
                    }
                    $head = '<thead>
                                <tr><th colspan="9">Book wise Fee Collection Report: '.$_POST['bookno'].'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Hallticket Number</th>
                                    <th>Name</th>
                                    <th>Amount</th>
                                    <th>Paid Date</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Department</th>
                                    <th>Fee Type</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$tot.'</b></td></tr>';
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Fee Collection by Book Wise</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="Book Number" class="form-control" name="bookno" id="bookno" required>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">             
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function test()
    {
        $mdata = Homem::getdata("SELECT * FROM user_master WHERE `user_role`='3'");
        $cur = array();
        $det = array();
        $fryer = array();
        foreach ($mdata as $h) 
        {
            $cur[] = $h['fk_course_id'];
            $det[] = $h['fk_dept_id'];
            $fryer[] = $h['fromyear'];
        }
        $course = array_values(array_unique($cur));
        sort($course);
        $dept = array_values(array_unique($det));
        sort($dept);
        $fyear = array_values(array_unique($fryer));
        sort($fyear);
        for($i=0; $i<sizeof($mdata); $i++)
        {
            for($j=0; $j<sizeof($course); $j++)
            {
                if($course[$j] == $mdata[$i]['fk_course_id'])
                {
                    echo 's';
                }
            }
        }

        if($_SESSION['user_role'] == 6)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['date']))
            {
                $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE sn.paid_date='$_POST[date]' order by sn.no ASC");
                if(sizeof($data) > 0)
                {
                    $dates = array();
                    $id = array();
                    foreach ($data as $h) 
                    {
                        $dates[] = $h['entry_date'];
                        $id[] = $h['entry_id'];
                    }
                    $edate = array_values(array_unique($dates));
                    sort($edate);
                    $uid = array_values(array_unique($id));
                    sort($uid);
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.static::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                </tr>';
                    }
                    $head = '<thead>
                                <tr>
                                    <th>S. No.</th>
                                    
                                    <th>Hallticket Number</th>
                                    <th>Name of the Student</th>
                                    <th>Amount</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Branch</th>
                                    <th>Fee Type</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Date Wise Fee Collection Report</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="Select Date" class="form-control" name="date" id="date" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
}