<?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';
$user = $_SESSION['reusername'];
?>
<!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 Trackers </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" rel="reportsdiv" onclick="myprint();"  style="float:left;">Print</a>
<a href="#" id="closenow" class="closenow" onclick="window.close();">Close</a></p>
<div id="printblk">
 <p><center><span style="font-size:22px;font-weight:bold;font-family:'Trebuchet MS'"> </span><center> <br/><span style="font-size:16px;font-weight:bold;"><?php echo ($_REQUEST['c']==='' ? 'All Trackers' : $_REQUEST['c']); ?></span>
 <span style="font-size:16px;font-weight:bold;font-family:'Trebuchet MS';"><center> TRACKERS LIST&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; From: &nbsp; <?php echo $_REQUEST['s']; ?> &nbsp; To: &nbsp; <?php echo $_REQUEST['e']; ?> </center></span></p>
<table id="treport" style="width:90%;margin-left:20px;font-weight:normal;">
<?php
echo '<thead>
     <th>JC Date</th> <th>IMEI No.</th> <th>Reg. No.</th> <th>Model</th> <th>Colour</th> <th>Chasis No.</th> <th>User ID</th> <th>Mobile No.</th> <th>Technician</th> <th>Status</th> <th>Remarks</th>';
	 if ($_REQUEST['c']==='' ) echo '<th>Dealer</th>'; 
	echo '</thead>';
	
$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);
$c = $_REQUEST['c'];    
																	// get jcno wise 
if ($_REQUEST['c'] !=='' ) {																	
    $query = "SELECT devstock.mobno, devstock.itype, devstock.stat, devstock.rmks, jcards.* FROM devstock, jcards WHERE jcards.jcno = devstock.jcno AND jcards.cname = '$c' AND repl = 0 AND jcards.jdate >='$sd' AND jcards.jdate <='$ed' ORDER BY jdate, jcno;";
	}
else { $query = "SELECT devstock.mobno, devstock.itype, devstock.stat, devstock.rmks, jcards.* FROM devstock, jcards WHERE jcards.jcno = devstock.jcno AND repl = 0 AND jcards.jdate >='$sd' AND jcards.jdate <='$ed' ORDER BY jdate, jcno;";
		}
    $result = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) );
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){  
		$jdate = substr($row['jdate'],8,2)."-".substr($row['jdate'],5,2)."-".substr($row['jdate'] ,0,4);
		echo '<tr><td>'.$jdate.'</td> <td>'.$row['imeino'].'</td> <td>'.$row['regno'].'</td> <td>'.$row['vehmod'].'</td> <td>'.$row['vcolor'].'</td> <td>'.$row['chasis'].'</td> <td>'.$row['itype'].'</td> <td>'.$row['mobno'].'</td> <td>'.$row['techn'].'</td> <td>'.$row['stat'].'</td> <td>'.$row['rmks'].'</td>'.(($_REQUEST['c']==='' ) ? ('<td style="width:120px;font-size:8px;">'.$row['cname'].'</td>'):'').'</tr>';
    }
 
?>	
</table>

<span align="left" style="font-size:x-small">Printed by: <?php echo $user; ?> &nbsp;&nbsp; <?php echo date("d-m-Y H:i:s"); ?> </span> <br />
<div style="page-break-after:always"> </div>
</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>