<?php
namespace App\Controllers;
SESSION_START();
use \Core\View;
use \Core\Inputs;
use \Core\Userlog;
use \Core\Menu;
use \Core\Form;
use \Core\File;
use App\Models\Homem;
use App\Email\Emails;
class Students extends \Core\Controller
{
    private static function nyear($id)
    {
        if($id != '')
        {
            if($id == 1)
            {
                return 'First Year';
            }
            if($id == 2)
            {
                return 'Second Year';
            }
            if($id == 3)
            {
                return 'Third Year';
            }
            if($id == 4)
            {
                return 'Fourth Year';
            }
            if($id == 5)
            {
                return 'Fifth Year';
            }
        }
    }
    private static function course($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'B.Com.';
                }
                if($id == 3)
                {
                    return 'B.A.';
                }
                if($id == 4)
                {
                    return 'Inter';
                }
                if($id == 5)
                {
                    return 'M.Sc.';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'B.Sc.';
                }
                if($id == 2)
                {
                    return 'M.Sc.';
                }
                if($id == 3)
                {
                    return 'M.Sc. (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Diploma';
                }
                if($id == 2)
                {
                    return 'B.Tech.';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'MCA';
                }
                if($id == 2)
                {
                    return 'M.Com';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function dept($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'MPCS';
                }
                if($id == 2)
                {
                    return 'MSCS';
                }
                if($id == 3)
                {
                    return 'MECS';
                }
                if($id == 4)
                {
                    return 'General';
                }
                if($id == 5)
                {
                    return 'Computers';
                }
                if($id == 6)
                {
                    return 'MPC';
                }
                if($id == 7)
                {
                    return 'BZC';
                }
                if($id == 8)
                {
                    return 'GPC';
                }
                if($id == 9)
                {
                    return 'MiBC';
                }
                if($id == 10)
                {
                    return 'BiMC';
                }
                if($id == 11)
                {
                    return 'HS';
                }
                if($id == 12)
                {
                    return 'BS';
                }
                if($id == 13)
                {
                    return 'HEP';
                }
                if($id == 14)
                {
                    return 'EHP';
                }
                if($id == 15)
                {
                    return 'MES';
                }
                if($id == 16)
                {
                    return 'EPC';
                }
                if($id == 17)
                {
                    return 'MPC';
                }
                if($id == 18)
                {
                    return 'BiPC';
                }
                if($id == 19)
                {
                    return 'MEC';
                }
                if($id == 20)
                {
                    return 'CEC';
                }
                if($id == 21)
                {
                    return 'ABC';
                }
                if($id == 22)
                {
                    return 'HBZ';
                }
                if($id == 23)
                {
                    return 'FTM';
                }
                if($id == 24)
                {
                    return 'PHYSICS';
                }if($id == 25)
                {
                    return 'CHEMISTRY';
                }
                if($id == 26)
                {
                    return 'BOTANY';
                }
                if($id == 27)
                {
                    return 'FOOD PROCESSING';
                }
                if($id == 28)
                {
                    return 'HORTICULTURAL LANDSCAPING';
                }
                if($id == 29)
                {
                    return 'General (Un-aided)';
                }
            }
            if($_SESSION['org_id'] == 2)
            {
                if($id == 1)
                {
                    return 'Agriculture';
                }
                if($id == 2)
                {
                    return 'Horticulture';
                }
                if($id == 3)
                {
                    return 'Food Technology';
                }
                if($id == 4)
                {
                    return 'Physics';
                }
                if($id == 5)
                {
                    return 'Chemistry';
                }
                if($id == 6)
                {
                    return 'Botany';
                }
                if($id == 7)
                {
                    return 'Food Processing (Vocational)';
                }
                if($id == 8)
                {
                    return 'Horticultural Landscaping (Vocational)';
                }
            }
            if($_SESSION['org_id'] == 3)
            {
                if($id == 1)
                {
                    return 'Civil Engineering';
                }
                else if($id == 2)
                {
                    return 'Electrical & Electronics Engineering';
                }
                else if($id == 3)
                {
                    return 'Mechanical Engineering';
                }
                else if($id == 4)
                {
                    return 'Electronics & Communication Engineering';
                }
                else if($id == 5)
                {
                    return 'Computer Science Engineering';
                }
                else if($id == 6)
                {
                    return 'Wed Design';
                }
                else
                {
                    return '';
                }
            }
            if($_SESSION['org_id'] == 4)
            {
                if($id == 1)
                {
                    return 'Computers';
                }
                if($id == 2)
                {
                    return 'Commerce';
                }
            }
            if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'MBA';
                }
            }
            if($_SESSION['org_id'] == 6)
            {
                if($id == 1)
                {
                    return 'M.Com';
                }
            }
        }
    }
    private static function feetype($id)
    {
        if($id != '')
        {
            if($_SESSION['org_id'] == 1)
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Add-on Course Fee';
                }
            }
            else if($_SESSION['org_id'] == 5)
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Processing Fee';
                }
                if($id == 3)
                {
                    return 'TC Fee';
                }
                if($id == 4)
                {
                    return 'Library Fee';
                }
                if($id == 5)
                {
                    return 'ANU Registration Fee';
                }
            }
            else
            {
                if($id == 1)
                {
                    return 'Tution Fee';
                }
                if($id == 2)
                {
                    return 'Bus Fee';
                }
                if($id == 3)
                {
                    return 'TC Fee';
                }
                if($id == 4)
                {
                    return 'Library Fee';
                }
            }
        }
    }
    private static function squota($id, $course)
    {
        if($id != '')
        {
            if($id == 'M' && $course==1)
            {
                return 'SPOT Admission';
            }
            if($id == 'M' && $course==2)
            {
                return 'Management Quota';
            }
            if($id == 'C' && ($course==1 || $course==2))
            {
                return 'Convenor Quota';
            }
            if($id == 'S')
            {
                return 'Spot Admission';
            }
        }
    }
        /** Browser Checking code started */
    private static function checkbrower()
    {
        $mystring = $_SERVER['HTTP_USER_AGENT'];
        $word = 'Chrome';
        if(strpos($mystring, $word) !== false)
        {
            if(strpos($mystring, 'Mozilla') !== false)
            {
                return "1";
            } 
        }
        else if(strpos($mystring, 'Mozilla') !== false)
        {
            return "1";
        } 
        else
        {
            return "0";
        }
    }
    private static function checkiphone()
    {
        $iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
        $iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
        $iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
        $Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
        $webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");
        if($iPod || $iPhone || $iPad || $Android || $webOS)
        {
            echo 1;
        }
        else
        {
            echo 0;
        }
    }
    /** Browser Checking code Ended */

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

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

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

            <!-- Script to prevent selection start-->
            <script>
                $(document).ready(function () {
                    $("body").bind("cut copy", function (e) {
                        e.preventDefault();
                    });
                });
            </script>
            <!-- Script to prevent selection end-->
                ';
        return $script;  
    }
    private static function datem($id)
    {
        $data = explode('-', $id);
        $final = $data[2].'-'.$data[1].'-'.$data[0];
        return $final;
    }
    /** CSS, Script Ended */
    public static function indstdntfeereport()
    {
        if($_SESSION['org_id'] == 1)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 2)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 3)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College of Engineering & Technology</h1>
                    <h5>Approved by AICTE, New Delhi and Affiliated to JNTUK, kakinada & APSBTET</h5>
                    <h5>Amaravathi Road, Guntur-522002</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 4)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 5)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                <h1>Hindu College of Management</h1>
                <h5>Amaravathi Road, Guntur-522002, Andhra Pradesh</h5>
                <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }
        if($_SESSION['org_id'] == 6)
        {
            return 
            '
            <tr style="text-align: center;">
                <th colspan="1">
                    <img src="https://assets.hinduengg.com/hindu/assets/img/logo-1.png" width="150px" height="150px">
                </th>
                <th colspan="7">
                    <h1>Hindu College</h1>
                    <h5>(Re-accredited by NAAC as Grade ‘A’ with CGPA 3.07)</h5>
                    <h5>Main Road, Opp. Sri Venkateswara Vignan Mandir, Guntur Ph.: 0863-2227649</h5>
                    <a style="border: solid 1px black; border-radius: 10px; padding: 5px; font-size: 20px;">Individual Student Fee Payment Details</a>
                </th>
            </tr>';
        }

    }
    public static function feestatement()
    {
        if($_SESSION['user_role'] == 3)
        {
            $subtable = '';
            $a = '';
            $_POST['htno'] = $_SESSION['user_no'];
            if(isset($_POST['htno']))
            {
                $sdata = Homem::getdata("SELECT * FROM `user_master` WHERE `no`='$_POST[htno]'");
                $uid = '';
                if(sizeof($sdata) > 0)
                {
                    $uid = $sdata[0]['id'];
                }
                $mdata = Homem::getdata("SELECT * FROM stdnt_feemaster sn JOIN user_master um ON um.id=sn.no WHERE sn.no='$uid'");
                $fdata = Homem::getdata("SELECT * FROM user_details WHERE `ht_no`='$_POST[htno]'");
                $data = Homem::getdata("SELECT * FROM stdnt_normalfee sn JOIN user_master um ON um.id=sn.no JOIN user_master uma on uma.id=sn.entry_id WHERE sn.no='$uid'");
                $photo = Homem::getdata("SELECT * FROM `stdent_photos` WHERE `no`='$_POST[htno]'");
                $image = '';
                if(isset($photo[0]['photo']))
                {
                    $image = '<img src="'.$photo[0]['photo'].'" width="250px" height="300px">';
                }
                if(sizeof($mdata) > 0)
                {
                    $feetype = array();
                    $feeyear = array();
                    foreach ($mdata as $h) {
                        $feetype[] = $h['fk_feetype_id'];
                        $feeyear[] = $h['year'];
                    }
                    $ftype = array_values(array_unique($feetype));
                    sort($ftype);
                    $fyear = array_values(array_unique($feeyear));
                    sort($fyear);
                    // calculate year row span
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $cnt = 0;
                        for($k=0; $k<sizeof($data); $k++)
                        {
                            if($data[$k]['year'] == $fyear[$j])
                            {
                                $cnt++;
                            }
                            if($k == sizeof($data)-1)
                            {
                                $f[$fyear[$j]] = $cnt;
                            }
                        }
                    }
                    // calculate year, feetype row span
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        for($i=0; $i<sizeof($ftype); $i++)
                        {
                            $b = 0;
                            $paida = 0;
                            for($l=0; $l<sizeof($data); $l++)
                            {
                                if($data[$l]['year'] == $fyear[$j] && $data[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    $b++;  
                                    $paida = $paida+$data[$l]['amount'];
                                }
                                if($l == sizeof($data)-1)
                                {
                                    $c[$fyear[$j]][$ftype[$i]] = $b;
                                    $paid[$fyear[$j]][$ftype[$i]] = $paida;
                                }
                            }
                            for($l=0; $l<sizeof($mdata); $l++)
                            {
                                if($mdata[$l]['year'] == $fyear[$j] && $mdata[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    $actual[$fyear[$j]][$ftype[$i]] = $mdata[$l]['feeamount'];
                                }
                            }
                            for($l=0; $l<sizeof($mdata); $l++)
                            {
                                if($mdata[$l]['year'] == $fyear[$j] && $mdata[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    if(!isset($paid[$fyear[$j]][$ftype[$i]]))
                                    {
                                        $paid[$fyear[$j]][$ftype[$i]] = 0;
                                    }
                                    $due[$fyear[$j]][$ftype[$i]] = $actual[$fyear[$j]][$ftype[$i]]-$paid[$fyear[$j]][$ftype[$i]];
                                }
                            }
                        }
                    }
                    // echo json_encode($paid);
                    $tactual = 0;
                    $tpaid = 0;
                    $tdue = 0;
                    for($j=0; $j<sizeof($fyear); $j++)
                    {
                        $e = 1;
                        $g = 0;
                        $newcount = 0;
                        for($i=0; $i<sizeof($ftype); $i++)
                        {
                            for($l=0; $l<sizeof($mdata); $l++)
                            {
                                if($mdata[$l]['year'] == $fyear[$j] && $mdata[$l]['fk_feetype_id'] == $ftype[$i])
                                {
                                    $b = 0;
                                    $cd = 0;
                                    for($k=0; $k<sizeof($data); $k++)
                                    {
                                        if($data[$k]['year'] == $fyear[$j] && $data[$k]['fk_feetype_id'] == $ftype[$i])
                                        {
                                            $b++;
                                            $g++;
                                            if($b == 1 && $e ==1 && $g==1)
                                            {
                                                $a .= '<tr>
                                                            <td rowspan="'.$f[$fyear[$j]].'">'.static::nyear($fyear[$j]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.static::feetype($ftype[$i]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$actual[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$paid[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$due[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                                $tactual = $tactual+$actual[$fyear[$j]][$ftype[$i]];
                                                $tpaid = $tpaid+$paid[$fyear[$j]][$ftype[$i]];
                                                $tdue = $tdue+$due[$fyear[$j]][$ftype[$i]];
                                                $e = 0;
                                                $cd = 1;
                                                $completed[$fyear[$j]][$ftype[$i]] = 1;
                                            }
                                            if(isset($s[$fyear[$j]][$ftype[$i]]))
                                            {
                                                $a .= '<tr>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                                $newcount = $newcount+1;
                                            }
                                            if(isset($subcompleted[$fyear[$j]][$ftype[$i]]) && $newcount == 1)
                                            {
                                                $a .= '<tr>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                                $s[$fyear[$j]][$ftype[$i]] = 1;
                                            }
                                            if(!isset($completed[$fyear[$j]][$ftype[$i]]) && $e ==0 && !isset($subcompleted[$fyear[$j]][$ftype[$i]]))
                                            {
                                                $a .= '<tr>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.static::feetype($ftype[$i]).'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$actual[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$paid[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td rowspan="'.$c[$fyear[$j]][$ftype[$i]].'">'.$due[$fyear[$j]][$ftype[$i]].'</td>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                                    $tactual = $tactual+$actual[$fyear[$j]][$ftype[$i]];
                                                    $tpaid = $tpaid+$paid[$fyear[$j]][$ftype[$i]];
                                                    $tdue = $tdue+$due[$fyear[$j]][$ftype[$i]];
                                                    $subcompleted[$fyear[$j]][$ftype[$i]] = 1;
                                                    $newcount = 1;
                                            }
                                            
                                            if($e == 0 && $b>1 && $newcount == 0)
                                            {
                                                $a .= '<tr>
                                                            <td>'.$data[$k]['recieptno'].'</td>
                                                            <td>'.$data[$k]['amount'].'</td>
                                                            <td>'.static::datem($data[$k]['paid_date']).'</td>
                                                        </tr>
                                                    ';
                                            }
                                            if($k == sizeof($data)-1)
                                            {
                                                $g = 0;
                                                // echo 'tets';
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    $a .= '<tr><td colspan="2"><b>Total</b></td><td><b>'.$tactual.'</b></td><td><b>'.$tpaid.'</b></td><td><b>'.$tdue.'</b></td><td colspan="3"></td></tr>';
                    for($i=0; $i<sizeof($data); $i++)
                    {
                        $k = $i+1;
                    }
                    $cheader='';
                    $cheader=static::indstdntfeereport();
                    if(sizeof($fdata) == 1)
                    {
                        $head = '<thead>
                                '.$cheader.'
                                <tr>
                                    <th colspan="2">Hall Ticket Number</th><th colspan="3">'.$_POST['htno'].'</th>
                                    <th rowspan="6" colspan="3">'.$image.'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Name of the Student</th><th colspan="3">'.$mdata[0]['name'].'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Father Name</th><th colspan="3">'.$fdata[0]['fname'].'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Course</th><th colspan="3">'.static::course($mdata[0]['fk_course_id']).' ('.static::squota($mdata[0]['squota'], $mdata[0]['fk_course_id']).')</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Department</th><th colspan="3">'.static::dept($mdata[0]['fk_dept_id']).'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Acadamic Year</th><th colspan="3">'.$mdata[0]['fromyear'].' - '.$mdata[0]['toyear'].'</th>
                                </tr>
                                <tr>
                                    <th>Year</th>
                                    <th>Fee Type</th>
                                    <th>Actual Amount</th>
                                    <th>Paid Amount</th>
                                    <th>Due Amount</th>
                                    <th>Bill Number</th>
                                    <th>Amount Paid</th>
                                    <th>Paid Date</th>
                                </tr>
                            </thead>';
                    }
                    else
                    {
                        $head = '<thead>
                                '.$cheader.'
                                <tr>
                                    <th colspan="2">Hall Ticket Number</th><th colspan="3">'.$_POST['htno'].'</th>
                                    <th rowspan="5" colspan="3">'.$image.'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Name of the Student</th><th colspan="3">'.$mdata[0]['name'].'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Course</th><th colspan="3">'.static::course($mdata[0]['fk_course_id']).' ('.static::squota($mdata[0]['squota'], $mdata[0]['fk_course_id']).')</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Department</th><th colspan="3">'.static::dept($mdata[0]['fk_dept_id']).'</th>
                                </tr>
                                <tr>
                                    <th colspan="2">Acadamic Year</th><th colspan="3">'.$mdata[0]['fromyear'].' - '.$mdata[0]['toyear'].'</th>
                                </tr>
                                <tr>
                                    <th>Year</th>
                                    <th>Fee Type</th>
                                    <th>Actual Amount</th>
                                    <th>Paid Amount</th>
                                    <th>Due Amount</th>
                                    <th>Bill Number</th>
                                    <th>Amount Paid</th>
                                    <th>Paid Date</th>
                                </tr>
                            </thead>';
                    }
                    
                    $body = '<tbody>'; 
                    $body .= $a;
                    $body .= '</tbody>';
                    $table = '
                        <div class="table-responsive" id="exporttable">
                            <table class="table table-responsive-sm print-this" border="1px">'.$head.'
                            '.$body.'
                            </table>
                        </div>
                    ';
                    $subtable .= $table;
                    $subtable .= '<button class="btn btn-primary" onclick="exportTableToExcel(`exporttable`, `results-data`)">Export</button>';
                }
            }
            echo static::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                <form action="#" method="POST">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"></div>
                            <div class="col-lg-4">                                       
                                <div class="row">
                                    <div class="col-lg-12">
                                        <section class="box" style="margin-top: 10px;">
                                            <header class="panel_header">
                                                <h5 class="title pull-left">Student Fee Report</h5>
                                                <div class="actions panel_actions pull-right">
                                                    <a class="fa fa-refresh" onclick="refreshClick()"></a>
                                                    <a class="box_toggle fa fa-chevron-down"></a>
                                                </div>
                                            </header>
                                            <div class="content-body">    
                                            </div>                        
                                        </section>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-4"></div>
                        </div>
                        <div class="row print-this">
                            <div class="col-lg-1"></div>
                            <div class="col-lg-10">
                            '.$subtable.'
                            </div>
                            <div class="col-lg-1"></div>
                        </div>
                    </div>
                </form>
                ';
            echo '</body>';
            echo static::script();
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
        }
    }
    
    
    public static function attendancebydate()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="container" style="margin-top:20px;">
                    <div class="container-fluid" >
                        <div class="row" >
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <div class="row">
                                    <div class="col-xl-12">
                                        <div class="form-group">
                                            <input type="text" name="date" id="date" class="form-control" placeholder="Date" onfocus="this.type=`date`" onblur="this.type=`text`">
                                        </div>
                                    </div>
                                    <div class="col-xl-12">
                                        <div class="form-group">
                                            <input type="submit" class="btn btn-primary">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-xl-4"></div>
                        </div>
                        <div class="row" >
                            <div class="col-xl-2"></div>
                            <div class="col-xl-8">'.static::datewiseattendance().'</div>
                            <div class="col-xl-2"></div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
        }
    }
    public static function datewiseattendance()
    {
        $_SESSION['org_id'] = '3';
        $_SESSION['user_no'] = '21624-EE-003';
        $date = date('Y-m-d');
        $data = Homem::getdata("SELECT sd.sub_id, sd.subcode, sd.subname, sam.hourid, sas.attendance FROM subject_attedancemaster sam JOIN subject_attedancestudents sas ON sam.id=sas.master_id JOIN user_master um ON um.id=sas.user_id JOIN subject_data sd ON sd.sub_id=sam.subid WHERE um.no='$_SESSION[user_no]' AND sam.edate='$date'");
        $a='';
        for($i=0; $i<sizeof($data); $i++)
        {
            $j = $i+1;
            $a .= '<tr>';
            $a .= '<td>'.$data[$i]['subcode'].'</td>';
            $a .= '<td>'.$data[$i]['subname'].'</td>';
            $a .= '<td>'.$data[$i]['hourid'].'</td>';
            if($data[$i]['attendance'] == '1')
            {
                $a .= '<td><span style="color:green;">Present</span></td>';
            }
            else
            {
                $a .= '<td><span style="color:red;">Absent</span></td>';
            }
            $a .= '</tr>';
        }
        $table = '
        <div class="table-responsive" id="exporttable">
            <table class="table table-responsive-sm print-this" border="1px">
            <thead><tr><td>Subject Code</td><td>Subject Name</td><td>Hour No.</td><td>Absent/Present</td></tr></thead>
                '.$a.'
            </table>
        </div>
        ';
        echo $table;
    }
    
    
    public static function home()
    {
        if($_SESSION['user_role'] != '')
        {
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:30px;">
                            <div class="col-xl-12">
                            <!--Welcome to HINDU COLLEGE-->
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
        }
    }
    public static function uploadphotos()
    {
        if($_SESSION['user_role'] != '')
        {
            // echo File::studentphotos();
            echo static::css();
            echo '<body>';
                echo $_SESSION['menu'];
                echo '
                <div class="container">
                    <div class="container-fluid">
                        <div class="row" style="margin-top:30px;">
                            <div class="col-xl-4"></div>
                            <div class="col-xl-4">
                                <form action="/Students/saveuploadphotos" method="POST" enctype="multipart/form-data">
                                <div class="row">
                                    <div class="col-xl-12">
                                        <div class="form-group">
                                            <h5 class="title pull-left">Campus Photos Phase - 1</h5>
                                        </div>
                                    </div>
                                    <div class="col-xl-12">
                                        <div class="form-group">
                                            <input type="file" class="form-control" name="file" id="ImageMedias" placeholder="Upload Your File" required>
                                            <div id="divImageMediaPreview"></div>
                                        </div>
                                    </div>
                                    <div class="col-xl-12">
                                        <div class="form-group">
                                            <input type="submit" class="bt bt-primary" name="submit" id="submit">
                                            
                                        </div>
                                    </div>
                                </div>
                                </form>
                            </div>
                            <div class="col-xl-4"></div>
                            </div>
                        </div>
                    </div>
                </div>
                ';
            echo '</body>';
            echo static::script();
            echo '
            <script>
            $("#ImageMedias").change(function () {
            if (typeof (FileReader) != "undefined") {
                var dvPreview = $("#divImageMediaPreview");
                dvPreview.html("");            
                $($(this)[0].files).each(function () {
                    var file = $(this);                
                        var reader = new FileReader();
                        reader.onload = function (e) {
                            var img = $("<img />");
                            img.attr("style", "width: 100%; height:auto; padding: 10px");
                            img.attr("src", e.target.result);
                            dvPreview.append(img);
                        }
                        reader.readAsDataURL(file[0]);                
                });
            } else {
                alert("This browser does not support HTML5 FileReader.");
            }
        });
            </script>
            ';
        }
    }
    public static function saveuploadphotos()
    {
        if(isset($_POST['submit']))
        {
            if(sizeof(Homem::getdata("SELECT * FROM `stdent_photos` WHERE `contest_id`='1' AND `sid`='$_SESSION[user_id]' AND `no`='$_SESSION[user_no]' AND `status`='1'")) < 5)
            {
                $date = date('Y-m-d');
                $name       = $_FILES['file']['name'];  
                $temp_name  = $_FILES['file']['tmp_name'];
                $extension=explode(".", $name);
                $ext = $extension[sizeof($extension)-1];
                $query = "INSERT INTO `stdent_photos` (`id`, `sid`, `no`, `edate`, `upload_by`, `photo`, `status`, `selection`, `contest_id`) VALUES (NULL, '$_SESSION[user_id]', '$_SESSION[user_no]', '$date', '', '', '1', '0', '1')";
                Homem::insert($query);
                $query = "SELECT * FROM `stdent_photos` WHERE `contest_id`='1' AND `sid`='$_SESSION[user_id]' AND `no`='$_SESSION[user_no]' AND `status`='1' AND `edate`='$date' ORDER BY `id` DESC";
                $data = Homem::getdata($query);
                $id = $data[0]['id'];
                $name=$id.".".$ext;
                Homem::update("UPDATE `stdent_photos` SET `photo`='$name' WHERE `id`='$id' AND `sid`='$_SESSION[user_id]' AND `no`='$_SESSION[user_no]' AND `edate`='$date'");
                File::studentphotos($temp_name, $name);
                echo '<script>window.location = "/Students/uploadphotos?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Students/uploadphotos?status=0";</script>';
            }
            
        }
    }
}