<?php include ("kfunctions.php");
//role("dos,hmp");
?>
<html>
<head>
<?php kheader(); ?>

<?php
 
if(isset($_POST["submit_feesitem"])){

$schoolclass=$_POST["schoolclass"];
$schoolyear=$_POST["schoolyear"];
$category=$_POST["category"];

if(!empty($schoolclass)&&!empty($schoolyear)&&!empty($category)){
$fsfilter="and schoolyear LIKE '%".$schoolyear."%' and schoolclass='$schoolclass' and category LIKE '%".$category."%'";}

elseif(!empty($schoolclass)&&!empty($schoolyear)&&empty($category)){
$fsfilter="and schoolyear LIKE '%".$schoolyear."%' and schoolclass='$schoolclass'";}

elseif(!empty($schoolclass)&&empty($schoolyear)&&empty($category)){
$fsfilter="and schoolclass='$schoolclass'";}

elseif(empty($schoolclass)&&!empty($schoolyear)&&!empty($category)){
$fsfilter="and schoolyear LIKE '%".$schoolyear."%' and category LIKE '%".$category."%'";}

elseif(empty($schoolclass)&&empty($schoolyear)&&!empty($category)){
$fsfilter="and category LIKE '%".$category."%'";}

elseif(empty($schoolclass)&&!empty($schoolyear)&&empty($category)){
$fsfilter="and schoolyear LIKE '%".$schoolyear."%'";}

elseif(!empty($schoolclass)&&empty($schoolyear)&&!empty($category)){
$fsfilter="and schoolclass='$schoolclass' and category LIKE '%".$category."%'";}

else {
    $fsfilter='';}

}

else {
    $fsfilter='';
}
?>


<?php
if(isset($_POST["filter"])){

$datefrom=$_POST["datefrom"];
$dateto=$_POST["dateto"];
$adj_types=$_POST['adj_type'];

if(!empty($datefrom)&&!empty($dateto)&&!empty($adj_types)){
$wd="and paytype='$adj_types' and DATE(paydate) bewteen '$dateto' and '$datefrom'";}

elseif(!empty($datefrom)&&!empty($dateto)&&empty($adj_types)){
$wd="and DATE(paydate) bewteen '$datefrom' and '$dateto'";}

elseif(!empty($datefrom)&&empty($dateto)&&empty($adj_types)){
$wd="and paydate LIKE '%".$datefrom."%'";}

elseif(empty($datefrom)&&!empty($dateto)&&!empty($adj_types)){
$wd="and paydate LIKE '%".$dateto."%' and paytype='$adj_types'";}

elseif(empty($datefrom)&&empty($dateto)&&!empty($adj_types)){
$wd="and paytype='$adj_types'";}

elseif(empty($datefrom)&&!empty($dateto)&&empty($adj_types)){
$wd="and paydate LIKE '%".$dateto."%'";}

elseif(!empty($datefrom)&&empty($dateto)&&!empty($adj_types)){
$wd="and paydate='$datefrom' and paytype='$adj_types'";}

else {
    $wd='';}

}

else {
    $wd='';
}

?>


<script src="js/print.js"></script>

<?php 
require_once("connect.php");
?>

<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script src="js/sorttable.js"></script>

<script>
function show_dis(ai){$("#dis_edit"+ai).toggle(500);}
function display_row(ai){$("#rows"+ai).toggle();}
function show_2(ai){$("#attachment"+ai).toggle(500);}  
function show_dis2(ai){$("#dis_edit2"+ai).toggle(500);}
function display_row2(ai){$("#row2"+ai).toggle();}
function get_no(ai){document.getElementById("no").value=ai;}
</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>&nbsp;</div>

                <div class="row">
                    <div class="col-sm-7">
                    <form method='post'>
<div class='row' style='color:maroon;'>
 <div class="col-sm-3"><input type='date' name='datefrom' class='form-control'></div>

 <div class="col-sm-2" style='margin-right:-87px;'><b>To :</b></div>
 <div class="col-sm-3"><input type='date' name='dateto' class='form-control'></div>  

<div class='col-lg-3'>
<select class='form-control' name='adj_type'>
<option value=''>Adjustment Type</option>
  <?php

