<?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;
use App\Controllers\Extra;
class Accounts extends \Core\Controller
{

    public static function ip()
    {
        // Check for shared internet/ISP IP
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        }
        // Check if the user is behind a proxy
        elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        // Otherwise, use the remote IP address
        else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        // Return the IP address (it may contain multiple IPs if behind proxies)
        return $ip;
    }
    public static function getUserAgent() {
        // Access the user agent from the $_SERVER array
        return $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown';
    }
    public static function getUserData() 
    {
        $data = [];
    
        $data['IP Address'] = $_SERVER['REMOTE_ADDR'] ?? 'Unknown IP';
        $data['User Agent'] = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown User Agent';
        $data['Referrer'] = $_SERVER['HTTP_REFERER'] ?? 'No Referrer';
        $data['Accepted Languages'] = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'No Language Preference';
        $data['Request Method'] = $_SERVER['REQUEST_METHOD'] ?? 'Unknown Method';
        $data['Current Script'] = $_SERVER['SCRIPT_NAME'] ?? 'Unknown Script';
        $data['Query String'] = $_SERVER['QUERY_STRING'] ?? 'No Query String';
        
        return $data;
    }
    public static function sevdata()
    {
        $user_data = static::getUserData();
        foreach ($user_data as $key => $value) {
            echo "$key: $value<br>";
        }
        $hostname = gethostname(); // Get the hostname of the server
        $internal_ip = gethostbyname($hostname); // Resolve the hostname to an IP address
        
        echo "Internal IP Address: " . $internal_ip;
        echo "Local IP Address: " . static::getLocalIPAddress();
        $device_type = static::getDeviceType();
        echo "Device Type: " . $device_type;
    }
    public static function getLocalIPAddress() {
    // Create a socket
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    if ($socket === false) {
        return 'Unable to create socket';
    }
    
    // Connect to a remote server (this could be any valid IP)
    socket_connect($socket, '8.8.8.8', 80); // Google Public DNS

    // Get local address
    socket_getsockname($socket, $local_ip);
    socket_close($socket); // Close the socket

    return $local_ip;
    }
    public static function getDeviceType() {
        $user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown User Agent';
    
        if (preg_match('/mobile/i', $user_agent)) {
            return 'Mobile';
        } elseif (preg_match('/tablet/i', $user_agent)) {
            return 'Tablet';
        } elseif (preg_match('/laptop|desktop/i', $user_agent)) {
            return 'Desktop/Laptop';
        } else {
            return 'Unknown Device';
        }
    }
    public static function bobspiltup()
    {
        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 um.fk_course_id, um.fk_dept_id, ddm.aided, sn.paid_date, sn.entry_date, sn.amount FROM user_master um JOIN stdnt_normalfee sn ON um.id=sn.no JOIN degree_dept_master ddm ON um.fk_dept_id=ddm.id WHERE sn.fk_feetype_id='2' AND sn.fk_feemode_id!='5' AND DATE(sn.paid_date) BETWEEN '$date1' AND '$date2'");
                $course = array();
                $opname = array();
                $feetype = array();
                $pdate = array();
                foreach ($data as $h) {
                    $feetype[] = $h['fk_dept_id'];
                    $course[] = $h['fk_course_id'];
                    $pdate[] = $h['paid_date'];
                }
                $curse = array_values(array_unique($course));
                sort($curse);
                $ftype = array_values(array_unique($feetype));
                sort($ftype);
                $paiddate = array_values(array_unique($pdate));
                sort($paiddate);
                $acc = array();
                $acc = ["Inter", "UGAided", "UGUnaided", "PG"];
                $total = 0;
                for($i=0; $i<sizeof($paiddate); $i++)
                {
                    $nacc[$paiddate[$i]]["Inter"] = 0;
                    $nacc[$paiddate[$i]]["UGAided"] = 0;
                    $nacc[$paiddate[$i]]["UGUnaided"] = 0;
                    $nacc[$paiddate[$i]]["PG"] = 0;
                    for($j=0; $j<sizeof($data); $j++)
                    {
                        if($data[$j]["paid_date"] == $paiddate[$i])
                        {
                            if($data[$j]["fk_course_id"] == 4)
                            {
                                $nacc[$paiddate[$i]]["Inter"] = $nacc[$paiddate[$i]]["Inter"]+$data[$j]["amount"];
                                $total = $total + $data[$j]["amount"];
                            }
                            if($data[$j]["fk_course_id"] == 5)
                            {
                                $nacc[$paiddate[$i]]["PG"] = $nacc[$paiddate[$i]]["PG"]+$data[$j]["amount"];
                                $total = $total + $data[$j]["amount"];
                            }
                            if($data[$j]["fk_course_id"] != 5 && $data[$j]["fk_course_id"] != 4)
                            {
                                if($data[$j]["aided"] == 0)
                                {
                                    $nacc[$paiddate[$i]]["UGUnaided"] = $nacc[$paiddate[$i]]["UGUnaided"]+$data[$j]["amount"];
                                    $total = $total + $data[$j]["amount"];
                                }
                                if($data[$j]["aided"] == 1)
                                {
                                    $nacc[$paiddate[$i]]["UGAided"] = $nacc[$paiddate[$i]]["UGAided"]+$data[$j]["amount"];
                                    $total = $total + $data[$j]["amount"];
                                }
                            }
                        }
                        
                    }
                }
                $k = 0;
                for($i=0; $i<sizeof($paiddate); $i++)
                {
                    for($j=0; $j<sizeof($acc); $j++)
                    {
                        $k = $k+1;
                        $a .= '<tr>';
                        $a .= '<td>'.$k.'</td>';
                        $a .= '<td>'.$paiddate[$i].'</td>';
                        $a .= '<td>'.$acc[$j].'</td>';
                        $a .= '<td>'.$nacc[$paiddate[$i]][$acc[$j]].'</td>';
                        $a .= '</tr>';
                    }
                }
                
                // print_r($data);
                // print_r($accounts);
                $head = '<thead>
                                <tr><th colspan="2">Date wise Fee Collection Report </th><th colspan="1">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="2">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Date</th>
                                    <th>Bank Account</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$total.'</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 json_encode($udet);
            echo Menus::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 Menus::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 reportbwndateswithopnameconsolidatedbyuserid()
    {
        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 a.*, um.*, u.name as opname FROM (SELECT * FROM `stdnt_normalfee` WHERE `entry_id`='$_POST[user]' AND DATE(paid_date) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.no JOIN user_master u ON u.id=a.entry_id AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");
                $course = array();
                $opname = array();
                $feetype = array();
                $pdate = array();
                foreach ($data as $h) {
                    $feetype[] = $h['fk_feetype_id'];
                    $opname[] = $h['opname'];
                    $course[] = $h['fk_course_id'];
                    $pdate[] = $h['paid_date'];
                }
                $curse = array_values(array_unique($course));
                sort($curse);
                $name = array_values(array_unique($opname));
                sort($name);
                $ftype = array_values(array_unique($feetype));
                sort($ftype);
                $paiddate = array_values(array_unique($pdate));
                sort($paiddate);
                $acc = array();
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        $acc[] = Extra::feeaccount($curse[$j], $ftype[$k]);
                    }
                }
                $accounts = array_values(array_unique($acc));
                sort($accounts);
                
                // echo json_encode($accounts);
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    for($i=0; $i<sizeof($name); $i++)
                    {
                        for($j=0; $j<sizeof($curse); $j++)
                        {
                            for($k=0; $k<sizeof($ftype); $k++)
                            {
                                if(!isset($uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]))
                                {
                                    $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = 0;
                                }
                                if(!isset($udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                                {
                                    
                                    $udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                                }
                                for($l=0; $l<sizeof($data); $l++)
                                {
                                    if($paiddate[$h] == $data[$l]['paid_date'] && $name[$i] == $data[$l]['opname'] && $curse[$j] == $data[$l]['fk_course_id'] && $ftype[$k] == $data[$l]['fk_feetype_id'])
                                    {
                                        $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = (int)$uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]+(int)$data[$l]['amount'];
                                        $udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = (int)$udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]+(int)$data[$l]['amount'];
                                        // echo $data[$l]['nid'];
                                    }
                                }
                            }
                        }
                    }
                }
                
                $total = 0;
                $s=1;
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    for($i=0; $i<sizeof($name); $i++)
                    {
                        for($j=0; $j<sizeof($accounts); $j++)
                        {
                            if(isset($udet[$paiddate[$h]][$name[$i]][$accounts[$j]]))
                            {
                                if($udet[$paiddate[$h]][$name[$i]][$accounts[$j]] > 0)
                                {
                                    $a .= '<tr><td>'.$s.'</td><td>'.$paiddate[$h].'</td><td>'.$name[$i].'</td><td>'.$accounts[$j].'</td><td>'.$udet[$paiddate[$h]][$name[$i]][$accounts[$j]].'</td></tr>';
                                    $total = $total+(int)$udet[$paiddate[$h]][$name[$i]][$accounts[$j]];
                                    $s++;
                                }
                            }
                        }
                    }
                }
                $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_examfee se JOIN user_master um ON um.id=se.entry_id WHERE se.entry_id='$_POST[user]' AND DATE(se.entry_date) BETWEEN '$date1' AND '$date2'");
                $opname = array();
                $pdate = array();
                foreach ($data as $h) {
                    $opname[] = $h['opname'];
                    $pdate[] = $h['entry_date'];
                }
                $ename = array_values(array_unique($opname));
                sort($ename);
                $epaiddate = array_values(array_unique($pdate));
                sort($epaiddate);
                $examaccounts[] = 'Exam Fee 14143-UBI';
                for($i=0; $i<sizeof($ename); $i++)
                {
                    for($j=0; $j<sizeof($epaiddate); $j++)
                    {
                        $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee 14143-UBI'] = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['entry_date'])
                            {
                                $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee 14143-UBI']+(int)$data[$k]['paidamount'];
                            }
                        }
                    }
                }
                for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($examaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$examaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                if($_SESSION["org_id"] == 1)
                {
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_provisionaladmissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE se.fk_user_id=$_POST[user] AND DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Pro-Inter Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Pro-Degree Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Pro-PG Fee 376-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Pro-Inter Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['Pro-Inter Fee 27950-BOB']+(int)$data[$k]['amount'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Pro-PG Fee 376-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Pro-PG Fee 376-UBI']+(int)$data[$k]['amount'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Pro-Degree Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['Pro-Degree Fee 27950-BOB']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proadmaccounts = array("Pro-Inter Fee 27950-BOB", "Pro-Degree Fee 27950-BOB", "Pro-PG Fee 376-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proadmaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proadmaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_admissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE se.fk_user_id=$_POST[user] AND DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['App-Inter Fee 14143-UBI'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['App-Degree Fee 14143-UBI'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['App-PG Fee 376-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['App-Inter Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['App-Inter Fee 14143-UBI']+(int)$data[$k]['amount'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['App-PG Fee 376-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['App-PG Fee 376-UBI']+(int)$data[$k]['amount'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['App-Degree Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['App-Degree Fee 14143-UBI']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proappaccounts = array("App-Inter Fee 14143-UBI", "App-Degree Fee 14143-UBI", "App-PG Fee 376-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proappaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proappaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_additionalfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE se.fk_user_id=$_POST[user] AND DATE(se.paid_date) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['paid_date'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Add-Inter Fee 14143-UBI'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Add-Degree Fee 14143-UBI'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Add-PG Fee 376-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['paid_date'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Add-Inter Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Add-Inter Fee 14143-UBI']+(int)$data[$k]['total'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Add-PG Fee 376-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Add-PG Fee 376-UBI']+(int)$data[$k]['total'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Add-Degree Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Add-Degree Fee 14143-UBI']+(int)$data[$k]['total'];
                                    }
                                }
                            }
                        }
                    }
                    $proaddaccounts = array("Add-Inter Fee 14143-UBI", "Add-Degree Fee 14143-UBI", "Add-PG Fee 376-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_monthlyfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE se.fk_user_id=$_POST[user] AND DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Mon-Inter Fee'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Mon-Degree Fee'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Mon-PG Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Mon-Inter Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Mon-Inter Fee']+(int)$data[$k]['amount'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Mon-PG Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Mon-PG Fee']+(int)$data[$k]['amount'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Mon-Degree Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Mon-Degree Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $promonaccounts = array("Mon-Inter Fee", "Mon-Degree Fee", "Mon-PG Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($promonaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$promonaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    
                    
                    // Event Fee Start
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdent_eventfee se JOIN user_master um ON um.id=se.fk_user_id WHERE se.fk_user_id=$_POST[user] AND DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    // print_r($data);
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Event Fee 14143-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Event Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Event Fee 14143-UBI']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $eventaddaccounts = array("Event Fee 14143-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($eventaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$eventaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_provisionaladmissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE se.fk_user_id=$_POST[user] AND DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Provisional Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Provisional Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Provisional Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proadmaccounts = array("Provisional Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proadmaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proadmaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_admissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE se.fk_user_id=$_POST[user] AND DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Application Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Application Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Application Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proappaccounts = array("Application Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proappaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proappaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_additionalfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE se.fk_user_id=$_POST[user] AND DATE(se.paid_date) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['paid_date'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Additional Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['paid_date'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Additional Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Additional Fee']+(int)$data[$k]['total'];
                                    }
                                }
                            }
                        }
                    }
                    $proaddaccounts = array("Additional Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_monthlyfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE se.fk_user_id=$_POST[user] AND DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Monthly Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Monthly Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Monthly Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $promonaccounts = array("Monthly Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($promonaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$promonaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_additional_addfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE se.fk_user_id=$_POST[user] AND DATE(se.paid_date) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['paid_date'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Provisional-Additional Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['paid_date'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Provisional-Additional Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Provisional-Additional Fee']+(int)$data[$k]['total'];
                                    }
                                }
                            }
                        }
                    }
                    $proadmaddaccounts = array("Provisional-Additional Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proadmaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proadmaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    
                    
                
                    // Event Fee Start
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdent_eventfee se JOIN user_master um ON um.id=se.fk_user_id WHERE se.fk_user_id=$_POST[user] AND DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    // print_r($data);
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Event Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Event Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Event Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $eventaddaccounts = array("Event Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($eventaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$eventaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]].'</td></tr>';
                                        // $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                }
                
                
                
                // print_r($data);
                // print_r($accounts);
                $head = '<thead>
                                <tr><th colspan="2">Date wise Fee Collection Report </th><th colspan="1">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="2">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Date</th>
                                    <th>Name of the operator</th>
                                    <th>Bank Account</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$total.'</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 json_encode($udet);
            if($_SESSION["org_id"] == 1)
            {
                $users=Inputs::optionsdb(Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='5' AND `status`='1' AND `id`='$_SESSION[user_id]'"),"id","name");
            }
            else
            {
                $users=Inputs::optionsdb(Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='5' AND `status`='1'"),"id","name");
            }
            echo Menus::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">             
                                                        <select name="user" id="user" class="form-control">
                                                        <option value="">Select Operator</option>
                                                        '.$users.'
                                                        </select>                               
                                                        </div>
                                                    </div>
                                                    <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 Menus::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 getstudentfeedetails()
    {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[no]'");
        if(sizeof($data) == 1)
        {
            $id = $data[0]["id"];
            $fdata = Homem::getdata("SELECT DISTINCT year, SUM(feeamount) as actual FROM `stdnt_feemaster` WHERE `no`='$id' GROUP BY year");
            $pdata = Homem::getdata("SELECT DISTINCT year, SUM(amount) as paid FROM stdnt_normalfee WHERE no='$id' GROUP BY year");
            $y = array();
            foreach ($fdata as $h) 
            {
                $y[] = $h['year'];
            }
            $year = array_values(array_unique($y));
            sort($year);
            // echo json_encode($fdata);
            echo '<table border="1px">';
            echo '<thead><tr><td>year</td><td>Actual</td><td>Due</td></tr></thead>';
            echo '<tbody>';
            for($h=0; $h<sizeof($year); $h++)
            {
                echo '<tr>';
                echo '<td>'.$year[$h].'</td>';
                for($i=0; $i<sizeof($fdata); $i++)
                {
                    if($year[$h] == $fdata[$i]['year'])
                    {
                        echo '<td>'.$fdata[$i]['actual'].'</td>';
                        $due = 0;
                        $status = 0;
                        for($j=0; $j<sizeof($pdata); $j++)
                        {
                            if($year[$h] == $pdata[$j]['year'])
                            {
                                $due = $fdata[$i]['actual']-$pdata[$i]['paid'];
                                echo '<td>'.$due.'</td>';
                                $status = 1;
                            }
                            if($status == 0 && $j == sizeof($pdata)-1)
                            {
                                echo '<td>'.$fdata[$i]['actual'].'</td>';
                            }
                        }
                    }
                }
                echo '</tr>';
            }
            echo '</tbody>';
            echo '</table>';
        }
    }
    public static function dateandcoursewiseoperatorreportbwndates()
    {
        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 a.*, um.*, u.name as opname FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.no JOIN user_master u ON u.id=a.entry_id AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");
                $course = array();
                $opname = array();
                $feetype = array();
                $pdate = array();
                foreach ($data as $h) {
                    $feetype[] = $h['fk_feetype_id'];
                    $opname[] = $h['opname'];
                    $course[] = $h['fk_course_id'];
                    $pdate[] = $h['paid_date'];
                }
                $curse = array_values(array_unique($course));
                sort($curse);
                $name = array_values(array_unique($opname));
                sort($name);
                $ftype = array_values(array_unique($feetype));
                sort($ftype);
                $paiddate = array_values(array_unique($pdate));
                sort($paiddate);
                $acc = array();
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        $acc[] = Extra::feeaccount($curse[$j], $ftype[$k]);
                    }
                }
                $accounts = array_values(array_unique($acc));
                sort($accounts);
                $accounts[] = 'Exam Fee';
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    for($i=0; $i<sizeof($name); $i++)
                    {
                        for($j=0; $j<sizeof($curse); $j++)
                        {
                            for($k=0; $k<sizeof($ftype); $k++)
                            {
                                if(!isset($uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]))
                                {
                                    $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = 0;
                                }
                                for($l=0; $l<sizeof($data); $l++)
                                {
                                    if($paiddate[$h] == $data[$l]['paid_date'] && $name[$i] == $data[$l]['opname'] && $curse[$j] == $data[$l]['fk_course_id'] && $ftype[$k] == $data[$l]['fk_feetype_id'])
                                    {
                                        $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = (int)$uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]+(int)$data[$l]['amount'];
                                    }
                                }
                            }
                        }
                    }
                }
                $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_examfee se JOIN user_master um ON um.id=se.entry_id JOIN user_master u ON u.id=se.id WHERE DATE(se.entry_date) BETWEEN '$date1' AND '$date2'");
                $opname = array();
                $pdate = array();
                $course = array();
                foreach ($data as $h) {
                    $course[] = $h['fk_course_id'];
                    $opname[] = $h['opname'];
                    $pdate[] = $h['entry_date'];
                }
                $curse = array_values(array_unique($course));
                sort($curse);
                $ename = array_values(array_unique($opname));
                sort($ename);
                $epaiddate = array_values(array_unique($pdate));
                sort($epaiddate);
                for($i=0; $i<sizeof($ename); $i++)
                {
                    for($j=0; $j<sizeof($epaiddate); $j++)
                    {
                        for($h=0; $h<sizeof($curse); $h++)
                        {
                            // if(!isset($uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]))
                            // {
                            //     $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = 0;
                            // }
                            $total = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['entry_date'])
                                {
                                    $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee']+(int)$data[$k]['paidamount'];
                                }
                            }
                        }
                        
                    }
                }
                $total = 0;
                $s=1;
                // for($h=0; $h<sizeof($paiddate); $h++)
                // {
                //     for($i=0; $i<sizeof($name); $i++)
                //     {
                //         for($j=0; $j<sizeof($accounts); $j++)
                //         {
                //             if(isset($udet[$paiddate[$h]][$name[$i]][$accounts[$j]]))
                //             {
                //                 if($udet[$paiddate[$h]][$name[$i]][$accounts[$j]] > 0)
                //                 {
                //                     $a .= '<tr><td>'.$s.'</td><td>'.$paiddate[$h].'</td><td>'.$name[$i].'</td><td>'.$accounts[$j].'</td><td>'.$udet[$paiddate[$h]][$name[$i]][$accounts[$j]].'</td></tr>';
                //                     $total = $total+(int)$udet[$paiddate[$h]][$name[$i]][$accounts[$j]];
                //                     $s++;
                //                 }
                //             }
                //         }
                //     }
                // }
                // print_r($accounts);
                $head = '<thead>
                                <tr><th colspan="2">Date wise Fee Collection Report </th><th colspan="1">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="2">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Date</th>
                                    <th>Name of the operator</th>
                                    <th>Bank Account</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$total.'</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 json_encode($udet);
            echo Menus::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 Menus::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 reportbwndateswithopnameconsolidated()
    {
        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 a.*, um.*, u.name as opname FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.no JOIN user_master u ON u.id=a.entry_id AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");
                $course = array();
                $opname = array();
                $feetype = array();
                $pdate = array();
                foreach ($data as $h) {
                    $feetype[] = $h['fk_feetype_id'];
                    $opname[] = $h['opname'];
                    $course[] = $h['fk_course_id'];
                    $pdate[] = $h['paid_date'];
                }
                $curse = array_values(array_unique($course));
                sort($curse);
                $name = array_values(array_unique($opname));
                sort($name);
                $ftype = array_values(array_unique($feetype));
                sort($ftype);
                $paiddate = array_values(array_unique($pdate));
                sort($paiddate);
                $acc = array();
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        $acc[] = Extra::feeaccount($curse[$j], $ftype[$k]);
                    }
                }
                $accounts = array_values(array_unique($acc));
                sort($accounts);
                
                // echo json_encode($accounts);
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    for($i=0; $i<sizeof($name); $i++)
                    {
                        for($j=0; $j<sizeof($curse); $j++)
                        {
                            for($k=0; $k<sizeof($ftype); $k++)
                            {
                                if(!isset($uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]))
                                {
                                    $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = 0;
                                }
                                if(!isset($udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                                {
                                    
                                    $udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                                }
                                for($l=0; $l<sizeof($data); $l++)
                                {
                                    if($paiddate[$h] == $data[$l]['paid_date'] && $name[$i] == $data[$l]['opname'] && $curse[$j] == $data[$l]['fk_course_id'] && $ftype[$k] == $data[$l]['fk_feetype_id'])
                                    {
                                        $uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]] = (int)$uind[$paiddate[$h]][$name[$i]][$curse[$j]][$ftype[$k]]+(int)$data[$l]['amount'];
                                        $udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = (int)$udet[$paiddate[$h]][$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]+(int)$data[$l]['amount'];
                                        // echo $data[$l]['nid'];
                                    }
                                }
                            }
                        }
                    }
                }
                
                $total = 0;
                $s=1;
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    for($i=0; $i<sizeof($name); $i++)
                    {
                        for($j=0; $j<sizeof($accounts); $j++)
                        {
                            if(isset($udet[$paiddate[$h]][$name[$i]][$accounts[$j]]))
                            {
                                if($udet[$paiddate[$h]][$name[$i]][$accounts[$j]] > 0)
                                {
                                    $a .= '<tr><td>'.$s.'</td><td>'.$paiddate[$h].'</td><td>'.$name[$i].'</td><td>'.$accounts[$j].'</td><td>'.$udet[$paiddate[$h]][$name[$i]][$accounts[$j]].'</td></tr>';
                                    $total = $total+(int)$udet[$paiddate[$h]][$name[$i]][$accounts[$j]];
                                    $s++;
                                }
                            }
                        }
                    }
                }
                $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_examfee se JOIN user_master um ON um.id=se.entry_id WHERE DATE(se.entry_date) BETWEEN '$date1' AND '$date2'");
                $opname = array();
                $pdate = array();
                foreach ($data as $h) {
                    $opname[] = $h['opname'];
                    $pdate[] = $h['entry_date'];
                }
                $ename = array_values(array_unique($opname));
                sort($ename);
                $epaiddate = array_values(array_unique($pdate));
                sort($epaiddate);
                $examaccounts[] = 'Exam Fee 14143-UBI';
                for($i=0; $i<sizeof($ename); $i++)
                {
                    for($j=0; $j<sizeof($epaiddate); $j++)
                    {
                        $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee 14143-UBI'] = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['entry_date'])
                            {
                                $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Exam Fee 14143-UBI']+(int)$data[$k]['paidamount'];
                            }
                        }
                    }
                }
                for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($examaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$examaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$examaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                if($_SESSION["org_id"] == 1)
                {
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_provisionaladmissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Pro-Inter Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Pro-Degree Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Pro-PG Fee 376-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Pro-Inter Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['Pro-Inter Fee 27950-BOB']+(int)$data[$k]['amount'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Pro-PG Fee 376-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Pro-PG Fee 376-UBI']+(int)$data[$k]['amount'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Pro-Degree Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['Pro-Degree Fee 27950-BOB']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proadmaccounts = array("Pro-Inter Fee 27950-BOB", "Pro-Degree Fee 27950-BOB", "Pro-PG Fee 376-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proadmaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proadmaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_admissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['App-Inter Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['App-Degree Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['App-PG Fee 376-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['App-Inter Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['App-Inter Fee 27950-BOB']+(int)$data[$k]['amount'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['App-PG Fee 376-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['App-PG Fee 376-UBI']+(int)$data[$k]['amount'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['App-Degree Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['App-Degree Fee 27950-BOB']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proappaccounts = array("App-Inter Fee 27950-BOB", "App-Degree Fee 27950-BOB", "App-PG Fee 376-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proappaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proappaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_additionalfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE DATE(se.paid_date) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['paid_date'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Add-Inter Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Add-Degree Fee 27950-BOB'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Add-PG Fee 376-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['paid_date'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Add-Inter Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['Add-Inter Fee 27950-BOB']+(int)$data[$k]['total'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Add-PG Fee 376-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Add-PG Fee 376-UBI']+(int)$data[$k]['total'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Add-Degree Fee 27950-BOB'] = $udet[$epaiddate[$j]][$ename[$i]]['Add-Degree Fee 27950-BOB']+(int)$data[$k]['total'];
                                    }
                                }
                            }
                        }
                    }
                    $proaddaccounts = array("Add-Inter Fee 27950-BOB", "Add-Degree Fee 27950-BOB", "Add-PG Fee 376-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_monthlyfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Mon-Inter Fee'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Mon-Degree Fee'] = 0;
                            $udet[$epaiddate[$j]][$ename[$i]]['Mon-PG Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    if($data[$k]['fk_course_id']==4)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Mon-Inter Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Mon-Inter Fee']+(int)$data[$k]['amount'];
                                    }
                                    elseif($data[$k]['fk_course_id']==5)
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Mon-PG Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Mon-PG Fee']+(int)$data[$k]['amount'];
                                    }
                                    else
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Mon-Degree Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Mon-Degree Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $promonaccounts = array("Mon-Inter Fee", "Mon-Degree Fee", "Mon-PG Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($promonaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$promonaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    
                    
                    // Event Fee Start
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdent_eventfee se JOIN user_master um ON um.id=se.fk_user_id WHERE DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    // print_r($data);
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Event Fee 14143-UBI'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Event Fee 14143-UBI'] = $udet[$epaiddate[$j]][$ename[$i]]['Event Fee 14143-UBI']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $eventaddaccounts = array("Event Fee 14143-UBI");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($eventaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$eventaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_provisionaladmissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Provisional Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Provisional Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Provisional Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proadmaccounts = array("Provisional Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proadmaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proadmaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proadmaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_admissionfee se JOIN user_master um ON um.id=se.fk_user_id WHERE DATE(se.regdate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['regdate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Application Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['regdate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Application Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Application Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $proappaccounts = array("Application Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proappaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proappaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proappaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_additionalfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE DATE(se.paid_date) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['paid_date'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Additional Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['paid_date'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Additional Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Additional Fee']+(int)$data[$k]['total'];
                                    }
                                }
                            }
                        }
                    }
                    $proaddaccounts = array("Additional Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_monthlyfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Monthly Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Monthly Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Monthly Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $promonaccounts = array("Monthly Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($promonaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$promonaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$promonaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    $data = Homem::getdata("SELECT se.*, um.name as opname, u.fk_course_id FROM stdnt_additional_addfee se JOIN user_master um ON um.id=se.fk_user_id JOIN user_master u ON se.sid=u.id WHERE DATE(se.paid_date) BETWEEN '$date1' AND '$date2'");
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['paid_date'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Provisional-Additional Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['paid_date'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Provisional-Additional Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Provisional-Additional Fee']+(int)$data[$k]['total'];
                                    }
                                }
                            }
                        }
                    }
                    $proadmaddaccounts = array("Provisional-Additional Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($proadmaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$proadmaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]].'</td></tr>';
                                        $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$proadmaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                    
                    
                
                    // Event Fee Start
                    $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdent_eventfee se JOIN user_master um ON um.id=se.fk_user_id WHERE DATE(se.edate) BETWEEN '$date1' AND '$date2'");
                    // print_r($data);
                    $opname = array();
                    $pdate = array();
                    foreach ($data as $h) {
                        $opname[] = $h['opname'];
                        $pdate[] = $h['edate'];
                    }
                    $ename = array_values(array_unique($opname));
                    sort($ename);
                    $epaiddate = array_values(array_unique($pdate));
                    sort($epaiddate);
                    for($i=0; $i<sizeof($ename); $i++)
                    {
                        for($j=0; $j<sizeof($epaiddate); $j++)
                        {
                            $udet[$epaiddate[$j]][$ename[$i]]['Event Fee'] = 0;
                            for($k=0; $k<sizeof($data); $k++)
                            {
                                if($ename[$i] == $data[$k]['opname'] && $epaiddate[$j] == $data[$k]['edate'])
                                {
                                    {
                                        $udet[$epaiddate[$j]][$ename[$i]]['Event Fee'] = $udet[$epaiddate[$j]][$ename[$i]]['Event Fee']+(int)$data[$k]['amount'];
                                    }
                                }
                            }
                        }
                    }
                    $eventaddaccounts = array("Event Fee");
                    for($h=0; $h<sizeof($epaiddate); $h++)
                    {
                        for($i=0; $i<sizeof($ename); $i++)
                        {
                            for($j=0; $j<sizeof($eventaddaccounts); $j++)
                            {
                                if(isset($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]]))
                                {
                                    if($udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]] > 0)
                                    {
                                        $a .= '<tr><td>'.$s.'</td><td>'.$epaiddate[$h].'</td><td>'.$ename[$i].'</td><td>'.$eventaddaccounts[$j].'</td><td>'.$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]].'</td></tr>';
                                        // $total = $total+(int)$udet[$epaiddate[$h]][$ename[$i]][$eventaddaccounts[$j]];
                                        $s++;
                                    }
                                }
                            }
                        }
                    }
                }
                
                
                
                // print_r($data);
                // print_r($accounts);
                $head = '<thead>
                                <tr><th colspan="2">Date wise Fee Collection Report </th><th colspan="1">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="2">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Date</th>
                                    <th>Name of the operator</th>
                                    <th>Bank Account</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$total.'</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 json_encode($udet);
            echo Menus::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 Menus::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 operatorwisedailysumaryreport()
    {
        if($_SESSION['user_role'] != '' && ($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5))
        {
            if(!isset($_POST['date']))
            {
                $date= date('Y-m-d');
            }
            else
            {
                $date = $_POST['date'];
            }
            $data = Homem::getdata("SELECT sn.*, um.name as opname FROM stdnt_normalfee sn JOIN user_master um ON sn.entry_id=um.id WHERE sn.paid_date='$date'");
            $course = array();
            $opname = array();
            $feetype = array();
            foreach ($data as $h) {
                $feetype[] = $h['fk_feetype_id'];
                $opname[] = $h['opname'];
            }
            $name = array_values(array_unique($opname));
            sort($name);
            $ftype = array_values(array_unique($feetype));
            sort($ftype);
            $ftypename = array();
            for($i=0; $i<sizeof($ftype); $i++)
            {
                $ftypename[] = Extra::feetype($ftype[$i]);
            }
            $fopname = array();
            for($i=0; $i<sizeof($name); $i++)
            {
                $fopname[] = $name[$i];
            }
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($ftype); $j++)
                {
                    $total = 0;
                    for($k=0; $k<sizeof($data); $k++)
                    {
                        if($data[$k]['opname'] == $name[$i] && $data[$k]['fk_feetype_id'] == $ftype[$j])
                        {
                            $total = $total+(int)$data[$k]['amount'];
                        }
                        if($k == sizeof($data)-1)
                        {
                            $udata[$name[$i]][Extra::feetype($ftype[$j])]=$total;
                        }
                    }
                }
            }
            $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_examfee se JOIN user_master um ON um.id=se.entry_id WHERE se.entry_date='$date'");
            $opname = array();
            foreach ($data as $h) {
                $opname[] = $h['opname'];
            }
            $name = array_values(array_unique($opname));
            sort($name);
            for($i=0; $i<sizeof($name); $i++)
            {
                $fopname[] = $name[$i];
            }
            for($i=0; $i<sizeof($name); $i++)
            {
                $total = 0;
                for($k=0; $k<sizeof($data); $k++)
                {
                    if($data[$k]['opname'] == $name[$i])
                    {
                        $total = $total+(int)$data[$k]['paidamount'];
                    }
                    if($k == sizeof($data)-1)
                    {
                        $udata[$name[$i]]['examfee']=$total;
                    }
                }
            }
            $ftypename[] = 'examfee';
            $data = Homem::getdata("SELECT sm.*, um.name as opname FROM stdnt_monthlyfee sm JOIN user_master um ON um.id=sm.fk_user_id WHERE sm.edate='$date'");
            $course = array();
            $opname = array();
            $feetype = array();
            foreach ($data as $h) {
                $opname[] = $h['opname'];
                $feetype[] = $h['feetype'];
            }
            $name = array_values(array_unique($opname));
            sort($name);
            $ftype = array_values(array_unique($feetype));
            sort($ftype);
            for($i=0; $i<sizeof($name); $i++)
            {
                $fopname[] = $name[$i];
            }
            $fname = array_values(array_unique($fopname));
            sort($fname);
            for($i=0; $i<sizeof($ftype); $i++)
            {
                $ftypename[] = Extra::monthlyfeetype($ftype[$i]);
            }
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($ftype); $j++)
                {
                    $total = 0;
                    for($k=0; $k<sizeof($data); $k++)
                    {
                        if($data[$k]['opname'] == $name[$i] && $data[$k]['feetype'] == $ftype[$j])
                        {
                            $total = $total+(int)$data[$k]['amount'];
                        }
                        if($k == sizeof($data)-1)
                        {
                            $udata[$name[$i]][Extra::monthlyfeetype($ftype[$j])]=$total;
                        }
                    }
                }
            }
            $data = Homem::getdata("SELECT sm.*, um.name as opname FROM stdnt_additionalfee sm JOIN user_master um ON um.id=sm.fk_user_id WHERE sm.paid_date='$date'");
            $feetypecount = Homem::getdata("SELECT * FROM `additional_fee_type`");
            $opname = array();
            foreach ($data as $h) {
                $opname[] = $h['opname'];
            }
            $name = array_values(array_unique($opname));
            sort($name);
            for($i=0; $i<sizeof($name); $i++)
            {
                $fopname[] = $name[$i];
            }
            $fname = array_values(array_unique($fopname));
            $ftype = array();
            for($i=1; $i<=sizeof($feetypecount); $i++)
            {
                $ftypename[] = Extra::additionalfeetype($i);
                $ftype[] = Extra::additionalfeetype($i);
            }
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($ftype); $j++)
                {
                    $udata[$name[$i]][$ftype[$j]] = 0;
                }
            }
            
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($data); $j++)
                {
                    if($data[$j]['opname'] == $name[$i])
                    {
                        $d = json_decode($data[$j]['fees'], true);
                        for($k=1; $k<=sizeof($feetypecount); $k++)
                        {
                            $udata[$name[$i]][Extra::additionalfeetype($k)] = $udata[$name[$i]][Extra::additionalfeetype($k)] +(int) $d[$k];
                        }
                    }
                }
            }
            $b = ''; 
            $s = 1;
            $total = 0;
            for($i=0; $i<sizeof($fname); $i++)
            {
                for($j=0; $j<sizeof($ftypename); $j++)
                {
                    if(isset($udata[$fname[$i]][$ftypename[$j]]))
                    {
                        if($udata[$fname[$i]][$ftypename[$j]]>0)
                        {
                            $b .= '<tr><td>'.$s.'</td><td>'.$date.'</td><td>'.$fname[$i].'</td><td>'.$ftypename[$j].'</td><td>'.$udata[$fname[$i]][$ftypename[$j]].'</td></tr>'; 
                            $s++;
                            $total = $total+(int) $udata[$fname[$i]][$ftypename[$j]];
                        }
                    }
                }
            }
            
            $a = '<table border="1px">';
            $a .= '<thead><tr><th>S.No.</th><th>Date</th><th>Name</th><th>Fee Type</th><th>Amount</th></tr></thead><tbody>';
            $a .= $b;
            $a .= '<tr><td colspan="4">Total</td><td>'.$total.'</td></tr>';
            $a .='</tbody></table>';
            echo Menus::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-4">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                            <div class="col-xl-4">
                                <form action="/Accounts/operatorwisedailysumaryreport" method="POST">
                                    <div class="form-control">
                                        <input type="text" name="date" id="date" class="form-control" placeholder="Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                    </div>
                                    <div class="form-control">
                                        <input type="submit">
                                    </div>
                                </form>
                            </div>
                            <div class="col-xl-4">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                            <div class="col-xl-2">
                            </div>
                            <div class="col-xl-8">
                            '.$a.'
                            </div>
                            <div class="col-xl-2">
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo Menus::script();
        }
    }
    public static function daywisefeesummaryreport()
    {
        if($_SESSION['user_role'] != '' && ($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 5))
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['fromdate']))
            {
                $date1 = $_POST['fromdate'];
                $date2 = $_POST['todate'];
                $data = Homem::getdata("SELECT a.*, um.*, u.name as opname FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.no JOIN user_master u ON u.id=a.entry_id AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");
                $course = array();
                $opname = array();
                $feetype = array();
                $pdate = array();
                foreach ($data as $h) {
                    $feetype[] = $h['fk_feetype_id'];
                    $opname[] = $h['opname'];
                    $course[] = $h['fk_course_id'];
                    $pdate[] = $h['paid_date'];
                }
                $curse = array_values(array_unique($course));
                sort($curse);
                $name = array_values(array_unique($opname));
                sort($name);
                $ftype = array_values(array_unique($feetype));
                sort($ftype);
                $paiddate = array_values(array_unique($pdate));
                sort($paiddate);
                $acc = array();
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        $acc[] = Extra::feeaccount($curse[$j], $ftype[$k]);
                    }
                }
                $accounts = array_values(array_unique($acc));
                sort($accounts);
                $accounts[] = 'Exam Fee';
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    {
                        for($j=0; $j<sizeof($curse); $j++)
                        {
                            for($k=0; $k<sizeof($ftype); $k++)
                            {
                                if(!isset($uind[$paiddate[$h]][$curse[$j]][$ftype[$k]]))
                                {
                                    $uind[$paiddate[$h]][$curse[$j]][$ftype[$k]] = 0;
                                }
                                if(!isset($udet[$paiddate[$h]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                                {
                                    
                                    $udet[$paiddate[$h]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                                }
                                for($l=0; $l<sizeof($data); $l++)
                                {
                                    if($paiddate[$h] == $data[$l]['paid_date'] && $curse[$j] == $data[$l]['fk_course_id'] && $ftype[$k] == $data[$l]['fk_feetype_id'])
                                    {
                                        $uind[$paiddate[$h]][$curse[$j]][$ftype[$k]] = (int)$uind[$paiddate[$h]][$curse[$j]][$ftype[$k]]+(int)$data[$l]['amount'];
                                        $udet[$paiddate[$h]][Extra::feeaccount($curse[$j], $ftype[$k])] = (int)$udet[$paiddate[$h]][Extra::feeaccount($curse[$j], $ftype[$k])]+(int)$data[$l]['amount'];
                                        // echo $data[$l]['nid'];
                                    }
                                }
                            }
                        }
                    }
                }
                $data = Homem::getdata("SELECT se.*, um.name as opname FROM stdnt_examfee se JOIN user_master um ON um.id=se.entry_id WHERE DATE(se.entry_date) BETWEEN '$date1' AND '$date2'");
                $opname = array();
                $pdate = array();
                foreach ($data as $h) {
                    $opname[] = $h['opname'];
                    $pdate[] = $h['entry_date'];
                }
                $ename = array_values(array_unique($opname));
                sort($ename);
                $epaiddate = array_values(array_unique($pdate));
                sort($epaiddate);
                {
                    for($j=0; $j<sizeof($epaiddate); $j++)
                    {
                        $udet[$epaiddate[$j]]['Exam Fee'] = 0;
                        $total = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($epaiddate[$j] == $data[$k]['entry_date'])
                            {
                                $udet[$epaiddate[$j]]['Exam Fee'] = $udet[$epaiddate[$j]]['Exam Fee']+(int)$data[$k]['paidamount'];
                            }
                        }
                    }
                }
                $total = 0;
                $s=1;
                for($h=0; $h<sizeof($paiddate); $h++)
                {
                    
                    {
                        for($j=0; $j<sizeof($accounts); $j++)
                        {
                            if(isset($udet[$paiddate[$h]][$accounts[$j]]))
                            {
                                if($udet[$paiddate[$h]][$accounts[$j]] > 0)
                                {
                                    $a .= '<tr><td>'.$s.'</td><td>'.$paiddate[$h].'</td><td>'.$accounts[$j].'</td><td>'.$udet[$paiddate[$h]][$accounts[$j]].'</td></tr>';
                                    $total = $total+(int)$udet[$paiddate[$h]][$accounts[$j]];
                                    $s++;
                                }
                            }
                        }
                    }
                }
                // print_r($accounts);
                $head = '<thead>
                                <tr><th colspan="1">Date wise Fee Collection Report </th><th colspan="1">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="2">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Date</th>
                                    <th>Bank Account</th>
                                    <th>Amount</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$total.'</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 Menus::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 Menus::script();
        }
    }
    public static function daywisetotalaccounts()
    {
        if($_SESSION['user_role'] != '' && ($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4))
        {
            if(!isset($_POST['date']))
            {
                $date= date('Y-m-d');
            }
            else
            {
                $date = $_POST['date'];
            }
        $data = Homem::getdata("SELECT sn.*, um.id, um.name as opname, u.fk_course_id, u.fk_dept_id FROM stdnt_normalfee sn JOIN user_master um ON sn.entry_id=um.id JOIN user_master u ON sn.no=u.id WHERE sn.entry_date='$date'");
        $course = array();
        $opname = array();
        $feetype = array();
        foreach ($data as $h) {
            $feetype[] = $h['fk_feetype_id'];
            $opname[] = $h['opname'];
            $course[] = $h['fk_course_id'];
        }
        $curse = array_values(array_unique($course));
        sort($curse);
        $name = array_values(array_unique($opname));
        sort($name);
        $ftype = array_values(array_unique($feetype));
        sort($ftype);
        for($i=0; $i<sizeof($name); $i++)
        {
            for($j=0; $j<sizeof($curse); $j++)
            {
                for($k=0; $k<sizeof($ftype); $k++)
                {
                    if(!isset($uind[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                    {
                        $uind[$name[$i]][$curse[$j]][$ftype[$k]] = 0;
                        $udet[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                    }
                    for($l=0; $l<sizeof($data); $l++)
                    {
                        if($name[$i] == $data[$l]['opname'] && $curse[$j] == $data[$l]['fk_course_id'] && $ftype[$k] == $data[$l]['fk_feetype_id'])
                        {
                            $uind[$name[$i]][$curse[$j]][$ftype[$k]] = (int)$uind[$name[$i]][$curse[$j]][$ftype[$k]]+(int)$data[$l]['amount'];
                            $udet[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = (int)$udet[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]+(int)$data[$l]['amount'];
                            
                        }
                    }
                }
            }
        
        }
        for($i=0; $i<sizeof($name); $i++)
        {
            for($j=0; $j<sizeof($curse); $j++)
            {
                for($k=0; $k<sizeof($ftype); $k++)
                {
                    if(!isset($udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                    {
                        $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                    }
                    $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]+$uind[$name[$i]][$curse[$j]][$ftype[$k]];
                }
            }
        }
        $a = '<table border="1px">';
        $a .= '<thead><tr><th>Name</th><th>Bank</th><th>Amount</th></tr></thead><tbody>';
        for($i=0; $i<sizeof($name); $i++)
        {
            for($j=0; $j<sizeof($curse); $j++)
            {
                for($k=0; $k<sizeof($ftype); $k++)
                {
                    if($udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] != 0)
                    {
                        $a .= '<tr><td>'.$name[$i].'</td><td>'.Extra::feeaccount($curse[$j], $ftype[$k]).'</td><td>'.$udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])].'</td></tr>';
                        $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] =0;
                        
                    }
                }
            }
        }
        $a .='</tbody></table>';
        // echo json_encode($udet1);
            echo Menus::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-4">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                            <div class="col-xl-4">
                                <form action="/Accounts/daywisetotalaccounts" method="POST">
                                    <div class="form-control">
                                    <input type="text" name="date" id="date" class="form-control" placeholder="Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                    </div>
                                    <div class="form-control">
                                    <input type="submit">
                                    </div>
                                </form>
                            </div>
                            <div class="col-xl-4">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                            <div class="col-xl-2">
                            </div>
                            <div class="col-xl-8">
                            '.$a.'
                            </div>
                            <div class="col-xl-2">
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo Menus::script();
        }
        
    }
    public static function daysummary()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 10)
        {
            if($_SESSION['user_role'] != '')
            {
                if(!isset($_POST['date']))
                {
                    $date= date('Y-m-d');
                }
                else
                {
                    $date = $_POST['date'];
                }
            $data = Homem::getdata("SELECT sn.*, um.id, um.name as opname, u.fk_course_id, u.fk_dept_id FROM stdnt_normalfee sn JOIN user_master um ON sn.entry_id=um.id JOIN user_master u ON sn.no=u.id WHERE sn.paid_date='$date' AND sn.fk_feemode_id!='5' AND sn.entry_id='$_SESSION[user_id]'");
            $course = array();
            $opname = array();
            $feetype = array();
            foreach ($data as $h) {
                $feetype[] = $h['fk_feetype_id'];
                $opname[] = $h['opname'];
                $course[] = $h['fk_course_id'];
            }
            $curse = array_values(array_unique($course));
            sort($curse);
            $name = array_values(array_unique($opname));
            sort($name);
            $ftype = array_values(array_unique($feetype));
            sort($ftype);
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        if(!isset($uind[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                        {
                            $uind[$name[$i]][$curse[$j]][$ftype[$k]] = 0;
                            $udet[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                        }
                        for($l=0; $l<sizeof($data); $l++)
                        {
                            if($name[$i] == $data[$l]['opname'] && $curse[$j] == $data[$l]['fk_course_id'] && $ftype[$k] == $data[$l]['fk_feetype_id'])
                            {
                                $uind[$name[$i]][$curse[$j]][$ftype[$k]] = (int)$uind[$name[$i]][$curse[$j]][$ftype[$k]]+(int)$data[$l]['amount'];
                                $udet[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = (int)$udet[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]+(int)$data[$l]['amount'];
                                
                            }
                        }
                    }
                }
            
            }
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        if(!isset($udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]))
                        {
                            $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = 0;
                        }
                        $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] = $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])]+$uind[$name[$i]][$curse[$j]][$ftype[$k]];
                    }
                }
            }
            $a = '<table border="1px">';
            $a .= '<thead><tr><th>Name</th><th>Bank</th><th>Amount</th></tr></thead><tbody>';
            for($i=0; $i<sizeof($name); $i++)
            {
                for($j=0; $j<sizeof($curse); $j++)
                {
                    for($k=0; $k<sizeof($ftype); $k++)
                    {
                        if($udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] != 0)
                        {
                            $a .= '<tr><td>'.$name[$i].'</td><td>'.Extra::feeaccount($curse[$j], $ftype[$k]).'</td><td>'.$udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])].'</td></tr>';
                            $udet1[$name[$i]][Extra::feeaccount($curse[$j], $ftype[$k])] =0;
                            
                        }
                    }
                }
            }
            $a .='</tbody></table>';
            // echo json_encode($udet1);
                echo Menus::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-4">
                                <!--Welcome to HINDU COLLEGE-->
                                </div>
                                <div class="col-xl-4">
                                    <form action="/Accounts/daysummary" method="POST">
                                        <div class="row">
                                            <div class="col-xl-12">
                                                <div class="form-control">
                                                    <input type="text" name="date" id="date" class="form-control" placeholder="Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                                </div>
                                                <div class="form-control">
                                                    <input type="submit">
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                <div class="col-xl-4">
                                <!--Welcome to HINDU COLLEGE-->
                                </div>
                                <div class="col-xl-2">
                                </div>
                                <div class="col-xl-8">
                                '.$a.'
                                </div>
                                <div class="col-xl-2">
                                </div>
                            </div>
                        </div>
                    </div>
                    ';
                echo '</body>';
                echo Menus::script();
            }
        }
    }
    

    /* start of Exam fee collection section */
    public static function examfeecollectionbetweendates()
    {
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 10)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['fromdate']) && $_POST['fromdate']!='')
            {
                $tot = 0;
                // $_POST['fromdate'] = '2021-12-01';
                // $_POST['todate'] = '2021-12-07';
                $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 a.*, um.*, u.name as uname FROM (SELECT * FROM `stdnt_examfee` WHERE DATE(paydate) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.id JOIN user_master u ON a.entry_id=u.id ORDER BY a.eid ASC");
                $a = '';
                for($i=0; $i<sizeof($data); $i++)
                {
                    $j = $i+1;
                    $a .= '<tr><td>'.$j.'</td><td>'.$data[$i]['eid'].'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.Extra::course($data[$i]['fk_course_id']).'</td><td>'.Extra::dept($data[$i]['fk_dept_id']).'</td><td>'.$data[$i]['paidamount'].'</td><td>'.Extra::datem($data[$i]['entry_date']).'</td><td>'.$data[$i]['uname'].'</td></tr>';
                    $tot = $tot+$data[$i]['paidamount'];
                }
                // $data1 = Homem::getdata("SELECT se.*, u.name as uname FROM stdnt_examfee se JOIN user_master u ON u.id=se.entry_id WHERE se.id=''");
                // for($k=0; $k<sizeof($data1); $k++)
                // {
                //     $j = sizeof($data);
                //     $l = $j+$k+1;
                //     $a .= '<tr><td>'.$l.'</td><td>'.$data1[$k]['eid'].'</td><td>'.$data1[$k]['no'].'</td><td></td><td></td><td></td><td>'.$data1[$k]['paidamount'].'</td><td>'.Extra::datem($data1[$k]['entry_date']).'</td><td>'.$data1[$k]['uname'].'</td></tr>';
                    
                //     $tot = $tot+$data1[$k]['paidamount'];
                // }
                $head = '<thead>
                        <tr><th colspan="3">Date wise Fee Collection Report From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="3">To: '.Extra::datem($_POST['todate']).'</th></tr>
                        <tr>
                            <th>S. No.</th>
                            <th>Reciept Number</th>
                            <th>Hallticket Number</th>
                            <th>Name</th>
                            <th>Department</th>
                            <th>Branch</th>
                            <th>Amount</th>
                            <th>Paid Date</th>
                            <th>Paid To</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 Menus::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 Menus::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 individualexamfeecollectionbetweendates()
    {
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 10)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['fromdate']) && $_POST['fromdate']!='')
            {
                $tot = 0;
                // $_POST['fromdate'] = '2021-12-01';
                // $_POST['todate'] = '2021-12-07';
                $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 a.*, um.*, u.name as uname FROM (SELECT * FROM `stdnt_examfee` WHERE DATE(paydate) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.id JOIN user_master u ON a.entry_id=u.id WHERE u.id='$_SESSION[user_id]' ORDER BY a.eid ASC");
                $a = '';
                for($i=0; $i<sizeof($data); $i++)
                {
                    $j = $i+1;
                    $a .= '<tr><td>'.$j.'</td><td>'.$data[$i]['eid'].'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.Extra::course($data[$i]['fk_course_id']).'</td><td>'.Extra::dept($data[$i]['fk_dept_id']).'</td><td>'.$data[$i]['paidamount'].'</td><td>'.Extra::datem($data[$i]['entry_date']).'</td><td>'.$data[$i]['uname'].'</td></tr>';
                    $tot = $tot+$data[$i]['paidamount'];
                }
                // $data1 = Homem::getdata("SELECT se.*, u.name as uname FROM stdnt_examfee se JOIN user_master u ON u.id=se.entry_id WHERE se.id=''");
                // for($k=0; $k<sizeof($data1); $k++)
                // {
                //     $j = sizeof($data);
                //     $l = $j+$k+1;
                //     $a .= '<tr><td>'.$l.'</td><td>'.$data1[$k]['eid'].'</td><td>'.$data1[$k]['no'].'</td><td></td><td></td><td></td><td>'.$data1[$k]['paidamount'].'</td><td>'.Extra::datem($data1[$k]['entry_date']).'</td><td>'.$data1[$k]['uname'].'</td></tr>';
                    
                //     $tot = $tot+$data1[$k]['paidamount'];
                // }
                $head = '<thead>
                        <tr><th colspan="3">Date wise Fee Collection Report From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="3">To: '.Extra::datem($_POST['todate']).'</th></tr>
                        <tr>
                            <th>S. No.</th>
                            <th>Reciept Number</th>
                            <th>Hallticket Number</th>
                            <th>Name</th>
                            <th>Department</th>
                            <th>Branch</th>
                            <th>Amount</th>
                            <th>Paid Date</th>
                            <th>Paid To</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 Menus::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 Menus::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 unblockexamfeecollect()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 10)
        {
            $table ='';
            $data = Homem::getdata("SELECT um.* FROM stdnt_examfeeblock se JOIN user_master um ON se.sno=um.no WHERE se.status='1'");
            $sub = '<div class="table-responsive">
                        <table class="table table-responsive-sm">
                            <thead>
                                <tr><td>No.</td><td>Name</td><td>Mobile</td><td>Course</td><td>Dept</td></tr>
                            </thead>
                            <tbody>
                    ';
            for($i=0; $i<sizeof($data); $i++)
            {
                $sub .= '<tr>
                            <td>'.$data[$i]['no'].'</td>
                            <td>'.$data[$i]['name'].'</td>
                            <td>'.$data[$i]['mobile'].'</td>
                            <td>'.Extra::course($data[$i]['fk_course_id']).'</td>
                            <td>'.Extra::dept($data[$i]['fk_dept_id']).'</td>
                        </tr>';
            }
            $sub .= '</table>
                    </div>';
            $table = $sub;
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/saveunblockexamfeecollect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Unblock Exam Fee Collect</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" required>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                   
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                        <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                    </div>
                                                </div>
                                            </div>  
                                        </div>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$table.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::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 saveunblockexamfeecollect()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            date_default_timezone_set('Asia/Kolkata'); 
            $date = date('Y-m-d');
            Homem::update("UPDATE `stdnt_examfeeblock` SET `status`='0', `fk_user_id`='$_SESSION[user_id]', `edate`='$date' WHERE `sno`='$_POST[no]'");
            echo '<script>window.location = "/Accounts/unblockexamfeecollect?status=1";</script>';
        }
        else
        {
            echo '<script>window.location = "/Accounts/unblockexamfeecollect?status=0";</script>';
        }
    }
    public static function examfeecollect()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 10)
        {
            $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_default_timezone_set('Asia/Kolkata'); 
                $date = date('Y-m-d');
                $blood = Homem::getdata("SELECT * FROM stdnt_examfee se JOIN user_master um ON se.id=um.id WHERE se.status='1' AND se.entry_date='$date' AND se.entry_id='$_SESSION[user_id]'");
                $table = Form::dbtableprint($blood, ['Hallticket Number', 'Name', 'Paid Amount'], ['no', 'name', 'paidamount'], '/Accounts/examfeeprint', 'eid', '');
                //$table = Form::dbtableprint($blood, ['Hallticket Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Accounts/print', 'nid', '');
                
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/saveexamfeecollect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Exam Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getexamfeestatus()" required>                                         
                                                    </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 required>
                                                        <input type="hidden" name="sid" id="sid" class="form-control" placeholder="Student ID" readonly required>
                                                    </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="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" required>
                                                            <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>
                                                            '.Menus::examyear().'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="examtype" id="examtype" class="form-control" required>
                                                            <option value="">Select Exam Type</option>
                                                            <option value="R">Regular</option>
                                                            <option value="S">Supply</option>
                                                            <option value="RE">Revaluation</option>
                                                            <option value="RC">Recounting</option>
                                                            <option value="C">Challenging Evaluation</option>
                                                            <option value="SS">Super-Supply</option>
                                                        </select>												
                                                    </div>
                                                </div>            
                                                ';
                                                if($_SESSION["org_id"] != 3)
                                                {
                                                    echo '
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <input type="text" name="subjects" id="subjects" class="form-control" placeholder="No of Subjects" required>
                                                        </div>
                                                    </div>      ';
                                                }
                                                if($_SESSION["org_id"] == 3)
                                                {
                                                    echo '
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="subjects" id="subjects" class="form-control" onchange="getamount(this)" required>
                                                                <option value="">Select Subjects</option>
                                                                <option value="6">All Subjects</option>
                                                                <option value="1">One Subject</option>
                                                                <option value="2">Two Subjects</option>
                                                                <option value="3">Three Subjects</option>
                                                                <option value="4">Four Subjects & Above</option>
                                                            </select>
                                                        </div>
                                                    </div>      ';
                                                }
                                        echo '
                                            </div>
                                            <div class="row">                            
                                                <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 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-12">
                                                    <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-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 id="duetable"></div>
                            </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 Menus::script();
            echo '
            <script>
                function getamount(subjects)
                {
                    var a = subjects.value;
                    document.getElementById("paidamount").readOnly = true;
                    if(a == 1)
                    {
                        document.getElementById("paidamount").value = 450;//400
                    }
                    if(a == 2)
                    {
                        document.getElementById("paidamount").value = 700;//550
                    }
                    if(a == 3)
                    {
                        document.getElementById("paidamount").value = 950;//700
                    }
                    if(a == 4)
                    {
                        document.getElementById("paidamount").value = 1200;//1000
                    }
                    if(a == 6)
                    {
                        document.getElementById("paidamount").value = 1200;//1000
                    }
                }
                function getexamfeestatus()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/blockexamfee",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d == 1)
                            {
                                swal("Not Eligible", "Please Aquire Permission", "error");
                                $("#btn_reg").hide();
                                setTimeout(function(){ 
                                window.location.reload(true);
                                }, 10000);
                                
                            }
                            if(d == 0)
                            {
                                getusername();
                                $("#btn_reg").show();
                            }
                        }
                    });
                }
                function getlatestduetable()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getstudentfeedetails",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                                // console.log(d);
                                document.getElementById("duetable").innerHTML = d;
                        }
                    });
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                            getuserid();
                            getlatestduetable();
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_examfee` WHERE `eid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                    </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 || $_SESSION['user_role'] == 5  || $_SESSION['user_role'] == 10)
        {
            date_default_timezone_set('Asia/Kolkata'); 
            $date = date('Y-m-d');
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
                if(sizeof($data) == 1)
                {
                    // Homem::insert("INSERT INTO `stdnt_examfee` (`no`, `id`, `year`, `sem`, `exammonth`, `examyear`, `examtype`, `subjects`, `paidamount`, `recieptno`, `fk_feemode_id`, `paydate`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`, `status`) VALUES 
                    // ('$_POST[no]', '$_POST[sid]', '$_POST[year]', '$_POST[sem]', '$_POST[exammonth]', '$_POST[examyear]', '$_POST[examtype]', '$_POST[subjects]', '$_POST[paidamount]', '', '$_POST[feemode]', '$date', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '', '1')");
                    $query = "INSERT INTO `stdnt_examfee` (`eid`, `no`, `id`, `year`, `sem`, `exammonth`, `examyear`, `examtype`, `subjects`, `paidamount`, `recieptno`, `fk_feemode_id`, `paydate`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`, `status`) VALUES 
                    (NULL, '$_POST[no]', '$_POST[sid]', '$_POST[year]', '$_POST[sem]', '$_POST[exammonth]', '$_POST[examyear]', '$_POST[examtype]', '$_POST[subjects]', '$_POST[paidamount]', '', '$_POST[feemode]', '$date', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '', '1')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Accounts/examfeecollect?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Accounts/examfeecollect?status=0";</script>';
                }
            }
        }
    }
    public static function blockexamfee()
    {
        if(isset($_POST['no']))
        {
            $data = Homem::getdata("SELECT * FROM `stdnt_examfeeblock` WHERE `sno`='$_POST[no]' AND `status`='1'");
            echo sizeof($data);
        }
    }
    public static function examfeesplitup($subjects)
    {
        if($_SESSION["org_id"] == 3)
        {
            if($subjects == 1)
            {
                return 300;//265
            }
            if($subjects == 2)
            {
                return 500;//390
            }
            if($subjects == 3)
            {
                return 750;//515
            }
            if($subjects == 4)
            {
                return 950;//770
            }
            if($subjects == 6)
            {
                return 950;//770
            }
        }
    }
    public static function examaddfeesplitup($subjects)
    {
        if($_SESSION["org_id"] == 3)
        {
            if($subjects == 1)
            {
                return 150;//135
            }
            if($subjects == 2)
            {
                return 200;//160
            }
            if($subjects == 3)
            {
                return 200;//185
            }
            if($subjects == 4)
            {
                return 250;//230
            }
            if($subjects == 6)
            {
                return 250;//230
            }
        }
    }
    public static function breakupstmt($type)
    {
        if($type == "R")
        {
            return "Laboratory Fee & Student Welfare Fee";
        }
        if($type == "S")
        {
            return "Miscellaneous Fee";
        }
    }
    public static function examfeeprint()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT se.*, um.*, fe.name as feemode FROM user_master um JOIN stdnt_examfee se ON se.id=um.id JOIN fee_mode fe ON fe.id=se.fk_feemode_id WHERE se.eid='$_GET[editid]' AND se.status='1' ");/*examfeeprint*/
            }
            if(sizeof($data) == 1)
            {
                echo Menus::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">
                                    <br/ ><br/ ><br/ ><br/ >
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        '.static::recieptheader().'
                                                        <tr>
                                                            <td><span style="margin-left: 10px;">Reciept Number: '.$data[0]['eid'].'</span></td>
                                                            <td style="text-align: right;"><span style="margin-right: 10px;">Date: '.Extra::datem($data[0]['entry_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>'.Extra::course($data[0]['fk_course_id']).'-'.Extra::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>'.Extra::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>
                                                    ';
                                                    if($_SESSION["org_id"] != 3)
                                                    {
                                                    echo '
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                '.Extra::romanyear($data[0]['year']).'-'.Extra::course($data[0]['fk_course_id']).' '.Extra::romanyear($data[0]['sem']).' Sem '.Extra::examtype($data[0]['examtype']).' Exam Fee, '.Extra::month($data[0]['exammonth']).'-'.$data[0]['examyear'].'
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                '.number_format($data[0]['paidamount'], 2).'
                                                            </td>
                                                        </tr>
                                                        ';
                                                    }
                                                    if($_SESSION["org_id"] == 3)
                                                    {
                                                        echo '
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                '.Extra::romanyear($data[0]['year']).'-'.Extra::course($data[0]['fk_course_id']).' '.Extra::romanyear($data[0]['sem']).' Sem '.Extra::examtype($data[0]['examtype']).' Exam Fee, '.Extra::month($data[0]['exammonth']).'-'.$data[0]['examyear'].'
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                '.number_format(static::examfeesplitup($data[0]['subjects']), 2).'
                                                            </td>
                                                        </tr>
                                                        <tr style="text-align: center;">
                                                            <td width="70%" style="border: thin solid black">
                                                                '.static::breakupstmt($data[0]['examtype']).'
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                '.number_format(static::examaddfeesplitup($data[0]['subjects']), 2).'
                                                            </td>
                                                        </tr>
                                                        ';
                                                    }
                                                    echo '
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td colspan="2">
                                                                <span style="margin-left: 10px;"><b>Amount in words: </b>'.Extra::numtotext($data[0]['paidamount']).'</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>('.$_SESSION['name'].')
                                                                </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 Menus::script();
        }
    }

    /* End of Exam fee collection section */
    /*Monthly Fee Collection --  started*/
    public static function monthlyfeecollection()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `feetypemonthly`"), 'id', '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 sn.id as nid, sn.*, um.* FROM stdnt_monthlyfee sn JOIN user_master um ON um.id=sn.sid WHERE (sn.fk_user_id='$_SESSION[user_id]')");//(sn.edate='$date') AND 
                $table = Form::dbtableprint($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Paid Amount'], ['ano', 'no', 'name', 'amount'], '/Accounts/monthlyprint', 'nid', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/savemonthlyfeecollection" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Monthly 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 required>                                         
                                                    </div>
                                                </div>
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Student Mobile Number" readonly>                                         
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="email" id="email" class="form-control" placeholder="Student Email" readonly required>                                         
                                                    </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-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="month" id="month" class="form-control" required>
                                                            <option value="">Select Month</option>
                                                            '.$month.'
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="syear" id="syear" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.Menus::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" required>                                         
                                                    </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" placeholder="Reciept Number">                                         
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                    <input type="hidden" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date"> 
                                                    <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                   
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row" id="modifylink" style="display:none;">
                                                    <div class="col-lg-12">
                                                        <div class="float-lg-right"><a href="javascript:void(0);" onclick="updatecontactdetails()">Change Contact Information</a></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 Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function savemonthlyfeecollection()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $_POST['paydate'] =$date;
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
            if(sizeof($data) == 1)
            {
                Homem::insert("INSERT INTO `stdnt_monthlyfee` (`id`, `no`, `sid`, `year`, `feetype`, `month`, `syear`, `amount`, `feemode`, `remarks`, `fk_user_id`, `edate`, `status`) VALUES (NULL, '$_POST[no]', '$_POST[sid]', '$_POST[year]', '$_POST[feetype]', '$_POST[month]', '$_POST[syear]', '$_POST[paidamount]', '$_POST[feemode]', '$_POST[remarks]', '$_SESSION[user_id]', '$date', '1')");
                echo '<script>window.location = "/Accounts/monthlyfeecollection?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Accounts/monthlyfeecollection?status=0";</script>';
            }
        }
    }
    public static function monthlyprint()
    {
        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.syear, sn.month, sn.id, sn.amount, sn.edate, sn.year, sn.feetype, sn.feemode, sn.fk_user_id, um.no, um.name, um.fk_course_id, um.fk_dept_id FROM stdnt_monthlyfee sn JOIN user_master um ON sn.sid=um.id WHERE sn.id='$_GET[editid]') a JOIN fee_mode fm ON a.feemode=fm.id JOIN user_master u ON a.fk_user_id=u.id");
            }
            if(sizeof($data) == 1)
            {
                echo Menus::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">
                                    <br/ ><br/ ><br/ ><br/ >
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        '.static::recieptheader().'
                                                        <tr>
                                                            <td><span style="margin-left: 10px;">Reciept Number: '.$data[0]['id'].'</span></td>
                                                            <td style="text-align: right;"><span style="margin-right: 10px;">Date: '.Extra::datem($data[0]['edate']).'</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>'.Extra::course($data[0]['fk_course_id']).'-'.Extra::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>'.Extra::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">
                                                                '.Extra::monthlyfeetype($data[0]['feetype']).'
                                                                ('.Extra::month($data[0]['month']).'-'.$data[0]['syear'].')
                                                            </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>'.ucwords(Extra::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 Menus::script();
        }
    }

    public static function monthlyfeecollectionsummary()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `feetypemonthly`"), 'id', 'name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $table = '';
            {
                $date = date('Y-m-d');
                if(!isset($_POST['month']))
                {
                    $_POST['month'] = date('m');
                    $_POST['syear'] = date('Y');
                    $_POST['feetype'] = '1';
                }
                // $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 sn.id as nid, sn.*, um.*, u.name as username FROM stdnt_monthlyfee sn JOIN user_master um ON um.id=sn.sid JOIN user_master u ON u.id=sn.fk_user_id WHERE sn.month='$_POST[month]' AND sn.syear='$_POST[syear]' AND sn.feetype='$_POST[feetype]'");//(sn.edate='$date') AND 
                $table = Form::dbtableprint($blood, ['Reciept No', 'Admission Number', 'Hallticket Number', 'Name', 'Paid Amount', 'Paid to', 'remarks'], ['nid', 'ano', 'no', 'name', 'amount', 'username', 'remarks'], '', '', '');
            }
            $a = '<div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr></tr>
                        </thead>
                    </table>
                </div>';
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"> 
                            </div>
                            <div class="col-lg-8">
                                <form action="/Accounts/monthlyfeecollectionsummary" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Monthly Fee Payment Summary</h5>
                                        </header>
                                        <div class="content-body"> 
                                            
                                            <div class="row">
                                                <div class="col-md-4">
                                                    <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 class="col-md-4">
                                                    <div class="form-group">                                            
                                                        <select name="month" id="month" class="form-control" required>
                                                            <option value="">Select Month</option>
                                                            '.$month.'
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-4">
                                                    <div class="form-group">
                                                        <select name="syear" id="syear" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.Menus::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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-2">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function monthlyfeecollectionsummarybetweendates()
    {
        // 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 = '';
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `feetypemonthly`"), 'id', 'name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $table = '';
            if(isset($_POST['fromdate']))
            {
                $date1 = $_POST['fromdate'];
                $date2 = $_POST['todate'];
                
                $table = '';
                {
                    $date = date('Y-m-d');
                    if(!isset($_POST['month']))
                    {
                        $_POST['month'] = date('m');
                        $_POST['syear'] = date('Y');
                        $_POST['feetype'] = '1';
                    }
                    // $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 sn.id as nid, sn.*, um.*, u.name as username FROM stdnt_monthlyfee sn JOIN user_master um ON um.id=sn.sid JOIN user_master u ON u.id=sn.fk_user_id WHERE (DATE(edate) BETWEEN '$date1' AND '$date2') AND sn.month='$_POST[month]' AND sn.syear='$_POST[syear]' AND sn.feetype='$_POST[feetype]'");//(sn.edate='$date') AND 
                    $table = Form::dbtableprint($blood, ['Reciept No', 'Admission Number', 'Hallticket Number', 'Name', 'Paid Amount', 'Paid to', 'remarks'], ['nid', 'ano', 'no', 'name', 'amount', 'username', 'remarks'], '', '', '');
                }
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Date Wise Fee Collection Report</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">   
                                            <div class="row">
                                                <div class="col-md-4">
                                                    <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 class="col-md-4">
                                                    <div class="form-group">                                            
                                                        <select name="month" id="month" class="form-control" required>
                                                            <option value="">Select Month</option>
                                                            '.$month.'
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-4">
                                                    <div class="form-group">
                                                        <select name="syear" id="syear" class="form-control" required>
                                                            <option value="">Select Year</option>
                                                            '.Menus::year().'
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>
                                        
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="From Date" class="form-control" name="fromdate" id="fromdate" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">             
                                                        <input placeholder="To Date" class="form-control" name="todate" id="todate" onfocus="(this.type=`date`)" onblur="(this.type=`text`)">                               
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$table.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo Menus::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>';
                }
            }
        }
    }
    /*Monthly Fee Collection --  Ended*/
    /*Addtional Fee Collection --  started*/
    public static function additionalfeecollection()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $feetype = Homem::getdata("SELECT * FROM `additional_fee_type`");
            $a = '<div class="row">';
            for($i=0; $i<sizeof($feetype); $i++)
            {
                $a .= '
                <div class="col-md-6">
                    <div class="form-group">
                        <input name="feetype['.$feetype[$i]['id'].']" id="feetype['.$feetype[$i]['id'].']" class="form-control" placeholder="'.$feetype[$i]['name'].'" >
                    </div>
                </div>';      
            }
            $a .= '</div>';
            $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 sa.id as rid, sa.*, um.* FROM stdnt_additionalfee sa JOIN user_master um ON um.id=sa.sid WHERE sa.fk_user_id='$_SESSION[user_id]' AND sa.paid_date='$date' AND sa.status='1'");
                $table = Form::dbtableprint($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'rid', 'total'], '/Accounts/additionalfeeprint', 'rid', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/saveadditionalfeecolectnew" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Additional 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 required>                                         
                                                    </div>
                                                </div>
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Student Mobile Number" readonly>                                         
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="email" id="email" class="form-control" placeholder="Student Email" readonly required>                                         
                                                    </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="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            '.$a.'
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">
                                                        <input type="number" name="total" id="total" class="form-control" placeholder="Total Amount Paid" required>
                                                        
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                    <input type="hidden" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date"> 
                                                    <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                   
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row" id="modifylink" style="display:none;">
                                                    <div class="col-lg-12">
                                                        <div class="float-lg-right"><a href="javascript:void(0);" onclick="updatecontactdetails()">Change Contact Information</a></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 Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function saveadditionalfeecolectnew()
    {
        $date = date('Y-m-d');
        $i = 1;
        $total = 0;
        foreach ($_POST['feetype'] as $value) {
                if($value=="")
                {
                    $value = 0;
                }
                  $a[$i] = $value;
                  $i++;
                  $total = $total+(int)$value;
            }
            $b = json_encode($a);
        if($total == $_POST['total'] && $total>0)
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
            if(sizeof($data) == 1)
            {
                $query="INSERT INTO `stdnt_additionalfee` (`id`, `sid`, `sno`, `year`, `mode`, `fees`, `total`, `remarks`, `fk_user_id`, `paid_date`, `status`) VALUES 
                (NULL, '$_POST[sid]', '$_POST[no]', '$_POST[year]', '$_POST[feemode]', '$b', '$_POST[total]', '$_POST[remarks]', '$_SESSION[user_id]', '$date', '1')";
                Homem::insert($query);
                echo '<script>window.location = "/Accounts/additionalfeecollection?status=1";</script>';
            }
            else
             {
                 echo '<script>window.location = "/Accounts/additionalfeecollection?status=0";</script>';
             } 
             
         }
         else
         {
             echo '<script>window.location = "/Accounts/additionalfeecollection?status=0";</script>';
         }
            // echo Extra::additionalfeetype(3);
            
    }
    public static function additionalfeeprint()
    {
        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.id, sn.total, sn.paid_date, sn.year, sn.mode, sn.fees, sn.fk_user_id, um.no, um.name, um.fk_course_id, um.fk_dept_id FROM stdnt_additionalfee sn JOIN user_master um ON sn.sid=um.id WHERE sn.id='$_GET[editid]') a JOIN fee_mode fm ON a.mode=fm.id JOIN user_master u ON a.fk_user_id=u.id");
                $a ='';
                $d = json_decode($data[0]['fees'], true);
                for($i=0; $i<sizeof($d); $i++)
                {
                    $j = $i+1;
                    if($d[$j] > 0)
                    {
                        $a .= '<tr style="text-align: center;"><td width="70%" style="border: thin solid black">'.Extra::additionalfeetype($j).'</td><td width="70%" style="border: thin solid black">'.number_format($d[$j], 2).'</td></tr>';        
                    }
                }
                $a .= '<tr style="text-align: center;"><td width="70%" style="border: thin solid black"><b>Total Amount</b></td><td width="70%" style="border: thin solid black">'.number_format($data[0]['total'], 2).'</td></tr>';
                
            }
            if(sizeof($data) == 1)
            {
                echo Menus::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">
                                    <br/ ><br/ ><br/ ><br/ >
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        '.static::recieptheader().'
                                                        <tr>
                                                            <td><span style="margin-left: 10px;">Reciept Number: '.$data[0]['id'].'</span></td>
                                                            <td style="text-align: right;"><span style="margin-right: 10px;">Date: '.Extra::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>'.Extra::course($data[0]['fk_course_id']).'-'.Extra::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>'.Extra::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>
                                                            '.$a.'
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td colspan="2">
                                                                <span style="margin-left: 10px;"><b>Amount in words: </b>'.Extra::numtotext($data[0]['total']).'</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 Menus::script();
        }
    }

    public static function additionalfeecollectionsummary()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            $feetype = Inputs::optionsdb(Homem::getdata("SELECT * FROM `additional_fee_type`"), 'id', 'name');
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), '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');
            $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');
            $table = '';
            $a ='';
            {
                $date = date('Y-m-d');
                if(isset($_POST['course']))
                {
                    $_POST['month'] = date('m');
                    $_POST['syear'] = date('Y');
                                    $blood = Homem::getdata("SELECT sn.id as nid, sn.*, um.name, um.ano, um.no, u.name as username FROM stdnt_additionalfee sn JOIN user_master um ON um.id=sn.sid JOIN user_master u ON u.id=sn.fk_user_id");//(sn.edate='$date') AND 
                $blood = Homem::getdata("SELECT sn.id as nid, sn.*, um.name, um.ano, um.no, u.name as username FROM stdnt_additionalfee sn JOIN user_master um ON um.id=sn.sid JOIN user_master u ON u.id=sn.fk_user_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]'  AND um.fromyear='$_POST[fromyear]' AND sn.year='$_POST[year]' ORDER BY um.no ASC");//(sn.edate='$date') AND 
                //additionalfeecollectionsummary
                $blood = Extra::additionalfeefeedivisonforreports(json_encode($blood));
                $type = $_POST['feetype'];
                $typename = Extra::additionalfeetype($type);
                $data = json_decode(Extra::additionalfeefeedivisonforreportsbysinlefeeid($blood, $type), true);
                $a = '';
                $type = 'type'.$_POST['feetype'];
                $k=0;
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i][$type] > 0)
                    {
                        $k++;
                        $a .= '<tr><td>'.$k.'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.$data[$i][$type].'</td><td>'.$data[$i]['username'].'</td><td>'.Extra::datem($data[$i]['paid_date']).'</td></tr>';
                    }
                }
                // echo json_encode($blood);
                // $table = Form::dbtableprint($blood, ['Reciept No', 'Admission Number', 'Hallticket Number', 'Name', 'Paid Amount', 'Paid to', 'remarks'], ['nid', 'ano', 'no', 'name', 'total', 'username', 'remarks'], '', '', '');
            }
            $a = '<div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr><th>S. No.</th><th>Pin</th><th>Name</th><th>Amount</th><th>Paid to</th><th>Paid Date</th></tr>
                        </thead>
                        <tbody>
                            '.$a.'
                        </tbody>
                    </table>
                </div>';
                }

            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"> 
                            </div>
                            <div class="col-lg-8">
                                <form action="/Accounts/additionalfeecollectionsummary" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Additional Fee Collection Summary</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="course" id="course" class="form-control" required>
                                                            <option value="">Course</option>
                                                            ';
                                                            echo $course;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="department" id="department" class="form-control" required>
                                                            <option value="">Department</option>
                                                            ';
                                                            echo $dept;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="fromyear" id="fromyear" class="form-control" required>
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo $styear;
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <div class="form-group">                                            
                                                            <select name="year" id="year" class="form-control" required>
                                                                <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-4">
                                                        <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-4">
                                                    <div class="form-group">
                                                    </div>
                                                </div> 
                                                <div class="col-md-4">
                                                    <div class="form-group">                                            
                                                       												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-4">
                                                    <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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-2">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$a.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function additionalfeecollectionsummarybetweentwodates()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $table = '';
            $a ='';
            {
                $date = date('Y-m-d');
                if(isset($_POST['fromdate']))
                {
                    $date1 = $_POST['fromdate'];
                    $date2 = $_POST['todate'];
                    //SELECT * FROM `stdnt_additionalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2'
                // $blood = Homem::getdata("SELECT sn.id as nid, sn.*, um.name, um.ano, um.no, u.name as username FROM stdnt_additionalfee sn JOIN user_master um ON um.id=sn.sid JOIN user_master u ON u.id=sn.fk_user_id");//(sn.edate='$date') AND 
                $data = Homem::getdata("SELECT um.no, um.name, um.fk_course_id, um.fk_dept_id, a.id, a.sno, a.sid, a.year, a.mode, a.fees, a.total, a.paid_date, u.name as uname FROM (SELECT * FROM `stdnt_additionalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2') a JOIN user_master um ON a.sid=um.id JOIN user_master u ON a.fk_user_id=u.id");//(sn.edate='$date') AND 
                //additionalfeecollectionsummary
                // $blood = Extra::additionalfeefeedivisonforreports(json_encode($blood));
                // $type = $_POST['feetype'];
                // $typename = Extra::additionalfeetype($type);
                // $data = json_decode(Extra::additionalfeefeedivisonforreportsbysinlefeeid($blood, $type), true);
                // $a = '';
                // $type = 'type'.$_POST['feetype'];
                $k=0;
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i]["total"] > 0)
                    {
                        $subdata = json_decode($data[$i]['fees'], true);
                        for($j=1; $j<=sizeof($subdata); $j++)
                        {
                            if($subdata[$j]>0 && $subdata[$j]!=0)
                            {
                                $k++;
                                $a .= '<tr><td>'.$k.'</td><td>'.$data[$i]['id'].'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.Extra::additionalfeetype($j).'</td><td>'.$subdata[$j].'</td><td>'.Extra::datem($data[$i]['paid_date']).'</td><td>'.$data[$i]['uname'].'</td></tr>';
                                
                            }
                        }
                    }
                }
                // echo json_encode($blood);
                // $table = Form::dbtableprint($blood, ['Reciept No', 'Admission Number', 'Hallticket Number', 'Name', 'Paid Amount', 'Paid to', 'remarks'], ['nid', 'ano', 'no', 'name', 'total', 'username', 'remarks'], '', '', '');
            }
            $a = '<div class="table-responsive">
                    <table class="table table-responsive-sm">
                        <thead>
                            <tr><th>S. No.</th><th>Receipt No</th><th>Pin</th><th>Name</th><th>Amount</th><th>Paid to</th><th>Paid Date</th><th>Received By</th></tr>
                        </thead>
                        <tbody>
                            '.$a.'
                        </tbody>
                    </table>
                </div>';
                }

            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-2"> 
                            </div>
                            <div class="col-lg-8">
                                <form action="/Accounts/additionalfeecollectionsummarybetweentwodates" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Additional Fee Collection Summary</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="fromdate" id="fromdate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="FROM DATE" required>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <input type="text" name="todate" id="todate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="TO DATE" required>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <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>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-2">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$a.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    /*Addtional Fee Collection --  Ended*/
    public static function allotstdprofeebulk()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Accounts/saveallotstdprofeebulk" 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 by Unique ID</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_collectiobyid_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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function saveallotstdprofeebulk()
    {
        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)
                    {
                        $_POST['sname'] = trim($data[0]);
                        $_POST['mobile'] = trim($data[1]);
                        $_POST['course'] = trim($data[2]);
                        $_POST['department'] = trim($data[3]);
                        $_POST['amount'] = trim($data[4]);
                        $recieptno = trim($data[5]);
                        $paid_date = trim($data[6]);
                        $date =Extra::datemodify($paid_date);
                        if($_POST['sname'] != '' && $_POST['amount'] !='')
                        {
                            Homem::insert("INSERT INTO `stdnt_provisionaladmissionfee` (`id`, `name`, `mobile`, `fk_course_id`, `fk_dept_id`, `amount`, `fk_stdntenquiry_id`, `receipt_no`, `fk_user_id`, `regdate`, `status`) VALUES (NULL, '$_POST[sname]', '$_POST[mobile]', '$_POST[course]', '$_POST[department]', '$_POST[amount]', '', '$recieptno', '$_SESSION[user_id]', '$date', '1')");
                            $i++;
                        }
                    }
                    echo '<script>window.location = "/Accounts/allotstdprofeebulk?status=1&count='.$i.'";</script>';
                }
            }
        }
    }
    public static function totalbetweendates($date1, $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");
    }
    public static function testnewreport()
    {
        $subtable = '';
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 && isset($_POST['year']))
        {
            $date1 = $_POST['fromdate'];
            $date2 = $_POST['todate'];
        $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='$_POST[feetype]' 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='$_POST[feetype]'  AND (um.discontinued='' OR um.tc_given='') AND (sf.paid_date<'$date1')");//DATE(paid_date) BETWEEN '$date1' AND '$date2'
                $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).'">'.Extra::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.Extra::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.Extra::dept($dept[$c]).'</td>'; 
                }
                $tt = 0;

                for($e=0; $e<=3; $e++)
                {
                    $t = 0;
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    for($ff=1; $ff<=$f; $ff++)
                    {
                        if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                        {
                            $a .= '<td><a href="/Accounts/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="/Accounts/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="/Accounts/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 Menus::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>
                                                            '.Menus::year().'
                                                        </select>                                          
                                                    </div>
                                                </div>                           
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">  
                                                    <div class="form-group">
                                                        <input type="text" name="fromdate" id="fromdate" onfocus="this.type=`date`" onblur="this.type=`text`" placeholder="To Date" class="form-control" required>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">  
                                                    <div class="form-group">
                                                        <input type="text" name="todate" id="todate" onfocus="this.type=`date`" onblur="this.type=`text`" placeholder="From Date" class="form-control">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">  
                                                    <div class="form-group">
                                                        <input type="text" name="feetype" id="feetype" placeholder="Fee Type" class="form-control" required>
                                                    </div>
                                                </div>
                                                <div class="col-md-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 Menus::script();
    }
    public static function testnewreporttwo()
    {
        $subtable = '';
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 && isset($_POST['year']))
        {
            $date1 = $_POST['fromdate'];
            $date2 = $_POST['todate'];
        $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='2' 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='2'  AND (um.discontinued='' OR um.tc_given='') AND (sf.paid_date<'$date1')");//DATE(paid_date) BETWEEN '$date1' AND '$date2'
                $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).'">'.Extra::course($course[$b]).'</td>'; 
            for($c=0; $c<sizeof($dept); $c++)
            {
                if($c == 0)
                {
                $a .= '<td>'.Extra::dept($dept[$c]).'</td>'; 
                }
                else
                {
                $a .= '<tr><td>'.Extra::dept($dept[$c]).'</td>'; 
                }
                $tt = 0;

                for($e=0; $e<=3; $e++)
                {
                    $t = 0;
                    $f = $e+1;
                    $ssyear = $styear-$e;
                    for($ff=1; $ff<=$f; $ff++)
                    {
                        if(isset($ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear']))
                        {
                            $a .= '<td><a href="/Accounts/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="/Accounts/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="/Accounts/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 Menus::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>
                                                            '.Menus::year().'
                                                        </select>                                          
                                                    </div>
                                                </div>                           
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">  
                                                    <div class="form-group">
                                                        <input type="text" name="fromdate" id="fromdate" onfocus="this.type=`date`" onblur="this.type=`text`" placeholder="To Date" class="form-control" required>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">  
                                                    <div class="form-group">
                                                        <input type="text" name="todate" id="todate" onfocus="this.type=`date`" onblur="this.type=`text`" placeholder="From Date" class="form-control" required>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                        <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                        
                                    </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 Menus::script();
    }
    public static function newindex()
    {
        echo Menus::css();
        echo '<body>';
        echo Menus::normalmenu();
        if(Menus::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="/Accounts/accountsauth" method="POST" enctype="multipart/form-data">-->
                                            <div class="form-group">
                                                <div class="float-center">Login Here</div>
                                            </div>
                                            <div class="form-group">
                                                <select class="form-control" name="orgname" id="orgname" required>
                                                    <option value="">Select College</option>
                                                    <option value="1">Hindu College - Main Campus</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>
                                            <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 otpinput" style="display: none;">
                                                <input type="text" class="form-control" name="otp" id="otp" placeholder="Enter OTP (Mobile / Email)" required>
                                            </div>
                                            <div class="form-group btn_reg">
                                                <div class="float-right">
                                                    <button type="submit" class="btn btn-primary" style="background-color: #002366 !important;" value="Submit" onclick="getotp()" >Get OTP</button>
                                                </div>
                                                
                                            </div>
                                            <div class="form-group btn_check" style="display: none;">
                                                <div class="float-right">
                                                    <button type="submit" class="btn btn-primary" style="background-color: #002366 !important;" value="Submit" onclick="getcheckotp()" >Verify & Login</button>
                                                </div>
                                                
                                            </div>
                                        <!-- </form>-->
                                    </div>
                                </div>
                                </div>
                                <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                ';
                echo '
                <script>
                function getotp()
                {
                    console.log("test");
                    var username = $("#username").val();
                    var orgname = $("#orgname").val();
                    var password = $("#password").val();
                    $.ajax({
                        url: "/Accounts/getotp",
                        type: "post",
                        data: {username: username, password: password, orgname: orgname},
                        success: function(d) {
                            if(d != "fail")
                            {
                                $(".otpinput").show();
                                $(".btn_reg").hide();
                                $(".btn_check").show();
                            }
                            else
                            {
                                $(".otpinput").hide();
                                $(".btn_check").hide();
                                <!--$(".btn_reg").hide();-->
                            }
                        }
                    });
                }
                function getcheckotp()
                {
                    var username = $("#username").val();
                    var orgname = $("#orgname").val();
                    var password = $("#password").val();
                    var otp = $("#otp").val();
                    $.ajax({
                        url: "/Accounts/getotp",
                        type: "post",
                        data: {username: username, password: password, orgname: orgname, otp: otp},
                        success: function(d) {
                            if(d != "fail")
                            {
                                $(".otpinput").show();
                                $(".btn_reg").hide();
                                $(".btn_check").show();
                            }
                            else
                            {
                                $(".otpinput").hide();
                                $(".btn_check").hide();
                                <!--$(".btn_reg").hide();-->
                            }
                        }
                    });
                }
                </script>';
        }
        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="/Accounts/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 Menus::script();
    }
    public static function getotp()
    {
        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)
            {
                $id=$data[0]['id'];
                date_default_timezone_set('Asia/Kolkata'); 
                $otptime= date('Y-m-d H:i:s A');
                $token = substr(str_shuffle('0123456789'), 1, 5);
                Homem::insert("INSERT INTO `login_otp` (`fk_user_id`, `fk_org_id`, `otp`, `otptime`, `status`) VALUES ('$id', '$_SESSION[org_id]', '$token', '$otptime', '1')");
                Emails::loginotpsend($data[0]['name'], $data[0]['email'], $token);
                echo 'success';
            }
            else
            {
                echo 'fail';
            }
        }
        else
        {
            echo 'fail';
        }
    }
    public static function profile()
    {
        if(Menus::checkbrower() == 1 && $_SESSION['user_role'] != '')
        {
            echo Menus::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-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/Accounts/saveprofile" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Profile</div>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="id" id="id" placeholder="Employee ID" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="text" class="form-control" name="name" id="name" placeholder="Name" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="number" class="form-control" name="mobile" id="mobile" placeholder="Mobile Number" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="email" class="form-control" name="email" id="email" placeholder="Email" 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-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        
        echo '</body>';
        echo Menus::script();
        if($_SESSION['user_id']!='')
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_SESSION[user_id]'");
            if($data[0]['id'] == $_SESSION['user_id'])
            {
                echo '<script>
                $("#id").val("'.$data[0]['no'].'");
                $("#name").val("'.$data[0]['name'].'");
                $("#mobile").val("'.$data[0]['mobile'].'");
                $("#email").val("'.$data[0]['email'].'");
                </script>';
            }
        }
        }
        if(isset($_GET['status']))
        {
            if($_GET['status'] == '1')
            {
                echo '<script>swal("Success", "Updated Scuccessfully", "success");</script>';
            }
            if($_GET['status'] == '0')
            {
                echo '<script>swal("Sorry", "Something went wrong .. Please try again later.", "error");</script>';
            }
        }
    }
    public static function saveprofile()
    {
        if(Menus::checkbrower() == 1 && $_SESSION['user_role'] != '')
        {
            if(isset($_POST['name']))
            {
                Homem::insert("UPDATE `user_master` SET `no`='$_POST[id]', `name`='$_POST[name]', `mobile`='$_POST[mobile]', `email`='$_POST[email]' WHERE `id`='$_SESSION[user_id]'");
                echo '<script>window.location = "/Accounts/profile?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Accounts/profile?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location = "/Accounts/logout";</script>';
        }
    }
    public static function changepassword()
    {
        if(Menus::checkbrower() == 1 && $_SESSION['user_role'] != '')
        {
            echo Menus::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-4"></div>
                                <div class="col-xl-4">
                                <div class="card">
                                    <div class="card-body">
                                        <form action="/Accounts/savechangepassword" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Change Password Here</div>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="oldpassword" id="oldpassword" placeholder="Old Password" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="newpassword" id="newpassword" placeholder="New Password" required>
                                            </div>
                                            <div class="form-group">
                                                <input type="password" class="form-control" name="cnfnewpassword" id="cnfnewpassword" placeholder="Confirm New 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-4"></div>
                            </div>
                        </div>
                    </div>
                ';
        }
        echo '</body>';
        echo Menus::script();
        if(isset($_GET['status']))
        {
            if($_GET['status'] == '1')
            {
                echo '<script>swal("Success", "Updated Scuccessfully", "success");</script>';
            }
            if($_GET['status'] == '0')
            {
                echo '<script>swal("Sorry", "Something went wrong .. Please try again later.", "error");</script>';
            }
        }
    }
    public static function savechangepassword()
    {
        if(Menus::checkbrower() == 1 && $_SESSION['user_role'] != '')
        {
            if($_POST['newpassword'] == $_POST['cnfnewpassword'])
            {
                Homem::insert("UPDATE `user_master` SET `password`='$_POST[newpassword]' WHERE `id`='$_SESSION[user_id]' AND `password`='$_POST[oldpassword]'");
                echo '<script>window.location = "/Accounts/changepassword?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Accounts/changepassword?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location = "/Accounts/logout";</script>';
        }
    }

    // testing for edit
    public static function indstdntfeereport()
    {
        if($_SESSION['org_id'] == 1)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 2)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 3)
        {
            return 
            '
            <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($_SESSION['org_id'] == 4)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 5)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                <h1>Hindu College of Management</h1>
                <h5>Amaravathi Road, Guntur-522002, Andhra Pradesh</h5>
                <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 6)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }

    }
    private static function recieptheader()
    {
        if($_SESSION['org_id'] == 1)
        {
            return '
            <tr style="text-align: center;">
                <td>
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </td>
                <td>
                    <h1>HINDU COLLEGE, GUNTUR</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                </td>
            </tr>
            ';
        }
        if($_SESSION['org_id'] == 2)
        {
            return '
            <tr style="text-align: center;">
                <td>
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </td>
                <td>
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                </td>
            </tr>
            ';
        }
        if($_SESSION['org_id'] == 3)
        {
            return '
            <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>
            ';
        }
        if($_SESSION['org_id'] == 4)
        {
            return '
            <tr style="text-align: center;">
                <td>
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </td>
                <td>
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                </td>
            </tr>
            ';
        }
        if($_SESSION['org_id'] == 5)
        {
            return '
            <tr style="text-align: center;">
                <td>
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </td>
                <td>
                    <h1>Hindu College of Management</h1>
                    <h5>Amaravathi Road, Guntur-522002, Andhra Pradesh</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                </td>
            </tr>
            ';
        }
        if($_SESSION['org_id'] == 6)
        {
            return '
            <tr style="text-align: center;">
                <td>
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </td>
                <td>
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Receipt</a>
                </td>
            </tr>
            ';
        }
    }
    private static function recieptfront()
    {
        date_default_timezone_set('Asia/Kolkata'); 
        $date =  date('ym'); 
        return $date;
    }
    public static function recieptno()
    {
        date_default_timezone_set('Asia/Kolkata'); 
        $date =  date('Y-m-');
        
        // $query = "SELECT * FROM `stdnt_normalfee` WHERE `entry_date`='$date'";
        $query = "SELECT * FROM `stdnt_normalfee` WHERE `paid_date` LIKE '%$date%'";
        $data = Homem::getdata($query);
        $count = sizeof($data);
        $new = $count+1;
        $rno = static::recieptfront().'-'.$new;
        $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `recieptno`='$rno'");
        if(sizeof($data) == 0)
        {
            return $rno;
        }
        else
        {
            return 'retry';
        }

    }
    public static function getusernamemobileemail()
    {
        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]'");
            $data[0]["deptname"] = Extra::course($data[0]["fk_course_id"]).' - '.Extra::dept($data[0]["fk_dept_id"]);
            echo json_encode($data);
        }
    }
    public static function addcoplayerinner()
    {
        echo '
        <div class="bootstrap-modal">
          <div class="modal fade" id="addcoplayerinner" role="dialog">
            <div class="modal-dialog">
            
              <!-- Modal content-->
              <div class="modal-content">
              <div class="modal-header">
                    <h5 class="modal-title">Update Student Contact Information</h5>
                    <button type="button" class="close" data-dismiss="modal"><span>×</span>
                    </button>
                </div>
                <div class="modal-body">
                <div class="row" >
                  <div class="col-md-12">
                    <div class="form-group">
                        <input type="hidden" name="id" id="id" class="form-control" placeholder="Student ID*" required>
                        <input type="text" name="sno" id="sno" class="form-control" placeholder="Hallticket Number*" required>
                    </div>
                    <div class="form-group">
                        <input id="sname" type="text" name="sname" class="form-control" placeholder="Full Name in Block Letters*" required="required"/>
                    </div>
                  </div>
                </div>
                <div class="row" >
                  <div class="col-md-6">
                    <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-md-6">
                    <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" required="">
                    </div>
                  </div>
                </div>
                <div class="row" >
                  <div class="col-md-6">
                    <div class="form-group">
                      <input id="semail" type="email" name="semail" class="form-control" placeholder="Mobile *" required="required" />
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                        <input id="smobile" type="number" name="smobile" class="form-control" placeholder="Student Mobile*" required="required" />
                    </div>
                  </div>
                </div>
            <div class="row" >
                <div class="col-md-6">
                  <div class="form-group">
                    <input id="fname" type="text" name="fname" class="form-control" placeholder="Parent Name *" required="required" />
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="form-group">
                      <input id="fmobile" type="number" name="fmobile" class="form-control" placeholder="Parent Mobile*" required="required" />
                  </div>
                </div>
              </div>
                <!--
                <div class="row" >
                  <div class="col-md-12">
                    <div class="form-group">
                      <input id="address" name="address" class="form-control" placeholder="Address *" required />
                    </div>
                  </div>
                </div>
                -->
                </div>
                <div class="modal-footer">
                    <div class="form-group"><button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button></div>
                    <div class="form-group"><button type="button" id="SaveNewCoplayer" class="btn btn-primary" onclick="snewcoplayer()">Save</button></div>
                </div>
              </div>
              
            </div>
          </div>
          </div>
        ';
        echo '
            <script>
                function snewcoplayer() 
                { 
                    var sid = document.getElementById("id");
                    var sno = document.getElementById("sno");
                    var sname = document.getElementById("sname");
                    var gender = document.getElementById("gender");
                    var dob = document.getElementById("dob");
                    var smobile = document.getElementById("smobile");
                    var semail = document.getElementById("semail");
                    var fname = document.getElementById("fname");
                    var fmobile = document.getElementById("fmobile");
                    if(sid.value==""){$("#sid").focus();}
                    else if(sno.value==""){$("#sno").focus();}
                    else if(sname.value==""){$("#sname").focus();}
                    else if(gender.value==""){$("#gender").focus();}
                    else if(dob.value==""){$("#dob").focus();}
                    else if(smobile.value==""){$("#smobile").focus();}
                    else if(semail.value==""){$("#semail").focus();}
                    else if(fname.value==""){$("#fname").focus();}
                    else if(fmobile.value==""){$("#fmobile").focus();}
                    else
                    {
                        $("#addcoplayerinner").modal("hide"); 
                        $.ajax({
                            url: "/Accounts/savesnewcoplayerinner",
                            type: "post",
                            data: {sid:sid.value, sno:sno.value, name: sname.value, gender:gender.value, dob:dob.value, mobile:smobile.value, email:semail.value, fname:fname.value, fmobile:fmobile.value},
                            success: function(d) {
                                if(d == "success")
                                {
                                    // alert(d);
                                    swal("Updated Successfully", "Please Click on Ok to Continue", "success");
                                    var delayMs = 500; // delay in milliseconds
                                    setTimeout(function(){
                                        window.location = "/Accounts/normalfeecolectnew?no="+sno.value;
                                    }, delayMs);
                                    
                                    // location.reload();
                                }
                                else
                                {
                                    // alert(d);
                                    swal("Not Updated", "Something went Wrong.. Please tryagain later..", "error");
                                    // var delayMs = 500; // delay in milliseconds
                                    // setTimeout(function(){
                                    //     $("#foundcoplayerinner").modal("show");
                                    // }, delayMs);
                                }
                            }
                        });
                    }
                }
            </script>';
    }
    public static function savesnewcoplayerinner()
    {
        if($_SESSION['user_id'] != '')
        {
            if($_POST['email'] != '' && $_POST['mobile'] != '')
            {
                $date = date('Y-m-d');
                $query = "UPDATE `user_master` SET `name`='$_POST[name]', `fname`='$_POST[fname]', `fmobile`='$_POST[fmobile]', `dob`='$_POST[dob]', `gender`='$_POST[gender]', `mobile`='$_POST[mobile]', `email`='$_POST[email]', `add_by`='$_SESSION[user_id]', `add_date`='$date' WHERE `id`='$_POST[sid]' AND `no`='$_POST[sno]'";
                Homem::insert($query);
                echo 'success';
            }
            else
            {
                echo 'fail';
            }
        }
    }
    public static function normalfeelatest()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $feetype = sizeof(Homem::getdata("SELECT * FROM `fee_types`"));
            $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::dbtableprint($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Accounts/print', 'nid', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/savenormalfeelatest" 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 required>                                         
                                                    </div>
                                                </div>
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Student Mobile Number" readonly>                                         
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="email" id="email" class="form-control" placeholder="Student Email" readonly required>                                         
                                                    </div>
                                                </div> 
                                                
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control" onchange="gettotaldueamount()" 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-12">
                                                    <div class="form-group">
                                                        <input type="hidden" name="duedata" id="duedata" class="form-control" placeholder="Due Data" required>
                                                        <input type="hidden" name="feetype" id="feetype" class="form-control" value="'.$feetype.'" required>
                                                    </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 required>                                         
                                                    </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="hidden" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">                                         
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                    <input type="hidden" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date"> 
                                                    <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                   
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row" id="modifylink" style="display:none;">
                                                    <div class="col-lg-12">
                                                        <div class="float-lg-right"><a href="javascript:void(0);" onclick="updatecontactdetails()">Change Contact Information</a></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 id="duetable" style="margin:20px;"></div>
                            </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 Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getlatestduetable()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getstudentfeedetails",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                                // console.log(d);
                                document.getElementById("duetable").innerHTML = d;
                        }
                    });
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getlatestduetable();
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function gettotaldueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    $.ajax({
                        url: "/Accounts/gettotaldueamount",
                        type: "post",
                        data: {no: no, year: year},
                        success: function(d) {
                        const a = JSON.parse(d);
                            if(d != "fail")
                            {
                                document.getElementById("duedata").value = d;
                                document.getElementById("dueamount").value = a["total"];
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function gettotaldueamount()
    {
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            if(isset($_POST['no']) && isset($_POST['year']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE `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]'");
                    if(sizeof($setdata) > 0)
                    {
                        $total = 0;
                        for($i=0; $i<sizeof($setdata); $i++)
                        {
                            $feetype= $setdata[$i]['fk_feetype_id'];
                            $feedata = Homem::getdata("SELECT SUM(amount) as amount FROM `stdnt_normalfee` WHERE `no`='$sid' AND `year`='$_POST[year]' AND `fk_feetype_id`='$feetype'");
                            $amount = $feedata[0]['amount'];
                            if($amount == NULL)
                            {
                                $amount = 0;
                            }
                            $adata[$feetype]['actual'] = $setdata[$i]['feeamount'];
                            $adata[$feetype]['paid'] = $amount;
                            $adata[$feetype]['due'] = (int)$adata[$feetype]['actual'] - (int)$adata[$feetype]['paid'];
                            $total = $total + $adata[$feetype]['due'];
                        }
                        $adata['total'] = $total;
                        echo json_encode($adata);
                    }
                    else
                    {
                        echo 'fail';
                    }
                }
            }
        }
    }
    }
    public static function savenormalfeelatest()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $_POST['paydate'] =$date;
            $data1 = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
            $balence = 0;
            $amount = $_POST['paidamount'];
            $data = json_decode($_POST['duedata'], true);
            $feetype = $_POST['feetype'];
            $_POST['paydate'] = date('Y-m-d');
            $date = date('Y-m-d');
            $count=0;
            if(sizeof($data1)==1 && $amount <=$data['total'])
            {
                //for($i=1; $i<=$feetype; $i++)
                for($i=$feetype; $i>=1; $i--) 
                {
                    if(isset($data[$i]))
                    {
                        if($amount>0 )
                        {
                            $al=0;
                            if($amount >= $data[$i]['due'])
                            {
                                $balence = $amount - $data[$i]['due'];
                                $data[$i]['newpaid'] = $data[$i]['due'];
                                $_POST['amount'] = $data[$i]['due'];
                                $amount = $balence;
                                $al=1;
                            }
                            if($amount < $data[$i]['due'] && $al==0)
                            {
                                $_POST['amount'] = $amount;
                                $amount = 0;
                            }
                            $_POST['recieptno'] = static::recieptno();
                            if($_POST['recieptno'] != 'retry')
                            {
                                $_POST['recieptno'] = $_POST['recieptno'];
                            }
                            $data[$i]['recieptno'] = $_POST['recieptno'];
                            
                            $data1 = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `no`='$_POST[sid]' AND `year`='$_POST[year]' AND `fk_feetype_id`='$i' AND `amount`='$_POST[amount]' AND `paid_date`='$date' AND `entry_id`='$_SESSION[user_id]'");
                            if(sizeof($data1) == 0)
                            {
                                $count++;
                                if($_POST['amount']>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]', '$i', '$_POST[amount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                                    Extra::sendsmsactive($_POST['name'], $_POST['amount'], Extra::datem($date), $_POST['recieptno'], $_POST['mobile']);
                                }
                                // echo '<script>window.location = "/Accounts/normalfeelatest?status=1";</script>';
                            }
                            else
                            {
                                echo '<script>window.location = "/Accounts/normalfeelatest?status=0";</script>';
                            }
                        }
                        // if($amount>0)
                        // {
                        //     $data[$i]['newpaid'] = $amount;
                        //     $balence = $amount - $data[$i]['due'];
                        //     $data[$i]['newpaid'] = $data[$i]['due'];
                            
                        //     $_POST['recieptno'] = static::recieptno();
                        //     if($_POST['recieptno'] != 'retry')
                        //     {
                        //         $_POST['recieptno'] = $_POST['recieptno'];
                        //     }
                        //     $data[$i]['recieptno'] = $_POST['recieptno'];
                        //     $_POST['amount'] = $amount;
                        //     $amount = $balence;
                        //     $data1 = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `no`='$_POST[sid]' AND `year`='$_POST[year]' AND `fk_feetype_id`='$i' AND `amount`='$_POST[amount]' AND `paid_date`='$date' AND `entry_id`='$_SESSION[user_id]'");
                        //     if(sizeof($data1) == 0)
                        //     {
                        //         $count++;
                        //         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]', '$i', '$_POST[amount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                        //         Extra::sendsmsactive($_POST['name'], $_POST['amount'], Extra::datem($date), $_POST['recieptno'], $_POST['mobile']);
                        //         echo '<script>window.location = "/Accounts/normalfeelatest?status=1";</script>';
                        //     }
                        //     else
                        //     {
                        //         echo '<script>window.location = "/Accounts/normalfeelatest?status=0";</script>';
                        //     }
                        // }
                    }
                }
                // echo json_encode($data);
                // $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 `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]', '', '')");
                //             Extra::sendsmsactive($_POST['name'], $_POST['paidamount'], Extra::datem($date), $_POST['recieptno'], $_POST['mobile']);
                //             echo '<script>window.location = "/Accounts/normalfeelatest?status=1";</script>';
                //         }
                //         else
                //         {
                //             echo '<script>window.location = "/Accounts/normalfeelatest?status=2";</script>';
                //         }
                //     }
                //     else
                //     {
                //         Homem::insert("UPDATE `stdnt_normalfee` SET `no`='$_POST[sid]', `year`='$_POST[year]', `fk_feetype_id`='$_POST[feetype]', `amount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paid_date`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `nid`='$_POST[edit_id]'");
                //         echo '<script>window.location = "/Accounts/normalfeelatest?status=2";</script>';
                //     }
                // }
            }
            else
            {
                echo '<script>window.location = "/Accounts/normalfeelatest?status=0";</script>';
            }
            if($count !=0)
            {
                echo '<script>window.location = "/Accounts/normalfeelatest?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Accounts/normalfeelatest?status=0";</script>';
            }
        }
    }
    
    public static function normalfeecolectnew()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $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::dbtableprint($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Accounts/print', 'nid', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/savenormalfeecolectnew" 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 required>                                         
                                                    </div>
                                                </div>
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Student Mobile Number" readonly>                                         
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="email" id="email" class="form-control" placeholder="Student Email" readonly required>                                         
                                                    </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="hidden" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">                                         
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                    <input type="hidden" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date"> 
                                                    <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                   
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row" id="modifylink" style="display:none;">
                                                    <div class="col-lg-12">
                                                        <div class="float-lg-right"><a href="javascript:void(0);" onclick="updatecontactdetails()">Change Contact Information</a></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 id="duetable"></div>
                            </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 Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Accounts/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Accounts/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getlatestduetable()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getstudentfeedetails",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                                // console.log(d);
                                document.getElementById("duetable").innerHTML = d;
                        }
                    });
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getlatestduetable();
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function savenormalfeecolectnew()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $_POST['paydate'] =$date;
            $_POST['recieptno'] = static::recieptno();
            if($_POST['recieptno'] != 'retry')
            {
                $_POST['recieptno'] = $_POST['recieptno'];
            
            $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 `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]', '', '')");
                        Extra::sendsmsactive($_POST['name'], $_POST['paidamount'], Extra::datem($date), $_POST['recieptno'], $_POST['mobile']);
                        echo '<script>window.location = "/Accounts/normalfeecolectnew?status=1";</script>';
                    }
                    else
                    {
                        echo '<script>window.location = "/Accounts/normalfeecolectnew?status=2";</script>';
                    }
                }
                else
                {
                    Homem::insert("UPDATE `stdnt_normalfee` SET `no`='$_POST[sid]', `year`='$_POST[year]', `fk_feetype_id`='$_POST[feetype]', `amount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paid_date`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `nid`='$_POST[edit_id]'");
                    echo '<script>window.location = "/Accounts/normalfeecolectnew?status=2";</script>';
                }
            }
            }
            else
            {
                echo '<script>window.location = "/Accounts/normalfeecolectnew?status=0";</script>';
            }
        }
    }
    /* alter table user_master convert to character set utf8 collate utf8_general_ci;*/

    /** Common Table alterrations - must needed
     * ALTER TABLE `user_master` ADD `fname` INT NOT NULL AFTER `name`;
     * ALTER TABLE `user_master` ADD `lateral` VARCHAR(1) NOT NULL AFTER `fk_dept_id`;
     * ALTER TABLE `user_master` ADD `add_by` VARCHAR(22) NOT NULL AFTER `v_email`, ADD `add_date` VARCHAR(30) NOT NULL AFTER `add_by`;
     */

     /**
      * ALTER TABLE `user_master` ADD `discontinued` VARCHAR(1) NOT NULL AFTER `add_date`, ADD `tc_given` VARCHAR(1) NOT NULL AFTER `discontinued`;
      */
    /**
     * Student marks uploading bulk - started
     */
    public static function uploadstdmarksbulk()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Accounts/saveuploadstdmarksbulk" 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-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_marks_bulkupload_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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }   
    public static function saveuploadstdmarksbulk()
    {
        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)
                    {
                        $course = trim($data[0]);
                        $regulation = trim($data[1]);
                        $year = trim($data[2]);
                        $sem = trim($data[3]);
                        $htno = trim($data[4]);
                        $subcode = trim($data[5]);
                        $subname = trim($data[6]);
                        $grade = trim($data[7]);
                        $credits = trim($data[8]);
                        $resulttype = trim($data[9]);
                        $exammonth = trim($data[10]);
                        $examyear = trim($data[11]);
                        $paid_date = trim($data[12]);
                        $resultdate =Extra::datemodify($paid_date);
                        if($htno != '' && $subcode !='')
                        {
                            $query = "INSERT INTO `results_data` (`id`, `year`, `sem`, `ht_no`, `sub_code`, `sub_name`, `internal`, `external`, `grade`, `credit`, `exammonth`, `examyear`, `resultdate`, `result_type`, `examtype`, `fk_user_id`, `status`, `fk_org_id`, `fk_course_id`) VALUES (NULL, '$year', '$sem', '$htno', '$subcode', '$subname', '', '', '$grade', '$credits', '$exammonth', '$examyear', '$resultdate', '$resulttype', '$resulttype', '$_SESSION[user_id]', '1', '$_SESSION[org_id]', '$course')";
                            Homem::insert($query);
                            $i++;
                        }
                    }
                    echo '<script>window.location = "/Accounts/uploadstdmarksbulk?status=1&count='.$i.'";</script>';
                }
            }
        }
    }

    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">'.Extra::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>'.Extra::month($sub_data[$sub_code[$k]]['month']).'</td>';
                                    $a .= '<td>'.$sub_data[$sub_code[$k]]['year'].'</td>';
                                    $a .= '<td>'.Extra::resulttype($sub_data[$sub_code[$k]]['examtype'], $sub_data[$sub_code[$k]]['count']).'</td>';
                                    $a .= '<td>'.Extra::datem($sub_data[$sub_code[$k]]['resultdate']).'</td>';
                                    $a .= '<td>'.Extra::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 Menus::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 Menus::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
     */
    /**
     * Student Fee payment details bulk uploading by id
     */
    public static function allotstdfeebyid()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Accounts/saveallotstdfeebyid" 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 by Unique ID</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_collectiobyid_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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function saveallotstdfeebyid()
    {
        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)
                    {
                        $id = trim($data[0]);
                        $year = trim($data[1]);
                        $feetype = trim($data[2]);
                        $amount = trim($data[3]);
                        $recieptno = trim($data[4]);
                        $feemode = trim($data[5]);
                        $paid_date = trim($data[6]);
                        $paiddate =Extra::datemodify($paid_date);
                        if($id != '' && $amount !='')
                        {
                            $query = "INSERT INTO `stdnt_normalfee` (`nid`, `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 (NULL, '$id', '$year', '$feetype', '$amount', '$recieptno', '$feemode', '$paiddate', '', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')";
                            Homem::insert($query);
                            $i++;
                        }
                    }
                    echo '<script>window.location = "/Accounts/allotstdfeebyid?status=1&count='.$i.'";</script>';
                }
            }
        }
    }




    /** 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 Menus::css();
        echo '<body>';
        echo Menus::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 Menus::script();
    }
    public static function suggestions()
    {
        echo Menus::css();
        echo '<body>';
        echo Menus::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 Menus::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="/Accounts/suggestions?status=1";</script>';
        }
        else
        {
            echo '<script>window.location="/Accounts/suggestions?status=0";</script>';
        }
    }
    public static function contactus()
    {
        echo Menus::css();
        echo '<body>';
        echo Menus::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="/Accounts/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 Menus::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="/Accounts/contactus?status=1";</script>';
        }
        else
        {
            echo '<script>window.location="/Accounts/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="/Accounts/index" >Home</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Accounts/latest" >Latest News</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Accounts/suggestions" >Suggestions</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" href="/Accounts/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;
    }
    public static function index()
    {
        echo Menus::css();
        echo '<body>';
        echo Menus::normalmenu();
        if(Menus::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="/Accounts/accountsauth" method="POST" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <div class="float-center">Login Here</div>
                                            </div>
                                            <div class="form-group">
                                                <select class="form-control" name="orgname" id="orgname" required>
                                                    <option value="">Select College</option>
                                                    <option value="1">Hindu College - Main Campus</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>
                                            <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>
                                        </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="/Accounts/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 Menus::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" >
                        Internal exams
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #002366;">
                        <a class="dropdown-item" href="/Internalexams/fixdatesofinternalexam" >Student Result</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="/Accounts/logout" >Logout</a>
                        </div>
                    </li>
                    </ul>
                </div>
            </nav>
        ';
        return $menu;
    }
    public static function collegename($id)
    {
        if($id == 1)
        {
            return "HINDU COLLEGE";
        }
        elseif($id == 3)
        {
            return "HINDU COLLEGE OF ENGINEERING AND TECHNOLOGY";
        }
        elseif($id == 4)
        {
            return "HINDU COLLEGE PG COURSES";
        }
        else
        {
            return "HINDU COLLEGE OF MANAGEMNET";
        }
    }
    public static function accountsauth()
    {
        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_start();
                $_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['org_name'] = static::collegename($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'] == 2)
                {
                    $_SESSION['menu'] = Menus::facultymenu();
                }
                if($data[0]['user_role'] == 3)
                {
                    $_SESSION['menu'] = Menus::studentmenu();
                }
                if($data[0]['user_role'] == 4)
                {
                    $_SESSION['menu'] = Menus::classinchargesmainmenu();
                }
                if($data[0]['user_role'] == 5)
                {
                    $_SESSION['menu'] = Menus::collectionmainmenu();
                }
                if($data[0]['user_role'] == 6)
                {
                    $_SESSION['menu'] = Menus::adminmainmenu();
                }
                if($data[0]['user_role'] == 9)
                {
                    $_SESSION['menu'] = Menus::usermenu();
                }
                if($data[0]['user_role'] == 10)
                {
                    $_SESSION['menu'] = Menus::examfeecollectionmenu();
                }
                echo '<script>window.location="/Accounts/home";</script>';
            }
            else
            {
                echo '<script>window.location="/Accounts/index?status=0";</script>';
            }
        }
        else
        {
            echo '<script>window.location="/Accounts/index?status=0";</script>';
        }
            
    }
    public static function home()
    {
        if($_SESSION['user_role'] != '')
        {
            echo Menus::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:30px;">
                            <div class="col-xl-12">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo Menus::script();
            if($_SESSION['user_role'] != "")
            {
                // $data = Homem::getdata("SELECT * FROM `user_master` WHERE ((`no`=`password`) OR (`mobile`=`password`) OR (`email`=`password`)) AND `id`='$_SESSION[user_id]'");
                // if(sizeof($data) != 0)
                // {
                //     echo '<script>window.location="/Homes/changepassword";</script>';
                // }
                // $data = Homem::getdata("SELECT * FROM `user_master` WHERE `mobile`='' AND `id`='$_SESSION[user_id]'");
                // if(sizeof($data) != 0)
                // {
                //     echo '<script>window.location="/Homes/changemobile";</script>';
                // }
                // $data = Homem::getdata("SELECT * FROM `user_master` WHERE `email`='' AND `id`='$_SESSION[user_id]'");
                // if(sizeof($data) != 0)
                // {
                //     echo '<script>window.location="/Homes/changeemail";</script>';
                // }
            }
        }
    }
    public static function userorgchange()
    {
        if($_SESSION['user_role'] == 6)
        {
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            if(Menus::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 Menus::script();
            echo '
                <script>
                    setTimeout(function(){ 
                        $("#orgname").val("'.$_SESSION['org_id'].'");
                    }, 1000);
                    function changeuserorgid()
                    {
                        var orgid = $("#orgname").val();
                        $.ajax({
                            url: "/Accounts/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()
    {
        $_SESSION['user_role'] = '';
        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="/Accounts/index";</script>';
    }
    /** Ending of Login Screen and Authentication */



    /* start of fee Setting section */
    public static function allotstdfee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Accounts/saveallotstdfee" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <header class="panel_header">
                                                    <h5 class="title pull-left">Bulk Fee Setting Entry</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                <input type="file" name="file" id="file" class="form-control" placeholder="Category Name">
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">   
                                                                <input type="hidden" name="type" id="type" class="form-control" value="bulk" placeholder="Type">                                         
                                                                <a href="/hindu/formats/stdnt_fee_format.csv">Click Here to Download Uploading Format</a>
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#amount").val("'.$data[0]['feeamount'].'");
                        $("#terms").val("'.$data[0]['terms'].'");
                        $("#edit_id").val("'.$data[0]['fid'].'");
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }

    public static function allotindstdfee()
    {
        if($_SESSION['user_role'] == 4 || $_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');
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/saveallotstdfee" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Setting Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()" required>      
                                                        <input type="hidden" name="sid" id="sid" class="form-control" placeholder="Student Uniq ID" required >
                                                    </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 required>                                         
                                                    </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" 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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                            getuserid();
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            // if(isset($_GET['editid']))
            // {
            //     $data = Homem::getdata("SELECT * FROM `stdnt_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 saveallotstdfee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            $date = date('Y-m-d');
            if($_POST['type'] == 'bulk')
            {
                $filename=$_FILES['file']['name'];
                $exts[0]='csv';
                $filetype1 = explode('.',$filename);
                if($_FILES['file']['name']!=null && $filetype1[sizeof($filetype1)-1] == $exts[0])
                {
                    $csv_file=$_FILES['file']['tmp_name'];
                    $size=$_FILES['file']['size'];
                    $handle = fopen($csv_file, "r");
                    $data = fgetcsv($handle, 100000, ",");
                    $i = 0;
                    while (($data = fgetcsv($handle, 100000, ","))!== FALSE)
                    {
                        $no = trim($data[0]);
                        $year = trim($data[1]);
                        $feetype = trim($data[2]);
                        $amount = trim($data[3]);
                        $terms = trim($data[4]);
                        $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `ano`='$no' OR `no`='$no'");
                        if(sizeof($udata) == 1)
                        {
                            $sid = $udata[0]['id'];
                            if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
                            {
                                Homem::insert("UPDATE `stdnt_feemaster` SET `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'");
                                $i++;
                            }
                            else
                            {
                                Homem::insert("INSERT INTO `stdnt_feemaster` (`no`, `year`, `fk_feetype_id`, `feeamount`, `fk_org_id`, `reg_date`, `fk_user_id`, `terms`) VALUES ('$sid', '$year', '$feetype', '$amount', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '$terms')");
                                $i++;
                            }
                        }
                    }
                    echo '<script>window.location = "/Accounts/allotstdfee?status=1&count='.$i.'";</script>';
                }
            }
            if($_POST['type'] == 'single')
            {
                $no = $_POST['no'];
                $year = $_POST['year'];
                $feetype = $_POST['feetype'];
                $amount = $_POST['amount'];
                $terms = $_POST['terms'];
                $udata = Homem::getdata("SELECT * FROM `user_master` WHERE `ano`='$no' OR `no`='$no'");
                if(sizeof($udata) == 1)
                {
                    $sid = $udata[0]['id'];
                    if($sid==$_POST['sid'])
                    {
                    if($_POST['edit_id'] == '')
                    {   
                        if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'")) > 0)
                        {
                            Homem::insert("UPDATE `stdnt_feemaster` SET `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `no`='$sid' AND `year`='$year' AND `fk_feetype_id`='$feetype' AND `fk_org_id`='$_SESSION[org_id]'");
                            echo '<script>window.location = "/Accounts/allotindstdfee?status=2";</script>';
                        }
                        else
                        {
                            Homem::insert("INSERT INTO `stdnt_feemaster` (`no`, `year`, `fk_feetype_id`, `feeamount`, `fk_org_id`, `reg_date`, `fk_user_id`, `terms`) VALUES ('$sid', '$year', '$feetype', '$amount', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '$terms')");
                            echo '<script>window.location = "/Accounts/allotindstdfee?status=1";</script>';
                        }
                    }
                    // else
                    // {
                    //     if(sizeof(Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'")) == 1)
                    //     {
                    //         Homem::insert("UPDATE `stdnt_feemaster` SET `no`='$sid', `year`='$year', `fk_feetype_id`='$feetype', `feeamount`='$amount', `reg_date`='$date', `fk_user_id`='$_SESSION[user_id]', `terms`='$terms' WHERE `fid`='$_POST[edit_id]' AND `fk_org_id`='$_SESSION[org_id]'");
                    //         echo '<script>window.location = "/Accounts/allotindstdfee?status=2";</script>';
                    //     }
                    // }
                    else
                    {
                        echo '<script>window.location = "/Accounts/allotindstdfee?status=0";</script>';
                    }
                    }
                }
            }
        }
    }
    public static function deptwisefeesettingreport()
    {
        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');
            $table = '';
            if(isset($_POST['course']))
            {
                $blood = Homem::getdata("SELECT * FROM user_master um JOIN stdnt_feemaster sf ON um.id=sf.no  JOIN fee_types ft ON sf.fk_feetype_id=ft.f_id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND um.toyear='$_POST[toyear]' AND um.org_id='$_SESSION[org_id]' AND sf.year='$_POST[years]' AND sf.fk_feetype_id='$_POST[feetypes]'");
                $table = Form::dbtableed($blood, ['Year', 'Fee Type', 'Hallticket Number', 'Name', 'Amount'], ['year', 'f_name', 'no', 'name', 'feeamount'], '/Accounts/allotindstdfee', 'fid', '');
            }
            echo Menus::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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `fid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#amount").val("'.$data[0]['feeamount'].'");
                        $("#terms").val("'.$data[0]['terms'].'");
                        $("#edit_id").val("'.$data[0]['fid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }

    public static function 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'], '/Accounts/normalfeeconcession', 'nid', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/savenormalfeecolect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Concession Details Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control">
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <select name="feetype" id="feetype" class="form-control" onchange="getdueamount()" required>
                                                            <option value="">Select Fee Type</option>
                                                            '.$feetype.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="dueamount" id="dueamount" class="form-control" placeholder="Due Amount" readonly>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount">                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Concession Date" required="">
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                         
                                                    </div>
                                                </div>   
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="recieptno" id="recieptno" class="form-control" value="CONCESSION" placeholder="Reciept Number">                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="feemode" id="feemode" class="form-control" value="0" required>
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </div>
                                                </div>                            
                                            </div> 
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                        <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                    </div>
                                                </div>
                                            </div>  
                                        </div>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    /* end of fee Setting section */
    
    /* start of fee collection section */

    public static function nfeecollectbulk()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4">
                            </div>
                            <div class="col-lg-4"> 
                                <form action="/Accounts/savebulknfeecollection" method="POST" enctype="multipart/form-data">                                      
                                    <div class="row">
                                        <div class="col-lg-12">
                                            <section class="box" style="margin-top: 30px;">
                                                <header class="panel_header">
                                                    <h5 class="title pull-left">Bulk Fee Collection Entry</h5>
                                                </header>
                                                <div class="content-body">    
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">                                      
                                                                <input type="file" name="file" id="file" class="form-control" placeholder="Category Name">
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="form-group">   
                                                                <input type="hidden" name="type" id="type" class="form-control" value="bulk" placeholder="Type">                                         
                                                                <a href="/hindu/formats/stdnt_fee_collection_format.csv">Click Here to Download Uploading Format</a>
                                                            </div>
                                                        </div>                              
                                                    </div>
                                                    <div class="row">
                                                        <div class="col-md-12">  
                                                            <div class="form-group">
                                                                <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>                        
                                            </section>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div class="col-lg-4">
                            </div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::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="/Accounts/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 ipgdata()
    {
        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 sn JOIN user_master um ON um.id=sn.no WHERE (sn.fk_feemode_id='7' AND sn.entry_id='639') AND sn.fk_org_id='$_SESSION[org_id]' ORDER BY sn.nid DESC");
                $table = Form::dbtableed($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Accounts/print', 'nid', '');
            }
            echo Menus::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">
                                
                            </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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                            getuserid();
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function 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'], '/Accounts/normalfeecolect', '', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Accounts/savenormalfeecolect" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly>                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control" 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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                            getuserid();
                        }
                    });
                }
                function getdueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    var feetype = $("#feetype").val();
                    $.ajax({
                        url: "/Accounts/getdueamount",
                        type: "post",
                        data: {no: no, year: year, feetype: feetype},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("dueamount").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function savenormalfeecolect()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 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 = "/Accounts/normalfeecolect?status=1";</script>';
                    }
                    else
                    {
                        echo '<script>window.location = "/Accounts/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 = "/Accounts/normalfeecolect?status=2";</script>';
                }
            }
            else
            {
                echo '<script>window.location = "/Accounts/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 (`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 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 10)
        {
            $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]].'">'.Extra::nyear($fyear[$j]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.Extra::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>'.Extra::datem($data[$k]['entry_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>'.Extra::datem($data[$k]['entry_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>'.Extra::datem($data[$k]['entry_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]].'">'.Extra::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>'.Extra::datem($data[$k]['entry_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>'.Extra::datem($data[$k]['entry_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=static::indstdntfeereport();
                    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">'.Extra::course($mdata[0]['fk_course_id']).' ('.Extra::squota($mdata[0]['squota'], $mdata[0]['fk_course_id']).')</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Department</th><th colspan="3">'.Extra::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">'.Extra::course($mdata[0]['fk_course_id']).' ('.Extra::squota($mdata[0]['squota'], $mdata[0]['fk_course_id']).')</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Department</th><th colspan="3">'.Extra::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;
                    $totalfee= Homem::getdata("SELECT SUM(`feeamount`) AS `amount` FROM `stdnt_feemaster` WHERE `no`='$uid'");
                    $totalpaid= Homem::getdata("SELECT SUM(`amount`) AS `amount` FROM `stdnt_normalfee` WHERE `no`='$uid'");
                    $actual = $totalfee[0]["amount"];
                    $paid = $totalpaid[0]["amount"];
                    if($actual-$paid <=0)
                    {
                        $subtable .= '<div id="feestatus" style="padding:10px; font-weight:bold; width:fit-content; border:1px solid #ccc; background-color:green; color:white;">Total Fee Cleared by the student. He / She is Eligible for Applying TC</div>';
                    }
                    else
                    {
                        $due = $actual-$paid;
                        $subtable .= '<div id="feestatus" style="padding:10px; font-weight:bold; width:fit-content; border:1px solid #ccc; background-color:red; color:white;">Student has a due amount of '.$due.'. Not Eligible for Applying TC</div>';
                    }
                    $subtable .= static::htnowisedetailedreport($uid);
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
                
            }
            echo Menus::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 Menus::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 htnowisedetailedreport($sid)
    {
        $data = Homem::getdata("SELECT sf.no, sf.year, sf.fk_feetype_id, ft.f_name, MAX(sf.feeamount) AS actual, COALESCE(SUM(sn.amount), 0) AS paid, MAX(sf.feeamount) - COALESCE(SUM(sn.amount), 0) AS due FROM stdnt_feemaster sf LEFT JOIN stdnt_normalfee sn ON sf.no = sn.no AND sf.year = sn.year AND sf.fk_feetype_id = sn.fk_feetype_id JOIN fee_types ft ON sf.fk_feetype_id = ft.f_id WHERE sf.no = '$sid' GROUP BY sf.no, sf.year, sf.fk_feetype_id, ft.f_name ORDER BY sf.year, sf.fk_feetype_id;");
        // $data = Homem::getdata("SELECT sf.no, sf.year, sf.fk_feetype_id, ft.f_name, COALESCE(SUM(sf.feeamount), 0) AS actual, COALESCE(SUM(sn.amount), 0) AS paid, COALESCE(SUM(sf.feeamount), 0) - COALESCE(SUM(sn.amount), 0) AS due FROM stdnt_feemaster sf LEFT JOIN stdnt_normalfee sn ON sf.no = sn.no AND sf.year = sn.year AND sf.fk_feetype_id = sn.fk_feetype_id JOIN fee_types ft ON sf.fk_feetype_id = ft.f_id WHERE sf.no = '$sid' GROUP BY sf.no, sf.year, sf.fk_feetype_id, ft.f_name ORDER BY sf.year, sf.fk_feetype_id");
        $table = Form::dbtableprint($data, ['Year', 'Fee Type', 'Actual', 'Paid', 'Due'], ['year', 'f_name', 'actual', 'paid', 'due'], '', '', '');
        return $table;
        
    }
    public static function slist()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 10)
        {
            $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 `id` ASC");
                if(sizeof($data) > 0)
                {
                    $table = Form::dbtableed($data, ['Admission Number', 'Hall Ticket Number', 'Name', 'Gender'], ['ano', 'no', 'name', 'gender'], '/Accounts/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 Menus::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 Menus::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 Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="/Accounts/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="C">Convener Quota</option>
                                                                <option value="M">Management Quota</option>
                                                                <option value="S">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>
                                                        </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" required>
                                                        </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" required>
                                                            <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" required>
                                                            <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" required>
                                                            <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" required>
                                                            <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" required>
                                                            <option value="">Starting Year</option>
                                                            ';
                                                            echo Menus::year();
                                                            echo '
                                                            </select>
                                                        </div>
                                                    </div>  
                                                    <div class="col-lg-4">
                                                        <div class="form-group">                                            
                                                            <select name="toyear" id="toyear" class="form-control" required>
                                                            <option value="">Ending Year</option>
                                                            ';
                                                            echo Menus::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 Menus::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success"); delay(5000); window.location.href="/Accounts/home";</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success"); delay(5000); window.location.href="/Accounts/home"; </script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error"); delay(5000); window.location="/Accounts/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`='$_SESSION[org_id]'"));
                if($mdata == 0 && $edata == 0 && $data == 0)
                {
                    $date = date('Y-m-d');
                    // $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')";
                    $query = "INSERT INTO `user_master` (`id`, `ano`, `roll_no`, `section`, `medieum`, `adm_type`, `squota`, `noofyears`, `no`, `name`, `fname`, `fmobile`, `dob`, `gender`, `blood_group`, `fk_course_id`, `fk_dept_id`, `lateral`, `org_id`, `fromyear`, `toyear`, `regulation`, `mobile`, `email`, `password`, `user_role`, `status`, `v_mobile`, `v_email`, `add_by`, `add_date`, `discontinued`, `tc_given`) VALUES (NULL, '$_POST[admission]', '$_POST[hallticket]', '', '', '$_POST[quota]', '', '', '$_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]', '123456789', '3', '1', '', '', '$_SESSION[user_id]', '$date', '', '')";
                    Homem::insert($query);
                    echo '<script>window.location = "/Accounts/addstudent?status=1";</script>';
                }
                else
                {
                    echo '<script>window.location = "/Accounts/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.id as opid, u.name as opname FROM (SELECT sn.nid, sn.recieptno, sn.amount, sn.paid_date, sn.year, sn.fk_feetype_id, sn.fk_feemode_id, sn.entry_id, um.id as sid, 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='$_GET[editid]') a JOIN fee_mode fm ON a.fk_feemode_id=fm.id JOIN user_master u ON a.entry_id=u.id");
                $rid = $data[0]['nid'];
                $id = $data[0]['sid'];
                $year=$data[0]['year'];
                $entry = $data[0]['opid'];
                $entrydate = $data[0]['paid_date'];
                $data1 =  Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `no`='$id' AND `year`='$year' AND `entry_id`='$entry' AND `entry_date`='$entrydate' AND `nid`!='$rid'");
                $a='';
                $sum = $data[0]['amount'];
                if(sizeof($data1)>0)
                {
                    
                    for($i=0; $i<sizeof($data1); $i++)
                    {
                        $sum = $sum+(int)$data1[$i]['amount'];
                        $a.='<tr style="text-align: center;">
                            <td width="70%" style="border: thin solid black">
                                '.Extra::feetype($data1[$i]['fk_feetype_id']).'-('.$data1[$i]['recieptno'].')
                            </td>
                            <td width="30%" style="border: thin solid black">
                                '.number_format($data1[$i]['amount'], 2).'
                            </td>
                            </tr>';
                    }
                
                }
            }
            if(sizeof($data) == 1)
            {
                echo Menus::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">
                                    <br/ ><br/ ><br/ ><br/ >
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        '.static::recieptheader().'
                                                        <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: '.Extra::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>'.Extra::course($data[0]['fk_course_id']).'-'.Extra::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>'.Extra::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">
                                                                '.Extra::feetype($data[0]['fk_feetype_id']).'
                                                            </td>
                                                            <td width="30%" style="border: thin solid black">
                                                                '.number_format($data[0]['amount'], 2).'
                                                            </td>
                                                        </tr>'.$a.'
                                                    </tbody>
                                                </table>
                                                <table width="100%">
                                                    <tbody>
                                                        <tr>
                                                            <td colspan="2">
                                                                <span style="margin-left: 10px;"><b>Amount in words: </b>'.Extra::numtotext($sum).'</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 Menus::script();
        }
    }
    public static function dprint()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $_SESSION['org_id'] = 6;
            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='$_GET[editid]') a JOIN fee_mode fm ON a.fk_feemode_id=fm.id JOIN user_master u ON a.entry_id=u.id");
            }
            $_SESSION['org_id'] = 1;
            if(sizeof($data) == 1)
            {
                echo Menus::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">
                                    <br/ ><br/ ><br/ ><br/ >
                                    <div style="border: solid 1px black; border-radius: 10px;">
                                        <div class="row">
                                            <div class="col-lg-12">
                                                <table width="100%">
                                                    <tbody>
                                                        '.static::recieptheader().'
                                                        <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: '.Extra::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>'.Extra::course($data[0]['fk_course_id']).'-'.Extra::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>'.Extra::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">
                                                                '.Extra::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>'.Extra::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 Menus::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">'.Extra::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 Menus::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 Menus::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 deptwiseconsoladditionalfee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 ||  $_SESSION['user_role'] == 5)
        {
            $subtable = '';
            $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 `additional_fee_type`"), 'id', 'name');
            if(isset($_POST['course']))
            {
                $data = Homem::getdata("SELECT sa.*, um.no, um.name, u.name as uname FROM stdnt_additionalfee sa JOIN user_master um ON um.id=sa.sid JOIN user_master u ON sa.fk_user_id=u.id WHERE um.fk_course_id='$_POST[course]' AND um.fk_dept_id='$_POST[department]' AND um.fromyear='$_POST[fromyear]' AND sa.status='1' ORDER BY um.no ASC");
                for($i=0; $i<sizeof($data); $i++)
                {
                    $d = json_decode($data[$i]['fees'],true);
                    $amount = $d[$_POST['feetype']];
                    $data[$i]['amount'] = $amount;
                }
                $a = '';
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i]['amount'] >0)
                    {
                        $j = $i+1;
                        $a .= '<tr><td>'.$j.'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.$data[$i]['amount'].'</td><td>'.Extra::datem($data[$i]['paid_date']).'</td><td>'.$data[$i]['uname'].'</td></tr>';
                        
                    }
                }
                $body = '<tbody>'.$a.'</tbody>';
            $head = '<thead><tr><th>S. NO.</th><th>Hall. NO.</th><th>Name</th><th>Amount</th><th>Date</th><th>Paid To</th></tr></thead>';
            $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 Menus::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="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>
                                                <div class="row">
                                                    <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 class="col-md-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 Menus::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 deptwiseconsolmonthlyfee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6 ||  $_SESSION['user_role'] == 5)
        {
            $subtable = '';
            $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 `feetypemonthly`"), 'id', 'name');
            $month = Inputs::optionsdb(Homem::getdata("SELECT * FROM `month`"), 'month_id', 'month_name');
            if(isset($_POST['feetype']))
            {
                $data = Homem::getdata("SELECT sa.*, um.no, um.name, u.name as uname FROM stdnt_monthlyfee sa JOIN user_master um ON um.id=sa.sid JOIN user_master u ON sa.fk_user_id=u.id WHERE  sa.status='1' AND sa.feetype='$_POST[feetype]' AND sa.syear='$_POST[syear]' AND sa.month='$_POST[month]' ORDER BY um.no ASC");
                $a = '';
                for($i=0; $i<sizeof($data); $i++)
                {
                    if($data[$i]['amount'] >0)
                    {
                        $j = $i+1;
                        $a .= '<tr><td>'.$j.'</td><td>'.$data[$i]['no'].'</td><td>'.$data[$i]['name'].'</td><td>'.$data[$i]['amount'].'</td><td>'.Extra::datem($data[$i]['edate']).'</td><td>'.$data[$i]['uname'].'</td></tr>';
                        
                    }
                }
                $body = '<tbody>'.$a.'</tbody>';
            $head = '<thead><tr><th>S. NO.</th><th>Hall. NO.</th><th>Name</th><th>Amount</th><th>Date</th><th>Paid To</th></tr></thead>';
            $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 Menus::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-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 class="col-md-6">
                                                        <div class="form-group">
                                                            <select name="month" id="month" class="form-control"  required>
                                                                <option value="">Select Month</option>
                                                                '.$month.'
                                                            </select>
                                                        </div>
                                                    </div>                                       
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6">  
                                                        <div class="form-group">
                                                            <select name="syear" id="syear" class="form-control"  required>
                                                            <option value="">Select Fee Year</option>
                                                            '.Menus::year().'
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">  
                                                        <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 Menus::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">'.Extra::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 Menus::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 Menus::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 deptwiseconsolactive()
    {
        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]' AND (um.discontinued='' AND um.tc_given='')");
                    $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]' AND (um.discontinued='' AND um.tc_given='')");
                }
                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]' AND (um.discontinued='' AND um.tc_given='')");
                    $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]' AND (um.discontinued='' AND um.tc_given='')");
                
                }
                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]' AND (um.discontinued='' OR um.tc_given='')");
                    $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]' AND (um.discontinued='' AND um.tc_given='')");
                
                }
                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));
                    asort($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'] = (int)$data[$no[$i]][$fyear[$j]]['actualamount']-(int)$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 = (int)$totalactual+(int)$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 = (int)$actualfee+(int)$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">'.Extra::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 Menus::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 Menus::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 deptwiseconsolactivenewallfeetypefundamental()
    {
        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 (um.discontinued='' AND um.tc_given!='1')");
                    $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 (um.discontinued='' AND um.tc_given!='1')");
                }
                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 (um.discontinued='' AND um.tc_given!='1')");
                    $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 (um.discontinued='' AND um.tc_given!='1')");
                
                }
                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 (um.discontinued='' AND um.tc_given!='1')");
                    $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.discontinued='' AND um.tc_given!='1')");
                
                }
                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'];
                                    if(!isset($data[$no[$i]][$fyear[$j]]['actualamount']))
                                    {
                                        $data[$no[$i]][$fyear[$j]]['actualamount'] = 0;
                                    }
                                    $data[$no[$i]][$fyear[$j]]['actualamount'] = (int)$data[$no[$i]][$fyear[$j]]['actualamount']+(int)$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">'.Extra::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 Menus::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">
                                                        </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 Menus::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 coursewiseconsolactive()
    {
        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]' AND (um.discontinued='' AND um.tc_given='')");
                $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]' AND (um.discontinued='' AND um.tc_given='')");
                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">'.Extra::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 Menus::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 Menus::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 deptwiseconsolinactive()
    {
        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]' AND (um.discontinued!='' AND um.tc_given!='')");
                    $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]' AND (um.discontinued!='' AND um.tc_given!='')");
                }
                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]' AND (um.discontinued!='' AND um.tc_given!='')");
                    $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]' AND (um.discontinued!='' AND um.tc_given!='')");
                
                }
                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]' AND (um.discontinued!='' AND um.tc_given!='')");
                    $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]' AND (um.discontinued!='' AND um.tc_given!='')");
                
                }
                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">'.Extra::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 Menus::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 Menus::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 coursewiseconsolinactive()
    {
        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]' AND (um.discontinued!='' AND um.tc_given!='')");
                $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]' AND (um.discontinued!='' AND um.tc_given!='')");
                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">'.Extra::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 Menus::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 Menus::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 Menus::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 Menus::script();
            echo '
            <script>
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusername",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            document.getElementById("name").value = d;
                        }
                    });
                }
            </script>';
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    public static function datewisecon()
    {
        if($_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 5)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['date']))
            {
                $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE sn.paid_date='$_POST[date]' AND sn.fk_feemode_id!='5' order by sn.no ASC");
                if($_SESSION['user_role'] == 5)
                {
                    $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE sn.paid_date='$_POST[date]' AND sn.entry_id='$_SESSION[user_id]' AND sn.fk_feemode_id!='5' 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]['ano'].'</td>
                                    <td>'.$data[$i]['roll_no'].'</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>'.Extra::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.Extra::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>Admission Number</th>
                                    <th>Roll Number</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 Menus::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 Menus::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  a.*, um.*, fm.name as fmname, u.name as uname FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.no  JOIN fee_mode fm ON a.fk_feemode_id=fm.id JOIN user_master u ON u.id=a.entry_id AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");
                if($_SESSION['user_role'] == 5)
                {
                    $data = Homem::getdata("SELECT * FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2') a JOIN user_master um ON um.id=a.no WHERE a.entry_id='$_SESSION[user_id]' AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");    
                }
                if(sizeof($data) > 0)
                {
                    $tot = 0;
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['ano'].'</td>
                                    <td>'.$data[$i]['roll_no'].'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.Extra::datem($data[$i]['paid_date']).'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.Extra::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.Extra::feetype($data[$i]['fk_feetype_id']).'</td>
                                    <td>'.$data[$i]['fmname'].'</td>
                                    <td>'.$data[$i]['uname'].'</td>
                                </tr>';
                        $tot = $tot+$data[$i]['amount'];
                    }
                    $head = '<thead>
                                <tr><th colspan="3">Date wise Fee Collection Report</th><th colspan="3">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="3">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Admission Number</th>
                                    <th>Roll Number</th>
                                    <th>Hallticket Number</th>
                                    <th>Name</th>
                                    <th>Amount</th>
                                    <th>Paid Date</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Department</th>
                                    <th>Fee Type</th>
                                    <th>Type</th>
                                    <th>Name</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 Menus::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 Menus::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 reportbwndateswithopname()
    {
        // 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 a.*, um.*, u.name as opname FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2' ) a JOIN user_master um ON um.id=a.no JOIN user_master u ON u.id=a.entry_id AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");
                if($_SESSION['user_role'] == 5)
                {
                    $data = Homem::getdata("SELECT * FROM (SELECT * FROM `stdnt_normalfee` WHERE DATE(paid_date) BETWEEN '$date1' AND '$date2') a JOIN user_master um ON um.id=a.no WHERE a.entry_id='$_SESSION[user_id]' AND a.fk_feemode_id!='5' ORDER BY a.paid_date ASC");    
                }
                if(sizeof($data) > 0)
                {
                    $tot = 0;
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                        $a .= '<tr>
                                    <td>'.$k.'</td>
                                    <td>'.$data[$i]['ano'].'</td>
                                    <td>'.$data[$i]['roll_no'].'</td>
                                    <td>'.$data[$i]['no'].'</td>
                                    <td>'.$data[$i]['name'].'</td>
                                    <td>'.$data[$i]['amount'].'</td>
                                    <td>'.Extra::datem($data[$i]['paid_date']).'</td>
                                    <td>'.$data[$i]['recieptno'].'</td>
                                    <td>'.$data[$i]['year'].'</td>
                                    <td>'.Extra::course($data[$i]['fk_course_id']).'</td>
                                    <td>'.Extra::dept($data[$i]['fk_dept_id']).'</td>
                                    <td>'.Extra::feetype($data[$i]['fk_feetype_id']).'</td>
                                    <td>'.$data[$i]['opname'].'</td>
                                </tr>';
                        $tot = $tot+$data[$i]['amount'];
                    }
                    $head = '<thead>
                                <tr><th colspan="3">Date wise Fee Collection Report</th><th colspan="3">From: '.Extra::datem($_POST['fromdate']).'</th><th colspan="3">To: '.Extra::datem($_POST['todate']).'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Admission Number</th>
                                    <th>Roll Number</th>
                                    <th>Hallticket Number</th>
                                    <th>Name</th>
                                    <th>Amount</th>
                                    <th>Paid Date</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Course</th>
                                    <th>Department</th>
                                    <th>Fee Type</th>
                                    <th>Operator Name</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 Menus::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 Menus::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>';
                }
            }
        }
    }


}