<?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 Sreportsmis extends \Core\Controller
{
    public static function menuopionsoldreferitfirst()
    {
        $a = '
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="/Accounts/admcmpforfuryer" >Admission Comparison for Four Years (MIS)</a>
                <a class="dropdown-item" href="/Accounts/ovabstractbyayyear" >Overall Abstract for Academic Year (MIS)</a>
                <a class="dropdown-item" href="/Accounts/ovabstractforallcurses" >Overall Abstract for All Courses (MIS)</a>
                <a class="dropdown-item" href="/Accounts/ovabstractdueinacy" >Overall Abstract for Dues in Academic year (MIS)</a>
                <a class="dropdown-item" href="/Accounts/ovabstractdueinacylinks" >Detailed Overall Abstract for Dues in Academic year (MIS)</a>
                <a class="dropdown-item" href="/Accounts/ovabstractduebydiscotnuesinacylinks" >Detailed Overall Abstract for Dues of transfer and discontinued(MIS)</a>
                <a class="dropdown-item" href="/Accounts/ovabstractduebyexcludeddiscotnuesinacylinks" >Detailed Overall Abstract for Dues excluding transfer and discontinued(MIS)</a>
            ';
    }
    public static function reportbybook()
    {
        // Month & Year
        // $date = '2021-03-';
        // $data = Homem::getdata("SELECT * FROM `stdnt_normalfee` WHERE `paid_date` LIKE '%$date%'");
        if($_SESSION['user_role'] == 6)
        {
            $subtable = '';
            $a = '';
            if(isset($_POST['bookno']))
            {
                $bookno = '/'.$_POST['bookno'];
                $data = Homem::getdata("SELECT * FROM (SELECT * FROM `stdnt_normalfee` WHERE `recieptno`LIKE '%$bookno%') a JOIN user_master um ON um.id=a.no ORDER BY a.paid_date ASC");
                // AND sn. entry_id='$_SESSION[user_id]'
                if(sizeof($data) > 0)
                {
                    $tot = 0;
                    $r = array();
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $rno = explode("/", $data[$i]['recieptno']);
                        $r[] = $rno[0];
                    }
                    sort($r);
                    $m = 0;
                    for($j=0; $j<sizeof($r); $j++)
                    {
                        for($i=0; $i<sizeof($data); $i++)
                        {
                            $finalr = $r[$j].'/'.$_POST['bookno'];
                            if($finalr == $data[$i]['recieptno'])
                            {
                                $m++;
                                $a .= '<tr>
                                            <td>'.$m.'</td>
                                            <td>'.$data[$i]['no'].'</td>
                                            <td>'.$data[$i]['name'].'</td>
                                            <td>'.$data[$i]['amount'].'</td>
                                            <td>'.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>
                                        </tr>';
                                $tot = $tot+$data[$i]['amount'];
                            }
                        }
                    }
                    $head = '<thead>
                                <tr><th colspan="9">Book wise Fee Collection Report: '.$_POST['bookno'].'</th></tr>
                                <tr>
                                    <th>S. No.</th>
                                    <th>Hallticket Number</th>
                                    <th>Name</th>
                                    <th>Amount</th>
                                    <th>Paid Date</th>
                                    <th>Reciept Number</th>
                                    <th>Year</th>
                                    <th>Department</th>
                                    <th>Fee Type</th>
                                </tr>
                            </thead>';
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '<tr><td colspan="3">Total Amount Collected</td><td><b>'.$tot.'</b></td></tr>';
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo 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">Fee Collection by Book Wise</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-6">
                                                        <div class="form-group">                                            
                                                            <input placeholder="Book Number" class="form-control" name="bookno" id="bookno" required>
                                                        </div>
                                                    </div>    
                                                    <div class="col-lg-6">
                                                        <div class="form-group">             
                                                        </div>
                                                    </div>                            
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                            <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo 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>';
                }
            }
        }
    }
    /** Mis Reports   */
    private static function maxarray($my_array)
    {
      $max_val = (int) $my_array[0];
      for ($i = 1; $i < sizeof($my_array); $i++)
      {
        if ($max_val < (int) $my_array[$i])
        {
          $max_val = (int) $my_array[$i];
        } 
      }
      return $max_val;
    }
    private static function minarray($my_array)
    {
      $min_val = (int) $my_array[0];
      for ($i = 1; $i < sizeof($my_array); $i++)
      {
        if ($min_val > (int) $my_array[$i])
        {
          $min_val = (int) $my_array[$i];
        } 
      }
      return $min_val;
    }
    public static function admcmpforfuryer()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3'");
            $maxyear = array();
            $cyear = array();
            $crse = array();
            $dep = array();
            foreach ($data as $h) 
            {
                $maxyear[] = $h['noofyears'];
                $cyear[] = $h['fromyear'];
                $crse[] = $h['fk_course_id'];
                $dep[] = $h['fk_dept_id'];
            }
            $myear = array_values(array_unique($maxyear));
            sort($myear);
            $year = static::maxarray($myear);
            $fyear = array_values(array_unique($cyear));
            sort($fyear);
            $course = array_values(array_unique($crse));
            sort($course);
            $dept = array_values(array_unique($dep));
            sort($dept);
            for($a=1; $a<=$year; $a++)
            {
                for($b=0; $b<sizeof($course); $b++)
                {
                for($c=0; $c<sizeof($dept); $c++)
                {
                    for($d=0; $d<sizeof($fyear); $d++)
                    {
                    $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                    $asize = sizeof($adata);
                    $afee = 0;
                    $avg = 0;
                    $mafee = 0;
                    $mifee = 0;
                    if(sizeof($adata) > 0)
                    {
                        for($e=0; $e<sizeof($adata); $e++)
                        {
                        $afee = $afee + $adata[$e]['feeamount'];
                        }
                        $avg = $afee / sizeof($adata);
                        if(is_float($avg))
                        {
                        $avg = number_format((float) $avg, 2, '.', '');
                        }
                        $sfe = array();
                        foreach ($adata as $h) 
                        {
                        $sfe[] = $h['feeamount'];
                        }
                        $sfee = array_values(array_unique($sfe));
                        sort($sfee);
                        $mafee = static::maxarray($sfee);
                        $mifee = static::minarray($sfee);
                    }
                    $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'");
                    $psize = sizeof($pdata);
                    $pfee = 0;
                    if(sizeof($pdata) > 0)
                    {
                        for($e=0; $e<sizeof($pdata); $e++)
                        {
                            $pfee = $pfee + $pdata[$e]['amount'];
                        }
                    }
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                    $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                    }
                }
                }
            }
            $a = '';
            if(isset($_POST['years']))
            {
                if(is_numeric($_POST['years']))
                {
                    $year = $_POST['years'];
                }
                else
                {
                    $year = 3;
                }
            }
            else
            {
                $year = 3;
            }
            if(isset($_POST['year']))
            {
                if(is_numeric($_POST['year']))
                {
                    $styear = $_POST['year'];
                }
                else
                {
                    if (date('m') > 6) 
                    {
                        $styear = date('Y');
                    }
                    else
                    {
                        $styear = date('Y')-1;
                    }
                }
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
            if(isset($_POST['syears']))
            {
                if(is_numeric($_POST['syears']))
                {
                    $qq = $_POST['syears'];
                }
                else
                {
                    $qq = 1;
                }
            }
            else
            {
                $qq = 1;
            }
            // $styear = 2020;
            $syears = array();
            for($i=$year; $i>0; $i--)
            {
                $syears[] = $styear-$i;
            }
            $head= '';
            $sqq = $year+2;
            $head .= '<thead>';
            $head .= '<tr><th colspan="'.$sqq.'">Admission Comparison for Last '.$year.' Years, As on Date: '.date('d-m-Y').'(Students Corrsespond to Year: '.$qq.')</th></tr>';
            $head .= '<tr>';
            $head .= '<th>Course</th>';
            $head .= '<th>Department</th>';
            for($e=0; $e<sizeof($syears); $e++)
            {
                $incyear = $syears[$e]+1;
                $head .= '<th>'.$syears[$e].'-'.$incyear.'</th>';
            }
            $head .= '</tr></thead>';
            // $tcount = 0;
            for($e=0; $e<sizeof($syears); $e++)
            {
                $t[$syears[$e]] = 0;
            }

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

                                                    </div>
                                                </div>                           
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                    
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                        
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4"></div>
                    </div>
                    <div class="row print-this">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                        '.$subtable.'
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
            </form>
            ';
            echo '</body>';
            echo 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 paidfee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1'");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1'");
            $htno = array();
            foreach ($data as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                $total = $total + $paid[$no[$i]];
                $count = $count + $rcount[$no[$i]];
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$paid[$no[$i]].'</td>';
                $a .= '<td>'.$rcount[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td><td>'.$count.'</td></tr>';
            $head = '<tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th><th>No of Terms</th></tr>';
            $body = '<tbody>'; 
            $body .= $a;
            $body .= '</tbody>';
            $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px"><thead>'.$head.'</thead>
                    '.$body.'
                    </table>
                </div>
            ';
            $subtable = $table;
            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            echo 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">Fee Paid by the Students</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
                echo '</body>';
                echo 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 duefee()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1'");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1'");
            $htno = array();
            foreach ($masterdata as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                        $actual[$no[$a]] = $masterdata[$b]['feeamount'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                if(isset($actual[$no[$i]]))
                {
                    if(isset($paid[$no[$i]]))
                    {
                        $due[$no[$i]] = $actual[$no[$i]]-$paid[$no[$i]];
                    }
                    else
                    {
                        $due[$no[$i]] = $actual[$no[$i]];
                    }
                }
                else
                {
                    $due[$no[$i]] = 0;
                }
                $total = $total + $due[$no[$i]];
                
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$due[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td></tr>';
            $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th></tr></thead>';
            $body = '<tbody>'; 
            $body .= $a;
            $body .= '</tbody>';
            $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px">'.$head.'
                    '.$body.'
                    </table>
                </div>
            ';
            $subtable = $table;
            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            echo 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">Fee Paid by the Students</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
                echo '</body>';
                echo 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 ovabstractduebydiscotnuesinacylinks() // MIS for Discontinued and TC issued candidates
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3' AND (`discontinued`='1' OR `tc_given`='1')");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1' AND (um.discontinued='1' OR um.tc_given='1')");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'  AND (um.discontinued='1' OR um.tc_given='1')");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
            //   $fnyear = $styear-$yaer;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
        $tsize = 0;
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $tsize = $tsize+3;
            }
        }
        $tsize = $tsize+2+($year-1)+1;
        $enyear = $styear+1;
        $a .= '<thead>';
        $a .= '<tr>';
        $a .= '<th colspan="'.$tsize.'">Overall Abstract for Dues in Academic Year '.$styear.'-'.$enyear.' as on Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="3">Course</th>';
        $a .= '<th rowspan="3">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            $size= $f*3;
            $incyear = $styear-$syears[$e]+1;
            if($e==0)
            {
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
            if($e>0)
            {
                $size = $size+1;
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
        }
        $a .= '<th rowspan="3">Grand Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                if($e==0)
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                else
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                if($e>0 && $ff==$f)
                {
                    $a .= '<th rowspan="2">Total Amount</th>';
                }
            }
        }
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= "<th>Actual Amount</th>";
                $a .= "<th>Paid Amount</th>";
                $a .= "<th>Due Amount</th>";
            }
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        // for($a=0; $a<sizeof($syears); $a++)
        {
            for($e=0; $e<=3; $e++)
            {
                $f = $e+1;
                for($ff=1; $ff<=$f; $ff++)
                {
                    $lrt[$e][$ff]['actual'] = 0;
                    $lrt[$e][$ff]['paid'] = 0;
                    $lrt[$e][$ff]['due'] = 0;
                }
                $lrt[$e]['tdue'] = 0;
            }
            $lrtgt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.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/actualfeediscontinued?year='.$ff.'&course='.$course[$b].'&dept='.$dept[$c].'&joinyear='.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear'].'">'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'].'</a></td>'; 
                            $a .= '<td><a href="/Accounts/paidfeediscontinued?year='.$ff.'&course='.$course[$b].'&dept='.$dept[$c].'&joinyear='.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear'].'">'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'].'</a></td>'; 
                            $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'] = $ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee']-$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $a .= '<td><a href="/Accounts/duefeediscontinued?year='.$ff.'&course='.$course[$b].'&dept='.$dept[$c].'&joinyear='.$ade[$f][$course[$b]][$dept[$c]][$ssyear]['joinyear'].'">'.$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'].'</a></td>'; 
                            $t = $t+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $tt = $tt+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                            $lrt[$e][$ff]['actual'] = $lrt[$e][$ff]['actual']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['afee'];
                            $lrt[$e][$ff]['paid'] = $lrt[$e][$ff]['paid']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['pfee'];
                            $lrt[$e][$ff]['due'] = $lrt[$e][$ff]['due']+$ade[$ff][$course[$b]][$dept[$c]][$ssyear]['dfee'];
                        }
                        else
                        {
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                            $a .= '<td>0</td>';
                        }
                        if($e>0 && $ff == $f)
                        {
                            $a .= '<td>'.$t.'</td>';
                            $lrt[$e]['tdue'] = $lrt[$e]['tdue']+$t;
                        }
                    }
                    if($e == 3)
                    {
                        $a .= '<td>'.$tt.'</td>';
                        $lrtgt = $lrtgt+$tt;
                    }
                    
                }
                $a .= '</tr>';
            }
            }
        }
        $a .= '<tr>';
        $a .= '<td colspan="2">Grand Total</td>';
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= '<td>'.$lrt[$e][$ff]['actual'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['paid'].'</td>';
                $a .= '<td>'.$lrt[$e][$ff]['due'].'</td>';
                if($e>0 && $ff==$f)
                {
                    $a .= '<td>'.$lrt[$e]['tdue'].'</td>';
                }
            }
        }
        $a .= '<td>'.$lrtgt.'</td>';
        $a .= '</tr>';
        $a .= '</tbody>';
        $body = $a;
        $table = '
            <div class="table-responsive" id="exporttable">
                <table class="table table-responsive-sm" border="1px">'.$head.'
                '.$body.'
                </table>
            </div>
            ';
        $subtable = $table;
        $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
        // echo $lrtgt;
        echo 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-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 actualfeediscontinued()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
        $data = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON sf.no=um.id WHERE um.fromyear='$_GET[joinyear]' AND um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND sf.year='$_GET[year]' AND (um.discontinued='1' OR um.tc_given='1') ORDER BY um.no ASC");
        $a ='';
        // echo json_encode($data);
        $total = 0;
        for($i=0; $i<sizeof($data); $i++)
        {
            $j = $i+1;
            $a .= '<tr>';
            $a .= '<td>'.$j.'</td>';
            $a .= '<td>'.$data[$i]['no'].'</td>';
            $a .= '<td>'.$data[$i]['name'].'</td>';
            $a .= '<td>'.$data[$i]['feeamount'].'</td>';
            $a .= '</tr>';
            $total  = $total+$data[$i]['feeamount'];
        }
        $a .= '<tr><td colspan="3">Total Amount</td><td>'.$total.'</td></tr>';
        $body = '<tbody>'.$a.'</tbody>';
        $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th></tr></thead>';
        $table = '
            <div class="table-responsive" id="exporttable">
                <table class="table table-responsive-sm" border="1px">'.$head.'
                '.$body.'
                </table>
            </div>
            ';
        $subtable = $table;
        $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
        echo 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">Actual Fee to be Paid</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">    
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">  

                                                    </div>
                                                </div>                           
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                    
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                        
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4"></div>
                    </div>
                    <div class="row print-this">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                        '.$subtable.'
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
            </form>
            ';
            echo '</body>';
            echo 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 paidfeediscontinued()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1' AND (um.discontinued='1' OR um.tc_given='1')");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1' AND (um.discontinued='1' OR um.tc_given='1')");
            $htno = array();
            foreach ($data as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                $total = $total + $paid[$no[$i]];
                $count = $count + $rcount[$no[$i]];
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$paid[$no[$i]].'</td>';
                $a .= '<td>'.$rcount[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td><td>'.$count.'</td></tr>';
            $head = '<tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th><th>No of Terms</th></tr>';
            $body = '<tbody>'; 
            $body .= $a;
            $body .= '</tbody>';
            $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px"><thead>'.$head.'</thead>
                    '.$body.'
                    </table>
                </div>
            ';
            $subtable = $table;
            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            echo 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">Fee Paid by the Students</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
                echo '</body>';
                echo 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 duefeediscontinued()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1' AND (um.discontinued='1' OR um.tc_given='1')");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1' AND (um.discontinued='1' OR um.tc_given='1') ");
            $htno = array();
            foreach ($masterdata as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                        $actual[$no[$a]] = $masterdata[$b]['feeamount'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                if(isset($actual[$no[$i]]))
                {
                    if(isset($paid[$no[$i]]))
                    {
                        $due[$no[$i]] = $actual[$no[$i]]-$paid[$no[$i]];
                    }
                    else
                    {
                        $due[$no[$i]] = $actual[$no[$i]];
                    }
                }
                else
                {
                    $due[$no[$i]] = 0;
                }
                $total = $total + $due[$no[$i]];
                
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$due[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td></tr>';
            $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th></tr></thead>';
            $body = '<tbody>'; 
            $body .= $a;
            $body .= '</tbody>';
            $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px">'.$head.'
                    '.$body.'
                    </table>
                </div>
            ';
            $subtable = $table;
            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            echo 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">Fee Paid by the Students</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
                echo '</body>';
                echo Menus::script();
        }
    } 
    public static function ovabstractduebyexcludeddiscotnuesinacylinks() // MIS for Excluded Discontinued and TC issued candidates
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
        $data = Homem::getdata("SELECT * FROM `user_master` WHERE `user_role`='3' AND (`discontinued`='' OR `tc_given`='')");
        $maxyear = array();
        $cyear = array();
        $crse = array();
        $dep = array();
        foreach ($data as $h) 
        {
            $maxyear[] = $h['noofyears'];
            $cyear[] = $h['fromyear'];
            $crse[] = $h['fk_course_id'];
            $dep[] = $h['fk_dept_id'];
        }
        $myear = array_values(array_unique($maxyear));
        sort($myear);
        $year = static::maxarray($myear);
        $fyear = array_values(array_unique($cyear));
        sort($fyear);
        $course = array_values(array_unique($crse));
        sort($course);
        $dept = array_values(array_unique($dep));
        sort($dept);
        for($a=1; $a<=$year; $a++)
        {
            for($b=0; $b<sizeof($course); $b++)
            {
            for($c=0; $c<sizeof($dept); $c++)
            {
                for($d=0; $d<sizeof($fyear); $d++)
                {
                $adata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1' AND (um.discontinued='' OR um.tc_given='')");
                $asize = sizeof($adata);
                $afee = 0;
                $avg = 0;
                $mafee = 0;
                $mifee = 0;
                if(sizeof($adata) > 0)
                {
                    for($e=0; $e<sizeof($adata); $e++)
                    {
                    $afee = $afee + $adata[$e]['feeamount'];
                    }
                    $avg = $afee / sizeof($adata);
                    if(is_float($avg))
                    {
                    $avg = number_format((float) $avg, 2, '.', '');
                    }
                    $sfe = array();
                    foreach ($adata as $h) 
                    {
                    $sfe[] = $h['feeamount'];
                    }
                    $sfee = array_values(array_unique($sfe));
                    sort($sfee);
                    $mafee = static::maxarray($sfee);
                    $mifee = static::minarray($sfee);
                }
                $pdata = Homem::getdata("SELECT * FROM stdnt_normalfee sf JOIN user_master um ON um.id=sf.no WHERE sf.year='$a' AND um.fk_course_id='$course[$b]' AND um.fk_dept_id='$dept[$c]' AND um.fromyear='$fyear[$d]' AND sf.fk_feetype_id='1'  AND (um.discontinued='' OR um.tc_given='')");
                $psize = sizeof($pdata);
                $pfee = 0;
                if(sizeof($pdata) > 0)
                {
                    for($e=0; $e<sizeof($pdata); $e++)
                    {
                    $pfee = $pfee + $pdata[$e]['amount'];
                    }
                }
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['joinyear'] = $fyear[$d]; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['count'] = $asize; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['avgfee'] = $avg;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['maxfee'] = $mafee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['minfee'] = $mifee;  
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['afee'] = $afee; 
                $ade[$a][$course[$b]][$dept[$c]][$fyear[$d]]['pfee'] = $pfee; 
                }
            }
            }
        }
        $a = '';
        if(isset($_POST['year']))
        {
            if(is_numeric($_POST['year']))
            {
                $styear = $_POST['year'];
            }
            else
            {
                if (date('m') > 6) 
                {
                    $styear = date('Y');
                }
                else
                {
                    $styear = date('Y')-1;
                }
            }
        }
        else
        {
            if (date('m') > 6) 
            {
                $styear = date('Y');
            }
            else
            {
                $styear = date('Y')-1;
            }
        }
            //   $fnyear = $styear-$yaer;
        $syears = array();
        for($i=0; $i<$year; $i++)
        {
            $syears[] = $styear-$i;
        }
        $tsize = 0;
        for($e=0; $e<=3; $e++)
        {
            $f = $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $tsize = $tsize+3;
            }
        }
        $tsize = $tsize+2+($year-1)+1;
        $enyear = $styear+1;
        $a .= '<thead>';
        $a .= '<tr>';
        $a .= '<th colspan="'.$tsize.'">Overall Abstract for Dues in Academic Year '.$styear.'-'.$enyear.' as on Date '.date('d-m-Y').'</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        $a .= '<th rowspan="3">Course</th>';
        $a .= '<th rowspan="3">Department</th>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            $size= $f*3;
            $incyear = $styear-$syears[$e]+1;
            if($e==0)
            {
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
            if($e>0)
            {
                $size = $size+1;
                $a .= '<th colspan="'.$size.'">'.$incyear.' - Year / Batch: '.$syears[$e].'</th>';
            }
        }
        $a .= '<th rowspan="3">Grand Total</th>';
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                if($e==0)
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                else
                {
                    $a .= '<th colspan="3">'.$ff.' - Year</th>';
                }
                if($e>0 && $ff==$f)
                {
                    $a .= '<th rowspan="2">Total Amount</th>';
                }
            }
        }
        $a .= '</tr>';
        $a .= '<tr>';
        for($e=0; $e<sizeof($syears); $e++)
        {
            $f= $e+1;
            for($ff=1; $ff<=$f; $ff++)
            {
                $a .= "<th>Actual Amount</th>";
                $a .= "<th>Paid Amount</th>";
                $a .= "<th>Due Amount</th>";
            }
        }
        $a .= '</tr>';
        $a .= '</thead>';
        $head = $a;
        $a = '';
        $a .= '<tbody>';
        // for($a=0; $a<sizeof($syears); $a++)
        {
            for($e=0; $e<=3; $e++)
            {
                $f = $e+1;
                for($ff=1; $ff<=$f; $ff++)
                {
                    $lrt[$e][$ff]['actual'] = 0;
                    $lrt[$e][$ff]['paid'] = 0;
                    $lrt[$e][$ff]['due'] = 0;
                }
                $lrt[$e]['tdue'] = 0;
            }
            $lrtgt = 0;
            for($b=0; $b<sizeof($course); $b++)
            {
            $a .= '<tr><td rowspan="'.sizeof($dept).'">'.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-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 actualfeeexcludediscontinued()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
        $data = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON sf.no=um.id WHERE um.fromyear='$_GET[joinyear]' AND um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND sf.year='$_GET[year]' AND (um.discontinued='' OR tc_given='') ORDER BY um.no ASC");
        $a ='';
        // echo json_encode($data);
        $total = 0;
        for($i=0; $i<sizeof($data); $i++)
        {
            $j = $i+1;
            $a .= '<tr>';
            $a .= '<td>'.$j.'</td>';
            $a .= '<td>'.$data[$i]['no'].'</td>';
            $a .= '<td>'.$data[$i]['name'].'</td>';
            $a .= '<td>'.$data[$i]['feeamount'].'</td>';
            $a .= '</tr>';
            $total  = $total+$data[$i]['feeamount'];
        }
        $a .= '<tr><td colspan="3">Total Amount</td><td>'.$total.'</td></tr>';
        $body = '<tbody>'.$a.'</tbody>';
        $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th></tr></thead>';
        $table = '
            <div class="table-responsive" id="exporttable">
                <table class="table table-responsive-sm" border="1px">'.$head.'
                '.$body.'
                </table>
            </div>
            ';
        $subtable = $table;
        $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
        echo 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">Actual Fee to be Paid</h5>
                                            <div class="actions panel_actions pull-right">
                                                <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                <a class="box_toggle fa fa-chevron-down"></a>
                                            </div>
                                        </header>
                                        <div class="content-body">    
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">  

                                                    </div>
                                                </div>                           
                                            </div>
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                    
                                                    </div>
                                                </div>
                                            </div>
                                        </div>                        
                                    </section>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-4"></div>
                    </div>
                    <div class="row print-this">
                        <div class="col-lg-1"></div>
                        <div class="col-lg-10">
                        '.$subtable.'
                        </div>
                        <div class="col-lg-1"></div>
                    </div>
                </div>
            </form>
            ';
            echo '</body>';
            echo 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 paidfeeexcludediscontinued()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1'  AND (um.discontinued='' OR tc_given='')");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1'  AND (um.discontinued='' OR tc_given='')");
            $htno = array();
            foreach ($data as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                $total = $total + $paid[$no[$i]];
                $count = $count + $rcount[$no[$i]];
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$paid[$no[$i]].'</td>';
                $a .= '<td>'.$rcount[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td><td>'.$count.'</td></tr>';
            $head = '<tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th><th>No of Terms</th></tr>';
            $body = '<tbody>'; 
            $body .= $a;
            $body .= '</tbody>';
            $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px"><thead>'.$head.'</thead>
                    '.$body.'
                    </table>
                </div>
            ';
            $subtable = $table;
            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            echo 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">Fee Paid by the Students</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
                echo '</body>';
                echo 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 duefeeexcludediscontinued()
    {
        if($_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 6)
        {
            $masterdata = Homem::getdata("SELECT * FROM stdnt_feemaster sf JOIN user_master um ON um.id=sf.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sf.fk_feetype_id='1'  AND (um.discontinued='' OR tc_given='')");
            $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no WHERE um.fk_course_id='$_GET[course]' AND um.fk_dept_id='$_GET[dept]' AND um.fromyear='$_GET[joinyear]' AND sn.year='$_GET[year]' AND sn.fk_feetype_id='1'  AND (um.discontinued='' OR tc_given='')");
            $htno = array();
            foreach ($masterdata as $h) 
            {
                $htno[] = $h['no'];
            }
            $no = array_values(array_unique($htno));
            sort($no);
            for($a=0; $a<sizeof($no); $a++)
            {
                for($b=0; $b<sizeof($masterdata); $b++)
                {
                    if($masterdata[$b]['no'] == $no[$a])
                    {
                        $name[$no[$a]] = $masterdata[$b]['name'];
                        $actual[$no[$a]] = $masterdata[$b]['feeamount'];
                    }
                }
            }
            for($a=0; $a<sizeof($no); $a++)
            {
                $total = 0;
                $count = 0;
                for($b=0; $b<sizeof($data); $b++)
                {
                    if($data[$b]['no'] == $no[$a])
                    {
                        $total = $total+$data[$b]['amount'];
                        $count = $count+1;
                    }
                    if($b == sizeof($data)-1)
                    {
                        $paid[$no[$a]] = $total;
                        $rcount[$no[$a]] = $count;
                    }
                }
            }
            $total = 0;
            $count = 0;
            for($i=0; $i<sizeof($no); $i++)
            {
                if(isset($actual[$no[$i]]))
                {
                    if(isset($paid[$no[$i]]))
                    {
                        $due[$no[$i]] = $actual[$no[$i]]-$paid[$no[$i]];
                    }
                    else
                    {
                        $due[$no[$i]] = $actual[$no[$i]];
                    }
                }
                else
                {
                    $due[$no[$i]] = 0;
                }
                $total = $total + $due[$no[$i]];
                
                $j = $i+1;
                $a .= '<tr>';
                $a .= '<td>'.$j.'</td>';
                $a .= '<td>'.$no[$i].'</td>';
                $a .= '<td>'.$name[$no[$i]].'</td>';
                $a .= '<td>'.$due[$no[$i]].'</td>';
                $a .= '</tr>';
            }
            $a .= '<tr><td colspan="3">Total Amount Collected</td><td>'.$total.'</td></tr>';
            $head = '<thead><tr><th>S. No.</th><th>Hallticket Number</th><th>Name</th><th>Amount</th></tr></thead>';
            $body = '<tbody>'; 
            $body .= $a;
            $body .= '</tbody>';
            $table = '
                <div class="table-responsive" id="exporttable">
                    <table class="table table-responsive-sm" border="1px">'.$head.'
                    '.$body.'
                    </table>
                </div>
            ';
            $subtable = $table;
            $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
            echo 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">Fee Paid by the Students</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                                <div class="row">
                                                    <div class="col-lg-12">
                                                        <div class="form-group">  

                                                        </div>
                                                    </div>                           
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-12">  
                                                        <div class="form-group">
                                                        
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
                echo '</body>';
                echo Menus::script();
        }
    } 
}