<?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 Accounts 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'] == 4)
        {
            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="/Accounts/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: "/Accounts/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'] == 4)
        {
            $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="/Accounts/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: "/Accounts/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'] == 4)
        {
            $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'], '/Accounts/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: "/Accounts/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'] == 4)
        {
            $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 = "/Accounts/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 = "/Accounts/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 = "/Accounts/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 = "/Accounts/allotindstdfee?status=2";</script>';
                        }
                    }
                }
            }
        }
    }
    public static function normalfeeconcession()
    {
        if($_SESSION['user_role'] == 4)
        {
            $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'], '/Accounts/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="/Accounts/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: "/Accounts/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: "/Accounts/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'] == 4)
        {
            $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]'");
                $table = Form::dbtableed($blood, ['Reciept Number', 'Paid Amount'], ['recieptno', 'amount'], '/Accounts/normalfeecolect', '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="/Accounts/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">
                                                            <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="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="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: "/Accounts/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: "/Accounts/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: "/Accounts/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'] == 4)
        {
            $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 = "/Accounts/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 = "/Accounts/normalfeecolect?status=2";</script>';
                }
            }
            else
            {
                echo '<script>window.location = "/Accounts/normalfeecolect?status=0";</script>';
            }
        }
    }
    public static function getdueamount()
    {
        if($_SESSION['user_role'] == 4)
        {
            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'] == 4)
        {
            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'] == 4)
        {
            $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'], '/Accounts/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="/Accounts/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: "/Accounts/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'] == 4)
        {
            $date = date('Y-m-d');
            if($_SESSION['user_role'] == 4)
            {
                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 = "/Accounts/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 = "/Accounts/examfeecollect?status=2";</script>';
                }
            }
        }
    }
    public static function nfeecollectbulk()
    {
        if($_SESSION['user_role'] == 4)
        {
            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="/Accounts/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'] == 4)
        {
            $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="/Accounts/nfeecollectbulk?status=1&count='.$i.'&duplicate='.$j.'";</script>';
                }
            }
        }
    }
    public static function getusername()
    {
        if($_SESSION['user_role'] == 4)
        {
            $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'] == 4)
        {
            $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 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 stdnt_normalfee sf JOIN user_master um 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'] == 4)
        {
            $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'] == 4)
        {
            $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'] == 4)
        {
            $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'] == 4)
        {
            $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]'");
                $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 testaa()
    {
        if($_SESSION['user_role'] == 4)
        {
            $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 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>';
    }
    /** Mis Reports   */
    private static function maxarray($my_array)
    {
      $max_val = (int) $my_array[0];
      for ($i = 1; $i < sizeof($my_array); $i++)
      {
        if ($max_val < (int) $my_array[$i])
        {
          $max_val = (int) $my_array[$i];
        } 
      }
      return $max_val;
    }
    private static function minarray($my_array)
    {
      $min_val = (int) $my_array[0];
      for ($i = 1; $i < sizeof($my_array); $i++)
      {
        if ($min_val > (int) $my_array[$i])
        {
          $min_val = (int) $my_array[$i];
        } 
      }
      return $min_val;
    }
    public static function admcmpforfuryer()
    {
        if($_SESSION['user_role'] == 4)
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
            $maxyear = array();
            $cyear = array();
            $crse = array();
            $dep = array();
            foreach ($data as $h) 
            {
                $maxyear[] = $h['noofyears'];
                $cyear[] = $h['fromyear'];
                $crse[] = $h['fk_course_id'];
                $dep[] = $h['fk_dept_id'];
            }
            $myear = array_values(array_unique($maxyear));
            sort($myear);
            $year = static::maxarray($myear);
            $fyear = array_values(array_unique($cyear));
            sort($fyear);
            $course = array_values(array_unique($crse));
            sort($course);
            $dept = array_values(array_unique($dep));
            sort($dept);
            for($a=1; $a<=$year; $a++)
            {
                for($b=0; $b<sizeof($course); $b++)
                {
                for($c=0; $c<sizeof($dept); $c++)
                {
                    for($d=0; $d<sizeof($fyear); $d++)
                    {
                    $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                    $asize = sizeof($adata);
                    $afee = 0;
                    $avg = 0;
                    $mafee = 0;
                    $mifee = 0;
                    if(sizeof($adata) > 0)
                    {
                        for($e=0; $e<sizeof($adata); $e++)
                        {
                        $afee = $afee + $adata[$e]['feeamount'];
                        }
                        $avg = $afee / sizeof($adata);
                        if(is_float($avg))
                        {
                        $avg = number_format((float) $avg, 2, '.', '');
                        }
                        $sfe = array();
                        foreach ($adata as $h) 
                        {
                        $sfe[] = $h['feeamount'];
                        }
                        $sfee = array_values(array_unique($sfe));
                        sort($sfee);
                        $mafee = static::maxarray($sfee);
                        $mifee = static::minarray($sfee);
                    }
                    $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                    $psize = sizeof($pdata);
                    $pfee = 0;
                    if(sizeof($pdata) > 0)
                    {
                        for($e=0; $e<sizeof($pdata); $e++)
                        {
                            $pfee = $pfee + $pdata[$e]['amount'];
                        }
                    }
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                    }
                }
                }
            }
            $a = '';
            if(isset($_POST['years']))
            {
                if(is_numeric($_POST['years']))
                {
                    $year = $_POST['years'];
                }
                else
                {
                    $year = 3;
                }
            }
            else
            {
                $year = 3;
            }
            if(isset($_POST['year']))
            {
                if(is_numeric($_POST['year']))
                {
                    $styear = $_POST['year'];
                }
                else
                {
                    if (date('m') > 6) 
                    {
                        $styear = date('Y');
                    }
                    else
                    {
                        $styear = date('Y')-1;
                    }
                }
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
            if(isset($_POST['syears']))
            {
                if(is_numeric($_POST['syears']))
                {
                    $qq = $_POST['syears'];
                }
                else
                {
                    $qq = 1;
                }
            }
            else
            {
                $qq = 1;
            }
            // $styear = 2020;
            $syears = array();
            for($i=$year; $i>0; $i--)
            {
                $syears[] = $styear-$i;
            }
            $head= '';
            $sqq = $year+2;
            $head .= '<thead>';
            $head .= '<tr><th colspan="'.$sqq.'">Admission Comparison for Last '.$year.' Years, As on Date: '.date('d-m-Y').'(Students Corrsespond to Year: '.$qq.')</th></tr>';
            $head .= '<tr>';
            $head .= '<th>Course</th>';
            $head .= '<th>Department</th>';
            for($e=0; $e<sizeof($syears); $e++)
            {
                $incyear = $syears[$e]+1;
                $head .= '<th>'.$syears[$e].'-'.$incyear.'</th>';
            }
            $head .= '</tr></thead>';
            // $tcount = 0;
            for($e=0; $e<sizeof($syears); $e++)
            {
                $t[$syears[$e]] = 0;
            }

            for($b=0; $b<sizeof($course); $b++)
            {
                $a .= '<tr><td rowspan="'.sizeof($dept).'">'.static::course($course[$b]).'</td>'; 
                for($c=0; $c<sizeof($dept); $c++)
                {
                    if($c == 0)
                    {
                    $a .= '<td>'.static::dept($dept[$c]).'</td>'; 
                    }
                    else
                    {
                    $a .= '<tr><td>'.static::dept($dept[$c]).'</td>'; 
                    }
                    for($e=0; $e<sizeof($syears); $e++)
                    {
                        if(isset($ade[$qq][$course[$b]][$dept[$c]][$syears[$e]]['joinyear']))
                        {
                            $a .= '<td>'.$ade[$qq][$course[$b]][$dept[$c]][$syears[$e]]['count'].'</td>'; 
                            $t[$syears[$e]] = $t[$syears[$e]]+$ade[$qq][$course[$b]][$dept[$c]][$syears[$e]]['count'];
                        }
                        else
                        {
                            $a .= '<td>0</td>';
                        }
                    }
                    $a .= '</tr>';
                }
            }
            $a .= '<tr>';
            $a .= '<td colspan="2">Grand Total</td>';
            for($e=0; $e<sizeof($syears); $e++)
            {
                $a .= '<td>'.$t[$syears[$e]].'</td>';
            }
            $a .= '</tr>';
            $body = $a;
            $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-3"></div>
                            <div class="col-lg-6">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Admission Comparison</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">  
                                                            <select id="year" name="year" class="form-control" required>
                                                                <option value="">Select Year</option>
                                                                '.static::year().'
                                                            </select>                                          
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">    
                                                            <select id="years" name="years" class="form-control" required>
                                                                <option value="">Select No of Years</option>
                                                                <option value="1">1</option>
                                                                <option value="2">2</option>
                                                                <option value="3">3</option>
                                                                <option value="4">4</option>
                                                                <option value="5">5</option>
                                                            </select>                                     
                                                        </div>
                                                    </div>                           
                                                    <div class="col-lg-4">
                                                        <div class="form-group">    
                                                            <select id="syears" name="syears" class="form-control" required>
                                                                <option value="">Select Year of Students</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-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-3"></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 ovabstractbyayyear()
    {
        if($_SESSION['user_role'] == 4)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
        $enyear = $styear+1;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
            // echo json_encode($ade);
        $a .= '<thead>';
        $sizex  = ($year*3)+3;
        $a .= '<tr>';
        $a .= '<th colspan="'.$sizex.'">Overall Abstract for FEE In Academic Year '.$styear.'-'.$enyear.' as on  Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="2">Course</th>';
        $a .= '<th rowspan="2">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $incyear = $styear-$syears[$e]+1;
            $a .= '<th colspan="3">'.$incyear.' - Year</th>';
        }
        $a .= '<th rowspan="2">Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $a .= "<th>Total Strength</th>";
            $a .= "<th>Avg. Fee Per Year</th>";
            $a .= "<th>Total Fee</th>";
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $tt[$syears[$e]] = 0;
            $ttt[$syears[$e]] = 0;
        }
        // for($a=0; $a<sizeof($syears); $a++)
        {
            $tttt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.static::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.static::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.static::dept($dept[$c]).'</td>'; 
                }
                $t = 0;
                for($e=0; $e<=3; $e++)
                {
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                    {
                        $a .= '<td>'.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['count'].'</td>'; 
                        $a .= '<td>'.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['avgfee'].'</td>'; 
                        $a .= '<td>'.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'].'</td>'; 
                        $t = $t+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'];
                        $tttt = $tttt+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'];
                        $tt[$syears[$e]] = $tt[$syears[$e]]+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['count'];
                        $ttt[$syears[$e]] = $ttt[$syears[$e]]+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'];
                    }
                    else
                    {
                        $a .= '<td>0</td>';
                        $a .= '<td>0</td>';
                        $a .= '<td>0</td>';
                    }
                    if($e == 3)
                    {
                        $a .= '<td>'.$t.'</td>'; 
                    }
                }
                $a .= '</tr>';
            }
            }
        }
        $a .= '<tr>';
        $a .= '<td colspan="2">Grand Total</td>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $a .= '<td>'.$tt[$syears[$e]].'</td>';
            $a .= '<td></td>';
            $a .= '<td>'.$ttt[$syears[$e]].'</td>';
            if($e == sizeof($syears)-1)
            {
                $a .= '<td>'.$tttt.'</td>';
            }
        }
        $a .= '</tr>';
        $a .= '</tbody>';
        $body = $a;
        $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">Overall Abstract for Academic Year</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">  
                                                        <select id="year" name="year" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.static::year().'
                                                        </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 ovabstractforallcurses()
    {
        if($_SESSION['user_role'] == 4)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
        $enyear = $styear+1;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
            // echo json_encode($ade);
        $a .= '<thead>';
        $sizex  = ($year*1)+3;
        $a .= '<tr>';
        $a .= '<th colspan="'.$sizex.'">Overall Abstract for All Courses In Academic Year '.$styear.'-'.$enyear.' as on  Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="2">Course</th>';
        $a .= '<th rowspan="2">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $incyear = $styear-$syears[$e]+1;
            $a .= '<th colspan="1">'.$incyear.' - Year</th>';
        }
        $a .= '<th rowspan="2">Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            // $a .= "<th>Total Strength</th>";
            // $a .= "<th>Avg. Fee Per Year</th>";
            $a .= "<th>Total Fee</th>";
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $tt[$syears[$e]] = 0;
            $ttt[$syears[$e]] = 0;
        }
        // for($a=0; $a<sizeof($syears); $a++)
        {
            $tttt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.static::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.static::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.static::dept($dept[$c]).'</td>'; 
                }
                $t = 0;
                for($e=0; $e<=3; $e++)
                {
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                    {
                        // $a .= '<td>'.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['count'].'</td>'; 
                        // $a .= '<td>'.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['avgfee'].'</td>'; 
                        $a .= '<td>'.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'].'</td>'; 
                        $t = $t+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'];
                        $tttt = $tttt+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'];
                        $tt[$syears[$e]] = $tt[$syears[$e]]+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['count'];
                        $ttt[$syears[$e]] = $ttt[$syears[$e]]+$ade[$f][$course[$b]][$dept[$c]][$ssyear]['afee'];
                    }
                    else
                    {
                        $a .= '<td>0</td>';
                    }
                    if($e == 3)
                    {
                        $a .= '<td>'.$t.'</td>'; 
                    }
                }
                $a .= '</tr>';
            }
            }
        }
        $a .= '<tr>';
        $a .= '<td colspan="2">Grand Total</td>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            // $a .= '<td>'.$tt[$syears[$e]].'</td>';
            // $a .= '<td></td>';
            $a .= '<td>'.$ttt[$syears[$e]].'</td>';
            if($e == sizeof($syears)-1)
            {
                $a .= '<td>'.$tttt.'</td>';
            }
        }
        $a .= '</tr>';
        $a .= '</tbody>';
        $body = $a;
        $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">Overall Abstract for Academic Year</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">  
                                                        <select id="year" name="year" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.static::year().'
                                                        </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 ovabstractdueinacy()
    {
        if($_SESSION['user_role'] == 4)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
            //   $fnyear = $styear-$yaer;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
        $tsize = 0;
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $tsize = $tsize+3;
            }
        }
        $tsize = $tsize+2+($year-1)+1;
        $enyear = $styear+1;
        $a .= '<thead>';
        $a .= '<tr>';
        $a .= '<th colspan="'.$tsize.'">Overall Abstract for Dues in Academic Year '.$styear.'-'.$enyear.' as on Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="3">Course</th>';
        $a .= '<th rowspan="3">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            $size= $f*3;
            $incyear = $styear-$syears[$e]+1;
            if($e==0)
            {
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
            if($e>0)
            {
                $size = $size+1;
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
        }
        $a .= '<th rowspan="3">Grand Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                if($e==0)
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                else
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                if($e>0 && $ff==$f)
                {
                    $a .= '<th rowspan="2">Total Amount</th>';
                }
            }
        }
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= "<th>Actual Amount</th>";
                $a .= "<th>Paid Amount</th>";
                $a .= "<th>Due Amount</th>";
            }
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        // for($a=0; $a<sizeof($syears); $a++)
        {
            for($e=0; $e<=3; $e++)
            {
                $f = $e+1;
                for($ff=1; $ff<=$f; $ff++)
                {
                    $lrt[$e][$ff]['actual'] = 0;
                    $lrt[$e][$ff]['paid'] = 0;
                    $lrt[$e][$ff]['due'] = 0;
                }
                $lrt[$e]['tdue'] = 0;
            }
            $lrtgt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.static::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.static::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.static::dept($dept[$c]).'</td>'; 
                }
                $tt = 0;

                for($e=0; $e<=3; $e++)
                {
                    $t = 0;
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    for($ff=1; $ff<=$f; $ff++)
                    {
                        if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                        {
                            $a .= '<td>'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'].'</td>'; 
                            $a .= '<td>'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'].'</td>'; 
                            $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'] = $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee']-$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $a .= '<td>'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'].'</td>'; 
                            $t = $t+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $tt = $tt+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $lrt[$e][$ff]['actual'] = $lrt[$e][$ff]['actual']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'];
                            $lrt[$e][$ff]['paid'] = $lrt[$e][$ff]['paid']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $lrt[$e][$ff]['due'] = $lrt[$e][$ff]['due']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                        }
                        else
                        {
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                        }
                        if($e>0 && $ff == $f)
                        {
                            $a .= '<td>'.$t.'</td>';
                            $lrt[$e]['tdue'] = $lrt[$e]['tdue']+$t;
                        }
                    }
                    if($e == 3)
                    {
                        $a .= '<td>'.$tt.'</td>';
                        $lrtgt = $lrtgt+$tt;
                    }
                    
                }
                $a .= '</tr>';
            }
            }
        }
        $a .= '<tr>';
        $a .= '<td colspan="2">Grand Total</td>';
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= '<td>'.$lrt[$e][$ff]['actual'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['paid'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['due'].'</td>';
                if($e>0 && $ff==$f)
                {
                    $a .= '<td>'.$lrt[$e]['tdue'].'</td>';
                }
            }
        }
        $a .= '<td>'.$lrtgt.'</td>';
        $a .= '</tr>';
        $a .= '</tbody>';
        $body = $a;
        $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 $lrtgt;
        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">Overall Abstract for Dues in Academic Year</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">  
                                                        <select id="year" name="year" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.static::year().'
                                                        </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 ovabstractdueinacylinks()
    {
        if($_SESSION['user_role'] == 4)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
            //   $fnyear = $styear-$yaer;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
        $tsize = 0;
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $tsize = $tsize+3;
            }
        }
        $tsize = $tsize+2+($year-1)+1;
        $enyear = $styear+1;
        $a .= '<thead>';
        $a .= '<tr>';
        $a .= '<th colspan="'.$tsize.'">Overall Abstract for Dues in Academic Year '.$styear.'-'.$enyear.' as on Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="3">Course</th>';
        $a .= '<th rowspan="3">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            $size= $f*3;
            $incyear = $styear-$syears[$e]+1;
            if($e==0)
            {
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
            if($e>0)
            {
                $size = $size+1;
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
        }
        $a .= '<th rowspan="3">Grand Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                if($e==0)
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                else
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                if($e>0 && $ff==$f)
                {
                    $a .= '<th rowspan="2">Total Amount</th>';
                }
            }
        }
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= "<th>Actual Amount</th>";
                $a .= "<th>Paid Amount</th>";
                $a .= "<th>Due Amount</th>";
            }
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        // for($a=0; $a<sizeof($syears); $a++)
        {
            for($e=0; $e<=3; $e++)
            {
                $f = $e+1;
                for($ff=1; $ff<=$f; $ff++)
                {
                    $lrt[$e][$ff]['actual'] = 0;
                    $lrt[$e][$ff]['paid'] = 0;
                    $lrt[$e][$ff]['due'] = 0;
                }
                $lrt[$e]['tdue'] = 0;
            }
            $lrtgt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.static::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.static::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.static::dept($dept[$c]).'</td>'; 
                }
                $tt = 0;

                for($e=0; $e<=3; $e++)
                {
                    $t = 0;
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    for($ff=1; $ff<=$f; $ff++)
                    {
                        if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                        {
                            $a .= '<td><a href="/Accounts/actualfee?year='.$ff.'&course='.$course[$b].'&dept='.$dept[$c].'&joinyear='.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear'].'">'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'].'</a></td>'; 
                            $a .= '<td><a href="/Accounts/paidfee?year='.$ff.'&course='.$course[$b].'&dept='.$dept[$c].'&joinyear='.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear'].'">'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'].'</a></td>'; 
                            $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'] = $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee']-$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $a .= '<td><a href="/Accounts/duefee?year='.$ff.'&course='.$course[$b].'&dept='.$dept[$c].'&joinyear='.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear'].'">'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'].'</a></td>'; 
                            $t = $t+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $tt = $tt+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $lrt[$e][$ff]['actual'] = $lrt[$e][$ff]['actual']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'];
                            $lrt[$e][$ff]['paid'] = $lrt[$e][$ff]['paid']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $lrt[$e][$ff]['due'] = $lrt[$e][$ff]['due']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                        }
                        else
                        {
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                        }
                        if($e>0 && $ff == $f)
                        {
                            $a .= '<td>'.$t.'</td>';
                            $lrt[$e]['tdue'] = $lrt[$e]['tdue']+$t;
                        }
                    }
                    if($e == 3)
                    {
                        $a .= '<td>'.$tt.'</td>';
                        $lrtgt = $lrtgt+$tt;
                    }
                    
                }
                $a .= '</tr>';
            }
            }
        }
        $a .= '<tr>';
        $a .= '<td colspan="2">Grand Total</td>';
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= '<td>'.$lrt[$e][$ff]['actual'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['paid'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['due'].'</td>';
                if($e>0 && $ff==$f)
                {
                    $a .= '<td>'.$lrt[$e]['tdue'].'</td>';
                }
            }
        }
        $a .= '<td>'.$lrtgt.'</td>';
        $a .= '</tr>';
        $a .= '</tbody>';
        $body = $a;
        $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 $lrtgt;
        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">Overall Abstract for Dues in Academic Year</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">  
                                                        <select id="year" name="year" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.static::year().'
                                                        </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 ovabstractdueinacytest()
    {
        if($_SESSION['user_role'] == 4)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
            //   $fnyear = $styear-$yaer;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
        $tsize = 0;
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $tsize = $tsize+3;
            }
        }
        $tsize = $tsize+2+($year-1)+1;
        $enyear = $styear+1;
        $a .= '<thead>';
        $a .= '<tr>';
        $a .= '<th colspan="'.$tsize.'">Overall Abstract for Dues in Academic Year '.$styear.'-'.$enyear.' as on Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="3">Course</th>';
        $a .= '<th rowspan="3">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            $size= $f*3;
            $incyear = $styear-$syears[$e]+1;
            if($e==0)
            {
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
            if($e>0)
            {
                $size = $size+1;
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
        }
        $a .= '<th rowspan="3">Grand Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                if($e==0)
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                else
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                if($e>0 && $ff==$f)
                {
                    $a .= '<th rowspan="2">Total Amount</th>';
                }
            }
        }
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= "<th>Actual Amount</th>";
                $a .= "<th>Paid Amount</th>";
                $a .= "<th>Due Amount</th>";
            }
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        // for($a=0; $a<sizeof($syears); $a++)
        {
            for($e=0; $e<=3; $e++)
            {
                $f = $e+1;
                for($ff=1; $ff<=$f; $ff++)
                {
                    $lrt[$e][$ff]['actual'] = 0;
                    $lrt[$e][$ff]['paid'] = 0;
                    $lrt[$e][$ff]['due'] = 0;
                }
                $lrt[$e]['tdue'] = 0;
            }
            $lrtgt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.static::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.static::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.static::dept($dept[$c]).'</td>'; 
                }
                $tt = 0;

                for($e=0; $e<=3; $e++)
                {
                    $t = 0;
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    for($ff=1; $ff<=$f; $ff++)
                    {
                        if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                        {
                            $a .= '<td>'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'].'</td>'; 
                            $a .= '<td>'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'].'</td>'; 
                            $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'] = $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee']-$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $a .= '<td>'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'].'</td>'; 
                            $t = $t+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $tt = $tt+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $lrt[$e][$ff]['actual'] = $lrt[$e][$ff]['actual']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'];
                            $lrt[$e][$ff]['paid'] = $lrt[$e][$ff]['paid']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $lrt[$e][$ff]['due'] = $lrt[$e][$ff]['due']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                        }
                        else
                        {
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                        }
                        if($e>0 && $ff == $f)
                        {
                            $a .= '<td>'.$t.'</td>';
                            $lrt[$e]['tdue'] = $lrt[$e]['tdue']+$t;
                        }
                    }
                    if($e == 3)
                    {
                        $a .= '<td>'.$tt.'</td>';
                        $lrtgt = $lrtgt+$tt;
                    }
                    
                }
                $a .= '</tr>';
            }
            }
        }
        $a .= '<tr>';
        $a .= '<td colspan="2">Grand Total</td>';
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= '<td>'.$lrt[$e][$ff]['actual'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['paid'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['due'].'</td>';
                if($e>0 && $ff==$f)
                {
                    $a .= '<td>'.$lrt[$e]['tdue'].'</td>';
                }
            }
        }
        $a .= '<td>'.$lrtgt.'</td>';
        $a .= '</tr>';
        $a .= '</tbody>';
        $body = $a;
        $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 $lrtgt;
        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">Overall Abstract for Dues in Academic Year</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">  
                                                        <select id="year" name="year" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.static::year().'
                                                        </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 actualfee()
    {
        if($_SESSION['user_role'] == 4)
        {
        $data = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON sf.no=um.id WHERE um.fromyear='$_GET[joinyear]' AND um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND sf.year='$_GET[year]' ORDER BY um.no ASC");
        $a ='';
        // echo json_encode($data);
        $total = 0;
        for($i=0; $i<sizeof($data); $i++)
        {
            $j = $i+1;
            $a .= '<tr>';
            $a .= '<td>'.$j.'</td>';
            $a .= '<td>'.$data[$i]['no'].'</td>';
            $a .= '<td>'.$data[$i]['name'].'</td>';
            $a .= '<td>'.$data[$i]['feeamount'].'</td>';
            $a .= '</tr>';
            $total  = $total+$data[$i]['feeamount'];
        }
        $a .= '<tr><td colspan="3">Total Amount</td><td>'.$total.'</td></tr>';
        $body = '<tbody>'.$a.'</tbody>';
        $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th></tr></thead>';
        $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">Actual Fee to be Paid</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">  

                                                    </div>
                                                </div>                           
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                    
                                                    </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 paidfee()
    {
        if($_SESSION['user_role'] == 4)
        {
            
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1'");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1'");
            $htno = array();
            foreach ($data as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                $total = $total + $paid[$no[$i]];
                $count = $count + $rcount[$no[$i]];
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$paid[$no[$i]].'</td>';
                $a .= '<td>'.$rcount[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td><td>'.$count.'</td></tr>';
            $head = '<tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th><th>No of Terms</th></tr>';
            $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">Fee Paid by the Students</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">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </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 duefee()
    {
        if($_SESSION['user_role'] == 4)
        {
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1'");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1'");
            $htno = array();
            foreach ($masterdata as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                        $actual[$no[$a]] = $masterdata[$b]['feeamount'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                if(isset($actual[$no[$i]]))
                {
                    if(isset($paid[$no[$i]]))
                    {
                        $due[$no[$i]] = $actual[$no[$i]]-$paid[$no[$i]];
                    }
                    else
                    {
                        $due[$no[$i]] = $actual[$no[$i]];
                    }
                }
                else
                {
                    $due[$no[$i]] = 0;
                }
                $total = $total + $due[$no[$i]];
                
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$due[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td></tr>';
            $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</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">Fee Paid by the Students</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">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </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>';
                    }
                }
        }
    }
    
}