<?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
{
    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="/hindu/assets/css/bootstrap.min.css">
            <link rel="stylesheet" href="/hindu/assets/css/style.css">
            <link rel="stylesheet" href="/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="/hindu/assets/word/jquery.min.js" ></script>
                <script src="/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="/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 year()
    {
        $year = date('Y')+5;
        $a = '';
        for($i=0; $i<=40; $i++)
        {
            $y = $year-$i;
            $a .= '<option value="'.$y.'">'.$y.'</option>';
        }
        return $a;
    }
    private static function alert($id)
    {
        if($id == 1)
        {
            return '<script>swal("success", "The details submitted successfully", "success");</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 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
            {
                return '';
            }
        }
    }
    private static function feetype($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'Tution Fee';
            }
            if($id == 2)
            {
                return 'Bus Fee';
            }
        }
    }
    private static function squota($id)
    {
        if($id != '')
        {
            if($id == 'M')
            {
                return 'Management Quota';
            }
            if($id == 'C')
            {
                return 'Convenor Quota';
            }
            if($id == 'S')
            {
                return 'Spot Admission';
            }
        }
    }
    /* start of fee Setting section */
    public static function allotstdfee()
    {
        if($_SESSION['user_role'] == 5)
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Collection/saveallotstdfee" 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">Bulk Fee Setting Entry</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                <input type="file" name="file" id="file" class="form-control" placeholder="Category Name">
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">   
                                                                <input type="hidden" name="type" id="type" class="form-control" value="bulk" placeholder="Type">                                         
                                                                <a href="/hindu/formats/stdnt_fee_format.csv">Click Here to Download Uploading Format</a>
                                                            </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-4">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#amount").val("'.$data[0]['feeamount'].'");
                        $("#terms").val("'.$data[0]['terms'].'");
                        $("#edit_id").val("'.$data[0]['fid'].'");
                    </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 allotindstdfee()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Collection/saveallotstdfee" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Setting Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Name of the Student" readonly>                                         
                                                    </div>
                                                </div>                             
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control">
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="feetype" id="feetype" class="form-control" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="amount" id="amount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="terms" id="terms" class="form-control" placeholder="No of Terms of Payment">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="type" id="type" class="form-control" value="single" placeholder="type">                                         
                                                    </div>
                                                </div>    
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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-4">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#amount").val("'.$data[0]['feeamount'].'");
                        $("#terms").val("'.$data[0]['terms'].'");
                        $("#edit_id").val("'.$data[0]['fid'].'");
                        setTimeout(function(){ getusername(); }, 500);
                    </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 deptwisefeesettingreport()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $table = '';
            if(isset($_POST['course']))
            {
                $blood = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_feemaster sf ON um.id=sf.no  JOIN fee_types ft ON sf.fk_feetype_id=ft.f_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND um.org_id='$_SESSION[org_id]' AND sf.year='$_POST[years]' AND sf.fk_feetype_id='$_POST[feetypes]'");
                $table = Form::dbtableed($blood, ['Year', 'Fee Type', 'Hallticket Number', 'Name', 'Amount'], ['year', 'f_name', 'no', 'name', 'feeamount'], '/Collection/allotindstdfee', 'fid', '');
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4">
                                <form action="#" method="POST">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">List by Department</h5>
                                        </header>
                                        <div class="content-body">    
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <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-6">
                                                    <div class="form-group">                                            
                                                        <select name="department" id="department" class="form-control">
                                                        <option value="">Department</option>
                                                        ';
                                                        echo $dept;
                                                        echo '
                                                        </select>
                                                    </div>
                                                </div>                            
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="fromyear" id="fromyear" class="form-control">
                                                        <option value="">Starting Year</option>
                                                        ';
                                                        echo $styear;
                                                        echo '
                                                        </select>
                                                    </div>
                                                </div>  
                                                <div class="col-lg-6">
                                                    <div class="form-group">                                            
                                                        <select name="toyear" id="toyear" class="form-control">
                                                        <option value="">Ending Year</option>
                                                        ';
                                                        echo $enyear;
                                                        echo '
                                                        </select>
                                                    </div>
                                                </div>  									
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="years" id="years" class="form-control">
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="feetypes" id="feetypes" class="form-control">
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </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>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </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();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#amount").val("'.$data[0]['feeamount'].'");
                        $("#terms").val("'.$data[0]['terms'].'");
                        $("#edit_id").val("'.$data[0]['fid'].'");
                        getusername();
                    </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 saveallotstdfee()
    {
        if($_SESSION['user_role'] == 5)
        {
            $date = date('Y-m-d');
            if($_POST['type'] == 'bulk')
            {
                $filename=$_FILES['file']['name'];
                $exts[0]='csv';
                $filetype1 = explode('.',$filename);
                if($_FILES['file']['name']!=null && $filetype1[sizeof($filetype1)-1] == $exts[0])
                {
                    $csv_file=$_FILES['file']['tmp_name'];
                    $size=$_FILES['file']['size'];
                    $handle = fopen($csv_file, "r");
                    $data = fgetcsv($handle, 100000, ",");
                    $i = 0;
                    while (($data = fgetcsv($handle, 100000, ","))!== FALSE)
                    {
                        $no = trim($data[0]);
                        $year = trim($data[1]);
                        $feetype = trim($data[2]);
                        $amount = trim($data[3]);
                        $terms = trim($data[4]);
                        $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `ano`='$no' OR `no`='$no'");
                        if(sizeof($udata) == 1)
                        {
                            $sid = $udata[0]['id'];
                            if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
                            {
                                Homem::insert("UPDATE `stdnt_feemaster` SET `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'");
                                $i++;
                            }
                            else
                            {
                                Homem::insert("INSERT INTO `stdnt_feemaster` (`no`, `year`, `fk_feetype_id`, `feeamount`, `fk_org_id`, `reg_date`, `fk_user_id`, `terms`) VALUES ('$sid', '$year', '$feetype', '$amount', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '$terms')");
                                $i++;
                            }
                        }
                    }
                    echo '<script>window.location = "/Collection/allotstdfee?status=1&count='.$i.'";</script>';
                }
            }
            if($_POST['type'] == 'single')
            {
                $no = $_POST['no'];
                $year = $_POST['year'];
                $feetype = $_POST['feetype'];
                $amount = $_POST['amount'];
                $terms = $_POST['terms'];
                $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `ano`='$no' OR `no`='$no'");
                if(sizeof($udata) == 1)
                {
                    $sid = $udata[0]['id'];
                    if($_POST['edit_id'] == '')
                    {   
                        if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
                        {
                            Homem::insert("UPDATE `stdnt_feemaster` SET `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'");
                            echo '<script>window.location = "/Collection/allotindstdfee?status=2";</script>';
                        }
                        else
                        {
                            Homem::insert("INSERT INTO `stdnt_feemaster` (`no`, `year`, `fk_feetype_id`, `feeamount`, `fk_org_id`, `reg_date`, `fk_user_id`, `terms`) VALUES ('$sid', '$year', '$feetype', '$amount', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '$terms')");
                            echo '<script>window.location = "/Collection/allotindstdfee?status=1";</script>';
                        }
                    }
                    else
                    {
                        if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'")) == 1)
                        {
                            Homem::insert("UPDATE `stdnt_feemaster` SET `no`='$sid', `year`='$year', `fk_feetype_id`='$feetype', `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `fid`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'");
                            echo '<script>window.location = "/Collection/allotindstdfee?status=2";</script>';
                        }
                    }
                }
            }
        }
    }
    public static function normalfeeconcession()
    {
        if($_SESSION['user_role'] == 5)
        {
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $table = '';
            {
                $date = date('Y-m-d');
                $blood = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE (`entry_date`='$date' OR `edit_date`='$date') AND (`entry_id`='$_SESSION[user_id]' OR `edit_id`='$_SESSION[user_id]') AND `fk_org_id`='$_SESSION[org_id]' AND `recieptno`='CONCESSION' AND `fk_feemode_id`='0'");
                $table = Form::dbtableed($blood, ['Hallticket Number', 'Concession Amount'], ['no', 'amount'], '/Collection/normalfeeconcession', 'nid', '');
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Collection/savenormalfeecolect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Concession Details Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control">
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="dueamount" id="dueamount" class="form-control" placeholder="Due Amount" readonly>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Concession Date" required="">
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="recieptno" id="recieptno" class="form-control" value="CONCESSION" placeholder="Reciept Number">                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="feemode" id="feemode" class="form-control" value="0" required>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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-4">
                            </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();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Collection/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </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>';
                }
            }
        }
    }
    /* end of fee Setting section */
    /* start of fee collection section */
    public static function normalfeecolect()
    {
        if($_SESSION['user_role'] == 5)
        {
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $table = '';
            {
                $date = date('Y-m-d');
                // $blood = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE (`entry_date`='$date' OR `edit_date`='$date') AND (`entry_id`='$_SESSION[user_id]' OR `edit_id`='$_SESSION[user_id]') AND `fk_org_id`='$_SESSION[org_id]'");
                $blood = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE (sn.entry_date='$date' OR sn.edit_date='$date') AND (sn.entry_id='$_SESSION[user_id]' OR sn.edit_id='$_SESSION[user_id]') AND sn.fk_org_id='$_SESSION[org_id]'");
                $table = Form::dbtableed($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Collection/normalfeecolect', '', '');
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Collection/savenormalfeecolect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control" required>
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="dueamount" id="dueamount" class="form-control" placeholder="Due Amount" readonly>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount" required>                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number" required>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date" required>
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group"> 
                                                        <input type="hidden" name="sid" id="sid" class="form-control" placeholder="user id" required>
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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-4">
                            </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();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                            getuserid();
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Collection/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </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 savenormalfeecolect()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 5)
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
            if(sizeof($data) == 1)
            {
                if($_POST['edit_id'] == '')
                {
                    Homem::insert("INSERT INTO `stdnt_normalfee` (`no`, `year`, `fk_feetype_id`, `amount`, `recieptno`, `fk_feemode_id`, `paid_date`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`) VALUES 
                    ('$_POST[sid]', '$_POST[year]', '$_POST[feetype]', '$_POST[paidamount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                    echo '<script>window.location = "/Collection/normalfeecolect?status=1";</script>';
                }
                else
                {
                    Homem::insert("UPDATE `stdnt_normalfee` SET `no`='$_POST[sid]', `year`='$_POST[year]', `fk_feetype_id`='$_POST[feetype]', `amount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paid_date`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `nid`='$_POST[edit_id]'");
                    echo '<script>window.location = "/Collection/normalfeecolect?status=2";</script>';
                }
            }
            else
            {
                echo '<script>window.location = "/Collection/normalfeecolect?status=0";</script>';
            }
        }
    }
    public static function getdueamount()
    {
        if($_SESSION['user_role'] == 5)
        {
            if(isset($_POST['no']) && isset($_POST['year']) && isset($_POST['feetype']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE (`ano`='$_POST[no]' OR `no`='$_POST[no]') AND `user_role`='3'");
                if(sizeof($data) == 1)
                {
                    $sid = $data[0]['id'];
                    $setdata = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$sid' AND `year`='$_POST[year]' AND `fk_feetype_id`='$_POST[feetype]'");
                    if(sizeof($setdata) == 1)
                    {
                        $feedata = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `no`='$sid' AND `year`='$_POST[year]' AND `fk_feetype_id`='$_POST[feetype]'");
                        if(sizeof($feedata) == 0)
                        {
                            echo $setdata[0]['feeamount'];
                        }
                        if(sizeof($feedata) == 1)
                        {
                            $due = $setdata[0]['feeamount']-$feedata[0]['amount'];
                            echo $due;
                        }
                        if(sizeof($feedata) > 1)
                        {
                            $total = 0;
                            for($i=0; $i<sizeof($feedata); $i++)
                            {
                                $total = $total+$feedata[$i]['amount'];
                            }
                            $due = $setdata[0]['feeamount']-$total;
                            echo $due;
                        }
                    }
                    else
                    {
                        echo 'fail';
                    }
                }
            }
        }
    }
    public static function getuserid()
    {
        if($_SESSION['user_role'] == 5)
        {
            if($_POST['no'] != '' && $_POST['no'] != 0)
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE (`ano`='$_POST[no]' OR `no`='$_POST[no]') AND `user_role`='3'");
                if(sizeof($data) == 1)
                {
                    echo $data[0]['id'];
                }
            }
        }
    }
    public static function examfeecollect()
    {
        if($_SESSION['user_role'] == 5)
        {
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $examtype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `examtype`"), 'id', 'name');
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            $table = '';
            {
                $date = date('Y-m-d');
                $blood = Homem::getdata("SELECT * FROM `stdnt_examfee` WHERE (`entry_date`='$date' OR `edit_date`='$date') AND (`entry_id`='$_SESSION[user_id]' OR `edit_id`='$_SESSION[user_id]') AND `status`='1' AND `fk_org_id`='$_SESSION[org_id]'");
                $table = Form::dbtableed($blood, ['Hallticket Number', 'Paid Amount'], ['no', 'paidamount'], '/Collection/examfeecollect', 'eid', '');
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Collection/saveexamfeecollect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Exam Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control">
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="sem" id="sem" class="form-control" required>
                                                            <option value="">Select Sem</option>
                                                            <option value="1">First Sem</option>
                                                            <option value="2">Second Sem</option>
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="exammonth" id="exammonth" class="form-control">
                                                            <option value="">Select Month of Exam</option>
                                                            '.$month.'
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="examyear" id="examyear" class="form-control" required>
                                                            <option value="">Select Year of Exam</option>
                                                            '.static::year().'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">                            
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date" required="">
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </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-4">
                            </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();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Collection/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_examfee` WHERE `eid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#sem").val("'.$data[0]['sem'].'");
                        $("#exammonth").val("'.$data[0]['exammonth'].'");
                        $("#examyear").val("'.$data[0]['examyear'].'");
                        $("#paidamount").val("'.$data[0]['paidamount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paydate'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </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 saveexamfeecollect()
    {
        if($_SESSION['user_role'] == 5)
        {
            $date = date('Y-m-d');
            if($_SESSION['user_role'] == 5)
            {
                if($_POST['edit_id'] == '')
                {
                    Homem::insert("INSERT INTO `stdnt_examfee` (`no`, `year`, `sem`, `exammonth`, `examyear`, `paidamount`, `recieptno`, `fk_feemode_id`, `paydate`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`, `status`) VALUES 
                    ('$_POST[no]', '$_POST[year]', '$_POST[sem]', '$_POST[exammonth]', '$_POST[examyear]', '$_POST[paidamount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '', '1')");
                    echo '<script>window.location = "/Collection/examfeecollect?status=1";</script>';
                }
                else
                {
                    Homem::insert("UPDATE `stdnt_examfee` SET `no`='$_POST[no]', `year`='$_POST[year]', `sem`='$_POST[sem]', `exammonth`='$_POST[exammonth]', `examyear`='$_POST[examyear]', `paidamount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paydate`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `eid`='$_POST[edit_id]'");
                    echo '<script>window.location = "/Collection/examfeecollect?status=2";</script>';
                }
            }
        }
    }
    public static function nfeecollectbulk()
    {
        if($_SESSION['user_role'] == 5)
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Collection/savebulknfeecollection" 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">Bulk Fee Collection Entry</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                <input type="file" name="file" id="file" class="form-control" placeholder="Category Name">
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">   
                                                                <input type="hidden" name="type" id="type" class="form-control" value="bulk" placeholder="Type">                                         
                                                                <a href="/hindu/formats/stdnt_fee_collection_format.csv">Click Here to Download Uploading Format</a>
                                                            </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-4">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
        }
    }
    public static function savebulknfeecollection()
    {
        if($_SESSION['user_role'] == 5)
        {
            $date = date('Y-m-d');
            if($_POST['type'] == 'bulk')
            {
                $filename=$_FILES['file']['name'];
                $exts[0]='csv';
                $filetype1 = explode('.',$filename);
                if($_FILES['file']['name']!=null && $filetype1[sizeof($filetype1)-1] == $exts[0])
                {
                    $csv_file=$_FILES['file']['tmp_name'];
                    $size=$_FILES['file']['size'];
                    $handle = fopen($csv_file, "r");
                    $data = fgetcsv($handle, 100000, ",");
                    $i = 0;
                    $j = 0;
                    $regdate = date('Y-m-d');
                    while (($data = fgetcsv($handle, 100000, ","))!== FALSE)
                    {
                        $htno =  trim($data[0]);
                        $year =  trim($data[1]);
                        $feetype =  trim($data[2]);
                        $amount =  trim($data[3]);
                        $reciept =  trim($data[4]);
                        $mode = trim($data[5]);
                        $date = trim($data[6]);
                        $remarks = trim($data[7]);
                        $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `ano`='$htno' OR `no`='$htno'");
                        if(sizeof($udata) == 1)
                        {
                            $sid = $udata[0]['id'];
                            $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `amount`='$amount' AND `recieptno`='$reciept' AND `paid_date`='$date'");
                            $key = explode("-", $date);
                            // echo sizeof($key);
                            if(sizeof($data) == 0 && strlen($date)==10 && sizeof($key) == 3)
                            {
                                $i++;
                                
                                    Homem::insert("INSERT INTO `stdnt_normalfee` (`no`, `year`, `fk_feetype_id`, `amount`, `recieptno`, `fk_feemode_id`, `paid_date`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`) VALUES ('$sid', '$year', '$feetype', '$amount', '$reciept', '$mode', '$date', '$remarks', '$_SESSION[org_id]', '$regdate', '$_SESSION[user_id]', '', '')");
                            }
                            else
                            {
                                $j++;
                            }
                        }
                        else
                        {
                            $j++;
                        }
                    }
                    echo '<script>window.location="/Collection/nfeecollectbulk?status=1&count='.$i.'&duplicate='.$j.'";</script>';
                }
            }
        }
    }
    public static function getusername()
    {
        if($_SESSION['user_role'] == 5)
        {
            $data[0]['name']= '';
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[no]'");
            echo $data[0]['name'];
        }
    }
    /* end of fee collection section */
    private static function nyear($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'First Year';
            }
            if($id == 2)
            {
                return 'Second Year';
            }
            if($id == 3)
            {
                return 'Third Year';
            }
            if($id == 4)
            {
                return 'Fourth Year';
            }
            if($id == 5)
            {
                return 'Fifth Year';
            }
        }
    }
    public static function deptwiseconsol()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $subtable = '';
            $a = '';
            if(isset($_POST['course']))
            {
                $masterdata = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_feemaster sf ON um.id=sf.no WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND sf.fk_feetype_id='$_POST[feetype]'");
                $paiddata = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_normalfee sf ON um.id=sf.no WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND sf.fk_feetype_id='$_POST[feetype]'");
                if(sizeof($masterdata) > 0)
                {
                    $ht_no = array();
                    $feeyear = array();
                    foreach ($masterdata as $h) {
                        $ht_no[] = $h['no'];
                        $feeyear[] = $h['year'];
                    }
                    $no = array_values(array_unique($ht_no));
                    sort($no);
                    $fyear = array_values(array_unique($feeyear));
                    sort($fyear);
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        for($j=0; $j<sizeof($fyear); $j++)
                        {
                            for($k=0; $k<sizeof($masterdata); $k++)
                            {
                                if($masterdata[$k]['no'] == $no[$i] && $masterdata[$k]['year'] == $fyear[$j])
                                {
                                    $data[$no[$i]]['name'] = $masterdata[$k]['name'];
                                    $data[$no[$i]][$fyear[$j]]['actualamount'] = $masterdata[$k]['feeamount'];
                                }
                                if($k == sizeof($masterdata)-1)
                                {
                                    if(!isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                    {
                                        $data[$no[$i]][$fyear[$j]]['actualamount'] = 0;
                                    }
                                }
                            }
                            $totalamount = 0;
                            if(sizeof($paiddata) > 0)
                            {
                                for($k=0; $k<sizeof($paiddata); $k++)
                                {
                                    if($paiddata[$k]['no'] == $no[$i] && $paiddata[$k]['year'] == $fyear[$j])
                                    {
                                        $totalamount = $totalamount+$paiddata[$k]['amount'];
                                    }
                                    $count = sizeof($paiddata)-1;
                                    if($k == $count && !isset($data[$no[$i]][$fyear[$j]]['paidamount']))
                                    {
                                        $data[$no[$i]][$fyear[$j]]['paidamount'] = $totalamount;
                                        if(isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                        {
                                            $data[$no[$i]][$fyear[$j]]['dueamount'] = $data[$no[$i]][$fyear[$j]]['actualamount']-$totalamount;
                                        }
                                        else
                                        {
                                            $data[$no[$i]][$fyear[$j]]['paidamount'] = 0;
                                            $data[$no[$i]][$fyear[$j]]['dueamount'] = 0;
                                        }
                                        if($data[$no[$i]][$fyear[$j]]['actualamount'] == 0)
                                        {
                                            $data[$no[$i]][$fyear[$j]]['paidamount'] = 0;
                                            $data[$no[$i]][$fyear[$j]]['dueamount'] = 0;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                $data[$no[$i]][$fyear[$j]]['paidamount'] = 0;
                                $data[$no[$i]][$fyear[$j]]['dueamount'] = 0;
                            }
                        }
                    }
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        $count = 0;
                        $totaldue = 0;
                        $totalpaid = 0;
                        $totalactual = 0;
                        $sno = $i+1;
                        $a.='<tr>';
                        $a.='<td>'.$sno.'</td>';
                        $a.='<td>'.$no[$i].'</td>';
                        $a.='<td>'.$data[$no[$i]]['name'].'</td>';
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            for($j=0; $j<sizeof($fyear); $j++)
                            {
                                if($count < sizeof($fyear))
                                {
                                    if(isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                    {
                                        $a.='<td>'.$data[$no[$i]][$fyear[$j]]['actualamount'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$fyear[$j]]['paidamount'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$fyear[$j]]['dueamount'].'</td>';
                                        $count++;
                                        $totalactual = $totalactual+$data[$no[$i]][$fyear[$j]]['actualamount'];
                                        $totalpaid = $totalpaid+$data[$no[$i]][$fyear[$j]]['paidamount'];
                                        $totaldue = $totaldue+$data[$no[$i]][$fyear[$j]]['dueamount'];
                                    }
                                }
                            }
                        }
                        $a.='<td>'.$totalactual.'</td>';
                        $a.='<td>'.$totalpaid.'</td>';
                        $a.='<td>'.$totaldue.'</td>';
                        $a.='</tr>';
                    }
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $actualfee = 0;
                        $paidfee = 0;
                        $duefee = 0;
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                $actualfee = $actualfee+$data[$no[$i]][$fyear[$j]]['actualamount'];
                                $paidfee = $paidfee+$data[$no[$i]][$fyear[$j]]['paidamount'];
                                $duefee = $duefee+$data[$no[$i]][$fyear[$j]]['dueamount'];
                            }
                        }
                        $afee[$fyear[$j]] = $actualfee/sizeof($no);
                        $pfee[$fyear[$j]] = $paidfee/sizeof($no);
                        $dfee[$fyear[$j]] = $duefee/sizeof($no);
                    }
                    $a .= '<tr>';
                    $a .= '<td colspan="3">Total Fee Collection Details</td>';
                    $t1 = 0;
                    $t2 = 0;
                    $t3 = 0;
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $t1 = $t1+$afee[$fyear[$j]];
                        $t2 = $t2+$pfee[$fyear[$j]];
                        $t3 = $t3+$dfee[$fyear[$j]];
                        $a .= '<td>'.$afee[$fyear[$j]].'</td>';
                        $a .= '<td>'.$pfee[$fyear[$j]].'</td>';
                        $a .= '<td>'.$dfee[$fyear[$j]].'</td>';
                        if($j == sizeof($fyear)-1)
                        {
                            $a .= '<td>'.$t1.'</td>';
                            $a .= '<td>'.$t2.'</td>';
                            $a .= '<td>'.$t3.'</td>';
                        }
                    }
                    $a .= '</tr>';
                    // echo json_encode($dfee);
                    $headyears = '';
                    $headcols = '';
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $headyears .= '<th colspan="3">'.static::nyear($fyear[$j]).'</th>';
                        $headcols .= '<th>Actual Amount</th><th>Paid Amount</th><th>Due Amount</th>';
                    }
                    $head = '<thead>
                                <tr>
                                    <th rowspan="2">S. No</th>
                                    <th rowspan="2">Hall Ticket Number</th>
                                    <th rowspan="2">Name of the student</th>
                                    '.$headyears.'
                                    <th rowspan="2">Total Actual Amount</th>
                                    <th rowspan="2">Total Paid Amount</th>
                                    <th rowspan="2">Total Due Amount</th>
                                </tr>
                                <tr>
                                    '.$headcols.'
                                </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">Department Wise Consolidated 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">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control">
                                                                <option value="">Select Year of Course</option>
                                                                <option value="1">First Year</option>
                                                                <option value="2">Second Year</option>
                                                                <option value="3">Third Year</option>
                                                                <option value="4">Fourth Year</option>
                                                            </select>												
                                                        </div>
                                                    </div>                              
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                                <option value="">Select Fee Type</option>
                                                                '.$feetype.'
                                                            </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-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 datewisecon()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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]'");
                if(sizeof($data) > 0)
                {
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                </tr>';
                    }
                    $head = '<thead>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Year</th>
                                    <th>Hallticket Number</th>
                                    <th>Name of the Student</th>
                                    <th>Amount</th>
                                    <th>Reciept Number</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'] == 5)
        {
            $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'");
                $master = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_feemaster sf ON um.id=sf.no");
                $ht_no = array();
                $feeyear = array();
                $crse = array();
                foreach ($master as $h) {
                    $ht_no[] = $h['no'];
                    $feeyear[] = $h['year'];
                    $crse[] = $h['fk_course_id'];
                }
                $no = array_values(array_unique($ht_no));
                sort($no);
                $fyear = array_values(array_unique($feeyear));
                sort($fyear);
                $course = array_values(array_unique($crse));
                sort($course);
                if(sizeof($data) > 0)
                {
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                </tr>';
                    }
                    $head = '<thead>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Year</th>
                                    <th>Hallticket Number</th>
                                    <th>Amount</th>
                                    <th>Reciept Number</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="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 hnowiseconsreport()
    {
        if($_SESSION['user_role'] == 5)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['htno']))
            {
                $sdata = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[htno]'");
                $uid = '';
                if(sizeof($sdata) > 0)
                {
                    $uid = $sdata[0]['id'];
                }
                $mdata = Homem::getdata("SELECT * FROM stdnt_feemaster sn JOIN user_master um ON um.id=sn.no WHERE sn.no='$uid'");
                $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no JOIN user_master uma on uma.id=sn.entry_id WHERE sn.no='$uid'");
                $photo = Homem::getdata("SELECT * FROM `stdent_photos` WHERE `no`='$_POST[htno]'");
                $image = '';
                if(isset($photo[0]['photo']))
                {
                    $image = '<img src="'.$photo[0]['photo'].'">';
                }
                if(sizeof($mdata) > 0)
                {
                    $feetype = array();
                    $feeyear = array();
                    foreach ($mdata as $h) {
                        $feetype[] = $h['fk_feetype_id'];
                        $feeyear[] = $h['year'];
                    }
                    $ftype = array_values(array_unique($feetype));
                    sort($ftype);
                    $fyear = array_values(array_unique($feeyear));
                    sort($fyear);
                    // calculate year row span
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $cnt = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($data[$k]['year'] == $fyear[$j])
                            {
                                $cnt++;
                            }
                            if($k == sizeof($data)-1)
                            {
                                $f[$fyear[$j]] = $cnt;
                            }
                        }
                    }
                    // calculate year, feetype row span
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        for($i=0; $i<sizeof($ftype); $i++)
                        {
                            $b = 0;
                            $paida = 0;
                            for($l=0; $l<sizeof($data); $l++)
                            {
                                if($data[$l]['year'] == $fyear[$j] && $data[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    $b++;  
                                    $paida = $paida+$data[$l]['amount'];
                                }
                                if($l == sizeof($data)-1)
                                {
                                    $c[$fyear[$j]][$ftype[$i]] = $b;
                                    $paid[$fyear[$j]][$ftype[$i]] = $paida;
                                }
                            }
                            for($l=0; $l<sizeof($mdata); $l++)
                            {
                                if($mdata[$l]['year'] == $fyear[$j] && $mdata[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    $actual[$fyear[$j]][$ftype[$i]] = $mdata[$l]['feeamount'];
                                }
                            }
                            for($l=0; $l<sizeof($mdata); $l++)
                            {
                                if($mdata[$l]['year'] == $fyear[$j] && $mdata[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    if(!isset($paid[$fyear[$j]][$ftype[$i]]))
                                    {
                                        $paid[$fyear[$j]][$ftype[$i]] = 0;
                                    }
                                    $due[$fyear[$j]][$ftype[$i]] = $actual[$fyear[$j]][$ftype[$i]]-$paid[$fyear[$j]][$ftype[$i]];
                                }
                            }
                        }
                    }
                    // echo json_encode($paid);
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $e = 1;
                        $g = 0;
                        $newcount = 0;
                        for($i=0; $i<sizeof($ftype); $i++)
                        {
                            for($l=0; $l<sizeof($mdata); $l++)
                            {
                                if($mdata[$l]['year'] == $fyear[$j] && $mdata[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    $b = 0;
                                    $cd = 0;
                                    for($k=0; $k<sizeof($data); $k++)
                                    {
                                        if($data[$k]['year'] == $fyear[$j] && $data[$k]['fk_feetype_id'] == $ftype[$i])
                                        {
                                            $b++;
                                            $g++;
                                            if($b == 1 && $e ==1 && $g==1)
                                            {
                                                $a .= '<tr>
                                                            <td rowspan="'.$f[$fyear[$j]].'">'.static::nyear($fyear[$j]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.static::feetype($ftype[$i]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$actual[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$paid[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$due[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.$data[$k]['paid_date'].'</td>
                                                        </tr>
                                                    ';
                                                $e = 0;
                                                $cd = 1;
                                                $completed[$fyear[$j]][$ftype[$i]] = 1;
                                            }
                                            if(isset($s[$fyear[$j]][$ftype[$i]]))
                                            {
                                                $a .= '<tr>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.$data[$k]['paid_date'].'</td>
                                                        </tr>
                                                    ';
                                                $newcount = $newcount+1;
                                            }
                                            if(isset($subcompleted[$fyear[$j]][$ftype[$i]]) && $newcount == 1)
                                            {
                                                $a .= '<tr>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.$data[$k]['paid_date'].'</td>
                                                        </tr>
                                                    ';
                                                $s[$fyear[$j]][$ftype[$i]] = 1;
                                            }
                                            if(!isset($completed[$fyear[$j]][$ftype[$i]]) && $e ==0 && !isset($subcompleted[$fyear[$j]][$ftype[$i]]))
                                            {
                                                $a .= '<tr>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.static::feetype($ftype[$i]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$actual[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$paid[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$due[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.$data[$k]['paid_date'].'</td>
                                                        </tr>
                                                    ';
                                                    $subcompleted[$fyear[$j]][$ftype[$i]] = 1;
                                                    $newcount = 1;
                                            }
                                            
                                            if($e == 0 && $b>1 && $newcount == 0)
                                            {
                                                $a .= '<tr>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.$data[$k]['paid_date'].'</td>
                                                        </tr>
                                                    ';
                                            }
                                            if($k == sizeof($data)-1)
                                            {
                                                $g = 0;
                                                // echo 'tets';
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                    }
                    $head = '<thead>
                                <tr>
                                    <th colspan="2">Hall Ticket Number</th><th colspan="3">'.$_POST['htno'].'</th>
                                    <th rowspan="5" colspan="3">'.$image.'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Name of the Student</th><th colspan="3">'.$mdata[0]['name'].'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Coures</th><th colspan="3">'.static::course($mdata[0]['fk_course_id']).'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Department</th><th colspan="3">'.static::dept($mdata[0]['fk_dept_id']).'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Acadamic Year</th><th colspan="3">'.$mdata[0]['fromyear'].' - '.$mdata[0]['toyear'].'</th>
                                </tr>
                                <tr>
                                    <th>Year</th>
                                    <th>Fee Type</th>
                                    <th>Actual Amount</th>
                                    <th>Paid Amount</th>
                                    <th>Due Amount</th>
                                    <th>Bill Number</th>
                                    <th>Amount Paid</th>
                                    <th>paid Date</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">Individual Student Fee 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-12">
                                                        <div class="form-group">                                            
                                                            <input placeholder="Hall Ticket Number" class="form-control" name="htno" id="htno" >
                                                        </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 coursewiseconsol()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $subtable = '';
            $a = '';
            if(isset($_POST['course']))
            {
                $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_POST[course]' AND sf.fk_feetype_id='$_POST[feetype]'");
                // $masterdata = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_feemaster sf ON um.id=sf.no WHERE um.fk_course_id='$_POST[course]' AND sf.fk_feetype_id='$_POST[feetype]'");
                $paiddata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_POST[course]' AND sf.fk_feetype_id='$_POST[feetype]'");
                if(sizeof($masterdata) > 0)
                {
                    $ht_no = array();
                    $feeyear = array();
                    foreach ($masterdata as $h) {
                        $ht_no[] = $h['no'];
                        $feeyear[] = $h['year'];
                    }
                    $no = array_values(array_unique($ht_no));
                    sort($no);
                    $fyear = array_values(array_unique($feeyear));
                    sort($fyear);
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        for($j=0; $j<sizeof($fyear); $j++)
                        {
                            for($k=0; $k<sizeof($masterdata); $k++)
                            {
                                if($masterdata[$k]['no'] == $no[$i] && $masterdata[$k]['year'] == $fyear[$j])
                                {
                                    $data[$no[$i]]['name'] = $masterdata[$k]['name'];
                                    $data[$no[$i]][$fyear[$j]]['actualamount'] = $masterdata[$k]['feeamount'];
                                }
                                if($k == sizeof($masterdata)-1)
                                {
                                    if(!isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                    {
                                        $data[$no[$i]][$fyear[$j]]['actualamount'] = 0;
                                    }
                                }
                            }
                            $totalamount = 0;
                            if(sizeof($paiddata) > 0)
                            {
                                for($k=0; $k<sizeof($paiddata); $k++)
                                {
                                    if($paiddata[$k]['no'] == $no[$i] && $paiddata[$k]['year'] == $fyear[$j])
                                    {
                                        $totalamount = $totalamount+$paiddata[$k]['amount'];
                                    }
                                    $count = sizeof($paiddata)-1;
                                    if($k == $count && !isset($data[$no[$i]][$fyear[$j]]['paidamount']))
                                    {
                                        $data[$no[$i]][$fyear[$j]]['paidamount'] = $totalamount;
                                        if(isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                        {
                                            $data[$no[$i]][$fyear[$j]]['dueamount'] = $data[$no[$i]][$fyear[$j]]['actualamount']-$totalamount;
                                        }
                                        else
                                        {
                                            $data[$no[$i]][$fyear[$j]]['paidamount'] = 0;
                                            $data[$no[$i]][$fyear[$j]]['dueamount'] = 0;
                                        }
                                        if($data[$no[$i]][$fyear[$j]]['actualamount'] == 0)
                                        {
                                            $data[$no[$i]][$fyear[$j]]['paidamount'] = 0;
                                            $data[$no[$i]][$fyear[$j]]['dueamount'] = 0;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                $data[$no[$i]][$fyear[$j]]['paidamount'] = 0;
                                $data[$no[$i]][$fyear[$j]]['dueamount'] = 0;
                            }
                        }
                    }
                    for($i=0; $i<sizeof($no); $i++)
                    {
                        $count = 0;
                        $totaldue = 0;
                        $totalpaid = 0;
                        $totalactual = 0;
                        $sno = $i+1;
                        $a.='<tr>';
                        $a.='<td>'.$sno.'</td>';
                        $a.='<td>'.$no[$i].'</td>';
                        $a.='<td>'.$data[$no[$i]]['name'].'</td>';
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            for($j=0; $j<sizeof($fyear); $j++)
                            {
                                if($count < sizeof($fyear))
                                {
                                    if(isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                    {
                                        $a.='<td>'.$data[$no[$i]][$fyear[$j]]['actualamount'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$fyear[$j]]['paidamount'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$fyear[$j]]['dueamount'].'</td>';
                                        $count++;
                                        $totalactual = $totalactual+$data[$no[$i]][$fyear[$j]]['actualamount'];
                                        $totalpaid = $totalpaid+$data[$no[$i]][$fyear[$j]]['paidamount'];
                                        $totaldue = $totaldue+$data[$no[$i]][$fyear[$j]]['dueamount'];
                                    }
                                }
                            }
                        }
                        $a.='<td>'.$totalactual.'</td>';
                        $a.='<td>'.$totalpaid.'</td>';
                        $a.='<td>'.$totaldue.'</td>';
                        $a.='</tr>';
                    }
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $actualfee = 0;
                        $paidfee = 0;
                        $duefee = 0;
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                $actualfee = $actualfee+$data[$no[$i]][$fyear[$j]]['actualamount'];
                                $paidfee = $paidfee+$data[$no[$i]][$fyear[$j]]['paidamount'];
                                $duefee = $duefee+$data[$no[$i]][$fyear[$j]]['dueamount'];
                            }
                        }
                        $afee[$fyear[$j]] = $actualfee/sizeof($no);
                        $pfee[$fyear[$j]] = $paidfee/sizeof($no);
                        $dfee[$fyear[$j]] = $duefee/sizeof($no);
                    }
                    $a .= '<tr>';
                    $a .= '<td colspan="3">Total Fee Collection Details</td>';
                    $t1 = 0;
                    $t2 = 0;
                    $t3 = 0;
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $t1 = $t1+$afee[$fyear[$j]];
                        $t2 = $t2+$pfee[$fyear[$j]];
                        $t3 = $t3+$dfee[$fyear[$j]];
                        $a .= '<td>'.$afee[$fyear[$j]].'</td>';
                        $a .= '<td>'.$pfee[$fyear[$j]].'</td>';
                        $a .= '<td>'.$dfee[$fyear[$j]].'</td>';
                        if($j == sizeof($fyear)-1)
                        {
                            $a .= '<td>'.$t1.'</td>';
                            $a .= '<td>'.$t2.'</td>';
                            $a .= '<td>'.$t3.'</td>';
                        }
                    }
                    $a .= '</tr>';
                    // echo json_encode($dfee);
                    $headyears = '';
                    $headcols = '';
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $headyears .= '<th colspan="3">'.static::nyear($fyear[$j]).'</th>';
                        $headcols .= '<th>Actual Amount</th><th>Paid Amount</th><th>Due Amount</th>';
                    }
                    $head = '<thead>
                                <tr>
                                    <th rowspan="2">S. No</th>
                                    <th rowspan="2">Admission Number</th>
                                    <th rowspan="2">Name of the student</th>
                                    '.$headyears.'
                                    <th rowspan="2">Total Actual Amount</th>
                                    <th rowspan="2">Total Paid Amount</th>
                                    <th rowspan="2">Total Due Amount</th>
                                </tr>
                                <tr>
                                    '.$headcols.'
                                </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">Course Wise Detailed 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">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">
                                                            <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                                <option value="">Select Fee Type</option>
                                                                '.$feetype.'
                                                            </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-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 admcmpforfuryer()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $subtable = '';
            $a = '';
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
            $ht_no = array();
            $frmyear = array();
            $toyear = array();
            $crse = array();
            $dep = array();
            foreach ($data as $h) {
                $ht_no[] = $h['no'];
                $frmyear[] = $h['fromyear'];
                $toyear[] = $h['toyear'];
                $crse[] = $h['fk_course_id'];
                $dep[] = $h['fk_dept_id'];
            }
            $no = array_values(array_unique($ht_no));
            sort($no);
            $syear = array_values(array_unique($frmyear));
            sort($syear);
            $eyear = array_values(array_unique($toyear));
            sort($eyear);
            $course = array_values(array_unique($crse));
            sort($course);
            $dept = array_values(array_unique($dep));
            sort($dept);
            $i=0;
            for($a=0; $a<sizeof($course); $a++)
            {
                for($b=0; $b<sizeof($dept); $b++)
                {
                    for($c=0; $c<sizeof($syear); $c++)
                    {
                        for($d=0; $d<sizeof($eyear); $d++)
                        {
                            $count = 0;
                            for($e=0; $e<sizeof($data); $e++)
                            {
                                if($data[$e]['fk_course_id'] == $course[$a]
                                && $data[$e]['fk_dept_id'] == $dept[$b]
                                && $data[$e]['fromyear'] == $syear[$c]
                                && $data[$e]['toyear'] == $eyear[$d])
                                {
                                    $count++;
                                }
                            }
                            $stdcount[$course[$a]][$dept[$b]][$syear[$c]][$eyear[$d]] = $count;
                        }
                    }
                }
            }
            echo json_encode($stdcount);
            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">Course Wise Detailed 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">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">
                                                            <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                                <option value="">Select Fee Type</option>
                                                                '.$feetype.'
                                                            </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-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 slist()
    {
        if($_SESSION['user_role'] == 5)
        {
            $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');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $a = '';
            if(isset($_POST['course']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[department]' AND `org_id`='$_SESSION[org_id]' AND `fromyear`='$_POST[fromyear]' AND `toyear`='$_POST[toyear]' AND `user_role`='3' ORDER BY `no` ASC");
                if(sizeof($data) > 0)
                {
                    $table = Form::dbtableed($data, ['Admission Number', 'Hall Ticket Number', 'Name', 'Gender'], ['ano', 'no', 'name', 'gender'], '/Collection/addstudent', 'id', '');
                    $a = '
                            <div class="row">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                '.$table.'
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                        ';
                }
            }
            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">List by Department</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">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </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-4"></div>
                        </div>'.$a.'
                    </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 addstudent()
    {
        if($_SESSION['user_role'] == 5)
        {
            $blood = Inputs::optionsdb(Homem::getdata("SELECT * FROM `blood_group`"), 'id', 'name');
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/Collection/saveaddstudent" 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">
                                                <h4 class="title pull-left">ADD NEW STUDENT</h4>
                                                <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 type="text" name="admission" id="admission" class="form-control" placeholder="Admission Number" required>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                      
                                                            <select type="text" name="quota" id="quota" class="form-control" required>
                                                                <option value="">Select Admission Type</option>    
                                                                <option value="M">Convener Quota</option>
                                                                <option value="M">Management Quota</option>
                                                                <option value="M">Spot Admission</option>
                                                            </select>
                                                        </div>
                                                    </div>                          
                                                </div>  
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                      
                                                            <input type="text" name="hallticket" id="hallticket" class="form-control" placeholder="Hall Ticket Number" required readonly>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="name" id="name" class="form-control" placeholder="Student Name">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  
                                                            <input type="text" name="dob" id="dob" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth">                                          
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="gender" id="gender" class="form-control">
                                                            <option value="">Select Gender</option>
                                                            <option value="M">Male</option>
                                                            <option value="F">Female</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="bloodgroup" id="bloodgroup" class="form-control">
                                                            <option value="">Select Blood Group</option>
                                                            '; 
                                                            echo $blood;
                                                            echo '</select>
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="nyears" id="nyears" class="form-control">
                                                            <option value="">Number of Years of Course</option>
                                                            <option value="1">1</option>
                                                            <option value="2">2</option>
                                                            <option value="3">3</option>
                                                            <option value="4">4</option>
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>  
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <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-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" maxlength="10" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="email" id="email" class="form-control" placeholder="Email Address">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">
                                                        </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>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_GET[editid]' AND `org_id`='$_SESSION[org_id]' AND `user_role`='3'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                        
                        
                            $("#admission").val("'.$data[0]['ano'].'");
                            $("#quota").val("'.$data[0]['squota'].'");
                            $("#nyears").val("'.$data[0]['noofyears'].'");
                            $("#hallticket").val("'.$data[0]['no'].'");
                            $("#name").val("'.$data[0]['name'].'");
                            $("#dob").val("'.$data[0]['dob'].'");
                            $("#gender").val("'.$data[0]['gender'].'");
                            $("#bloodgroup").val("'.$data[0]['blood_group'].'");
                            $("#course").val("'.$data[0]['fk_course_id'].'");
                            $("#department").val("'.$data[0]['fk_dept_id'].'");
                            $("#fromyear").val("'.$data[0]['fromyear'].'");
                            $("#toyear").val("'.$data[0]['toyear'].'");
                            $("#regulation").val("'.$data[0]['regulation'].'");
                            $("#mobile").val("'.$data[0]['mobile'].'");
                            $("#email").val("'.$data[0]['email'].'");
                            $("#edit_id").val("'.$_GET['editid'].'");
                        </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success"); delay(5000); window.location.href="/Collection/home";</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success"); delay(5000); window.location.href="/Collection/home"; </script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error"); delay(5000); window.location="/Collection/home";</script>';
                }
            }
        }
    }
    public static function saveaddstudent()
    {
        if($_SESSION['user_role'] != '')
        {
            if($_POST['edit_id'] == '')
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]'"));
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]'"));
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[hallticket]' AND `org_id`='$_POST[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 0)
                {
                    $query = "INSERT INTO `user_master`(`no`, `name`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`) VALUES ('$_POST[hallticket]', '$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[bloodgroup]', '$_POST[course]', '$_POST[department]', '$_SESSION[org_id]', '$_POST[fromyear]', '$_POST[toyear]', '$_POST[regulation]', '$_POST[mobile]', '$_POST[email]', '$_POST[hallticket]', '3', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Collection/addstudent?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Collection/addstudent?status=0";</script>';
                }
            }
            else
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' OR `id`='$_POST[edit_id]'"));
                    if($mdata1 == 1)
                    {
                        $mdata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' AND `id`='$_POST[edit_id]'"));
                        if(($mdata2 == 0) || ($mdata2 == 1))
                        {
                            $mdata = 0;
                        }
                        else
                        {
                            $mdata = 1;
                        }
                    }
                    else
                    {
                        $mdata = 1;
                    }
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `id`='$_POST[edit_id]'"));
                    if($edata1 == 1)
                    {
                        $edata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' AND `id`='$_POST[edit_id]'"));
                        if(($edata2 == 0) || ($edata2 == 1))
                        {
                            $edata = 0;
                        }
                        else
                        {
                            $edata = 1;
                        }
                    }
                    else
                    {
                        $edata = 1;
                    }
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[edit_id]' AND `org_id`='$_SESSION[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 1)
                {
                    $query = "UPDATE `user_master` SET `ano`='$_POST[admission]', `squota`='$_POST[quota]', `noofyears`='$_POST[nyears]', `no`='$_POST[hallticket]', `name`='$_POST[name]', `dob`='$_POST[dob]', 
                    `gender`='$_POST[gender]', `blood_group`='$_POST[bloodgroup]', `fk_course_id`='$_POST[course]', 
                    `fk_dept_id`='$_POST[department]', `org_id`='$_SESSION[org_id]', `fromyear`='$_POST[fromyear]', 
                    `toyear`='$_POST[toyear]', `regulation`='$_POST[regulation]', `mobile`='$_POST[mobile]', `email`='$_POST[email]', `password`='$_POST[hallticket]', 
                    `user_role`='3', `status`='1' WHERE `id`='$_POST[edit_id]'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Collection/addstudent?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Collection/addstudent?status=0";</script>';
                }
            }
        }
    }
    public static function print()
    {
        if($_SESSION['user_role'] == 5)
        {
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT a.*, fm.name as feemode, u.name as opname FROM (SELECT sn.recieptno, sn.amount, sn.paid_date, sn.year, sn.fk_feetype_id, sn.fk_feemode_id, sn.entry_id, um.no, um.name, um.fk_course_id, um.fk_dept_id FROM stdnt_normalfee sn JOIN user_master um ON sn.no=um.id WHERE sn.nid='469') a JOIN fee_mode fm ON a.fk_feemode_id=fm.id JOIN user_master u ON a.entry_id=u.id");
            }
            if(sizeof($data) == 1)
            {
                echo static::css();
                echo '<body>';
                echo $_SESSION['menu'];
                echo '
                    <form action="" method="POST">
                        <div class="container-fluid">
                            <div class="row print-this">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        <tr style="text-align: center;">
                                                            <td>
                                                                <img src="/hindu/assets/img/logo.png" width="150px" height="150px">
                                                            </td>
                                                            <td>
                                                                <h1>Hindu College of Engineering & Technology</h1>
                                                                <h5>Approved by AICTE, New Delhi and Affiliated to JNTUK, kakinada & APSBTET</h5>
                                                                <h5>Amaravathi Road, Guntur-522002</h5>
                                                                <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td><span style="margin-left: 10px;">Reciept Number: '.$data[0]['recieptno'].'</span></td>
                                                            <td style="text-align: right;"><span style="margin-right: 10px;">Date: '.static::datem($data[0]['paid_date']).'</span></td>
                                                        </tr>
                                                        <tr>
                                                            <td colspan="2">
                                                                <hr />
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>Name : &nbsp; </b>'.$data[0]['name'].'</span>
                                                            </td>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>Department :  &nbsp; </b>'.static::course($data[0]['fk_course_id']).'-'.static::dept($data[0]['fk_dept_id']).'</span>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>HT No. / PIN : &nbsp; </b>'.$data[0]['no'].'</span>
                                                            </td>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>Year :  &nbsp; </b>'.static::nyear($data[0]['year']).'</span>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <table width="90%" align="center" style="border: 2px single black;">
                                                    <tbody>
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                <b>Fee Particulars</b>
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                <b>Amount (Rs.)</b>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                    <tbody>
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                '.static::feetype($data[0]['fk_feetype_id']).'
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                '.number_format($data[0]['amount'], 2).'
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td colspan="2">
                                                                <span style="margin-left: 10px;"><b>Amount in words: </b>'.static::numtotext($data[0]['amount']).'</span>
                                                            </td>
                                                            <td style="text-align: right;">
                                                                <span style="margin-right: 10px;">
                                                                    <b>Mode of payment: </b> '.$data[0]['feemode'].'
                                                                </span>
                                                            </td>
                                                        </tr>
                                                        <tr style="text-align: center;">
                                                            <td colspan="3" style="text-align: right;">
                                                                <span style="margin-right: 10px; margin-top: 20px;">
                                                                    <br><br><br>
                                                                    <b>Office Inchage / Accountant </b> <br>('.$data[0]['opname'].')
                                                                </span>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                            <div class="row">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                    <button onclick="window.print()">Print this page</button>
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                        </div>
                    </form>';
            }
            echo '</body>';
            echo static::script();
        }
    }
    public static function numtotext($number)
    {
        $decimal = round($number - ($no = floor($number)), 2) * 100;
        $hundred = null;
        $digits_length = strlen($no);
        $i = 0;
        $str = array();
        $words = array(0 => '', 1 => 'one', 2 => 'two',
            3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
            7 => 'seven', 8 => 'eight', 9 => 'nine',
            10 => 'ten', 11 => 'eleven', 12 => 'twelve',
            13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
            16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen',
            19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
            40 => 'forty', 50 => 'fifty', 60 => 'sixty',
            70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
        $digits = array('', 'hundred','thousand','lakh', 'crore');
        while( $i < $digits_length ) {
            $divider = ($i == 2) ? 10 : 100;
            $number = floor($no % $divider);
            $no = floor($no / $divider);
            $i += $divider == 10 ? 1 : 2;
            if ($number) {
                $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
                $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
                $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred;
            } else $str[] = null;
        }
        $Rupees = implode('', array_reverse($str));
        $paise = ($decimal > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
        return ($Rupees ? $Rupees . 'Rupees Only' : '') . $paise;
    }
    public static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
    public static function test()
    {
        $start = 2018;
        $end = 2021;
        $no = 3;
        $middle = $start;
        $present = 2019;// date('Y');
        $month = date('m');
        for($i=1; ($i<=$no && $middle != $end); $i++)
        {
            $st = $middle;
            $middle = $middle+1;
            if($month > 6 && $middle==$present)
            {
                $pyear = $i;
            }
            if($month < 6 && $middle==$present)
            {
                $pyear = $i;
            }
            echo $st.'-'.$middle;
        }
        if (date('m') > 6) 
        {
            $year = date('Y')."-".(date('Y') +1);
        }
        else 
        {
            $year = (date('Y')-1)."-".date('Y');
        }
        echo '<a href="mailto:s.krishnarjuna@gmail.com">s.krishnarjuna@gmail.com</a>';
        echo '<a href="tel:9494470239">9494470239</a>';
    }
}