<?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">

<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>Customer Outstanding</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 id="example" class="table table-bordered table-hover" style="width:100%; font-size: 14px; text-transform: capitalize;">
        <thead>
            <tr class="table-active">
                <th>Name</th>
                <th>Mobile</th>
				<th>NIC</th>
                <th>Total Bill</th>
                <th>Balance</th>
            </tr>
        </thead>
        <tbody>
			<?php
			$amount=0;
			$list_qury=mysqli_query($connation,"SELECT * FROM customer_details ORDER BY cs_name DESC");
			while($list_resalt=mysqli_fetch_assoc($list_qury)){
				
			if(cus_balance($list_resalt['cs_mobile'])<0){
			$amount+=(float)cus_balance($list_resalt['cs_mobile']);
			?>
            <tr>
                <td><?php echo $list_resalt['cs_name']; ?></td>
                <td><?php echo '0'.(int)$list_resalt['cs_mobile']; ?></td>
				<td><?php echo $list_resalt['cs_nic']; ?></td>
                <td align="right"><?php echo number_format((float)cus_bill($list_resalt['cs_mobile'])); ?></td>
                <td align="right">
					<?php echo number_format((float)cus_balance($list_resalt['cs_mobile']),2); ?>
				</td>
            </tr>
            <?php } } ?>
        </tbody>
	<tfoot>
		<tr class="table-active">
                <td colspan="4">Total Amount</td>
				<td align="right"><?php echo number_format((float)$amount,2); ?></td>
		</tr>
	</tfoot>
    </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); ?>