<?php 
include ("kfunctions.php");
?>
<html>
<head>
<?php kheader(); ?>
<?php 
require_once("connect.php");

?>
<script src="js/sorttable.js"></script>
</head>
<body>


    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

                <!-- Page Heading -->
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">
                            
                        </h1>
                        
                    </div>
                </div>
                <!-- /.row -->

                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-body">

                                <?php

                                if(isset($_POST["transubmit"])){
error_reporting(E_ALL | E_STRICT);
include ("connect.php");
$term=$_POST["term"];
$tid=$_POST["tid"];
$cid=$_POST["cid"];
$datepaid=$_POST["datepaid"];
$slipid=$_POST["slipid"];
$term=$_POST["term"];
$amount=$_POST["amount"];
$bcf=$_POST["bcf"];


$update=$dbh->query("update received set tid='$tid',datepaid='$datepaid',slipid='$slipid',term='$term',amount='$amount',bcf='$bcf' where tid='$tid' and cid='$cid'"); 

if($term=='Term 1'){
$update=$dbh->query("update children set datebcf='$datepaid',bcf='$bcf', t1='$bcf' where cid='$cid'"); 

}elseif($term=='Term 2'){
$update=$dbh->query("update children set datebcf='$datepaid',bcf='$bcf', t2='$bcf' where cid='$cid'"); 

}elseif($term=='Term 3'){
$update=$dbh->query("update children set datebcf='$datepaid',bcf='$bcf', t3='$bcf' where cid='$cid'"); 

}



echo "<div class='alert alert-success'> Details on Transaction ID:&nbsp;".$tid."  have been Updated. </div>";
}
?>

<form method="post">
                            
<div class="panel panel-green"><!--Initiative-->
<div class="panel-heading"><h3 class="panel-title">Update Transaction ID</h3></div>
<div class="panel-body">
<table class="table table-bordered table-hover table-striped sortable">

 <thead>
<tr>
<th>ID</th>
<th>Date earned</th>
<th>Slip date</th>
<th>Student name</th>
<th>Slip ID</th>
<th>Term</th>
<th>Amount</th>
<th>Balance	</th>

</tr></thead>
<?php
$tid=$_GET["tid"];
$term=$_GET["term"];

require_once("connect.php");

$mytoday=date("Y-m-d");
$result=$dbh->query("select * from received where tid='$tid' order by autodate desc limit 0,20");
$row=$result->fetchObject();
$count=$result->rowCount();




// If result matched $myusername and $mypassword, table row must be 1 row

echo "<input type='hidden' name='term' value='".$term."'>";
if($count>0){ 
do {
	$result2=$dbh->query("select * from children where cid='$row->cid'");
$row2=$result2->fetchObject();
echo "


<input type='hidden' name='tid' value='".$row->tid."'>
<input type='hidden' name='cid' value='".$row->cid."'>

<tr>
<td>".$row->tid."</td>
<td>".$row->autodate."</td>
<td><input type='text' name='datepaid' class='form-control' value='".$row->datepaid."'></td>
<td>".$row->cid."-".$row2->fname."&nbsp;".$row2->sname."</td>
<td><input type='text' name='slipid' class='form-control' value='".$row->slipid."'></td>
<td><input type='text' name='term' class='form-control' value='".$row->term."'></td>
<td><input type='text' name='amount' class='form-control' value='".$row->amount."'></td>
<td><input type='text' name='bcf' class='form-control' value='".$row->bcf."'></td>
</tr>

";}
while($row=$result->fetchObject());
}
else {echo "So far, no children have paid today. Click <a href='allfees.php'>here to view income including other days</a> ";}

?>
</table>
<input type='submit' style="float:right;" name='transubmit' class='btn btn-sm btn-primary' value='Submit Updates'>


</div></div>
</form>
</div>
                            </div> </div>
                    </div>
                </div>
                <!-- /.row -->

               

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

</body>

</html>
