<?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['a'],6,4)."-".substr($_REQUEST['a'],3,2)."-".substr($_REQUEST['a'],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="8"><center><span style="font-size:18px;font-weight:normal;float:left;"> <b>TRACKERS EXPIRY LIST </b></span><span style="font-size:22px;font-weight:bold"></span><center>
<br/><span style="font-size:16px;font-weight:bold;"><center>'. str_repeat('&nbsp;',25).' Expiring By : '.$_REQUEST['a'].'&nbsp;&nbsp; </center></span></td></tr>';

echo'<tr><u> <th>JC Date</th> <th>JC No.</th> <th>IMEI No.</th> <th>Mobile No.</th> <th>Type</th> <th>Renewal Date</th> <th>Details</th> <th>Customer</th> </u></tr>';
echo '<tr><td colspan="8"><hr/></td></tr>'; 
$sql = mysqli_query($db->connection, "SELECT DISTINCT jcards.jcno, jcards.jdate, jcards.cname, jcards.rendate, jcards.imeino, devstock.mobno, devstock.itype, CONCAT(jcards.regno,'-',jcards.vehmod,'-',jcards.chasis) as nar FROM jcards LEFT OUTER JOIN devstock ON jcards.jcno = devstock.jcno WHERE MONTH('$sd') = MONTH(jcards.rendate) AND YEAR('$sd') = YEAR(jcards.rendate) ORDER BY jcards.jcno;") or die (mysqli_error($db->connection) );
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
    $jdate = substr($row['jdate'],8,2)."-".substr($row['jdate'],5,2)."-".substr($row['jdate'],0,4);
	$edate = substr($row['rendate'],8,2)."-".substr($row['rendate'],5,2)."-".substr($row['rendate'],0,4);
    echo "<tr><td>".$jdate."</td> <td>".$row['jcno']."</td> </td> <td>".$row['imeino']."</td> <td>".$row['mobno']."</td> <td>".$row['itype']."</td> <td>".$edate."</td> <td>".$row['nar']."</td> <td>".$row['cname']."</td> </tr>";
    $i++; 
    }
echo '<tr><td colspan="8"><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>