<?php
session_start();
if (!isset($_SESSION['reusername'])) { echo 'Sorry You Dont Have permissions to View this Page!'; exit();}
require_once 'includes/database.php';
require_once 'includes/display.php';
require_once 'includes/funcs.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>QPL | List of Insurance </title>
<script type="text/javascript" src="js/jquery-1.10.2.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="css/allcss.css">

</head>
<body>


<p><a href="#" id="printnow" class="printnow" onclick="myprint();" style="float:left;">Print</a>
<a href="#" id="closenow" class="closenow" onclick="window.close();">Close</a></p>
<div id="printblk">
<center><span style="font-size:18px;font-weight:normal;float:left;"> <b>INSURANCE LIST </b></span><span style="font-size:22px;font-weight:bold">QOOLPOINT INSURANCE AGENCY</span><center>
<br/>
<p align="center" style="font-size:16px;font-weight:bold;"> <?php echo 'From: '.$_REQUEST['s'].'&nbsp;&nbsp; To: '.$_REQUEST['e'] ?></p><br>
<table id="treport" style="width:90%;margin-left:20px;border-collapse:collapse;">
<?php 

$user = $_SESSION['reusername'];
$db=new MySQLDatabase();
$db->open_connection();
$sd = substr($_REQUEST['s'],6,4)."-".substr($_REQUEST['s'],3,2)."-".substr($_REQUEST['s'],0,2);
$ed = substr($_REQUEST['e'],6,4)."-".substr($_REQUEST['e'],3,2)."-".substr($_REQUEST['e'],0,2);       
$i=1;

echo '<thead><th>Booking No.</th> <th>Date</th> <th>Details</th> <th>Customer</th> <th>Provider</th> <th>Charged</th> <th>Bill Amount</th> <th>GP</th></thead>';
$sql = mysqli_query($db->connection, "SELECT tt.insno, tt.idate, tt.nar, tt.cname, tt.supp, tt.iam, insbills.amount, 0 as gp FROM (SELECT insrecs.insno, insrecs.idate, insrecs.cname, insrecs.supp, CONCAT(insrecs.regno,' - ',insrecs.vehmod) as nar, insinvoices.amount as iam FROM insrecs LEFT OUTER JOIN insinvoices ON insrecs.insno = insinvoices.insno) as tt LEFT OUTER JOIN insbills ON insbills.insno = tt.insno  WHERE tt.idate >= '$sd' AND tt.idate <= '$ed' ORDER BY tt.insno;") or die (mysqli_error($db->connection) );
$gtot = 0;
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
    $idate = substr($row['idate'],8,2)."-".substr($row['idate'],5,2)."-".substr($row['idate'],0,4);
	$tot = floatval($row['iam']) - floatval($row['amount']);
    echo "<tr><td>".$row['insno']."</td> <td>".$idate."</td> <td>".$row['nar']."</td> <td>".$row['cname']."</td> <td>".getsupplier($row['supp'])."</td> <td align='right'>".number_format($row['iam'],0)."</td> <td align='right'>".number_format($row['amount'],0)."</td> <td align='right'>".number_format($tot,0)."</td></tr>";
    $i++; $gtot = $gtot + $tot;
    }
echo '<tr><td><hr/></td><td><hr/></td><td><hr/></td><td><hr/></td><td><hr/></td><td><hr/></td><td><hr/></td><td><hr/></td></tr>'; 
echo '<tr><td></td> <td></td> <td></td> <td></td> <td></td> <td></td><td>TOTAL</td><td align="right">' . number_format($gtot, 0). '</td></tr>'; 
?> 

</table>
<span style="font-size:14px;font-weight:normal;float:left;font-family:Arial;margin-left:30px;">
<i>Printed by:</i><?php echo $user.'&nbsp;&nbsp;&nbsp;&nbsp;'.date("d-m-Y  H:i:s"); ?><br/><br/>
<i>Checked by:</i> _____________________<br/><br/>
<i>Approved by:</i> _____________________<br/></span>
</div>
</body></html>

<script type="text/javascript">
$(document).ready(function() {
$('#treport').dataTable( {
	"bSort": false,
	"iDisplayLength": 50,
	"aLengthMenu": [[50, 100, 200, -1], [50, 100, 200, "All"]]
  } );
});
  
function myprint(){
	var w = window.open('', '', 'width=800,height=600,resizeable,scrollbars');
	 w.document.write($("#printblk").html());
	 w.document.write('<link rel="stylesheet" type="text/css" href="css/allcss.css">');
	 w.document.close(); 										// needed for chrome and safari
	 javascript:w.print();
	 w.close();
};	
</script>