<?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 tr td{
		font-size: 14px;
		padding: 5px;
	}
	.table tr th{
		font-size: 14px;
		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>Day End Report</h4>
<p><strong>Run time:</strong> <?php echo $current_date." - ".$current_time ?> | <strong>User:</strong> <?php echo $current_user_resalt['user_fname']; ?></p>
</div>	
<hr>

<table style="margin: auto;">
  <tbody>
<?php
if($_POST['user']=="all"){
$u_quy=mysqli_query($connation,"SELECT user_id,CONCAT(user_fname,' ',user_lname) AS u_name FROM user_details ORDER BY CONCAT(user_fname,' ',user_lname) ASC");
}
else{
$u_quy=mysqli_query($connation,"SELECT user_id,CONCAT(user_fname,' ',user_lname) AS u_name FROM user_details WHERE user_id='$_POST[user]' ORDER BY CONCAT(user_fname,' ',user_lname) ASC");
}
while($u_resalt=mysqli_fetch_assoc($u_quy)){
$total=(float)(start_amount($_POST['end_date'],$u_resalt['user_id'])+user_cash_amount($_POST['end_date'],$u_resalt['user_id']))-(user_expenses($_POST['end_date'],$u_resalt['user_id']));
	
$st_qury=mysqli_query($connation,"SELECT * FROM start_balance_details WHERE Start_balance_date='$_POST[end_date]' AND Start_balance_start_user='$u_resalt[user_id]'");
$st_resalt=mysqli_fetch_assoc($st_qury);
?>
    <tr>
      <td colspan="2"><strong><?php echo $u_resalt['u_name']; ?></strong></td>
    </tr>
    <tr>
      <td>Day Start Cash Amount</td>
      <td align="right"><?php echo number_format((float)start_amount($_POST['end_date'],$u_resalt['user_id']),2); ?></td>
    </tr>
    <tr>
      <td>Sale Cash Amount</td>
      <td align="right"><?php echo number_format((float)user_cash_amount($_POST['end_date'],$u_resalt['user_id']),2); ?></td>
    </tr>
    <tr>
      <td>Sale Card Amount</td>
      <td align="right"><?php echo number_format((float)user_card_amount($_POST['end_date'],$u_resalt['user_id']),2); ?></td>
    </tr>
    <tr>
      <td>Discount Amount</td>
      <td align="right"><?php echo number_format((float)user_discount_amount($_POST['end_date'],$u_resalt['user_id']),2); ?></td>
    </tr>
    <tr>
      <td>Expenses</td>
      <td align="right"><?php echo number_format((float)user_expenses($_POST['end_date'],$u_resalt['user_id']),2); ?></td>
    </tr>
    <tr class="font-weight-bold" style="background-color: rgba(0,128,0,0.1);">
      <td>Cash Balance</td>
      <td align="right"><?php echo number_format((float)(start_amount($_POST['end_date'],$u_resalt['user_id'])+user_cash_amount($_POST['end_date'],$u_resalt['user_id']))-(user_expenses($_POST['end_date'],$u_resalt['user_id'])),2); ?></td>
    </tr>
    <tr>
      <td>Hand Count Cash Amount</td>
      <td align="right"><?php echo number_format((float)end_amount($_POST['end_date'],$u_resalt['user_id']),2); ?></td>
    </tr>
    <tr>
      <td>Difference</td>
      <td align="right"><?php echo number_format((float)end_amount($_POST['end_date'],$u_resalt['user_id'])-((start_amount($_POST['end_date'],$u_resalt['user_id'])+user_cash_amount($_POST['end_date'],$u_resalt['user_id']))-(user_expenses($_POST['end_date'],$u_resalt['user_id']))),2); ?></td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
<?php } ?>
  </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); ?>