<?php
session_start();
require("php_con.php");
require("check_user.php");
require("function.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.ico">
<title>Report - <?php echo $system_name; ?></title>
<link rel="stylesheet" href="main_css.css">
	
<style>
	.table{
		border-collapse: collapse;
		margin: auto;
	}
	.table tr td,th{
		font-size: 14px;
		padding: 5px;
		border: 1px solid #000000;
		padding: 5px;
	}
</style>
</head>

<body>
<script>
window.addEventListener("load",function(){
	var load_screen=document.getElementById('load_screen');
	document.body.removeChild(load_screen);
});
</script>

<div id="load_screen"><div id="loading"><img src="image/loading.gif" width="80px;"></div></div>

<div align="right"><button type="button" class="btn btn-success btn-sm" onClick="JavaScript:printDiv('print_aria');">Print Report</button></div>
	
<div class="m-4" id="print_aria">

<div align="center" class="mb-2">
<h4>Expenses Report</h4>
<p><strong>Run time:</strong> <?php echo $current_date." - ".$current_time ?> | <strong>User:</strong> <?php echo $current_user_resalt['user_fname']; ?></p>
<p><strong>Duration:</strong> <?php echo $_POST['st_date']." to ".$_POST['en_date'] ?></p>
</div>	
<hr><br>

<table class="table">
  <tbody>
    <tr>
      <td>#No</td>
      <td>Category</td>
      <td>Amount</td>
    </tr>
<?php
$count=0;
$total=0;
$l_qury=mysqli_query($connation,"SELECT ec.expenses_text AS cat_text,SUM(ed.expenses_details_amount) AS Amount
FROM expenses_details ed INNER JOIN expenses_category ec ON ed.expenses_details_category=ec.expenses_id
WHERE ed.expenses_details_date BETWEEN '$_POST[st_date]' AND '$_POST[en_date]'
GROUP BY ed.expenses_details_category
ORDER BY ec.expenses_text ASC");
while($l_resalt=mysqli_fetch_assoc($l_qury)){
$count++;
$total+=(float)$l_resalt['Amount'];
?>
    <tr>
      <td><?php echo number_format((float)$count); ?></td>
      <td><?php echo $l_resalt['cat_text']; ?></td>
      <td align="right"><?php echo number_format((float)$l_resalt['Amount'],2); ?></td>
    </tr>
<?php } ?>
    <tr>
      <td colspan="2">Total Amount</td>
      <td align="right"><?php echo number_format((float)$total,2); ?></td>
    </tr>
  </tbody>
</table>


</div>
	
<script>
function printDiv(print_aria){
	var printcontents=document.getElementById('print_aria').innerHTML;
	var orginalcontain=document.body.innerHTML;
	document.body.innerHTML=printcontents;
	window.print();
	document.body.innerHTML=orginalcontain;

}
</script>

	
</body>
</html>
<?php @mysqli_close($connation); ?>