<?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 Collection extends \Core\Controller
{
    
    /*Add new faculty start*/
    public static function addnewfaculty()
    {
        {
        // if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $_SESSION['org_id'] = 3;
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $query = "SELECT * FROM `user_master` WHERE `user_role`!='3' AND `status`='1' AND `user_role`!='5' AND `user_role`!='6'";
            $blood = Homem::getdata($query);
            $table = Form::dbtableprint($blood, ['Name', 'email', 'mobile'], ['name', 'email', 'mobile'], '', '', '');
            
            $a = '';
            echo static::css();
            echo '<body>';
            echo static::normalmenu();
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"> 
                            </div>
                            <div class="col-lg-8">
                                <form action="/Accounts/saveaddnewfaculty" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">New Faculty Registration</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="name" id="name" placeholder="Name" class="form-control" required>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="number" name="mobile" id="mobile" placeholder="Mobile" class="form-control" required>												
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="email" id="email" placeholder="Email" class="form-control" required>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control" required>
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <input type="password" name="password" id="password" placeholder="Create Password" class="form-control" required>
                                                        </div>
                                                    </div>    
                                                    <div class="col-md-4">
                                                        <div class="form-group">
                                                            <input type="hidden" name="role" id="role" placeholder="Role" class="form-control" value="2" required>
                                                        </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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-2">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            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 saveaddnewfaculty()
    {
        if(isset($_POST['name']))
        {
            $_SESSION['org_id'] = 3;
            $query = "INSERT INTO `user_master` (`id`, `ano`, `roll_no`, `section`, `medieum`, `adm_type`, `squota`, `noofyears`, `no`, `name`, `fname`, `fmobile`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `lateral`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`, `v_mobile`, `v_email`, `add_by`, `add_date`, `discontinued`, `tc_given`) VALUES ('', '', '', '', '', '', '', '', '', '$_POST[name]', '', '', '', '', '', '', '$_POST[department]', '', '3', '', '', '', '$_POST[mobile]', '$_POST[email]', '$_POST[password]', '2', '1', '', '', '', '', '', '');";
            Homem::insert($query);
            echo '<script>window.location = "/Accounts/addnewfaculty?status=1";</script>';
        }
        else
        {
            echo '<script>window.location = "/Accounts/addnewfaculty?status=0";</script>';
        }
    }
    /*Add new faculty end*/
    // $data = Homem::getdata("SELECT um.id, um.ano, um.roll_no, um.no, um.name, um.fromyear, um.toyear, um.fk_course_id, um.fk_dept_id, a.* FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '2022-04-01' AND '2022-04-04' ) a JOIN user_master um ON um.id=a.no JOIN degree_dept_master ddm ON ddm.id=um.fk_dept_id WHERE ddm.aided='1' AND um.fk_course_id<'4' AND a.amount!='0'");
    public static function accountsspllitting()
    {
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 2)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['fromdate']))
            {
                $date1 = $_POST['fromdate'];
                $date2 = $_POST['todate'];
                if($_POST['type'] == 1)
                {
                    $data = Homem::getdata("SELECT um.id, um.ano, um.roll_no, um.no, um.name, um.fromyear, um.toyear, um.fk_course_id, um.fk_dept_id, a.* FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '2022-04-01' AND '2022-04-04' ) a JOIN user_master um ON um.id=a.no JOIN degree_dept_master ddm ON ddm.id=um.fk_dept_id WHERE ddm.aided='1' AND um.fk_course_id<'4' AND a.amount!='0'");
                }
                // $data = Homem::getdata("SELECT um.id, um.ano, um.roll_no, um.no, um.name, um.fromyear, um.toyear, um.fk_course_id, um.fk_dept_id, a.* FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '2022-04-01' AND '2022-04-04' ) a JOIN user_master um ON um.id=a.no JOIN degree_dept_master ddm ON ddm.id=um.fk_dept_id WHERE ddm.aided='1' AND um.fk_course_id<'4' AND a.amount!='0'");
                $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 AND a.fk_feemode_id!='5' AND um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' 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]['ano'].'</td>
                                    <td>'.$data[$i]['roll_no'].'</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>Admission Number</th>
                                    <th>Roll Number</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>';
                }
            }
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            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-2"></div>
                            <div class="col-lg-8">                                       
                                <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-4">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <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-4">
                                                        <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 class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="type" id="type" class="form-control">
                                                            <option value="">Report Type</option>
                                                            <option value="1">Aided - Degree</option>
                                                            <option value="2">UnAided - Degree</option>
                                                            <option value="3">Intermediate/option>
                                                            </select>
                                                        </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-2"></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 testing()
    {
        $_SESSION['org_id'] = '1';
        $id='1358';
        $acyear = '1';
        $feetype = '1';
        $fromyear = '2021';
        $course = '1';
        $dept = '1';
        $splidata = Homem::getdata("SELECT fb.* FROM feebreakup fb JOIN user_master um ON fb.fk_course_id=um.fk_course_id WHERE um.id='$id' AND um.fk_dept_id=fb.fk_dept_id AND fb.joinyear=um.fromyear AND fb.acyear='$acyear' AND fb.status='1'");
        if(sizeof($splidata) == 1)
        {
            $split= $splidata[0]['childsplit'];
            $split= json_decode($split, true);
            $csum = static::cummulativesum($split);
            $already = static::feepaiddetails();
            $newpaid = 1500;
            for($i=1; $i<=sizeof($csum); $i++)
            {
                if($csum[$i] >= $already)
                {
                    if($already >0)
                    {
                        $diff = $already-$csum[$i-1];
                    }
                    else
                    {
                        $diff = -1;
                    }
                    if($diff >=0)
                    {
                        $newsplit[$i] = $split[$i]-$diff;
                    }
                    else
                    {
                        $newsplit[$i] = $split[$i];    
                    }
                }
                else
                {
                    $newsplit[$i] = 0;
                }
            }
            echo json_encode($split);
            // echo json_encode($csum);
            echo json_encode($newsplit);
            // print_r($adiff);
            // echo $pos;
            // echo '</br>';
            // echo $diff;
        }
    }
    public static function feepaiddetails()
    {
        $data = Homem::getdata("SELECT SUM(amount) as paid FROM `stdnt_normalfee` WHERE `no`='1358' AND `year`='1' AND `fk_feetype_id`='1'");
        if($data[0]['paid'] != '')
        {
            return $data[0]['paid'];
        }
        else
        {
            return 0;
        }
    }
    public static function cummulativesum($data)
    {
        $a = 0;
        for($i=1; $i<=sizeof($data); $i++)
        {
            $b[$i] = $data[$i] + $a;
            $a = $b[$i];
        }
        return $b;
    }
    
        /** CSS, Script started */
    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;  
    }
    private static function blockscript()
    {
        $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/sweetalert2/dist/sweetalert2.min.js" ></script>
                <!-- Script to stop mouse right click start-->
            <script>
                //Disable right click script
                var message = "";
                ///////////////////////////////////
                function clickIE() {
                    if (document.all) {
                        (message);
                        return false;
                    }
                }

                function clickNS(e) {
                    if (document.layers || (document.getElementById && !document.all)) {
                        if (e.which == 2 || e.which == 3) {
                            (message);
                            return false;
                        }
                    }
                }
                if (document.layers) {
                    document.captureEvents(Event.MOUSEDOWN);
                    document.onmousedown = clickNS;
                } else {
                    document.onmouseup = clickNS;
                    document.oncontextmenu = clickIE;
                }

                document.oncontextmenu = new Function("return false")
            </script>
            <!-- Script to stop mouse right click end-->

            <!-- Script to prevent selection start-->
            <script>
                $(document).ready(function () {
                    $("body").bind("cut copy", function (e) {
                        e.preventDefault();
                    });
                });
            </script>
            <!-- Script to prevent selection end-->
                ';
        return $script;  
    }
    /** CSS, Script Ended */
    private static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
        private static function course($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'B.Com.';
                }
                if($id == 3)
                {
                    return 'B.A.';
                }
                if($id == 4)
                {
                    return 'Inter';
                }
                if($id == 5)
                {
                    return 'M.Sc.';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'M.Sc.';
                }
                if($id == 3)
                {
                    return 'M.Sc. (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Diploma';
                }
                if($id == 2)
                {
                    return 'B.Tech.';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'MCA';
                }
                if($id == 2)
                {
                    return 'M.Com';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function dept($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'MPCS';
                }
                if($id == 2)
                {
                    return 'MSCS';
                }
                if($id == 3)
                {
                    return 'MECS';
                }
                if($id == 4)
                {
                    return 'General';
                }
                if($id == 5)
                {
                    return 'Computers';
                }
                if($id == 6)
                {
                    return 'MPC';
                }
                if($id == 7)
                {
                    return 'BZC';
                }
                if($id == 8)
                {
                    return 'GPC';
                }
                if($id == 9)
                {
                    return 'MiBC';
                }
                if($id == 10)
                {
                    return 'BiMC';
                }
                if($id == 11)
                {
                    return 'HS';
                }
                if($id == 12)
                {
                    return 'BS';
                }
                if($id == 13)
                {
                    return 'HEP';
                }
                if($id == 14)
                {
                    return 'EHP';
                }
                if($id == 15)
                {
                    return 'MES';
                }
                if($id == 16)
                {
                    return 'EPC';
                }
                if($id == 17)
                {
                    return 'MPC';
                }
                if($id == 18)
                {
                    return 'BiPC';
                }
                if($id == 19)
                {
                    return 'MEC';
                }
                if($id == 20)
                {
                    return 'CEC';
                }
                if($id == 21)
                {
                    return 'ABC';
                }
                if($id == 22)
                {
                    return 'HBZ';
                }
                if($id == 23)
                {
                    return 'FTM';
                }
                if($id == 24)
                {
                    return 'PHYSICS';
                }if($id == 25)
                {
                    return 'CHEMISTRY';
                }
                if($id == 26)
                {
                    return 'BOTANY';
                }
                if($id == 27)
                {
                    return 'FOOD PROCESSING';
                }
                if($id == 28)
                {
                    return 'HORTICULTURAL LANDSCAPING';
                }
                if($id == 29)
                {
                    return 'General (Un-aided)';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'Agriculture';
                }
                if($id == 2)
                {
                    return 'Horticulture';
                }
                if($id == 3)
                {
                    return 'Food Technology';
                }
                if($id == 4)
                {
                    return 'Physics';
                }
                if($id == 5)
                {
                    return 'Chemistry';
                }
                if($id == 6)
                {
                    return 'Botany';
                }
                if($id == 7)
                {
                    return 'Food Processing (Vocational)';
                }
                if($id == 8)
                {
                    return 'Horticultural Landscaping (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Civil Engineering';
                }
                else if($id == 2)
                {
                    return 'Electrical & Electronics Engineering';
                }
                else if($id == 3)
                {
                    return 'Mechanical Engineering';
                }
                else if($id == 4)
                {
                    return 'Electronics & Communication Engineering';
                }
                else if($id == 5)
                {
                    return 'Computer Science Engineering';
                }
                else if($id == 6)
                {
                    return 'Wed Design';
                }
                else
                {
                    return '';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'Computers';
                }
                if($id == 2)
                {
                    return 'Commerce';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function feetype($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Add-on Course Fee';
                }
            }
            else if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Processing Fee';
                }
                if($id == 3)
                {
                    return 'TC Fee';
                }
                if($id == 4)
                {
                    return 'Library Fee';
                }
                if($id == 5)
                {
                    return 'ANU Registration Fee';
                }
            }
            else
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Bus Fee';
                }
                if($id == 3)
                {
                    return 'TC Fee';
                }
                if($id == 4)
                {
                    return 'Library Fee';
                }
            }
        }
    }
    
    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 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 2)
        {
            $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 AND a.fk_feemode_id!='5' AND um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' ORDER BY a.paid_date ASC");
                if($_SESSION['user_role'] == 5)
                {
                    $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 WHERE a.entry_id='$_SESSION[user_id]' AND a.fk_feemode_id!='5' 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]['ano'].'</td>
                                    <td>'.$data[$i]['roll_no'].'</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>Admission Number</th>
                                    <th>Roll Number</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>';
                }
            }
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            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-4">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                </div>
                                                <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>';
                }
            }
        }
    }
}