
<!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 Tracker Invoices </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">
<style>
    html, body {margin:0; padding:0; height:100%; width:100%; min-width:100%; min-height:100%; overflow:scroll;}
</style>			
</head>
<?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'];
?>
<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;">
 <span style="font-size:16px;font-weight:bold;font-family:'Trebuchet MS';"><center> REPOSESSION ORDERS 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;">

<thead>
     <u><th>Order No.</th> <th>Date</th> <th>Details</th> <th>Customer</th> <th>Auctioneer</th> <th>Charged</th> <th>Expenses</th> <th>GP</th> </u>
</thead>
    
	
<?php	
$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);
    
$sql = mysql_query("SELECT tt.repono, tt.odate, tt.nar, tt.cname, tt.auct, tt.ram, SUM(paytrans.amount) as pam, 0 as tot FROM (SELECT reporders.repono, reporders.odate, reporders.auct, CONCAT(reporders.regno,'-',reporders.vehmod) as nar, reporders.cname, repoinvoices.amount as ram FROM reporders 
		LEFT OUTER JOIN repoinvoices ON reporders.repono = repoinvoices.repono) as tt LEFT OUTER JOIN paytrans ON paytrans.repono = tt.repono WHERE tt.odate >= '$sd' AND tt.odate <= '$ed' GROUP BY tt.repono") or die (mysql_error());
$gtot = 0;
while ($row = mysql_fetch_array($sql)){
    $odate = substr($row['odate'],8,2)."-".substr($row['odate'],5,2)."-".substr($row['odate'],0,4);
	$tot = floatval($row['ram']) - floatval($row['pam']);
    echo "<tr><td>".$row['repono']."</td> <td>".$odate."</td> <td>".$row['nar']."</td> <td>".$row['cname']."</td> <td>".$row['auct']."</td> <td align='right'>".number_format($row['ram'],0)."</td> <td align='right'>".number_format($row['pam'],0)."</td> <td align='right'>".number_format($tot,0)."</td></tr>";
    $gtot = $gtot + $tot;
    }
echo '<tr><td colspan="8"><hr/></td></tr>'; 
echo '<tr><td colspan="7">TOTAL</td><td align="right">' . number_format($gtot, 0). '</td></tr>'; 
echo '<tr><td colspan="8"><hr/></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": 20,
	"aLengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "All"]]
  } );
});
  
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>