<?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 Scholarship extends \Core\Controller
{
    public static function index()
    {
        $_SESSION["org_id"] = "3";
        Homem::insert("UPDATE stdnt_scholarship ss JOIN user_master um ON ss.sid=um.id SET ss.fk_course_id=um.fk_course_id, ss.fk_dept_id=um.fk_dept_id WHERE ss.status='1' AND ss.no=um.no");
        $data = Homem::getdata("SELECT ss.id, ss.sid, ss.no, ss.name, dn.code AS course, dd.code AS dept, dd.aided, um.fromyear, ss.year, ss.releasedamount FROM stdnt_scholarship ss JOIN user_master um ON ss.sid=um.id JOIN degree_name_master dn ON dn.id=ss.fk_course_id JOIN degree_dept_master dd ON dd.id=ss.fk_dept_id WHERE ss.status='1' ORDER BY ss.id ASC");
        $data1 = Homem::getdata("SELECT ss.sid, ss.no, ss.name, ss.year, SUM(sf.feeamount) AS amount FROM stdnt_scholarship ss JOIN stdnt_feemaster sf ON ss.sid=sf.no WHERE ss.year=sf.year AND ss.status='1' GROUP BY ss.sid ORDER BY ss.id ASC");
        $data2 = Homem::getdata("SELECT ss.sid, ss.no, ss.name, ss.year, IFNULL(SUM(sn.amount), 0) AS amount FROM stdnt_scholarship ss LEFT JOIN stdnt_normalfee sn ON ss.sid = sn.no AND sn.year = ss.year WHERE ss.status = '1' GROUP BY ss.sid ORDER BY ss.id ASC");
        $data3 = Homem::getdata("SELECT ss.sid, ss.no, ss.name, ss.year, SUM(sf.feeamount) AS amount FROM stdnt_scholarship ss JOIN stdnt_feemaster sf ON ss.sid=sf.no WHERE ss.status='1' GROUP BY ss.sid ORDER BY ss.id ASC");
        $data4 = Homem::getdata("SELECT ss.sid, ss.no, ss.name, ss.year, SUM(sn.amount) AS amount FROM stdnt_scholarship ss JOIN stdnt_normalfee sn ON ss.sid=sn.no WHERE ss.status='1' GROUP BY ss.sid ORDER BY ss.id ASC");
        // $data5 = Homem::getdata("SELECT ss.sid, ss.no, ss.name, ss.year, SUM(sf.feeamount) AS amount FROM stdnt_scholarship ss JOIN stdnt_feemaster sf ON ss.sid=sf.no WHERE ss.year=sf.year AND ss.status='1' GROUP BY ss.sid ORDER BY ss.id ASC");
        // $data6 = Homem::getdata("SELECT ss.sid, ss.no, ss.name, ss.year, IFNULL(SUM(sn.amount), 0) AS amount FROM stdnt_scholarship ss LEFT JOIN stdnt_normalfee sn ON ss.sid = sn.no AND sn.year = ss.year WHERE ss.status = '1' GROUP BY ss.sid ORDER BY ss.id ASC");
        
        $a = '<table border="1px">';
        $a .= '<tr><td>id</td><td>SID</td><td>No</td><td>Name</td><td>Course</td><td>Department</td><td>Aided</td><td>From year</td><td>year</td><td>released amount</td>
        <td>Actual Tution Fee Same Year</td><td>Paid Tution Fee Same Year</td><td>Due Tution Fee Same Year</td>
        <td>Total Actual Fee</td><td>Total Paid Fee</td><td>Total Due Fee</td>
        <!-- <td>Total Actual Fee</td><td>Total Paid Fee</td> -->
        </tr>';
        for($i=0; $i<sizeof($data); $i++)
        {
            $a .= '<tr>';
            $a .= '<td>'.$data[$i]["id"].'</td>';
            $a .= '<td>'.$data[$i]["sid"].'</td>';
            $a .= '<td>'.$data[$i]["no"].'</td>';
            $a .= '<td>'.$data[$i]["name"].'</td>';
            $a .= '<td>'.$data[$i]["course"].'</td>';
            $a .= '<td>'.$data[$i]["dept"].'</td>';
            $a .= '<td>'.$data[$i]["aided"].'</td>';
            $a .= '<td>'.$data[$i]["fromyear"].'</td>';
            $a .= '<td>'.$data[$i]["year"].'</td>';
            $a .= '<td>'.$data[$i]["releasedamount"].'</td>';
            $a .= '<td>'.$data1[$i]["amount"].'</td>';
            $a .= '<td>'.$data2[$i]["amount"].'</td>';
            $yeardue = $data1[$i]["amount"]-$data2[$i]["amount"];
            $a .= '<td>'.$yeardue.'</td>';
            // $a .= '<td>'.$data5[$i]["amount"].'</td>';
            // $a .= '<td>'.$data6[$i]["amount"].'</td>';
            $a .= '<td>'.$data3[$i]["amount"].'</td>';
            $a .= '<td>'.$data4[$i]["amount"].'</td>';
            $totaldue = $data3[$i]["amount"]-$data4[$i]["amount"];
            $a .= '<td>'.$totaldue.'</td>';
            $a .= '</tr>';
        }
        $a .= '</table>';
        
        echo $a;
    }
    public static function normalfeelatest()
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4 || $_SESSION['user_role'] == 8)
        {
            $feetype = sizeof(Homem::getdata("SELECT * FROM `fee_types`"));
            $feemode = Inputs::optionsdb(Homem::getdata("SELECT * FROM `fee_mode`"), 'id', 'name');
            $table = '';
            {
                $date = date('Y-m-d');
                // $blood = Homem::getdata("SELECT * FROM `stdnt_normalfeetest` WHERE (`entry_date`='$date' OR `edit_date`='$date') AND (`entry_id`='$_SESSION[user_id]' OR `edit_id`='$_SESSION[user_id]') AND `fk_org_id`='$_SESSION[org_id]'");
                $blood = Homem::getdata("SELECT * FROM stdnt_normalfeetest sn JOIN user_master um ON um.id=sn.no WHERE (sn.entry_date='$date' OR sn.edit_date='$date') AND (sn.entry_id='$_SESSION[user_id]' OR sn.edit_id='$_SESSION[user_id]') AND sn.fk_org_id='$_SESSION[org_id]'");
                $table = Form::dbtableprint($blood, ['Admission Number', 'Hallticket Number', 'Name', 'Reciept Number', 'Paid Amount'], ['ano', 'no', 'name', 'recieptno', 'amount'], '/Scholarship/print', 'nid', '');
            }
            echo Menus::css();
            echo '<body>';
            echo $_SESSION['menu'];
            echo '
                <div class="clearfix"></div>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-lg-4"> 
                            </div>
                            <div class="col-lg-4">
                                <form action="/Scholarship/savenormalfeelatest" method="POST" enctype="multipart/form-data">
                                    <section class="box" style="margin-top: 30px;">
                                        <header class="panel_header">
                                            <h5 class="title pull-left">Individual Fee Payment Entry</h5>
                                        </header>
                                        <div class="content-body"> 
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="no" id="no" class="form-control" placeholder="Hallticket Number" onchange="getusername()">                                         
                                                    </div>
                                                </div>                              
                                            </div>   
                                            <div class="row">
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="name" id="name" class="form-control" placeholder="Student Name" readonly required>                                         
                                                    </div>
                                                </div>
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="mobile" id="mobile" class="form-control" placeholder="Student Mobile Number" readonly>                                         
                                                    </div>
                                                </div>
                                                
                                                <div class="col-lg-12">
                                                    <div class="form-group">   
                                                        <input type="text" name="email" id="email" class="form-control" placeholder="Student Email" readonly required>                                         
                                                    </div>
                                                </div> 
                                                
                                            </div>   
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">                                            
                                                        <select name="year" id="year" class="form-control" onchange="gettotaldueamount()" required>
                                                            <option value="">Select Year to which fee applicable</option>
                                                            <option value="1">First Year</option>
                                                            <option value="2">Second Year</option>
                                                            <option value="3">Third Year</option>
                                                            <option value="4">Fourth Year</option>
                                                        </select>												
                                                    </div>
                                                </div>                              
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                        <input type="hidden" name="duedata" id="duedata" class="form-control" placeholder="Due Data" required>
                                                        <input type="hidden" name="feetype" id="feetype" class="form-control" value="'.$feetype.'" required>
                                                    </div>
                                                </div>                              
                                            </div>
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="dueamount" id="dueamount" class="form-control" placeholder="Due Amount" readonly required>                                         
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="text" name="paidamount" id="paidamount" class="form-control" placeholder="Fee Amount" required>                                         
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row">
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                        <input type="hidden" name="recieptno" id="recieptno" class="form-control" placeholder="Reciept Number">                                         
                                                        <select name="feemode" id="feemode" class="form-control" required>
                                                            <option value="">Select Mode of Payment</option>
                                                            '.$feemode.'
                                                        </select>
                                                    </div>
                                                </div>                              
                                                <div class="col-lg-6">
                                                    <div class="form-group">   
                                                    <input type="hidden" name="paydate" id="paydate" class="form-control" onfocus="(this.type=`date`)" onblur="(this.type=`text`)" placeholder="Fee Paid Date"> 
                                                    <input type="text" name="remarks" id="remarks" class="form-control" placeholder="Remarks">                                   
                                                    </div>
                                                </div>                              
                                            </div> 
                                            <div class="row" id="modifylink" style="display:none;">
                                                    <div class="col-lg-12">
                                                        <div class="float-lg-right"><a href="javascript:void(0);" onclick="updatecontactdetails()">Change Contact Information</a></div> 
                                                    </div>
                                            </div>
                                            <div class="row"> 
                                                <div class="col-lg-12">
                                                    <div class="form-group"> 
                                                        <input type="hidden" name="sid" id="sid" class="form-control" placeholder="user id" required>
                                                        <input type="hidden" name="edit_id" id="edit_id" class="form-control" placeholder="edit id">                                         
                                                    </div>
                                                </div>                            
                                            </div> 
                                            <div class="row">
                                                <div class="col-md-12">  
                                                    <div class="form-group">
                                                        <button id="btn_reg" class="btn btn-primary pull-right" type="submit" style="background-color: #002366 !important;">Submit</button>
                                                    </div>
                                                </div>
                                            </div>  
                                        </div>
                                    </selection>
                                </form>
                            </div>
                            <div class="col-lg-4">
                                <div id="duetable" style="margin:20px;"></div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-lg-2"></div>
                            <div class="col-lg-8">
                            '.$table.'
                            </div>
                            <div class="col-lg-2"></div>
                        </div>
                    </div>
                
                ';
            echo '</body>';
            echo Menus::script();
            echo '
            <script>
                $(document).ready(function(){
                    var div = document.createElement("div");
                    div.id = "addcoplayerinner1";
                    document.getElementsByTagName("body")[0].appendChild(div);
                    $("#addcoplayerinner1").load("/Scholarship/addcoplayerinner");
                });
                // $(document).ready(function(){
                //     var div = document.createElement("div");
                //     div.id = "foundcoplayerinner1";
                //     document.getElementsByTagName("body")[0].appendChild(div);
                //     $("#foundcoplayerinner1").load("/Scholarship/foundcoplayerinner");
                // });
                function updatecontactdetails()
                {
                    $("#addcoplayerinner").modal("show");
                }
                function getlatestduetable()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getstudentfeedetails",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                                // console.log(d);
                                document.getElementById("duetable").innerHTML = d;
                        }
                    });
                }
                function getusername()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getusernamemobileemail",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            const a = JSON.parse(d);
                            document.getElementById("name").value = a[0]["name"];
                            document.getElementById("mobile").value = a[0]["mobile"];
                            document.getElementById("email").value = a[0]["email"];
                            if(a[0]["id"] != "")
                            {
                                $("#modifylink").show();
                            }
                            getlatestduetable();
                            getuserid();
                            setTimeout(function(){ $("#id").val(a[0]["id"]); }, 500);
                            $("#id").val(a[0]["id"]);
                            $("#sno").val(a[0]["no"]);
                            $("#sname").val(a[0]["name"]);
                            $("#gender").val(a[0]["gender"]);
                            $("#dob").val(a[0]["dob"]);
                            $("#smobile").val(a[0]["mobile"]);
                            $("#semail").val(a[0]["email"]);
                            $("#fname").val(a[0]["fname"]);
                            $("#fmobile").val(a[0]["fmobile"]);
                        }
                    });
                }
                function gettotaldueamount()
                {
                    var no = $("#no").val();
                    var year = $("#year").val();
                    $.ajax({
                        url: "/Scholarship/gettotaldueamount",
                        type: "post",
                        data: {no: no, year: year},
                        success: function(d) {
                        const a = JSON.parse(d);
                            if(d != "fail")
                            {
                                document.getElementById("duedata").value = d;
                                document.getElementById("dueamount").value = a["total"];
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
                function getuserid()
                {
                    var no = $("#no").val();
                    $.ajax({
                        url: "/Accounts/getuserid",
                        type: "post",
                        data: {no: no},
                        success: function(d) {
                            if(d != "fail")
                            {
                                document.getElementById("sid").value = d;
                                
                                $("#btn_reg").show();
                            }
                            else
                            {
                                $("#btn_reg").hide();
                            }
                        }
                    });
                }
            </script>';
            if(isset($_GET['editid']))
            {
                $data = Homem::getdata("SELECT * FROM `stdnt_normalfeetest` WHERE `nid`='$_GET[editid]' AND `fk_org_id`='$_SESSION[org_id]'");
                if(sizeof($data) == 1)
                {
                    echo '
                    <script>
                        $("#no").val("'.$data[0]['no'].'");
                        $("#year").val("'.$data[0]['year'].'");
                        $("#feetype").val("'.$data[0]['fk_feetype_id'].'");
                        $("#paidamount").val("'.$data[0]['amount'].'");
                        $("#recieptno").val("'.$data[0]['recieptno'].'");
                        $("#feemode").val("'.$data[0]['fk_feemode_id'].'");
                        $("#paydate").val("'.$data[0]['paid_date'].'");
                        $("#remarks").val("'.$data[0]['remarks'].'");
                        $("#edit_id").val("'.$_GET['editid'].'");
                        getusername();
                    </script>
                    ';
                }
            }
            if(isset($_GET['status']))
            {
                if($_GET['status'] == 1)
                {
                    echo '<script>swal("", "Inserted Successfully", "success");</script>';
                }
                else if($_GET['status'] == 2)
                {
                    echo '<script>swal("", "Updated Successfully", "success");</script>';
                }
                else
                {
                    echo '<script>swal("", "Something went Wrong.. Please try again later..", "error");</script>';
                }
            }
            if(isset($_GET['no']))
            {
                echo '
                    <script>
                        $("#no").val("'.$_GET['no'].'");
                        getusername();
                    </script>';
            }
        }
    }
    public static function gettotaldueamount()
    {
    {
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            if(isset($_POST['no']) && isset($_POST['year']))
            {
                $data = Homem::getdata("SELECT * FROM `user_master` WHERE (`ano`='$_POST[no]' OR `no`='$_POST[no]') AND `user_role`='3'");
                if(sizeof($data) == 1)
                {
                    $sid = $data[0]['id'];
                    $setdata = Homem::getdata("SELECT * FROM `stdnt_feemaster` WHERE `no`='$sid' AND `year`='$_POST[year]'");
                    if(sizeof($setdata) > 0)
                    {
                        $total = 0;
                        for($i=0; $i<sizeof($setdata); $i++)
                        {
                            $feetype= $setdata[$i]['fk_feetype_id'];
                            $feedata = Homem::getdata("SELECT SUM(amount) as amount FROM `stdnt_normalfeetest` WHERE `no`='$sid' AND `year`='$_POST[year]' AND `fk_feetype_id`='$feetype'");
                            $amount = $feedata[0]['amount'];
                            if($amount == NULL)
                            {
                                $amount = 0;
                            }
                            $adata[$feetype]['actual'] = $setdata[$i]['feeamount'];
                            $adata[$feetype]['paid'] = $amount;
                            $adata[$feetype]['due'] = (int)$adata[$feetype]['actual'] - (int)$adata[$feetype]['paid'];
                            $total = $total + $adata[$feetype]['due'];
                        }
                        $adata['total'] = $total;
                        echo json_encode($adata);
                    }
                    else
                    {
                        echo 'fail';
                    }
                }
            }
        }
    }
    }
    public static function savenormalfeelatest()
    {
        $date = date('Y-m-d');
        if($_SESSION['user_role'] == 5 || $_SESSION['user_role'] == 6 || $_SESSION['user_role'] == 4)
        {
            $_POST['paydate'] =$date;
            $data1 = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
            $balence = 0;
            $amount = $_POST['paidamount'];
            $data = json_decode($_POST['duedata'], true);
            $feetype = $_POST['feetype'];
            $_POST['paydate'] = date('Y-m-d');
            $date = date('Y-m-d');
            $count=0;
            if(sizeof($data1)==1 && $amount <=$data['total'])
            {
                for($i=$feetype; $i>=1; $i--)
                {
                    if(isset($data[$i]))
                    {
                        if($amount>0 )
                        {
                            $al=0;
                            if($amount >= $data[$i]['due'])
                            {
                                $balence = $amount - $data[$i]['due'];
                                $data[$i]['newpaid'] = $data[$i]['due'];
                                $_POST['amount'] = $data[$i]['due'];
                                $amount = $balence;
                                $al=1;
                            }
                            if($amount < $data[$i]['due'] && $al==0)
                            {
                                $_POST['amount'] = $amount;
                                $amount = 0;
                            }
                            $_POST['recieptno'] = static::recieptno();
                            if($_POST['recieptno'] != 'retry')
                            {
                                $_POST['recieptno'] = $_POST['recieptno'];
                            }
                            $data[$i]['recieptno'] = $_POST['recieptno'];
                            
                            $data1 = Homem::getdata("SELECT * FROM `stdnt_normalfeetest` WHERE `no`='$_POST[sid]' AND `year`='$_POST[year]' AND `fk_feetype_id`='$i' AND `amount`='$_POST[amount]' AND `paid_date`='$date' AND `entry_id`='$_SESSION[user_id]'");
                            if(sizeof($data1) == 0)
                            {
                                $count++;
                                if($_POST['amount']>0)
                                {
                                    Homem::insert("INSERT INTO `stdnt_normalfeetest` (`no`, `year`, `fk_feetype_id`, `amount`, `recieptno`, `fk_feemode_id`, `paid_date`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`) VALUES 
                                    ('$_POST[sid]', '$_POST[year]', '$i', '$_POST[amount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                                    
                                }
                                // echo '<script>window.location = "/Scholarship/normalfeelatest?status=1";</script>';
                            }
                            else
                            {
                                echo '<script>window.location = "/Scholarship/normalfeelatest?status=0";</script>';
                            }
                        }
                        // if($amount>0)
                        // {
                        //     $data[$i]['newpaid'] = $amount;
                        //     $balence = $amount - $data[$i]['due'];
                        //     $data[$i]['newpaid'] = $data[$i]['due'];
                            
                        //     $_POST['recieptno'] = static::recieptno();
                        //     if($_POST['recieptno'] != 'retry')
                        //     {
                        //         $_POST['recieptno'] = $_POST['recieptno'];
                        //     }
                        //     $data[$i]['recieptno'] = $_POST['recieptno'];
                        //     $_POST['amount'] = $amount;
                        //     $amount = $balence;
                        //     $data1 = Homem::getdata("SELECT * FROM `stdnt_normalfeetest` WHERE `no`='$_POST[sid]' AND `year`='$_POST[year]' AND `fk_feetype_id`='$i' AND `amount`='$_POST[amount]' AND `paid_date`='$date' AND `entry_id`='$_SESSION[user_id]'");
                        //     if(sizeof($data1) == 0)
                        //     {
                        //         $count++;
                        //         Homem::insert("INSERT INTO `stdnt_normalfeetest` (`no`, `year`, `fk_feetype_id`, `amount`, `recieptno`, `fk_feemode_id`, `paid_date`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`) VALUES 
                        //         ('$_POST[sid]', '$_POST[year]', '$i', '$_POST[amount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                        //         Extra::sendsmsactive($_POST['name'], $_POST['amount'], Extra::datem($date), $_POST['recieptno'], $_POST['mobile']);
                        //         echo '<script>window.location = "/Scholarship/normalfeelatest?status=1";</script>';
                        //     }
                        //     else
                        //     {
                        //         echo '<script>window.location = "/Scholarship/normalfeelatest?status=0";</script>';
                        //     }
                        // }
                    }
                }
                // echo json_encode($data);
                // $data = Homem::getdata("SELECT * FROM `user_master` WHERE `id`='$_POST[sid]' AND (`ano`='$_POST[no]' OR `no`='$_POST[no]')");
                // $data1 = Homem::getdata("SELECT * FROM `stdnt_normalfeetest` WHERE `no`='$_POST[sid]' AND `year`='$_POST[year]' AND `fk_feetype_id`='$_POST[feetype]' AND `amount`='$_POST[paidamount]' AND `paid_date`='$_POST[paydate]'");
                // if(sizeof($data) == 1)
                // {
                //     if($_POST['edit_id'] == '')
                //     {
                //         if(sizeof($data1) == 0)
                //         {
                //             Homem::insert("INSERT INTO `stdnt_normalfeetest` (`no`, `year`, `fk_feetype_id`, `amount`, `recieptno`, `fk_feemode_id`, `paid_date`, `remarks`, `fk_org_id`, `entry_date`, `entry_id`, `edit_date`, `edit_id`) VALUES 
                //             ('$_POST[sid]', '$_POST[year]', '$_POST[feetype]', '$_POST[paidamount]', '$_POST[recieptno]', '$_POST[feemode]', '$_POST[paydate]', '$_POST[remarks]', '$_SESSION[org_id]', '$date', '$_SESSION[user_id]', '', '')");
                //             Extra::sendsmsactive($_POST['name'], $_POST['paidamount'], Extra::datem($date), $_POST['recieptno'], $_POST['mobile']);
                //             echo '<script>window.location = "/Scholarship/normalfeelatest?status=1";</script>';
                //         }
                //         else
                //         {
                //             echo '<script>window.location = "/Scholarship/normalfeelatest?status=2";</script>';
                //         }
                //     }
                //     else
                //     {
                //         Homem::insert("UPDATE `stdnt_normalfeetest` SET `no`='$_POST[sid]', `year`='$_POST[year]', `fk_feetype_id`='$_POST[feetype]', `amount`='$_POST[paidamount]', `recieptno`='$_POST[recieptno]', `fk_feemode_id`='$_POST[feemode]', `paid_date`='$_POST[paydate]', `remarks`='$_POST[remarks]', `edit_date`='$date', `edit_id`='$_SESSION[user_id]' WHERE `nid`='$_POST[edit_id]'");
                //         echo '<script>window.location = "/Scholarship/normalfeelatest?status=2";</script>';
                //     }
                // }
            }
            else
            {
                echo '<script>window.location = "/Scholarship/normalfeelatest?status=0";</script>';
            }
            if($count !=0)
            {
                echo '<script>window.location = "/Scholarship/normalfeelatest?status=1";</script>';
            }
            else
            {
                echo '<script>window.location = "/Scholarship/normalfeelatest?status=0";</script>';
            }
        }
    }
    public static function recieptno()
    {
        date_default_timezone_set('Asia/Kolkata'); 
        $date =  date('Y-m-');
        
        // $query = "SELECT * FROM `stdnt_normalfee` WHERE `entry_date`='$date'";
        $query = "SELECT * FROM `stdnt_normalfeetest` WHERE `paid_date` LIKE '%$date%'";
        $data = Homem::getdata($query);
        $count = sizeof($data);
        $new = $count+1;
        $rno = static::recieptfront().'-'.$new;
        $data = Homem::getdata("SELECT * FROM `stdnt_normalfeetest` WHERE `recieptno`='$rno'");
        if(sizeof($data) == 0)
        {
            return $rno;
        }
        else
        {
            return 'retry';
        }

    }
    private static function recieptfront()
    {
        date_default_timezone_set('Asia/Kolkata'); 
        $date =  date('ym'); 
        return $date;
    }
}