<?php
session_start();
require("php_con.php");
require("check_user.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">
	
<script src="data_table/js/jquery-3.5.1.js"></script>
<script src="data_table/js/jquery.dataTables.min.js"></script>
<script src="data_table/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="data_table/css/bootstrap.css">
<link rel="stylesheet" href="data_table/css/dataTables.bootstrap4.min.css">
	
<link rel="stylesheet" href="icon/css/font-awesome.css">
<link rel="stylesheet" href="icon/css/font-awesome.min.css">
	
<link rel="stylesheet" href="alert/sweetalert2.min.css">
<script src="alert/sweetalert2.min.js"></script>
	
<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 class="p-2 text-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>Return Report</h4>
<p>Run time: <?php echo $current_date." - ".$current_time ?> | User: <?php echo $current_user_resalt['user_fname']; ?></p>
</div>	
<hr>
	
<table class="table-sm table table-bordered" style="font-size: 14px;">
  <tbody>
    <tr class="table-active">
		<td>Bill</td>
      <td>Product</td>
      <td>Reson</td>
      <td>User</td>
      <td>Time</td>
      <td>Qty</td>
    </tr>
<?php 
if($_POST['user']=="all"){
$l_qury=mysqli_query($connation,"SELECT rd.rd_system_id,pd.product_barcode,pd.product_name,rd.rd_reson,rd.rd_qty,CONCAT(ud.user_fname,' ',ud.user_lname) AS u_name,CONCAT(rd.rd_add_date,' ',rd.rd_add_time) AS c_time
FROM return_details rd LEFT JOIN product_details pd ON rd.rd_barcode=pd.product_barcode
LEFT JOIN user_details ud ON rd.rd_user=ud.user_id
INNER JOIN sale_details sd ON rd.rd_system_id=sd.sale_details_billid
WHERE rd.rd_add_date BETWEEN '$_POST[st_date]' AND '$_POST[en_date]'
ORDER BY rd.rd_id DESC");
}
else{
$l_qury=mysqli_query($connation,"SELECT rd.rd_system_id,pd.product_barcode,pd.product_name,rd.rd_reson,rd.rd_qty,CONCAT(ud.user_fname,' ',ud.user_lname) AS u_name,CONCAT(rd.rd_add_date,' ',rd.rd_add_time) AS c_time
FROM return_details rd LEFT JOIN product_details pd ON rd.rd_barcode=pd.product_barcode
LEFT JOIN user_details ud ON rd.rd_user=ud.user_id
INNER JOIN sale_details sd ON rd.rd_system_id=sd.sale_details_billid
WHERE rd.rd_add_date BETWEEN '$_POST[st_date]' AND '$_POST[en_date]' AND rd.rd_user='$_POST[user]'
ORDER BY rd.rd_id DESC");
}
while($l_resalt=mysqli_fetch_assoc($l_qury)){
?>
    <tr>
		<td><?php echo $l_resalt['rd_system_id']; ?></td>
      <td><?php echo $l_resalt['product_barcode']; ?> • <?php echo $l_resalt['product_name']; ?></td>
      <td><?php echo $l_resalt['rd_reson']; ?></td>
      <td><?php echo $l_resalt['u_name']; ?></td>
      <td><?php echo date("Y-m-d h:i:s A",strtotime($l_resalt['c_time'])); ?></td>
      <td align="right"><?php echo $l_resalt['rd_qty']; ?></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); ?>