<?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 Training extends \Core\Controller
{
    private static function month($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'Jan';
            }
            if($id == 2)
            {
                return 'Feb';
            }
            if($id == 3)
            {
                return 'Mar';
            }
            if($id == 4)
            {
                return 'Apr';
            }
            if($id == 5)
            {
                return 'May';
            }
            if($id == 6)
            {
                return 'June';
            }
            if($id == 7)
            {
                return 'July';
            }
            if($id == 8)
            {
                return 'Aug';
            }
            if($id == 9)
            {
                return 'Sept';
            }
            if($id == 10)
            {
                return 'Oct';
            }
            if($id == 11)
            {
                return 'Nov';
            }
            if($id == 12)
            {
                return 'Dec';
            }
        }
    }
    private static function resulttype($id, $count)
    {
        if($_SESSION['org_id'] == 3)
        {
            if($id == 1 && $count == 1)
            {
                return 'REG';
            }
            else if($id == 1 && $count > 1)
            {
                return 'SUP';
            }
            else if($id == 2)
            {
                return 'REV';
            }
            else
            {
                return 'REG/SUP';
            }
        }
    }
    private static function resultstatus($id, $course)
    {
        if($_SESSION['org_id'] == 3)
        {
            if($id == 1 && $course == 2)
            {
                return 'FAIL';
            }
            if($id == 0 && $course == 2)
            {
                return 'PASS';
            }
        }
    }
    private static function yearandsem($year, $sem)
    {
        if($_SESSION['org_id'] == 3)
        {
            if($year == 1 && $sem == 1)
            {
                return 'First Year - First Sem';
            }
            if($year == 1 && $sem == 2)
            {
                return 'First Year - Second Sem';
            }
            if($year == 2 && $sem == 1)
            {
                return 'Second Year - First Sem';
            }
            if($year == 2 && $sem == 2)
            {
                return 'Second Year - Second Sem';
            }
            if($year == 3 && $sem == 1)
            {
                return 'Third Year - First Sem';
            }
            if($year == 3 && $sem == 2)
            {
                return 'Third Year - Second Sem';
            }
        }
    }
    public static function resulttest()
    {
        $data = Homem::getdata("SELECT rd.*, ugg.grade as gradepoint, ugg.failstatus FROM results_data rd JOIN ug_grademarks ugg ON ugg.level=rd.grade WHERE rd.ht_no='192x1a0501' ORDER BY rd.resultdate DESC");
        $crse = array();
        $yer = array();
        $sm = array();
        $subcode = array();
        $subname = array();
        $rdate = array();
        foreach ($data as $h) {
            $crse[] = $h['fk_course_id'];
            $yer[] = $h['year'];
            $sm[] = $h['sem'];
            $subcode[] = $h['sub_code'];
            $subname[] = $h['sub_name'];
            $rdate[] = $h['resultdate'];
        }
        $course = array_values(array_unique($crse));
        sort($course);
        $year = array_values(array_unique($yer));
        sort($year);
        $sem = array_values(array_unique($sm));
        sort($sem);
        $sub_code = array_values(array_unique($subcode));
        sort($sub_code);
        $sub_name = array_values(array_unique($subname));
        sort($sub_name);
        $resultdate = array_values(array_unique($rdate));
        sort($resultdate);
        for($i=0; $i<sizeof($sub_code); $i++)
        {
            for($j=0; $j<sizeof($data); $j++)
            {
                $sub_code_name[$sub_code[$i]] = $data[$j]['sub_code'];
            }
        }
        for($i=0; $i<sizeof($year); $i++)
        {
            for($j=0; $j<sizeof($sem); $j++)
            {
                $year_sem_sub[$year[$i]][$sem[$j]] = array();
                for($k=0; $k<sizeof($sub_code); $k++)
                {
                    for($l=0; $l<sizeof($data); $l++)
                    {
                        if($data[$l]['year'] == $year[$i] && 
                        $data[$l]['sem'] == $sem[$j] &&
                        $data[$l]['sub_code'] == $sub_code[$k])
                        {
                            $year_sem_sub[$year[$i]][$sem[$j]][] = $data[$l]['sub_code'];
                            $year_sem_sub1[$year[$i]][$sem[$j]][$data[$l]['sub_code']] = $data[$l]['sub_code'];
                            break;
                        }
                    }
                }    
            }
        }
        for($i=0; $i<sizeof($sub_code); $i++)
        {
            $a = 0;
            for($j=0; $j<sizeof($data); $j++)
            {
                if($data[$j]['sub_code'] == $sub_code[$i])
                {
                    if($a == 0)
                    {
                        $sub_data[$sub_code[$i]]['grade'] = $data[$j]['grade'];
                        $sub_data[$sub_code[$i]]['gradepoint'] = $data[$j]['gradepoint'];
                        $sub_data[$sub_code[$i]]['credit'] = $data[$j]['credit'];
                        $sub_data[$sub_code[$i]]['failstatus'] = $data[$j]['failstatus'];
                        $sub_data[$sub_code[$i]]['sub_name'] = $data[$j]['sub_name'];
                        $sub_data[$sub_code[$i]]['resultdate'] = $data[$j]['resultdate'];
                        $sub_data[$sub_code[$i]]['sub_code'] = $data[$j]['sub_code'];
                        $sub_data[$sub_code[$i]]['month'] = $data[$j]['exammonth'];
                        $sub_data[$sub_code[$i]]['year'] = $data[$j]['examyear'];
                        $sub_data[$sub_code[$i]]['examtype'] = $data[$j]['examtype'];
                    }
                    $a++;
                }
                if($j == sizeof($data)-1)
                {
                    if($a > 0)
                    {
                        $sub_data[$sub_code[$i]]['count'] = $a;
                    }
                }
            }
        }
        $a = '';
        $a .= '<div class="table-responsive" id="exporttable">';													
        $a .= '<table class="table table-responsive-sm print-this" border="1px">';
        if(sizeof($course) == 1)
        {
            if($course[0] == 2)
            {
                for($i=0; $i<sizeof($year); $i++)
                {
                    for($j=0; $j<sizeof($sem); $j++)
                    {
                        $b = 0;
                        for($k=0; $k<sizeof($sub_code); $k++)
                        {
                            if(sizeof($year_sem_sub[$year[$i]][$sem[$j]])>0)
                            {
                                if(isset($year_sem_sub1[$year[$i]][$sem[$j]][$sub_code[$k]]))
                                {
                                    if($b == 0)
                                    {
                                        $a .= '<tr><th colspan="10">'.static::yearandsem($year[$i], $sem[$j]).'</th></tr>';
                                        $a .= '<tr><th>Subject Code</th><th>Subject Name</th><th>Grade</th><th>Points</th><th>Credits</th><th>Month</th><th>Year</th><th>Type</th><th>Date</th><th>Status</th></tr>';
                                    }
                                    $a .= '<tr>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_code'].'</td>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['sub_name'].'</td>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['grade'].'</td>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['gradepoint'].'</td>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['credit'].'</td>';
                                    $a .= '<td>'.static::month($sub_data[$sub_code[$k]]['month']).'</td>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['year'].'</td>';
                                    $a .= '<td>'.static::resulttype($sub_data[$sub_code[$k]]['examtype'], $sub_data[$sub_code[$k]]['count']).'</td>';
                                    $a .= '<td>'.static::datem($sub_data[$sub_code[$k]]['resultdate']).'</td>';
                                    $a .= '<td>'.static::resultstatus($sub_data[$sub_code[$k]]['failstatus'], $course[0]).'</td>';
                                    $a .= '</tr>';
                                    $b++;
                                }
                            }
                        }
                    }
                }
            }
        }
        $a .= '</tbody>';
        $a .= "</table>";
        $a .= "</div>";
        $a .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-12"> 
                                <form action="" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <header class="panel_header">
                                                    <h5 class="title pull-left">Bulk Students Marks</h5>
                                                </header>
                                                <div class="content-body">    

                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                '.$a.'
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            </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 resulttesting()
    {
        $data = Homem::getdata("SELECT * FROM `results_data` ORDER BY `resultdate` DESC");
        $crse = array();
        $yer = array();
        $sm = array();
        $subcode = array();
        $subname = array();
        $rdate = array();
        $exam_year = array();
        $exam_month = array();
        foreach ($data as $h) {
            $crse[] = $h['fk_course_id'];
            $yer[] = $h['year'];
            $sm[] = $h['sem'];
            $subcode[] = $h['result_type'];
            $rdate[] = $h['resultdate'];
            $exam_year[] = $h['examyear'];
            $exam_month[] = $h['exammonth'];
        }
        $course = array_values(array_unique($crse));
        sort($course);
        $year = array_values(array_unique($yer));
        sort($year);
        $sem = array_values(array_unique($sm));
        sort($sem);
        $resulttype = array_values(array_unique($subcode));
        sort($resulttype);
        $resultdate = array_values(array_unique($rdate));
        sort($resultdate);
        $examyear = array_values(array_unique($exam_year));
        sort($examyear);
        $exammonth = array_values(array_unique($exam_month));
        sort($exammonth);
    }
    /**
     * Student marks uploading bulk - ended
     */
    /* Modify date started*/
    public static function dtest() // testing for date conversion
    {
        $date = '34/35/36';
        echo static::datemodify($date);
    }
    private static function datemodify($date)
    {
        $ar = static::datesplit($date);
        if(is_array($ar))
        {
            return static::datesort($ar);
        }
    }
    private static function datesplit($date)
    {
        if(isset($date))
        {
            $d = explode("-", $date);
            if(is_array($d))
            {
                if(sizeof($d) == 3)
                {
                    return $d;
                }
                else
                {
                    $e = explode("/", $date);
                    if(is_array($e))
                    {
                        if(sizeof($e) == 3)
                        {
                            return $e;
                        }
                        else
                        {
                            $f = explode(".", $date);
                            if(is_array($f))
                            {
                                if(sizeof($f) == 3)
                                {
                                    return $f;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    private static function datesort($a)
    {
        if(strlen($a[0]) == 4)
        {
            return $a[0].'-'.static::appendzeromonth($a[1]).'-'.static::appendzerodate($a[2]);
        }
        if(strlen($a[2]) == 4)
        {
            return $a[2].'-'.static::appendzeromonth($a[1]).'-'.static::appendzerodate($a[0]);
        }
        if(strlen($a[2]) <= 2 && strlen($a[1]) <= 2 && strlen($a[0]) <= 2)
        {
            return static::apendyearfront($a[2]).'-'.static::appendzeromonth($a[1]).'-'.static::appendzerodate($a[0]);
        }
    }
    private static function appendzeromonth($m)
    {
        if($m >=1 && $m <=12)
        {
            if(strlen($m) == 2)
            {
                return $m;
            }
            else
            {
                return '0'.$m;
            }
        }
        else
        {
            return '01';
        }
    }
    private static function appendzerodate($m)
    {
        if($m >=1 && $m <=31)
        {
            if(strlen($m) == 2)
            {
                return $m;
            }
            else
            {
                return '0'.$m;
            }
        }
        else
        {
            return '01';
        }
    }
    private static function apendyearfront($a)
    {
        if(strlen($a) == 2)
        {
            if(date('y') >=$a)
            {
                return '20'.$a;
            }
            else
            {
                return date('Y');
            }
        }
    }
    /* Modify date Ended*/

    /** Browser Checking code started */
    private static function checkbrower()
    {
        $mystring = $_SERVER['HTTP_USER_AGENT'];
        $word = 'Chrome';
        if(strpos($mystring, $word) !== false)
        {
            if(strpos($mystring, 'Mozilla') !== false)
            {
                return "1";
            } 
        }
        else if(strpos($mystring, 'Mozilla') !== false)
        {
            return "1";
        } 
        else
        {
            return "0";
        }
    }
    private static function checkiphone()
    {
        $iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
        $iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
        $iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
        $Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
        $webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
        if($iPod || $iPhone || $iPad || $Android || $webOS)
        {
            echo 1;
        }
        else
        {
            echo 0;
        }
    }
    /** Browser Checking code Ended */

    /** CSS, Script started */
    private static function css()
    {
        $css = 
        '<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
            <title>Hindu College of Engineering & Technology || Guntur</title>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
            <title>Hindu College of Engineering & Technology || Guntur</title>
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/bootstrap.min.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/css/style.css">
            <link rel="stylesheet" href="https://assets.hinduengg.com/hindu/assets/sweetalert2/dist/sweetalert2.min.css" >
            <style>
                @media print
                {
                    body * {
                        visibility: hidden;
                    }
                    .print-this, .print-this * {
                        visibility: visible;
                    }
                }
            </style>
            <script>
                function exportTableToExcel(tableID, filename = "")
                {
                    var downloadLink;
                    var dataType = "application/vnd.ms-excel";
                    var tableSelect = document.getElementById(tableID);
                    var tableHTML = tableSelect.outerHTML.replace(/ /g, "%20");
                    
                    // Specify file name
                    filename = filename?filename+".xls":"excel_data.xls";
                    
                    // Create download link element
                    downloadLink = document.createElement("a");
                    
                    document.body.appendChild(downloadLink);
                    
                    if(navigator.msSaveOrOpenBlob){
                        var blob = new Blob(["\ufeff", tableHTML], {
                            type: dataType
                        });
                        navigator.msSaveOrOpenBlob( blob, filename);
                    }else{
                        // Create a link to the file
                        downloadLink.href = "data:" + dataType + ", " + tableHTML;
                    
                        // Setting the file name
                        downloadLink.download = filename;
                        
                        //triggering the function
                        downloadLink.click();
                    }
                }
            </script>
        </head>';
        return $css;  
    }
    private static function script()
    {
        $script =
                '
                <div class="footer navbar-fixed-bottom text-center">        
                    <span class="text-muted text-center">Copyright &#169 2020. Hindu College of Engineering & Technology, Guntur</span>
                </div>
                <script src="https://assets.hinduengg.com/hindu/assets/word/jquery.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/vendor/sweetalert2/dist/sweetalert2.min.js" ></script>';
        return $script;  
    }
    private static function blockscript()
    {
        $script =
                '
                <div class="footer navbar-fixed-bottom text-center">        
                    <span class="text-muted text-center">Copyright &#169 2020. Hindu College of Engineering & Technology, Guntur</span>
                </div>
                <script src="https://assets.hinduengg.com/hindu/assets/word/jquery.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/js/bootstrap.min.js" ></script>
                <script src="https://assets.hinduengg.com/hindu/assets/sweetalert2/dist/sweetalert2.min.js" ></script>
                <!-- Script to stop mouse right click start-->
            <script>
                //Disable right click script
                var message = "";
                ///////////////////////////////////
                function clickIE() {
                    if (document.all) {
                        (message);
                        return false;
                    }
                }

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

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

            <!-- Script to prevent selection start-->
            <script>
                $(document).ready(function () {
                    $("body").bind("cut copy", function (e) {
                        e.preventDefault();
                    });
                });
            </script>
            <!-- Script to prevent selection end-->
                ';
        return $script;  
    }
    /** CSS, Script Ended */

    /**Default functions to support the main functions starting*/
    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 course($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'B.Com.';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'M.Sc.';
                }
                if($id == 3)
                {
                    return 'M.Sc. (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Diploma';
                }
                if($id == 2)
                {
                    return 'B.Tech.';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'MCA';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function dept($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'MPCS';
                }
                if($id == 2)
                {
                    return 'MSCS';
                }
                if($id == 3)
                {
                    return 'MECS';
                }
                if($id == 4)
                {
                    return 'General';
                }
                if($id == 5)
                {
                    return 'Computers';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'Agriculture';
                }
                if($id == 2)
                {
                    return 'Horticulture';
                }
                if($id == 3)
                {
                    return 'Food Technology';
                }
                if($id == 4)
                {
                    return 'Physics';
                }
                if($id == 5)
                {
                    return 'Chemistry';
                }
                if($id == 6)
                {
                    return 'Botany';
                }
                if($id == 7)
                {
                    return 'Food Processing (Vocational)';
                }
                if($id == 8)
                {
                    return 'Horticultural Landscaping (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Civil Engineering';
                }
                else if($id == 2)
                {
                    return 'Electrical & Electronics Engineering';
                }
                else if($id == 3)
                {
                    return 'Mechanical Engineering';
                }
                else if($id == 4)
                {
                    return 'Electronics & Communication Engineering';
                }
                else if($id == 5)
                {
                    return 'Computer Science Engineering';
                }
                else
                {
                    return '';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'Computers';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function feetype($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'Andhra Bank<br> Tution Fee';
                }
                if($id == 2)
                {
                    return 'Baroda Bank<br> Tution Fee';
                }
            }
            else if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Service Fee';
                }
            }
            else
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Bus Fee';
                }
            }
        }
    }
    private static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
    private static function squota($id, $course)
    {
        if($id != '')
        {
            if($id == 'M' && $course==1)
            {
                return 'SPOT Admission';
            }
            if($id == 'M' && $course==2)
            {
                return 'Management Quota';
            }
            if($id == 'C' && ($course==1 || $course==2))
            {
                return 'Convenor Quota';
            }
            if($id == 'S')
            {
                return 'Spot Admission';
            }
        }
    }
    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 numtotext($number)
    {
        $decimal = round($number - ($no = floor($number)), 2) * 100;
        $hundred = null;
        $digits_length = strlen($no);
        $i = 0;
        $str = array();
        $words = array(0 => '', 1 => 'one', 2 => 'two',
            3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six',
            7 => 'seven', 8 => 'eight', 9 => 'nine',
            10 => 'ten', 11 => 'eleven', 12 => 'twelve',
            13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
            16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen',
            19 => 'nineteen', 20 => 'twenty', 30 => 'thirty',
            40 => 'forty', 50 => 'fifty', 60 => 'sixty',
            70 => 'seventy', 80 => 'eighty', 90 => 'ninety');
        $digits = array('', 'hundred','thousand','lakh', 'crore');
        while( $i < $digits_length ) {
            $divider = ($i == 2) ? 10 : 100;
            $number = floor($no % $divider);
            $no = floor($no / $divider);
            $i += $divider == 10 ? 1 : 2;
            if ($number) {
                $plural = (($counter = count($str)) && $number > 9) ? 's' : null;
                $hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
                $str [] = ($number < 21) ? $words[$number].' '. $digits[$counter]. $plural.' '.$hundred:$words[floor($number / 10) * 10].' '.$words[$number % 10]. ' '.$digits[$counter].$plural.' '.$hundred;
            } else $str[] = null;
        }
        $Rupees = implode('', array_reverse($str));
        $paise = ($decimal > 0) ? "." . ($words[$decimal / 10] . " " . $words[$decimal % 10]) . ' Paise' : '';
        return ($Rupees ? $Rupees . 'Rupees Only' : '') . $paise;
    }
    /**Default functions to support the main functions ending*/

    /** Before login menu work start */
    public static function latest()
    {
        $data = Homem::getdata("SELECT * FROM `latest_news` WHERE `status`='1' ORDER BY id asc");
        $tdata = '';
        if(sizeof($data) > 0)
        {
            for($i=0; $i < sizeof($data); $i++)
            {
                $j=$i+1;
                $tdata .= '<tr><td>'.$j.'</td><td>'.$data[$i]['description'].'</td><td>'.$data[$i]['edate'].'</td></tr>';
            }
        }
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        echo '
        <div class="clearfix"></div>
		<form action="Search.php" method="POST">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-2"></div>
                    <div class="col-md-8">                                       
                        <div class="row">
                            <div class="col-md-12">
                                <section class="box" style="margin-top: 30px;">
                                    <header class="panel_header">
                                        <h2 class="title pull-left">LATEST NEWS / INFORMATION</h2>
                                        <div class="actions panel_actions pull-right">
                                            <a class="box_toggle fa fa-chevron-down"></a>
                                        </div>
                                    </header>
                                    <div class="content-body"> 						
                                            <div class="row">
                                                <div class="col-md-12">
                                                <div class="table-responsive">													
                                                    <table class="table table-bordered">
                                                        <thead>
                                                        <tr>
                                                            <th>S. No.</th>
                                                            <th>Description</th>
                                                            <th>Date</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>';
                                                        echo $tdata;
                                                        
                                                echo '</tbody>
                                                    </table>
                                                </div>
                                                </div>
                                            </div>
                                            
                                    </div>  
                                </section>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-2"></div>
                </div>
            </div>
        </form>
        ';
        echo '</body>';
        echo static::script();
    }
    public static function suggestions()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        echo '
        <div class="clearfix"></div>
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-1"></div>
                <div class="col-lg-10">                                       
                    <div class="row">
                        <div class="col-md-12">
                            <section class="box" style="margin-top: 30px;">
                                <header class="panel_header">
                                    <h2 class="title pull-left">Suggest Us Here</h2>
                                    <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">
									<form action="savesuggestions" method="POST">	
											<div class="row">
												<div class="col-md-12">  
													<div class="form-group">
														Your Suggestions are most valuble in improving our services.
													</div>
												</div>
											</div>
											<div class="row">
												<div class="col-md-12">
													<div class="row">
														<div class="col-md-6">
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="name" class="form-control" placeholder="Name" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="email" class="form-control" placeholder="Email" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="mobile" class="form-control" placeholder="Mobile" required />
																	</div>
																</div>  
															</div>													
														</div>
														<div class="col-md-6">
															<div class="form-group">							
																<textarea name="Suggestions" id="Suggestions" type="text" class="form-control" placeholder="Enter your Suggestions here..." style="height:138px;resize:none;" required /></textarea>
															</div>
														</div>  
													</div>											
												</div>
											</div>										
											<div class="row">
												<div class="col-md-12">  
													<div class="form-group">
														<label id="lbl_msg" class="label label-primary pull-left"></label>
														<button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
														<div id="spinner1" class="pull-right circle-loader ">
															<div class="checkmark draw"></div>
														</div>
													</div>
												</div>
											</div>										

									</form>
                                </div>                        
                            </section>
                        </div>
                    </div>
                </div>
                <div class="col-lg-1"></div>
            </div>
        </div>
        ';
        echo '</body>';
        echo static::script();
        if(isset($_GET['status']))
        {
            if($_GET['status'] == 1)
            {
                echo '<script>swal("Submitted Successfully", "We will contact you regarding your query..", "success");</script>';
            }
            else
            {
                echo '<script>swal("Something Went Wrong..", "Please Tryagain Later", "error");</script>';
            }
        }
    }
    public static function savesuggestions()
    {
        if($_POST['name'] != '' && $_POST['email'] != '' && $_POST['mobile'] != '')
        {
            date_default_timezone_set('Asia/Kolkata'); 
            $today_time =  date('d-m-Y h:i:s A');
            $status = Homem::insert("INSERT INTO `suggestions` (`id`, `name`, `email`, `mobile`, `suggestions`, `endate`, `status`) VALUES ('', '$_POST[name]', '$_POST[email]', '$_POST[mobile]', '$_POST[Suggestions]', '$today_time', '1')");
            echo '<script>window.location="/Training/suggestions?status=1";</script>';
        }
        else
        {
            echo '<script>window.location="/Training/suggestions?status=0";</script>';
        }
    }
    public static function contactus()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        echo '
        <div class="clearfix"></div>
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">                                       
                    <div class="row">
                        <div class="col-lg-1"> </div>  
                        <div class="col-md-10">
                            <section class="box" style="margin-top: 30px;">
                                <header class="panel_header">
                                    <h2 class="title pull-left">Contact Us</h2>
                                    <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">
									<form action="/Training/savecontactus" method="POST">	
											<div class="row">
                                                
												<div class="col-md-12">
													<div class="row">
														<div class="col-md-3">
														</div>
														<div class="col-md-6">
															<div class="row">
																<div class="col-md-12">  
																	<div class="form-group">
																		For Any Other Queries:
																	</div>
																</div>
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="name" class="form-control" placeholder="Name" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="email" class="form-control" placeholder="Email" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="mobile" class="form-control" placeholder="Mobile" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group"> 
																		<input type="text" name="subject" class="form-control" placeholder="Subject" required />
																	</div>
																</div>  
															</div>
															<div class="row">
																<div class="col-md-12">
																	<div class="form-group">							
																		<textarea name="message" id="Suggestions" type="text" class="form-control" placeholder="Message" style="height:138px;resize:none;" required /></textarea>
																	</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>  
                                                        <div class="col-md-3">
														</div>
													</div>											
												</div>
                                               
											</div>										
									</form>
                                </div>                        
                            </section>
                        </div>
                        <div class="col-lg-1"> </div>  
                    </div>
                </div>
            </div>
        </div>
        ';
        echo '</body>';
        echo static::script();
        if(isset($_GET['status']))
        {
            if($_GET['status'] == 1)
            {
                echo '<script>swal("Submitted Successfully", "We will contact you regarding your query..", "success");</script>';
            }
            else
            {
                echo '<script>swal("Something Went Wrong..", "Please Tryagain Later", "error");</script>';
            }
        }
    }
    public static function savecontactus()
    {
        if($_POST['name'] != '' && $_POST['email'] != '' && $_POST['mobile'] != '')
        {
            date_default_timezone_set('Asia/Kolkata'); 
            $today_time =  date('d-m-Y h:i:s A');
            $status = Homem::insert("INSERT INTO `contactus`(`name`, `email`, `mobile`, `subject`, `message`, `edate`, `status`)  VALUES ('$_POST[name]', '$_POST[email]', '$_POST[mobile]', '$_POST[subject]','$_POST[message]', '$today_time', '1')");
            echo '<script>window.location="/Training/contactus?status=1";</script>';
        }
        else
        {
            echo '<script>window.location="/Training/contactus?status=0";</script>';
        }
    }
    /** Before login menu work end */
    /** Strting of Login Screen  and Authentication */
    private static function normalmenu()
    {
        // bg-light
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light ">
                <a class="navbar-brand" href="#" >HINDU COLLEGE</a>
                <button style="background-color:white;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ml-auto navbar-right">
                    
                    <li class="nav-item active" >
                        <a class="nav-link" href="/Training/index" >Home</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Training/latest" >Latest News</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Training/suggestions" >Suggestions</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Training/contactus" >Contact Us</a>
                    </li>
                    <!--
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Dropdown
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                        <a class="dropdown-item" href="#">Action</a>
                        <a class="dropdown-item" href="#">Another action</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#">Something else here</a>
                        </div>
                    </li>
                    -->
                    </ul>
                    <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-light my-2 my-sm-0" type="submit">Search</button>
                    </form>
                </div>
            </nav>
        ';
        return $menu;
    }
    /** Registration starts */
    public static function register()
    {
        $course = Homem::cgetdata("SELECT * FROM `org_courses`");
        $dept = Homem::cgetdata("SELECT * FROM `org_dept`");
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        if(static::checkbrower() == 1)
        {
            echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-3"></div>
                                <div class="col-xl-6">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/Training/saveregister" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Register Here</div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                        <select class="form-control" name="orgid" id="orgid" onchange="get_courses(this)" required>
                                                            <option value="">Select College</option>
                                                            <option value="1">Hindu College</option>
                                                            <option value="2">Hindu College of Engineering & Technology</option>
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select class="form-control" name="course" id="course" onchange="get_dept(this)" required>
                                                            <option value="">Select Course</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select class="form-control" name="dept" id="dept" required>
                                                            <option value="">Select Department</option>
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select class="form-control" name="status" id="status" required>
                                                            <option value="">Is course completed?</option>
                                                            <option value="1">Yes</option>
                                                            <option value="0">No</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <input type="number" class="form-control" name="finalyear" id="finalyear" placeholder="Year of Completion" required>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="htno" id="htno" placeholder="Hallticket Number" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="name" id="name" placeholder="Name" required>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select class="form-control" name="gender" id="gender" required>
                                                            <option value="">Select Gender</option>
                                                            <option value="M">Male</option>
                                                            <option value="F">Female</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <input type="text" class="form-control" name="dob" id="dob" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth" required />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                    <input type="number" class="form-control" name="mobile" id="mobile" placeholder="Mobile Number" required />
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <input type="email" class="form-control" name="email" id="email" placeholder="Email" required />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                    <input type="text" class="form-control" name="pname" id="pname" placeholder="Parent Name" required />
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <input type="number" class="form-control" name="pmobile" id="pmobile" placeholder="Parent Mobile" required />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="password" id="password" placeholder="Password" required>
                                            </div>
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <input type="submit" class="btn btn-primary" style="background-color: #002366 !important;" value="Submit">
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-3"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        else
        {
                echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <a>Please use Google Chrome / Microsoft Edge Browser for Best user Experience.</a>
                                                </div> 
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        echo '</body>';
        echo static::script();
        echo '<script>
        function get_courses(org)
        {
            {
                var course = '.json_encode($course).';
                select = document.getElementById("course");
                for(i=0; i<course.length; i++)
                {
                    if(course[i]["fk_org_id"] == org.value)
                    {
                        var opt = document.createElement("option");
                        opt.value = course[i]["id"];
                        opt.innerHTML = course[i]["name"];
                        select.appendChild(opt);
                    }
                    else
                    {
                        for(j=0; j<select.length; j++)
                        {
                            if (select.options[j].value == course[i]["id"])
                            {
                                select.remove(j);
                            }
                        }
                    }
                }
            }
        }
        function get_dept(course)
        {
            {
                var dept = '.json_encode($dept).';
                select = document.getElementById("dept");
                for(i=0; i<dept.length; i++)
                {
                    if(dept[i]["fk_course_id"] == course.value)
                    {
                        var opt = document.createElement("option");
                        opt.value = dept[i]["id"];
                        opt.innerHTML = dept[i]["name"];
                        select.appendChild(opt);
                    }
                    else
                    {
                        for(j=0; j<select.length; j++)
                        {
                            if (select.options[j].value == dept[i]["id"])
                            {
                                select.remove(j);
                            }
                        }
                    }
                }
            }
        }
        </script>';
    }
    public static function saveregister()
    {
        if($_POST['name'] != '')
        {
            $data = Homem::cgetdata("SELECT * FROM `user_master` WHERE `htno`='$_POST[htno]' OR `mobile`='$_POST[mobile]' OR `email`='$_POST[email]'");
            if(sizeof($data) == 0)
            {
                $query = "INSERT INTO `user_master` (`id`, `fk_org_id`, `fk_course_id`, `fk_dept_id`, `course_status`, `course_endyear`, `htno`, `name`, `gender`, `dob`, `mobile`, `email`, `pname`, `pmobile`, `password`, `user_role`, `v_mobile`, `v_email`, `add_by`, `add_date`, `status`, `lockuser`) VALUES (NULL, '$_POST[orgid]', '$_POST[course]', '$_POST[dept]', '$_POST[status]', '$_POST[finalyear]', '$_POST[htno]', '$_POST[name]', '$_POST[gender]', '$_POST[dob]', '$_POST[mobile]', '$_POST[email]', '$_POST[pname]', '$_POST[pmobile]', '$_POST[password]', '1', '', '', '', '', '', '')";
                Homem::cinsert($query);
                $token = substr(str_shuffle("abcdefghijklmenopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 25);
            }
            else
            {
                echo sizeof($data);
            }
        }
    }
    public function emailverification()
    {
        if(isset($_GET['token']))
        {
            if(strlen($_GET['token']) == 25)
            {
                $t_data = Homem::getdata("SELECT * FROM `email_token` WHERE `token`='$_GET[token]' AND `status`='1'");
                if(sizeof($t_data) == 1)
                { 
                    date_default_timezone_set('Asia/Kolkata'); 
                    $today_time =  date('Y-m-d H:i:s');
                    $date1 = strtotime($t_data[0]["e_time"]); 
                    $date2 = strtotime($today_time); 
                    $diff = abs($date2 - $date1); 
                    $minutes = $diff/(60);
                        if($minutes <= 45)
                        {
                            if($t_data[0]["email_type"] == 1)
                            {
                                $fk_user_id = $t_data[0]["fk_user_id"];
                                Homem::insert("UPDATE `user_details` SET `v_status`='1' WHERE `user_id`='$fk_user_id'");
                                Homem::insert("UPDATE `user_logins` SET `status`='1' WHERE `type`='1' AND `pref`='1' AND `fk_user_id`='$fk_user_id'");
                                Homem::insert("UPDATE `email_token` SET `status`='0' WHERE `token`='$_GET[token]'");
                                $status = "<script>swal('Verification Success', 'Please Login to Continue..', 'success');</script>";
                                // View::render('Home/index.php', ['status'=>$status]);  
                                $status = "<script>window.location =`/Training/Home?status=1`;</script>";
                                echo $status; 
                            }
                        }
                        else
                        {
                            $status = "<script>swal('Verification Failed..', 'The link expaired due to time.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
                            // View::render('Home/index.php', ['status'=>$status]); 
                            $status = "<script>window.location =`/Training/Home?status=0`;</script>";
                            echo $status; 
                        }
                }
                else
                {
                    $status = "<script>swal('Verification Failed..', 'Details not found or Expired Details.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
                    // View::render('Home/index.php', ['status'=>$status]); 
                    $status = "<script>window.location =`/Training/Home?status=0`;</script>";
                    echo $status; 
                }
            }
            else
            {
                $status = "<script>swal('Verification Failed..', 'Invalid Detils for verification.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
                // View::render('Home/index.php', ['status'=>$status]); 
                $status = "<script>window.location =`/Training/Home?status=0`;</script>";
                echo $status; 
            }
        }
        else
        {

            $status = "<script>swal('Verification Failed..', 'Something wrong.. Please try again.', 'error');setTimeout(function(){ location.href='/'; }, 5000);</script>";
            // View::render('Home/index.php', ['status'=>$status]);
            $status = "<script>window.location =`/Training/index?status=0`;</script>";
            echo $status; 
        }
    }
    /** Registration ends */
    public static function index()
    {
        echo static::css();
        echo '<body>';
        echo static::normalmenu();
        if(static::checkbrower() == 1)
        {
            echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/Training/auth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Login Here</div>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="username" id="username" placeholder="User Name" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="password" id="password" placeholder="Password" required>
                                            </div>
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <input type="submit" class="btn btn-primary" style="background-color: #002366 !important;" value="Submit">
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="float-left">
                                                    <a href="/Training/forgotpassword">Forgot Password</a>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        else
        {
                echo '
                <div class="container">
                        <div class="container-fluid">
                            <div class="row" style="margin-top:20px;">
                                <div class="col-xl-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/Training/auth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-right">
                                                    <a>Please use Google Chrome / Microsoft Edge Browser for Best user Experience.</a>
                                                </div> 
                                            </div>
                                        </form>
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        echo '</body>';
        echo static::script();
    }
    private static function usermenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">HINDU COLLEGE</a>
                <button style="background-color:white;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ml-auto navbar-right">
                    <li class="nav-item active">
                        <a class="nav-link" href="/Main/home" >Home</a>
                    </li>
                <!--
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Masters
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/bloodgroup" >Blood Group</a>
                        <a class="dropdown-item" href="/Main/courses">Courses</a>
                        <a class="dropdown-item" href="/Main/departments">Departments</a>
                        <a class="dropdown-item" href="/Main/category">Category</a>
                        </div>
                    </li>
                    
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Students
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/supload" >Upload Student Details</a>
                        <a class="dropdown-item" href="/Main/slist" >View List of Students</a>
                        <a class="dropdown-item" href="/Main/addstudent">Individual Student Entry</a>
                        <a class="dropdown-item" href="/Main/ssearch" >Search a Student</a>
                        <a class="dropdown-item" href="/Main/upstdntphotos">Upload Students Photos</a>
                        <a class="dropdown-item" href="/Main/stdntadditional">Student Additional Details</a>
                        </div>
                    </li>
                    
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        User
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/ulist">View List of Users</a>
                        <a class="dropdown-item" href="/Main/adduser">Individual User Entry</a>
                        </div>
                    </li>
                    
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Subject
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/searchsub">Search Subjects Available</a>
                        <a class="dropdown-item" href="/Main/indsubject">Individual Subject Entry</a>
                        <a class="dropdown-item" href="/Main/bulksubject">Bulk Subject Uploading</a>
                        </div>
                    </li>
                
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Marks Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/uploadmarks" >B.Tech Marks Entry</a>
                        <a class="dropdown-item" href="/Main/mdipinformat">Diploma Marks (College Format)</a>
                        <a class="dropdown-item" href="/Main/mindividual" >Individual Marks Entry</a>
                        <a class="dropdown-item" href="/Main/editindstdmarks"  >Edit Individual Student Marks</a>
                        </div>
                    </li>
                    -->
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Reports 
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/studentresultfinal" >Student Result</a>
                        <!--<a class="dropdown-item" href="/Main/sattempts" >Student Attempts</a>-->
                        <a class="dropdown-item" href="/Main/semwiseconmarks" >Sem wise Consolidated Marks Report</a>
                        <a class="dropdown-item" href="/Main/sbacklogs" >Sem Wise Student Backlogs</a>
                        <a class="dropdown-item" href="/Main/subwisefailistinsem" >Subject wise Baclogs in Sem</a>
                        <a class="dropdown-item" href="/Main/subwiseresults" >Subject Wise Results</a>
                        <a class="dropdown-item" href="/Main/deptwiseresult" >Semester Wise Result Analysis</a>
                        </div>
                    </li>
                <!--
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Fee 
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Main/allotstdfee" >Allot Fee for Students</a>
                        <a class="dropdown-item" href="/Main/normalfeecolect" >Normal Fee Collection</a>
                        <a class="dropdown-item" href="/Main/examfeecollect" >Exam Fee Collection</a>
                        <a class="dropdown-item" href="/Main/stdntindfee" >Check Student Fees</a>
                        </div>
                    </li>
                -->
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    public static function auth()
    {
        if($_POST['username'] != '' && $_POST['password'] != '')
        {
            $_SESSION['org_id'] = $_POST['orgname'];
            $qurey = "SELECT * FROM `user_master` WHERE (`no` = '$_POST[username]' OR `mobile` = '$_POST[username]' OR `email` = '$_POST[username]') AND `password`='$_POST[password]' AND status='1'";
            $data = Homem::getdata($qurey);
            if(sizeof($data) == 1)
            {
                $_SESSION['user_id'] = $data[0]['id'];
                $_SESSION['user_no'] = $data[0]['no'];
                $_SESSION['name'] = $data[0]['name'];
                $_SESSION['org_id'] = $data[0]['org_id'];
                $_SESSION['mobile'] = $data[0]['mobile'];
                $_SESSION['email'] = $data[0]['email'];
                $_SESSION['user_role'] = $data[0]['user_role'];
                if($data[0]['user_role'] == 4)
                {
                    $_SESSION['menu'] = static::accountsmainmenu();
                }
                if($data[0]['user_role'] == 5)
                {
                    $_SESSION['menu'] = static::collectionmainmenu();
                }
                if($data[0]['user_role'] == 6)
                {
                    $_SESSION['menu'] = static::adminmainmenu();
                }
                if($data[0]['user_role'] == 9)
                {
                    $_SESSION['menu'] = static::usermenu();
                }
                echo '<script>window.location="/Training/home";</script>';
            }
            else
            {
                echo '<script>window.location="/Training/index?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location="/Training/index?status=0";</script>';
        }
            
    }
    private static function accountsmainmenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">HINDU COLLEGE</a>
                <button style="background-color:white;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ml-auto navbar-right">
                    <li class="nav-item active">
                        <a class="nav-link" href="/Training/home" >Home</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Fee Setting Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/allotstdfee" >Bulk Uploading of Student Fee</a>
                        <a class="dropdown-item" href="/Training/allotindstdfee" >Individual Fee Upload</a>
                        <a class="dropdown-item" href="/Training/normalfeeconcession" >Concession Fee Details</a>
                        <a class="dropdown-item" href="/Training/deptwisefeesettingreport" >Department wise Fee List</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Fee Collection Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/normalfeecolect" >Normal Fee Collection</a>
                        <a class="dropdown-item" href="/Training/examfeecollect" >Exam Fee Collection</a>
                        <a class="dropdown-item" href="/Training/nfeecollectbulk" >Normal Fee Collection (Bulk Upload)</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Fee Collection Reports
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/hnowiseconsreport" >Individual Student Fee Report</a>
                        <a class="dropdown-item" href="/Training/deptwiseconsol" >Dept Wise Consolidated Report</a>
                        <a class="dropdown-item" href="/Training/coursewiseconsol" >Course Wise Detailed Report</a>
                        <a class="dropdown-item" href="/Training/datewisecon" >Date wise fee collection report</a>
                        <a class="dropdown-item" href="/Training/reportbwndates" >Fee Collection betwen two dates</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        MIS Reports
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/admcmpforfuryer" >Admission Comparison for Four Years</a>
                        <a class="dropdown-item" href="/Training/ovabstractbyayyear" >Overall Abstract for Academic Year</a>
                        <a class="dropdown-item" href="/Training/ovabstractforallcurses" >Overall Abstract for All Courses</a>
                        <a class="dropdown-item" href="/Training/ovabstractdueinacy" >Overall Abstract for Dues in Academic year</a>
                        <a class="dropdown-item" href="/Training/ovabstractdueinacylinks" >Detailed Overall Abstract for Dues in Academic year</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function collectionmainmenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">HINDU COLLEGE</a>
                <button style="background-color:white;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <ul class="navbar-nav ml-auto navbar-right">
                    <li class="nav-item active">
                        <a class="nav-link" href="/Training/home" >Home</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Training/normalfeecolect" >Normal Fee Collection</a>
                    </li>
                    <li class="nav-item active">
                    <a class="nav-link" href="/Training/hnowiseconsreport" >Individual Student Fee Report</a>
                    </li>
                    
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Fee Collection Reports
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/slist" >List of Students</a>
                        <a class="dropdown-item" href="/Training/deptwisefeesettingreport" >Department wise Fee List</a>
                        <a class="dropdown-item" href="/Training/deptwiseconsol" >Dept Wise Consolidated Report</a>
                        <a class="dropdown-item" href="/Training/coursewiseconsol" >Course Wise Detailed Report</a>
                        <a class="dropdown-item" href="/Training/datewisecon" >Date wise fee collection report</a>
                        <a class="dropdown-item" href="/Training/reportbwndates" >Fee Collection betwen two dates</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    private static function adminmainmenu()
    {
        $menu = '
            <nav class="navbar navbar-expand-lg navbar-light " style="background-color: #002366; text-color: #ffffff;">
                <a class="navbar-brand" href="#" style="color: #ffffff;">HINDU COLLEGE</a>
                <button style="background-color:white;" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>

                    <div class="collapse navbar-collapse" id="navbarSupportedContent">
                        <ul class="navbar-nav ml-auto navbar-right">
                        <li class="nav-item active">
                            <a class="nav-link" href="/Training/home" >Home</a>
                        </li>
                        <!--
                        <li class="nav-item active">
                        <a class="nav-link" href="/Training/hnowiseconsreport" >Individual Student Fee Report</a>
                        </li>
                        -->
                        <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Academics
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/subjectsyllabus" >Add Syllabus to subjects</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Quiz Questions Entry
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/addmcqquestions" >Add MCQ Questions</a>
                        <a class="dropdown-item" href="/Exams/addmcqquestionsupload" >Add MCQ Questions (Images)</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanks" >Add Fill in Blanks</a>
                        <a class="dropdown-item" href="/Exams/addfillinblanksupload" >Add Fill in Blanks (Images)</a>
                        <a class="dropdown-item" href="/Exams/addinterquestions" >Intermediate Answer Questions</a>
                        <a class="dropdown-item" href="/Exams/addinterquestionsupload" >Intermediate Answer Questions(Images)</a>
                        <a class="dropdown-item" href="/Exams/approvalquestions" >Approve Questions</a>
                        <a class="dropdown-item" href="/Exams/questionscount" >Available Questions</a>
                        <a class="dropdown-item" href="/Exams/viewquestions" >View Approved Questions</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Quiz Exam
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/singletopicexam" >Single Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/singlechaptexam" >Single Chapter Exam</a>
                        <a class="dropdown-item" href="/Exams/multipletopicexam" >Multiple Topic Exam</a>
                        <a class="dropdown-item" href="/Exams/multiplechaptexam" >Multiple Chapter Exam</a>
                        <a class="dropdown-item" href="/Exams/examreports" >Completed Exam Reports</a>
                        <a class="dropdown-item" href="/Exams/totalexamreports" >All Exam Details</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Accounts Section
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/allotstdfee" >Bulk Uploading of Student Fee</a>
                        <a class="dropdown-item" href="/Training/allotindstdfee" >Individual Fee Upload</a>
                        <a class="dropdown-item" href="/Training/normalfeeconcession" >Concession Fee Details</a>
                        <a class="dropdown-item" href="/Training/deptwisefeesettingreport" >Department wise Fee List</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/Training/normalfeecolect" >Normal Fee Collection</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/Training/hnowiseconsreport" >Individual Student Fee Report</a>
                        <a class="dropdown-item" href="/Training/deptwiseconsol" >Dept Wise Consolidated Report</a>
                        <a class="dropdown-item" href="/Training/coursewiseconsol" >Course Wise Detailed Report</a>
                        <a class="dropdown-item" href="/Training/dailyreport" >Operator Entry Report Date Wise</a>
                        <a class="dropdown-item" href="/Training/datewisecon" >Date wise Fee Collection</a>
                        <a class="dropdown-item" href="/Training/reportbwndates" >Fee Collection Between Two Dates</a>
                        <a class="dropdown-item" href="/Training/reportbybook" >Book Wise Fee Reciept Details</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="/Training/admcmpforfuryer" >Admission Comparison for Four Years (MIS)</a>
                        <a class="dropdown-item" href="/Training/ovabstractbyayyear" >Overall Abstract for Academic Year (MIS)</a>
                        <a class="dropdown-item" href="/Training/ovabstractforallcurses" >Overall Abstract for All Courses (MIS)</a>
                        <a class="dropdown-item" href="/Training/ovabstractdueinacy" >Overall Abstract for Dues in Academic year (MIS)</a>
                        <a class="dropdown-item" href="/Training/ovabstractdueinacylinks" >Detailed Overall Abstract for Dues in Academic year (MIS)</a>
                        <a class="dropdown-item" href="/Training/ovabstractduebydiscotnuesinacylinks" >Detailed Overall Abstract for Dues of transfer and discontinued(MIS)</a>
                        <a class="dropdown-item" href="/Training/ovabstractduebyexcludeddiscotnuesinacylinks" >Detailed Overall Abstract for Dues excluding transfer and discontinued(MIS)</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        Extra
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Exams/stdntdetails" >Student Details</a>
                        <a class="dropdown-item" href="/Exams/userdetails" >User Details</a>
                        <a class="dropdown-item" href="/Exams/zeroexam" >Zero Exam Subjects</a>
                        <a class="dropdown-item" href="/Exams/zeroquestion" >Zero Question Subjects</a>
                        <a class="dropdown-item" href="/Exams/texamreports" >Detailed Exam Reports</a>
                        </div>
                    </li>';
                $menu .='<li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                    Results 
                    </a>
                    <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                    <a class="dropdown-item" href="/Main/studentresultfinal" >Student Result</a>
                    <!--<a class="dropdown-item" href="/Main/sattempts" >Student Attempts</a>-->
                    <a class="dropdown-item" href="/Main/semwiseconmarks" >Sem wise Consolidated Marks Report</a>
                    <a class="dropdown-item" href="/Main/sbacklogs" >Sem Wise Student Backlogs</a>
                    <a class="dropdown-item" href="/Main/subwisefailistinsem" >Subject wise Baclogs in Sem</a>
                    <a class="dropdown-item" href="/Main/subwiseresults" >Subject Wise Results</a>
                    <a class="dropdown-item" href="/Main/deptwiseresult" >Semester Wise Result Analysis</a>
                    </div>
                </li>';
                $menu .='<li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
                        '.$_SESSION['name'].'
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Training/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    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();
        }
    }
    public static function userorgchange()
    {
        if($_SESSION['user_role'] == 6)
        {
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            if(static::checkbrower() == 1)
            {
                echo '
                    <div class="container">
                            <div class="container-fluid">
                                <div class="row" style="margin-top:20px;">
                                    <div class="col-xl-4"></div>
                                    <div class="col-xl-4">
                                    <div class="card">
                                        <div class="card-body">
                                            <form action="" method="POST" enctype="multipart/form-data">
                                                <div class="form-group">
                                                    <div class="float-center">Please Select Institution here</div>
                                                </div>
                                                <div class="form-group">
                                                    <select class="form-control" name="orgname" id="orgname" onchange="changeuserorgid()" required>
                                                        <option value="">Select College</option>
                                                        <option value="1">Hindu College - Main Campus (Unaided)</option>
                                                        <option value="2">Hindu College (UG & PG Courses)- Amaravathi Road Campus</option>
                                                        <option value="3">Hindu College of Engineering & Technology</option>
                                                        <option value="4">Hindu College -MCA</option>
                                                        <option value="5">Hindu College of Management</option>
                                                        <option value="6">Hindu College - M.Com</option>
                                                    </select>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                    </div>
                                    <div class="col-xl-4"></div>
                                </div>
                            </div>
                        </div>
                    ';
            }
            echo '</body>';
            echo static::script();
            echo '
                <script>
                    setTimeout(function(){ 
                        $("#orgname").val("'.$_SESSION['org_id'].'");
                    }, 1000);
                    function changeuserorgid()
                    {
                        var orgid = $("#orgname").val();
                        $.ajax({
                            url: "/Training/changeuserorgid",
                            type: "post",
                            data: {orgid: orgid},
                            success: function(d) {
                                if(d == "success")
                                {
                                    swal("Successfull..", "You can view reports of the selected organization now..", "success");
                                    setTimeout(function(){ 
                                        location.reload();
                                    }, 3000);
                                }
                            }
                        });
                    }
                </script>
            ';
        }
    }
    public static function changeuserorgid()
    {
        if($_SESSION['user_role'] == 6)
        {
            if(isset($_POST['orgid']))
            {
                if($_POST['orgid'] != '') 
                {
                    $_SESSION['org_id'] = $_POST['orgid'];
                    echo 'success';
                }
            }
        }
    }
    public static function logout()
    {
        unset($_SESSION['user_id']);
        unset($_SESSION['user_no']);
        unset($_SESSION['name']);
        unset($_SESSION['org_id']);
        unset($_SESSION['mobile']);
        unset($_SESSION['email']);
        unset($_SESSION['user_role']);
        session_unset();
        session_destroy();
        echo '<script>window.location="/Training/index";</script>';
    }
    /** Ending of Login Screen and Authentication */

    /* Start of master section */
    public static function bloodgroup()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            if(isset($_GET['deleteid']))
            {
                Homem::insert("DELETE FROM `blood_group` WHERE `id`='$_GET[deleteid]'");
            }
            $blood = Homem::getdata("SELECT * FROM `blood_group`");
            $table = Form::dbtableed($blood, ['S. No.', 'Blood Group'], ['id', 'name'], '/Training/bloodgroup', 'id', 'id');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Training/savebloodgroup" method="POST">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-4">                                       
                            <div class="row">
                                <div class="col-lg-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">ADD NEW BLOOD GROUP</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 type="text" name="group" id="group" class="form-control" placeholder="Blood Group">
                                                    </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="editid">
                                                    </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-1"></div>
                        <div class="col-lg-5">
                        ';
                        echo $table;
                        echo '
                        </div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                for($i=0; $i<sizeof($blood); $i++)
                {
                    if($blood[$i]['id'] == $_GET['editid'])
                    {
                        echo '
                        <script>
                            $("#group").val("'.$blood[$i]['name'].'");
                            $("#edit_id").val("'.$blood[$i]['id'].'");
                        </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 savebloodgroup()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            if($_POST['edit_id'] != '')
            {
                Homem::insert("UPDATE `blood_group` SET `name`='$_POST[group]' WHERE `id`='$_POST[edit_id]'");
            }
            else
            {
                Homem::insert("INSERT INTO `blood_group`(`name`) VALUES ('$_POST[group]')");
            }
            echo '<script>window.location = "/Training/bloodgroup?status=1";</script>';
        }
    }
    public static function courses()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            $blood = Homem::getdata("SELECT * FROM `degree_name_master`");
            $table = Form::dbtableed($blood, ['S. No.', 'Code', 'Name'], ['id', 'code', 'name'], '/Training/courses', 'id', '');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Training/savecourses" method="POST">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-4">                                       
                            <div class="row">
                                <div class="col-lg-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">ADD NEW COURSE</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 type="text" name="code" id="code" class="form-control" placeholder="Courses Code">
                                                    </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="Course Name">
                                                    </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="editid">
                                                    </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-5">
                        ';
                        echo $table;
                        echo '
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                for($i=0; $i<sizeof($blood); $i++)
                {
                    if($blood[$i]['id'] == $_GET['editid'])
                    {
                        echo '
                        <script>
                            $("#code").val("'.$blood[$i]['code'].'");
                            $("#name").val("'.$blood[$i]['name'].'");
                            $("#edit_id").val("'.$blood[$i]['id'].'");
                        </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 savecourses()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            if($_POST['edit_id'] != '')
            {
                Homem::insert("UPDATE `degree_name_master` SET `code`='$_POST[code]', `name`='$_POST[name]' WHERE `id`='$_POST[edit_id]'");
            }
            else
            {
                Homem::insert("INSERT INTO `degree_name_master`(`code`, `name`) VALUES ('$_POST[code]', '$_POST[name]')");
            }
            echo '<script>window.location = "/Training/courses?status=1";</script>';
        }
    }
    public static function departments()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            $blood = Homem::getdata("SELECT * FROM `degree_dept_master`");
            $table = Form::dbtableed($blood, ['S. No.', 'Name'], ['id', 'name'], '/Training/departments', 'id', '');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Training/savedepartments" method="POST">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-4">                                       
                            <div class="row">
                                <div class="col-lg-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">ADD NEW DEPARTMENT</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">    
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">                                      
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Department Name">
                                                    </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="editid">
                                                    </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-5">
                        ';
                        echo $table;
                        echo '
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                for($i=0; $i<sizeof($blood); $i++)
                {
                    if($blood[$i]['id'] == $_GET['editid'])
                    {
                        echo '
                        <script>
                            $("#name").val("'.$blood[$i]['name'].'");
                            $("#edit_id").val("'.$blood[$i]['id'].'");
                        </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 savedepartments()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            if($_POST['edit_id'] != '')
            {
                Homem::insert("UPDATE `degree_dept_master` SET `name`='$_POST[name]' WHERE `id`='$_POST[edit_id]'");
            }
            else
            {
                Homem::insert("INSERT INTO `degree_dept_master`(`name`) VALUES ('$_POST[name]')");
            }
            echo '<script>window.location = "/Training/departments?status=1";</script>';
        }
    }
    public static function category()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            $blood = Homem::getdata("SELECT * FROM `category`");
            $table = Form::dbtableed($blood, ['S. No.', 'Name'], ['id', 'name'], '/Training/category', 'id', '');
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="clearfix"></div>
                <form action="/Training/savecategory" method="POST">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-4">                                       
                            <div class="row">
                                <div class="col-lg-12">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">ADD NEW CATEGORY</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 type="text" name="name" id="name" 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="edit_id" id="edit_id" class="form-control" placeholder="editid">
                                                    </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-5">
                        ';
                        echo $table;
                        echo '
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                for($i=0; $i<sizeof($blood); $i++)
                {
                    if($blood[$i]['id'] == $_GET['editid'])
                    {
                        echo '
                        <script>
                            $("#name").val("'.$blood[$i]['name'].'");
                            $("#edit_id").val("'.$blood[$i]['id'].'");
                        </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 savecategory()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            if($_POST['edit_id'] != '')
            {
                Homem::insert("UPDATE `category` SET `name`='$_POST[name]' WHERE `id`='$_POST[edit_id]'");
            }
            else
            {
                Homem::insert("INSERT INTO `category`(`name`) VALUES ('$_POST[name]')");
            }
            echo '<script>window.location = "/Training/category?status=1";</script>';
        }
    }
    /* end of master section */

    /* start of fee Setting section */
    public static function allotstdfee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            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="/Training/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: "/Training/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 || $_SESSION['user_role'] == 6)
        {
            $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="/Training/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: "/Training/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 || $_SESSION['user_role'] == 6)
        {
            $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'], '/Training/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: "/Training/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 || $_SESSION['user_role'] == 6)
        {
            $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 = "/Training/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 = "/Training/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 = "/Training/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 = "/Training/allotindstdfee?status=2";</script>';
                        }
                    }
                }
            }
        }
    }
    public static function normalfeeconcession()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            $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'], '/Training/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="/Training/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: "/Training/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: "/Training/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 examfeecollect()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            $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'], '/Training/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="/Training/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: "/Training/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 || $_SESSION['user_role'] == 6)
        {
            $date = date('Y-m-d');
            if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
            {
                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 = "/Training/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 = "/Training/examfeecollect?status=2";</script>';
                }
            }
        }
    }
    public static function nfeecollectbulk()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            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="/Training/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 || $_SESSION['user_role'] == 6)
        {
            $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="/Training/nfeecollectbulk?status=1&count='.$i.'&duplicate='.$j.'";</script>';
                }
            }
        }
    }
    public static function getusername()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            $data[0]['name']= '';
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[no]'");
            echo $data[0]['name'];
        }
    }
    public static function normalfeecolect()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_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]'");
                $blood = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE (sn.entry_date='$date' OR sn.edit_date='$date') AND (sn.entry_id='$_SESSION[user_id]' OR sn.edit_id='$_SESSION[user_id]') AND sn.fk_org_id='$_SESSION[org_id]'");
                $table = Form::dbtableed($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Training/normalfeecolect', '', '');
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Training/savenormalfeecolect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control" required>
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="dueamount" id="dueamount" class="form-control" placeholder="Due Amount" readonly>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount" required>                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number" required>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date" required>
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group"> 
                                                        <input type="hidden" name="sid" id="sid" class="form-control" placeholder="user id" required>
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </div>
                                                </div>                            
                                            </div> 
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                        <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                    </div>
                                                </div>
                                            </div>  
                                        </div>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Training/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: "/Training/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: "/Training/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function savenormalfeecolect()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
            $data1 = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `no`='$_POST[sid]' AND `year`='$_POST[year]' AND `fk_feetype_id`='$_POST[feetype]' AND `amount`='$_POST[paidamount]' AND `recieptno`='$_POST[recieptno]' AND `paid_date`='$_POST[paydate]'");
            if(sizeof($data) == 1)
            {
                if($_POST['edit_id'] == '')
                {
                    if(sizeof($data1) == 0)
                    {
                        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 = "/Training/normalfeecolect?status=1";</script>';
                    }
                    else
                    {
                        echo '<script>window.location = "/Training/normalfeecolect?status=0";</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 = "/Training/normalfeecolect?status=2";</script>';
                }
            }
            else
            {
                echo '<script>window.location = "/Training/normalfeecolect?status=0";</script>';
            }
        }
    }
    public static function getdueamount()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_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'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            if($_POST['no'] != '')
            {
                $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 hnowiseconsreport()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6)
        {
            $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'");
                $fdata = Homem::getdata("SELECT * FROM user_details WHERE `ht_no`='$_POST[htno]'");
                $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'].'" width="250px" height="300px">';
                }
                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);
                    $tactual = 0;
                    $tpaid = 0;
                    $tdue = 0;
                    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>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                                $tactual = $tactual+$actual[$fyear[$j]][$ftype[$i]];
                                                $tpaid = $tpaid+$paid[$fyear[$j]][$ftype[$i]];
                                                $tdue = $tdue+$due[$fyear[$j]][$ftype[$i]];
                                                $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>'.static::datem($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>'.static::datem($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>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                                    $tactual = $tactual+$actual[$fyear[$j]][$ftype[$i]];
                                                    $tpaid = $tpaid+$paid[$fyear[$j]][$ftype[$i]];
                                                    $tdue = $tdue+$due[$fyear[$j]][$ftype[$i]];
                                                    $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>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                            }
                                            if($k == sizeof($data)-1)
                                            {
                                                $g = 0;
                                                // echo 'tets';
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    $a .= '<tr><td colspan="2"><b>Total</b></td><td><b>'.$tactual.'</b></td><td><b>'.$tpaid.'</b></td><td><b>'.$tdue.'</b></td><td colspan="3"></td></tr>';
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                    }
                    $cheader='';
                    $cheader='
                        <tr style="text-align: center;">
                            <th colspan="1">
                                <img src="https://assets.hinduengg.com/hindu/assets/img/logo.png" width="150px" height="150px">
                            </th>
                            <th colspan="7">
                                <h1>Hindu College of Engineering & Technology</h1>
                                <h5>Approved by AICTE, New Delhi and Affiliated to JNTUK, kakinada & APSBTET</h5>
                                <h5>Amaravathi Road, Guntur-522002</h5>
                                <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                            </th>
                        </tr>';
                    if(sizeof($fdata) == 1)
                    {
                        $head = '<thead>
                                '.$cheader.'
                                <tr>
                                    <th colspan="2">Hall Ticket Number</th><th colspan="3">'.$_POST['htno'].'</th>
                                    <th rowspan="6" 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">Father Name</th><th colspan="3">'.$fdata[0]['fname'].'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Course</th><th colspan="3">'.static::course($mdata[0]['fk_course_id']).' ('.static::squota($mdata[0]['squota'], $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>';
                    }
                    else
                    {
                        $head = '<thead>
                                '.$cheader.'
                                <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">Course</th><th colspan="3">'.static::course($mdata[0]['fk_course_id']).' ('.static::squota($mdata[0]['squota'], $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 print-this" 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 slist()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_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');
            $a = '';
            if(isset($_POST['course']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `fk_course_id`='$_POST[course]' AND `fk_dept_id`='$_POST[department]' AND `org_id`='$_SESSION[org_id]' AND `fromyear`='$_POST[fromyear]' AND `toyear`='$_POST[toyear]' AND `user_role`='3' ORDER BY `no` ASC");
                if(sizeof($data) > 0)
                {
                    $table = Form::dbtableed($data, ['Admission Number', 'Hall Ticket Number', 'Name', 'Gender'], ['ano', 'no', 'name', 'gender'], '/Training/addstudent', 'id', '');
                    $a = '
                            <div class="row">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                '.$table.'
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                        ';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">List by Department</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo $enyear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>'.$a.'
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function addstudent()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $blood = Inputs::optionsdb(Homem::getdata("SELECT * FROM `blood_group`"), 'id', 'name');
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/Training/saveaddstudent" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h4 class="title pull-left">ADD NEW STUDENT</h4>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">  
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                      
                                                            <input type="text" name="admission" id="admission" class="form-control" placeholder="Admission Number" required>
                                                        </div>
                                                    </div>      
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                      
                                                            <select type="text" name="quota" id="quota" class="form-control" required>
                                                                <option value="">Select Admission Type</option>    
                                                                <option value="M">Convener Quota</option>
                                                                <option value="M">Management Quota</option>
                                                                <option value="M">Spot Admission</option>
                                                            </select>
                                                        </div>
                                                    </div>                          
                                                </div>  
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                      
                                                            <input type="text" name="hallticket" id="hallticket" class="form-control" placeholder="Hall Ticket Number" required readonly>
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="name" id="name" class="form-control" placeholder="Student Name">
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  
                                                            <input type="text" name="dob" id="dob" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Date of Birth">                                          
                                                        </div>
                                                    </div>                              
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="gender" id="gender" class="form-control">
                                                            <option value="">Select Gender</option>
                                                            <option value="M">Male</option>
                                                            <option value="F">Female</option>
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="bloodgroup" id="bloodgroup" class="form-control">
                                                            <option value="">Select Blood Group</option>
                                                            '; 
                                                            echo $blood;
                                                            echo '</select>
                                                        </div>
                                                    </div> 	
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="nyears" id="nyears" class="form-control">
                                                            <option value="">Number of Years of Course</option>
                                                            <option value="1">1</option>
                                                            <option value="2">2</option>
                                                            <option value="3">3</option>
                                                            <option value="4">4</option>
                                                            </select>
                                                        </div>
                                                    </div>  									
                                                </div>  
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control">
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control">
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control">
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control">
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo static::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="regulation" id="regulation" class="form-control" placeholder="Regulation">
                                                        </div>
                                                    </div> 										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Mobile Number" maxlength="10" onkeypress="return isNumber(event)">
                                                        </div>
                                                    </div>  									
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="email" id="email" class="form-control" placeholder="Email Address">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">                                            
                                                            <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">
                                                        </div>
                                                    </div>  										
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_GET[editid]' AND `org_id`='$_SESSION[org_id]' AND `user_role`='3'");
                if(sizeof($data) == 1)
                {
                    echo '
                        <script>
                        
                        
                            $("#admission").val("'.$data[0]['ano'].'");
                            $("#quota").val("'.$data[0]['squota'].'");
                            $("#nyears").val("'.$data[0]['noofyears'].'");
                            $("#hallticket").val("'.$data[0]['no'].'");
                            $("#name").val("'.$data[0]['name'].'");
                            $("#dob").val("'.$data[0]['dob'].'");
                            $("#gender").val("'.$data[0]['gender'].'");
                            $("#bloodgroup").val("'.$data[0]['blood_group'].'");
                            $("#course").val("'.$data[0]['fk_course_id'].'");
                            $("#department").val("'.$data[0]['fk_dept_id'].'");
                            $("#fromyear").val("'.$data[0]['fromyear'].'");
                            $("#toyear").val("'.$data[0]['toyear'].'");
                            $("#regulation").val("'.$data[0]['regulation'].'");
                            $("#mobile").val("'.$data[0]['mobile'].'");
                            $("#email").val("'.$data[0]['email'].'");
                            $("#edit_id").val("'.$_GET['editid'].'");
                        </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success"); delay(5000); window.location.href="/Training/home";</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success"); delay(5000); window.location.href="/Training/home"; </script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error"); delay(5000); window.location="/Training/home";</script>';
                }
            }
        }
    }
    public static function saveaddstudent()
    {
        if($_SESSION['user_role'] != '')
        {
            if($_POST['edit_id'] == '')
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]'"));
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]'"));
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[hallticket]' AND `org_id`='$_POST[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 0)
                {
                    $query = "INSERT INTO `user_master`(`no`, `name`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`) VALUES ('$_POST[hallticket]', '$_POST[name]', '$_POST[dob]', '$_POST[gender]', '$_POST[bloodgroup]', '$_POST[course]', '$_POST[department]', '$_SESSION[org_id]', '$_POST[fromyear]', '$_POST[toyear]', '$_POST[regulation]', '$_POST[mobile]', '$_POST[email]', '$_POST[hallticket]', '3', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Training/addstudent?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Training/addstudent?status=0";</script>';
                }
            }
            else
            {
                $mdata = 0;
                if($_POST['mobile'] != '')
                {
                    $mdata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' OR `id`='$_POST[edit_id]'"));
                    if($mdata1 == 1)
                    {
                        $mdata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='$_POST[mobile]' AND `id`='$_POST[edit_id]'"));
                        if(($mdata2 == 0) || ($mdata2 == 1))
                        {
                            $mdata = 0;
                        }
                        else
                        {
                            $mdata = 1;
                        }
                    }
                    else
                    {
                        $mdata = 1;
                    }
                }
                $edata = 0;
                if($_POST['email'] != '')
                {
                    $edata1 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' OR `id`='$_POST[edit_id]'"));
                    if($edata1 == 1)
                    {
                        $edata2 = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `email`='$_POST[email]' AND `id`='$_POST[edit_id]'"));
                        if(($edata2 == 0) || ($edata2 == 1))
                        {
                            $edata = 0;
                        }
                        else
                        {
                            $edata = 1;
                        }
                    }
                    else
                    {
                        $edata = 1;
                    }
                }
                $data = sizeof(Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[edit_id]' AND `org_id`='$_SESSION[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 1)
                {
                    $query = "UPDATE `user_master` SET `ano`='$_POST[admission]', `squota`='$_POST[quota]', `noofyears`='$_POST[nyears]', `no`='$_POST[hallticket]', `name`='$_POST[name]', `dob`='$_POST[dob]', 
                    `gender`='$_POST[gender]', `blood_group`='$_POST[bloodgroup]', `fk_course_id`='$_POST[course]', 
                    `fk_dept_id`='$_POST[department]', `org_id`='$_SESSION[org_id]', `fromyear`='$_POST[fromyear]', 
                    `toyear`='$_POST[toyear]', `regulation`='$_POST[regulation]', `mobile`='$_POST[mobile]', `email`='$_POST[email]', `password`='$_POST[hallticket]', 
                    `user_role`='3', `status`='1' WHERE `id`='$_POST[edit_id]'";
                    Homem::insert($query);
                    echo '<script>window.location = "/Training/addstudent?status=2";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Training/addstudent?status=0";</script>';
                }
            }
        }
    }
    public static function print()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT a.*, fm.name as feemode, u.name as opname FROM (SELECT sn.recieptno, sn.amount, sn.paid_date, sn.year, sn.fk_feetype_id, sn.fk_feemode_id, sn.entry_id, um.no, um.name, um.fk_course_id, um.fk_dept_id FROM stdnt_normalfee sn JOIN user_master um ON sn.no=um.id WHERE sn.nid='469') a JOIN fee_mode fm ON a.fk_feemode_id=fm.id JOIN user_master u ON a.entry_id=u.id");
            }
            if(sizeof($data) == 1)
            {
                echo static::css();
                echo '<body>';
                echo $_SESSION['menu'];
                echo '
                    <form action="" method="POST">
                        <div class="container-fluid">
                            <div class="row print-this">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        <tr style="text-align: center;">
                                                            <td>
                                                                <img src="https://assets.hinduengg.com/hindu/assets/img/logo.png" width="150px" height="150px">
                                                            </td>
                                                            <td>
                                                                <h1>Hindu College of Engineering & Technology</h1>
                                                                <h5>Approved by AICTE, New Delhi and Affiliated to JNTUK, kakinada & APSBTET</h5>
                                                                <h5>Amaravathi Road, Guntur-522002</h5>
                                                                <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td><span style="margin-left: 10px;">Reciept Number: '.$data[0]['recieptno'].'</span></td>
                                                            <td style="text-align: right;"><span style="margin-right: 10px;">Date: '.static::datem($data[0]['paid_date']).'</span></td>
                                                        </tr>
                                                        <tr>
                                                            <td colspan="2">
                                                                <hr />
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>Name : &nbsp; </b>'.$data[0]['name'].'</span>
                                                            </td>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>Department :  &nbsp; </b>'.static::course($data[0]['fk_course_id']).'-'.static::dept($data[0]['fk_dept_id']).'</span>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>HT No. / PIN : &nbsp; </b>'.$data[0]['no'].'</span>
                                                            </td>
                                                            <td width="50%">
                                                                <span style="margin-left: 10px;"><b>Year :  &nbsp; </b>'.static::nyear($data[0]['year']).'</span>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <table width="90%" align="center" style="border: 2px single black;">
                                                    <tbody>
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                <b>Fee Particulars</b>
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                <b>Amount (Rs.)</b>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                    <tbody>
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                '.static::feetype($data[0]['fk_feetype_id']).'
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                '.number_format($data[0]['amount'], 2).'
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td colspan="2">
                                                                <span style="margin-left: 10px;"><b>Amount in words: </b>'.static::numtotext($data[0]['amount']).'</span>
                                                            </td>
                                                            <td style="text-align: right;">
                                                                <span style="margin-right: 10px;">
                                                                    <b>Mode of payment: </b> '.$data[0]['feemode'].'
                                                                </span>
                                                            </td>
                                                        </tr>
                                                        <tr style="text-align: center;">
                                                            <td colspan="3" style="text-align: right;">
                                                                <span style="margin-right: 10px; margin-top: 20px;">
                                                                    <br><br><br>
                                                                    <b>Office Inchage / Accountant </b> <br>('.$data[0]['opname'].')
                                                                </span>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                            <div class="row">
                                <div class="col-lg-1"></div>
                                <div class="col-lg-10">
                                    <button onclick="window.print()">Print this page</button>
                                </div>
                                <div class="col-lg-1"></div>
                            </div>
                        </div>
                    </form>';
            }
            echo '</body>';
            echo static::script();
        }
    }
    /* end of fee collection section */

    public static function deptwiseconsol()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 ||  $_SESSION['user_role'] == 5)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $subtable = '';
            $a = '';
            if(isset($_POST['course']))
            {
                if($_POST['squota'] == 1)
                {
                    $_POST['squota'] = 'C';
                    $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.squota='$_POST[squota]' 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.squota='$_POST[squota]' AND sf.fk_feetype_id='$_POST[feetype]'");
                }
                if($_POST['squota'] == 2)
                {
                    $_POST['squota'] = 'C';
                    $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.squota!='$_POST[squota]' 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.squota!='$_POST[squota]' AND sf.fk_feetype_id='$_POST[feetype]'");
                
                }
                if($_POST['squota'] == 'ALL')
                {
                    $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 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 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]]['quota'] = $masterdata[$k]['squota'];
                                    $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;
                            }
                        }
                    }
                    if($_POST['year'] == "ALL")
                    {
                        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>';
                            $a.='<td>'.$data[$no[$i]]['quota'].'</td>';
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                for($j=0; $j<sizeof($fyear); $j++)
                                {
                                    if($count < sizeof($fyear))
                                    {
                                        if($_POST['year'] == "ALL")
                                        {
                                            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>';
                        $a .= '<td></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>';
                        $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>
                                        <th rowspan="2">Admission Type</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 print-this" border="1px">'.$head.'
                                '.$body.'
                                </table>
                            </div>
                        ';
                        $subtable .= $table;
                        $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                    }
                    if($_POST['year'] != "ALL")
                    {
                        $totaldue = 0;
                            $totalpaid = 0;
                            $totalactual = 0;
                        for($i=0; $i<sizeof($no); $i++)
                        {
                            // $count = 0;
                            // for($k=0; $k<sizeof($data); $k++)
                            {
                                if(isset($data[$no[$i]][$_POST['year']]['actualamount']))
                                {
                                    $sno = $i+1;
                                    $a.='<tr>';
                                        $a.='<td>'.$sno.'</td>';
                                        $a.='<td>'.$no[$i].'</td>';
                                        $a.='<td>'.$data[$no[$i]]['name'].'</td>';
                                        $a.='<td>'.$data[$no[$i]]['quota'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$_POST['year']]['actualamount'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$_POST['year']]['paidamount'].'</td>';
                                        $a.='<td>'.$data[$no[$i]][$_POST['year']]['dueamount'].'</td>';
                                        $totalactual = $totalactual+$data[$no[$i]][$_POST['year']]['actualamount'];
                                        $totalpaid = $totalpaid+$data[$no[$i]][$_POST['year']]['paidamount'];
                                        $totaldue = $totaldue+$data[$no[$i]][$_POST['year']]['dueamount'];
                                    $a.='</tr>';
                                    if($i ==sizeof($no)-1)
                                    {
                                        $a.='<tr>';
                                            $a.='<td colspan="3">Total Fee Collection Details</td>';
                                            $a.='<td></td>';
                                            $a.='<td>'.$totalactual.'</td>';
                                            $a.='<td>'.$totalpaid.'</td>';
                                            $a.='<td>'.$totaldue.'</td>';
                                        $a.='</tr>';
                                    }
                                }
                            }
                            
                        }
                        $headyears = '';
                        $headcols = '';
                        $head = '<thead>
                                    <tr>
                                        <th rowspan="2">S. No</th>
                                        <th rowspan="2">Hall Ticket Number</th>
                                        <th rowspan="2">Name of the student</th>
                                        <th rowspan="2">Admission Type</th>
                                        <th rowspan="2">Total Actual Amount</th>
                                        <th rowspan="2">Total Paid Amount</th>
                                        <th rowspan="2">Total Due Amount</th>
                                    </tr>
                                </thead>';
                        $body = '<tbody>'; 
                        $body .= $a;
                        $body .= '</tbody>';
                        $table = '
                            <div class="table-responsive" id="exporttable">
                                <table class="table table-responsive-sm print-this" 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="squota" id="squota" class="form-control" required>
                                                                <option value="">Select Admission Type</option>
                                                                <option value="1">Convenor Quota</option>
                                                                <option value="2">Spot / Management Quota</option>
                                                                <option value="ALL">All Types</option>
                                                            </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>
                                                                <option value="ALL">All Years</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 coursewiseconsol()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            $course = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_name_master`"), 'id', 'code');
            $dept = Inputs::optionsdb(Homem::getdata("SELECT * FROM `degree_dept_master`"), 'id', 'name');
            $styear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT fromyear FROM `user_master` where `fromyear`!='' AND `user_role`='3' ORDER BY `fromyear` ASC"), 'fromyear', 'fromyear');
            $enyear = Inputs::optionsdb(Homem::getdata("SELECT DISTINCT toyear FROM `user_master` where `toyear`!='' AND `user_role`='3' ORDER BY `toyear` ASC"), 'toyear', 'toyear');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_types`"), 'f_id', 'f_name');
            $subtable = '';
            $a = '';
            if(isset($_POST['course']))
            {
                $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_POST[course]' AND sf.fk_feetype_id='$_POST[feetype]'");
                $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]]['quota'] = $masterdata[$k]['squota'];
                                    $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>';
                        $a.='<td>'.$data[$no[$i]]['quota'].'</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>
                                    <th rowspan="2">Admission Type</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>';
                }
            }
        }   
    }
    /** Basic Reports for adminstrator */
    public static function dailyreport()
    {
        if($_SESSION['user_role'] == 6)
        {
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON sn.entry_id=um.id");
            if(sizeof($data) > 0)
            {
                $a = '';
                $head = '<thead><tr><th>Date</th><th>Name</th><th>No of Reciepts Entered</th><th>Total Amount</th></tr></thead>';
                $dates = array();
                $id = array();
                foreach ($data as $h) 
                {
                    $dates[] = $h['entry_date'];
                    $id[] = $h['entry_id'];
                }
                $edate = array_values(array_unique($dates));
                sort($edate);
                $uid = array_values(array_unique($id));
                sort($uid);
                for($j=0; $j<sizeof($uid); $j++)
                {
                    for($k=0; $k<sizeof($data); $k++)
                    {
                        if($uid[$j] == $data[$k]['id'])
                        {
                            $name[$uid[$j]] = $data[$k]['name'];
                        }
                    }
                }
                $tamount = 0;
                $tcount = 0;
                for($i=0; $i<sizeof($edate); $i++)
                {
                    for($j=0; $j<sizeof($uid); $j++)
                    {
                        $amount = 0;
                        $count = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($data[$k]['entry_date'] == $edate[$i] && $data[$k]['entry_id'] == $uid[$j])
                            {
                                $count++;
                                $amount = $amount+$data[$k]['amount'];
                                $tcount++;
                                $tamount = $tamount+$data[$k]['amount'];
                            }
                            if($k == sizeof($data)-1)
                            {
                                $details[$edate[$i]][$uid[$j]]['count'] = $count;
                                $details[$edate[$i]][$uid[$j]]['amount'] = $amount;
                            }
                        }
                    }
                }
                for($i=0; $i<sizeof($edate); $i++)
                {
                    for($j=0; $j<sizeof($uid); $j++)
                    {
                        if($j == 0)
                        {
                            $a .= '<tr>';
                            $a .= '<td rowspan="'.sizeof($uid).'">';
                            $a .= $edate[$i];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $name[$uid[$j]];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['count'];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['amount'];
                            $a .= '</td>';
                        }
                        else
                        {
                            $a .= '<tr>';
                            $a .= '<td>';
                            $a .= $name[$uid[$j]];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['count'];
                            $a .= '</td>';
                            $a .= '<td>';
                            $a .= $details[$edate[$i]][$uid[$j]]['amount'];
                            $a .= '</td>';
                        }
                        $a .= '</tr>';
                    }
                }
                $a .= '<tr><td>Total Days: '.sizeof($edate).'</td><td>Total Users: '.sizeof($uid).'</td><td>Total Recipts: '.$tcount.'</td><td>Total Amount: '.$tamount.'</td></tr>';
                $body = $a;
                $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-3">
                            </div>
                            <div class="col-lg-6"> 
                                <form action="" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <header class="panel_header">
                                                    <h5 class="title pull-left">Daily Accounts Report (By Entry Date)</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                '.$table.'
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <!--
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    -->
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="col-lg-3">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Training/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function datewisecon()
    {
        if($_SESSION['user_role'] == 6)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['date']))
            {
                $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE sn.paid_date='$_POST[date]' order by sn.no ASC");
                if(sizeof($data) > 0)
                {
                    $total = 0;
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.static::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.static::feetype($data[$i]['fk_feetype_id']).'</td>
                                </tr>';
                        $total = $total+$data[$i]['amount'];
                        if($i == sizeof($data)-1)
                        {
                            $a .= '<tr>
                                    <td colspan="3"><b>Total Amount Collected</b></td>
                                    <td><b>'.$total.'</b></td>
                                    <td colspan="4"></td>
                                </tr>';
                        }
                    }
                    $head = '<thead>
                                <tr>
                                    <th>S. No.</th>
                                    
                                    <th>Hallticket Number</th>
                                    <th>Name of the Student</th>
                                    <th>Amount</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Branch</th>
                                    <th>Fee Type</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Date Wise Fee Collection Report</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="Select Date" class="form-control" name="date" id="date" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function reportbwndates()
    {
        // Month & Year
        // $date = '2021-03-';
        // $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `paid_date` LIKE '%$date%'");
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['fromdate']))
            {
                $date1 = $_POST['fromdate'];
                $date2 = $_POST['todate'];
                // $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2'");
                $data = Homem::getdata("SELECT * FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2') a JOIN user_master um ON um.id=a.no ORDER BY a.paid_date ASC");

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

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