<?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><?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>
</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;">Please Wait...</div></div>
	
<div class="contaner mt-4">
	
<div class="row">
<div class="table-responsive">
<table id="example" class="table list-table" style="width:100%; font-size: 14px; text-transform: capitalize;">
        <thead>
            <tr>
                <th>No.</th>
				<th></th>
				<th>Create Time</th>
                <th>Invoice</th>
                <th>Amount</th>
                <th>Payment</th>
				<th>User</th>
            </tr>
        </thead>
        <tbody>
<?php
$row_count=0;
$list_qury=mysqli_query($connation,"SELECT sd.*,'Invoice' AS type_text,sd.sale_details_date AS c_date,sd.sale_details_billid AS invoice_cheque,CONCAT(sd.sale_details_date,' ',sd.sale_details_time) AS c_time,sd.sale_details_cash_payment+sd.sale_details_card_payment AS payment,CONCAT(sud.user_fname,' ',sud.user_lname) c_user
FROM sale_details sd INNER JOIN user_details sud ON sd.sale_details_user=sud.user_id
WHERE sd.sale_details_customer='$_GET[sale_details_customer]'
ORDER BY sale_details_date DESC");
while($list_resalt=mysqli_fetch_assoc($list_qury)){
$row_count++;
?>			
<tr>
<td><?php echo number_format($row_count); ?></td>
<td>
<a href="poin-of-sale?bill_id=<?php echo $list_resalt['sale_details_billid']; ?>" class="badge badge-dark" title="View Bill"><i class="fa fa-edit"></i></a>
<a href="view-sale?sale_billid=<?php echo $list_resalt['sale_details_billid']; ?>" target="_blank" class="badge badge-primary" title="View Bill"><i class="fa fa-eye"></i></a>
<a href="bill_print.php?print=<?php echo $list_resalt['sale_details_billid']; ?>" target="re_print_bill" class="badge badge-info" title="Re-print Bill"><i class="fa fa-print"></i></a>
<a href="sales?remove=<?php echo $list_resalt['sale_details_billid']; ?>" class="badge badge-danger" title="Remove Sale" onClick="return confirm('Are you sure to remove this sale?');"><i class="fa fa-trash"></i></a>
</td>
<td><?php echo date("Y-m-d h:i:s A",strtotime($list_resalt['c_time'])); ?></td>
<td><?php echo $list_resalt['invoice_cheque']; ?></td>
<td><?php echo number_format(bill_amount($list_resalt['invoice_cheque']),2); ?></td>
<td><?php echo number_format($list_resalt['payment'],2); ?></td>
<td><?php echo $list_resalt['c_user']; ?></td>
</tr>
<?php
}
?>
        </tbody>
    </table>
</div>
		
</div>
</div>
	
<iframe name="re_print_bill" style="display: none;"></iframe>
	
<script>
$(document).ready(function() {
    $('#example').DataTable();
} );	
</script>
	
</body>
</html>
<?php @mysqli_close($connation); ?>