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

<script src='../../js/jquery.js'></script>
<script src='../../js/thousandseparator.js'></script>

<style type="text/css">
table{ width: 100%;border-collapse: collapse;background:  }
tr:nth-of-type(odd){background: #eee;}
th{background: #333;color: #ffffff;font-weight: bold;}
td, th{padding: 6px;text-align: left;}  
@media
only screen and (max-width: 760px),
(min-device-width:768px) and (max-device-width:1024px ){
 
table,thead,tbody,th,td,tr{display: block;}
thead tr{position: absolute;top: -9999px;left: -9999px;}
tr{border: 1px solid #ccc; }
.td{border: none;border-bottom: 1px solid #eee;position: relative;padding-left: 50%;}
.td:before{position: absolute;top:6px;left: 6px;width: 45%;padding-right: 10px;white-space: nowrap;}
.td:nth-of-type(1):before{content: "No";}
.td:nth-of-type(2):before{content: "Given to";}
.td:nth-of-type(3):before{content: "Location";}
.td:nth-of-type(4):before{content: "Date";}
.td:nth-of-type(5):before{content: "Amount";}
.td:nth-of-type(6):before{content: "Category";}
.td:nth-of-type(7):before{content: "Details";}

} 

</style>

<?php kheader(); ?>

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


<?php 
require_once("../core/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 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'>    

              <div class="card-header d-flex p-0">
                <h3 class="card-title p-3"></h3>
                <ul class="nav nav-pills ml-auto p-2">
                  <li class="nav-item"><a class="nav-link active" href="entry_expense.php" >Expenses</a></li>
                  <li class="nav-item"><a class="nav-link active" href="expense_categories.php">Categories</a></li>  
                  <li class="nav-item"><a class="nav-link active" href="view_expenses.php">View expenses</a></li>

                </ul>
              </div>

          </div><!--  close panel-heading -->



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

            <div class="card">
<div class='card-body'>
<div class="tab-content">

 <form method='post'>
<div class='row' style='color:maroon;'>
<div class="col-md-1" style='margin-right:-35px;'><b>From :</b></div>
<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-lg-2'>
<select class='form-control' name='category'>
<option value=''>Category</option>
<?php
$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{
echo "<option value='".$row_scrap->item."'>".$row_scrap->item2."</option>";
}while($row_scrap=$result_scrap->fetchObject());
}else{echo "<option value=''>There is no data as yet. </option>";}

?>
</select></div>

 <div class='col-lg-1'>
<input type='submit' style='float:right;' class='btn btn-sm btn-success' name='filter' value='Filter'></div>
</div>
<div class='col-lg-12'><br></div>
</form>
<?php
if(isset($_POST["filter"])){
$datefrom=$_POST["datefrom"];
$dateto=$_POST["dateto"];
if(!empty($_POST["category"])){$catid=$_POST["category"]; $dacat="and category='$catid'"; }
else{$dacat='';}
if(!empty($_POST["spentby"])){$userid=$_POST["spentby"]; $dauser="and requestfrom='$userid'"; }
else{$dauser='';}

if(!empty($datefrom)&&!empty($dateto)){$dadate="and (datez>='$datefrom' && datez<='$dateto')"; }
elseif(!empty($datefrom)&&empty($dateto)){$dadate="and datez='$datefrom'"; }
elseif(empty($datefrom)&&!empty($dateto)){$dadate="and datez='$dateto'"; }
elseif(empty($datefrom)&&empty($dateto)){$dadate='';}
}else{$dadate='and autoid!=0'; $dauser=''; $dacat='';}
?>
               
                  <table>
                    
                    <tr>
<?php
$result_scrap=$dbh->query("select * from scrap where type='expense' order by autoid desc");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();
if ($count_scrap>0) {do{
 echo "<th width='30%'>".$row_scrap->item2."</th>"; 
?>
<td width="5%"></td>
<td class='mycategorytd'>
<?php
$result_expenses=$dbh->query("select sum(cost) from expenses where category='$row_scrap->item' and status=2 $dacat $dadate $dauser");
$count_expenses=$result_expenses->rowCount();
$row_expenses=$result_expenses->fetch();
if ($count_expenses>0){$total=$row_expenses['0'];}else{$total=0;}
echo "<span style='color:maroon'>".number_format($total)."</span></td></tr>";
}while($row_scrap=$result_scrap->fetchObject()); }
?>         
</table>  
              </div><!-- /.card  -->
 <div class='col-lg-12'><br></div>             
              </div><!-- /.card-body -->


      </div><!--  close panel panel-yellow -->

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

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


    <!-- /#wrapper -->
    <script>
function checkall(){
<?php
include("../core/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>

</div><!--  close col-lg-12 -->
</div><!--  close myDiv -->
</div><!--  close container fluid -->
</div><!--  close page wrapper -->
</div><!--  close wrapper -->

</body>

</html>