$result_scrap = $dbh->query("SELECT * from scrap where type='adj_type' order by autoid asc");
$row_scrap = $result_scrap->fetchObject();
$count_scrap = $result_scrap->rowCount();
if($count_scrap>0){
do{
echo "<option value='".$row_scrap->item."'>".$row_scrap->item2."</option>";
}while($row_scrap = $result_scrap->fetchObject());
}else{
echo "<option value=''>Please contact your IT department. </option>";
}
?>
</select>
    </div>

 <div class='col-sm-1'>
<input type='submit' style='float:right;' class='btn btn-sm btn-success' name='filter' value='Filter'></div>
</form> &nbsp &nbsp
</div></div>

<div class="col-sm-3"></div>

<div class="col-sm-1">
<button onClick="PrintDiv('myDiv')" style='float:right' class='btn btn-sm btn-primary'>Print</button>
</div>

</div>

<div class='col-lg-12'><p>&nbsp;

</div>

<?php
$cid=$_GET['cid'];

$result_children=$dbh->query("SELECT * from children where cid='$cid' order by autoid asc");
$row_children=$result_children->fetchObject();
$count_children=$result_children->rowCount();

?>

<div id='myDiv'>
<form method='post'>
<div class='col-lg-12'><br></div>
<div class="col-lg-12">
<div class='panel panel-yellow'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Finance statement for <?php echo $row_children->fname." ".$row_children->sname; ?> </h3></div>
<div class='panel-body'>
<table class='table table-bordered table-hover table-striped sortable' border='1'>
    <tr>
    <th width='2%'>No</th>

    <th width='15%'>Date</th>
    <th >Item</th>
    <th >Amount</th>
    <th >Type</th>

    </tr>

<?php 

$result_homelands=$dbh->query("SELECT * from homeland where cid='$cid' $wd $fsfilter order by autoid asc");
$row_homelands=$result_homelands->fetchObject();
$count_homelands=$result_homelands->rowCount();

if($count_homelands>0){ 

$r=1;

do {

$result_scrapp=$dbh->query("select * from scrap where  item='$row_homelands->fsitemid'");
$row_scrapp=$result_scrapp->fetchObject();
$count_scrapp=$result_scrapp->rowCount();

echo "
    <tr>
    <td>".$r++."</td>

    <td>".$row_homelands->paydate."</td>
    <td>".$row_scrapp->item2."</td>
    <td >".number_format($row_homelands->amount)."</td>
    <td >";
if ($row_homelands->paytype=='d' && $row_homelands->adjustment>=1) {
   echo 'Debt(Adjustment)';
}
elseif ($row_homelands->paytype=='c' && $row_homelands->adjustment>=1) {
    echo 'Deduction';
}
elseif ($row_homelands->paytype=='d' && $row_homelands->adjustment<1) {
    echo 'Debt';
}
elseif ($row_homelands->paytype=='c' && $row_homelands->adjustment<1) {
    echo 'Payment';
}
else {}

    echo "</td></tr>";

} while ($row_homelands=$result_homelands->fetchObject()); } 

?>

</td></tr>

<tr>
        <td></td>   <td></td>
    <td ><b>Outstanding Balance</b> </td>
    <td colspan='2'><?php


$result_bravoss=$dbh->query("SELECT * from bravos where cid='$row_children->cid' and fsitemid='fullpay'");
        $row_bravoss=$result_bravoss->fetchObject();
        $count_bravoss=$result_bravoss->rowCount();

        echo "<b><u>".number_format($row_bravoss->balance)."</u></b>";

     ?>
     </td>

</tr>

</table>
</div></div>
</div>
</form>

</div>

</div>

</form>

                            </div> 

                <!-- /.row -->

            </div>
            <!-- /.container-fluid -->
<?php useractivity("on page", "56"); ?>
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
    <script>
function checkall(){
<?php
include("connect.php");
$result_citadel=$dbh->query("select * from citadel_o where schoolyear='$schoolyear' and term='$schoolterm' and schoolclass='$schoolclass'");
$row_citadel=$result_citadel->fetchObject();
$count_citadel=$result_citadel->rowCount();

if($count_citadel>0){
    do{
?>
if(document.getElementById('checkallz').checked){
document.getElementById('cidcheck<?php echo $row_citadel->autoid; ?>').checked=true;
}else{
document.getElementById('cidcheck<?php echo $row_citadel->autoid; ?>').checked=false; 
}
<?php
}while($row_citadel=$result_citadel->fetchObject());
}
?>
}
</script>

    <!-- 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>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
</body>

</html>
