<?php 
include ("../core/kfunctions.php");?>
<html>
<head>
<?php kheader(); 

include("../core/connect.php");

$yy=date("Y");
$mm=date("m");
$dd=date("d");
$status_date=$yy."-".$mm."-".$dd;

// if(isset($_POST["item_filter"])){

// $filteryear=$_POST["schoolyear"];
// $filterterm=$_POST["term"];

// $cy=date("y");
// $yeartotake="datez = '$cy'";

// if ($filterterm==1){$cm>='1' and $cm<='4'}

// $cm = date("m");
// if ($cm>='1' and $cm<='4'){$termtotake="1";}
// elseif ($cm>='5' and $cm<='8'){$termtotake="2";}
// elseif ($cm>='9' and $cm<='12'){$termtotake="3";}

// if(!empty($filteryear)&&!empty($filterterm)){
// $dadate="AND datez like '%".$filteryear."-%'  AND datez like '$filterterm'";
// $prod_date=$dadate;  
// $wd="<span style='color:maroon;'> For 20</span>".$filteryear.",<span style='color:maroon;'><i> Term </i></span>".$filterterm."; ";

// $insert_scrapp=$dbh->query("INSERT into scrap (item,item2,item3,type) values('$rolenumber','$filteryear','$filterterm','payment_filter')");
// $filter_show="$wd";}

// else{

// $dadate=" and schoolyear = '$cy' and schoolterm = '$termtotake'"; $wd='';
// $filter_show="$wd";

// "<div class='alert alert-warning' style='text-align:center;font-weight:bold;font-style:italic;'> ".$wd."</div>";
// } }

// else{

// $cm = date("m");
// if ($cm>='1' and $cm<='4'){$termtotake="1";}
// elseif ($cm>='5' and $cm<='8'){$termtotake="2";}
// elseif ($cm>='9' and $cm<='12'){$termtotake="3";}

// $cy=date("y");
// $dadate=" and schoolyear = '$cy' and schoolterm = '$termtotake'"; $wd='';
// $filter_show="$wd";} 


// isset for filtering by year and term 


if(isset($_POST["expenses_filter"])){
$datefrom=$_POST["datefrom"];
$dateto=$_POST["dateto"];

if(!empty($datefrom)&&!empty($dateto)){
$dadate="AND DATE(datez) BETWEEN '$datefrom' AND '$dateto'";
$prod_date=$dadate;  
$wd="<span style='color:maroon;'>  From Between : </span>".$datefrom."<span style='color:maroon;'><i> To : </i></span>".$dateto."; ";
$insert_scrapp=$dbh->query("INSERT into scrap (item,item2,item3,type) values('$rolenumber','$datefrom','$dateto','expense_filter')");
$filter_show="$wd";}

elseif(!empty($datefrom)&&empty($dateto)){
$dadate="and datez='$datefrom'";
$prod_date=$dadate; 
$wd="<span style='color:maroon;'><i> On : </i></span>".$datefrom."; ";
$insert_scrapp=$dbh->query("INSERT into scrap (item,item2,item3,type) values('$rolenumber','$datefrom','$dateto','expense_filter')");
$filter_show="$wd";}

elseif(empty($datefrom)&&!empty($dateto)){
$dadate="and datez='$dateto'";
$prod_date=$dadate; 
$wd="<span style='color:maroon;'><i> On : </i></span>".$dateto."; ";
$insert_scrapp=$dbh->query("INSERT into scrap (item,item2,item3,type) values('$rolenumber','$datefrom','$dateto','expense_filter')");
$filter_show="$wd";}

else{
$dadate=" and datez = '$status_date'";
$prod_date="$dadate"; 
$wd="";
$filter_show="";}}

else{
$dadate=" and datez = '$status_date'";
$prod_date="$dadate"; 
$wd="";
$filter_show="";}

?>


</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='col-lg-12'><br> &nbsp </div>
            
            <div class="container-fluid">

<!-- /.row profile-->
<?php

$year = date('y');

echo "
<div class='col-lg-12'>
<div class='panel panel-yellow'>
<div class='panel-heading'>
<h3 class='panel-title'>Expenses ". $wd."</h3>
</div>
<div class='panel-body'>

<form method='post'>

<!--
<div class='col-lg-2'>
<select name='schoolyear' class='form-control' required='required'>
<option value='$year'> 20$year </option>";

$result2 = $dbh->query("select * from scrap where type='ya'");
$row2 = $result2->fetchObject();

do{
echo "<option value='$row2->item'>".$row2->item2."</option>";
}while($row2 = $result2->fetchObject());

echo"
</select>
</div>

<div class='col-lg-2'>
<select name='term' class='form-control' required='required'>
<option value='$year'> Term $termtotake </option>";

$result3 = $dbh->query("select * from scrap where type='ts'");
$row3 = $result3->fetchObject();

do{
echo "<option value='$row3->item'>Term ".$row3->item2."</option>";
}while($row3 = $result3->fetchObject());

echo"
</select>
</div>
<div class='col-lg-1'>
<input type='submit' class='btn btn-sm btn-primary' name='item_filter' value='Filter'>
</div> 

<div class='col-md-1'>  </div>   

commented out filter by year and term by robot
-->

<div class='row' style='color:maroon;'>
 <div class='col-md-2'><input type='date' name='datefrom' class='form-control'></div>

 <div class='col-md-1' style='margin-right:-60px;'><b>To :</b></div>
 <div class='col-md-2'><input type='date' name='dateto' class='form-control'></div>  

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

</form>

<div class='col-lg-12'><br> </div>";

echo "
<table class='table table-bordered table-hover table-striped sortable'>
<tr>
<th>Item</th>

<th>Amount</th>

</tr>";
$result_scrap=$dbh->query("SELECT * from scrap where type='expense'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowcount();


if ($count_scrap>0){
do {
 
$expensesum=$dbh->query("select sum(cost) from expenses where category='$row_scrap->item' $dadate ");

$row_expenses=$expensesum->fetch();
$totalnewfeeexpenses= $row_expenses['0'];//all homeland fees except balcarriedforward
$totalnewfeeexpenses=intval($totalnewfeeexpenses);//turn that homeland figure to int

echo "
<tr>
<td>".$row_scrap->item2."</td>

<td>".number_format($totalnewfeeexpenses)."</td>
</tr>";

}while($row_scrap=$result_scrap->fetchObject());
}
echo "</table>

</div>
</div>
</div>";
?>      
    </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>

    <!-- Morris Charts JavaScript -->
    
    <!-- bursar tracker -->
    <?php
    useractivity("Dashboard","1");
    ?>
    <!-- bursar tracker -->
    

</body>

</html>