<?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';
echo $htmlheaders;  echo '<head>';
echo $js;
echo '<script type="text/javascript" src="js/jquery.tools.min.js"></script>
<script type="text/javascript" src="js/jquery.PrintArea.js"></script>';
echo $recss;
echo '</head><body>';
$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 '<p><a href="#" id="printnow" class="printnow" onclick="myprint();" style="float:left;">Print</a>';
echo '<a href="#" id="closenow" class="closenow" onclick="window.close();">Close</a></p>';
echo '<div id="printblk">';	
echo '<table id="treport" style="width:90%;margin-left:20px;">
<tr><td colspan="9"><center><span style="font-size:18px;font-weight:normal;float:left;"> <b>INSURANCE EXPIRY LIST </b></span><span style="font-size:22px;font-weight:bold">QOOLPOINT LTD</span><center>
<br/><span style="font-size:16px;font-weight:bold;"><center>'. str_repeat('&nbsp;',25).' Expiring Between : '.$_REQUEST['s'].'&nbsp;&nbsp; and '.$_REQUEST['e'].'</center></span></td></tr>';

echo'<tr><u><th>Booking No.</th> <th>Date Issued</th> <th>Expiry Date</th> <th>Details</th> <th>Customer</th> <th>Provider</th> <th>Type</th> <th>Value</th> <th>Premium</th></u></tr>';
echo '<tr><td colspan="9"><hr/></td></tr>'; 
$sql = mysqli_query($db->connection, "SELECT insrecs.insno, insrecs.idate, insrecs.cname, insrecs.expdate, insrecs.icat, insrecs.inam, insrecs.insprem, insrecs.supp, CONCAT(insrecs.regno,'-',insrecs.vehmod) as nar FROM insrecs WHERE expdate BETWEEN '$sd' AND '$ed' ORDER BY insno;") or die (mysqli_error($db->connection) );
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
    $idate = substr($row['idate'],8,2)."-".substr($row['idate'],5,2)."-".substr($row['idate'],0,4);
	$edate = substr($row['expdate'],8,2)."-".substr($row['expdate'],5,2)."-".substr($row['expdate'],0,4);
    echo "<tr><td>".$row['insno']."</td> <td>".$idate."</td> </td> <td>".$edate."</td> <td>".$row['nar']."</td> <td>".$row['cname']."</td> <td>".getsupplier($row['supp'])."</td> <td>".$row['icat']."</td> <td align='right'>".number_format($row['inam'],0)."</td> <td align='right'>".number_format($row['insprem'],0)."</td> </tr>";
    $i++; 
    }
echo '<tr><td colspan="9"><hr/></td></tr>';  
echo '</table>'; 
echo '<span style="font-size:14px;font-weight:normal;float:left;font-family:Arial;margin-left:30px;">'; 
echo '<i>Printed by:</i> '.$user.'&nbsp;&nbsp;&nbsp;&nbsp;'.date("d-m-Y  H:i:s").'<br/><br/>'; 
echo '</div>';
echo '</body></html>';
?> 
<script type="text/javascript">
function myprint(){
	var w = window.open('', '', 'width=800,height=600,resizeable,scrollbars');
	 w.document.write($("#printblk").html());
	 w.document.close(); 										// needed for chrome and safari
	 javascript:w.print();
	 w.close();
};	
</script>