<!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" />
<link rel="stylesheet" href="css/allcss.css" type="text/css" />
<style>
html, body {margin:15px; padding:0; height:100%; width:100%; min-width:100%; min-height:100%; overflow:scroll;z-index: 100;}
#treport
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:12px;
width:auto;
border-collapse:collapse; 
}
</style>
<script type="text/javascript" src="js/jquery.tools.min.js"></script>
<script type="text/javascript" src="js/jquery.PrintArea.js"></script>
</head>
<body>
<?php
session_start();
require_once 'includes/database.php';
require_once 'includes/funcs.php';

if (isset($_GET['i'])){	$invno =  $_GET['i']; }
elseif (isset($_GET['r'])){	$repono =  $_GET['r']; }
$sec =  $_GET['sec'];
echo '<p><a href="#" id="printnow" class="printnow" onclick="invprint();" style="float:left;">Print</a>';
echo '<a href="#" id="closenow" class="closenow" onclick="window.close();">Close</a></p>';
	
echo '<div id="inv">';	
echo '<table class="printable" id="treport" style="width:680px;font-family:Trebuchet MS, Arial;font-size:18px;">';
	  		   
//echo '<tr><td colspan="3" class="borderclass" align="right"></td></tr>';	
//echo '<tr><td colspan="3"><hr></td></tr>';	   

$db=new MySQLDatabase();
$db->open_connection();
if($sec === "t"){
	$query="SELECT DISTINCT customers.cname, customers.address, customers.city, customers.phone, trackinvoices.rmks, trackinvoices.amount, trackinvoices.idate, trackinvoices.us, trackinvoices.ts, trackinvoices.invno, trackinvoices.invoicecredit FROM customers, trackinvoices WHERE customers.cname = trackinvoices.cname AND trackinvoices.invno = '$invno'"; 
}
else
{ $query="SELECT DISTINCT customers.cname, customers.address, customers.city, customers.phone, repoinvoices.rmks, repoinvoices.amount, repoinvoices.idate, repoinvoices.us, repoinvoices.ts, repoinvoices.invno, repoinvoices.invoicecredit FROM customers, repoinvoices WHERE customers.cname = repoinvoices.cname AND repoinvoices.repono = '$repono'"; 
}
$sql = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 	   
if($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
    echo '<div id="printheader">
		<tr><td align"left" colspan="2"> </td>
			<td style="width:250px;font-weight:bold;font-family:Arial;font-size:24px;text-align:right; padding-right:30px;">'.($row['invoicecredit']=="0" ? 'CREDIT NOTE' : 'INVOICE').'</td></tr>
           </div>'; 
	$idate = substr($row['idate'],8,2)."-".substr($row['idate'],5,2)."-".substr($row['idate'] ,0,4); 
	echo '<tr class="borderclass" style="font-family:Trebuchet MS, Arial;font-size:16px;"><td colspan="2" style="width:450px;">Invoice No. &nbsp;'.$row['invno'].'</td> <td align="right" style="margin-right:20px;">Date &nbsp;'.$idate.'</td></tr>';
	echo '<tr> <td colspan="2" style="border: 2px solid black; width:700px; padding:10px;"><b> To: &nbsp;<br/></b>'.$row['cname'].'   '
        . '<br/>'.$row['address'].'<br>'.$row['phone'].'<br>'.$row['city'].'</td> <td class="borderclass" style="width:125px;"> </td>  </tr><br/>';
}
echo '<table style="border-collapse: collapse;width:700px; font-family:Trebuchet MS, Arial; font-size:14px;">';	  		   
echo '<tr><td colspan="3"></td></tr>'; 
echo '<tr><td colspan="3"></td></tr>';

echo '<tr><td colspan="3"><table cellspacing="0" style="border-collapse: collapse;border: 2px solid black;width:680px;line-height:30px;">
<thead><th style="width:450px" class="borderclass">DESCRIPTION</th> <th  style="width:115px" class="borderclass">QUANTITY</th> <th style="width:115px" class="borderclass">AMOUNT</th> </thead>'; 
if($sec === "t"){
$query="SELECT imeino, regno, vehmod, chasis, am, jdate, jcno, rmks FROM jcards WHERE invno = '$invno'"; 
$sql = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 
    while ($rowj = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
            $jdate = substr($rowj['jdate'],8,2)."-".substr($rowj['jdate'],5,2)."-".substr($rowj['jdate'] ,0,4); 
			echo '<tr><td class="borderclass" align="left">JobCard No.'.$rowj['jcno'].' - Date: '.$jdate.' - Model: '.$rowj['vehmod'].' - Chasis No. '.$rowj['chasis'].' - Reg. No. '.$rowj['regno'].' - '.$rowj['rmks'].' </td> <td align="center" class="borderclass">1</td> <td align="right"  class="borderclass" style="padding-right:3px;">'.number_format($rowj['am'],0).'</td></tr>'; 
		}
}
else {
$query="SELECT vcolor, regno, vehmod, chasis, odate, repono FROM reporders WHERE repono = '$repono'"; 
$sql = mysqli_query($db->connection, $query) or die(mysqli_error($db->connection) ); 
    if ($rowj = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
            $odate = substr($rowj['odate'],8,2)."-".substr($rowj['odate'],5,2)."-".substr($rowj['odate'] ,0,4); 
			echo '<tr><td class="borderclass" align="left">Order No.'.$rowj['repono'].' - Date: '.$odate.' - REPOSESSION OF VEHICLE Model: '.$rowj['vehmod'].' - Chasis No. '.$rowj['chasis'].' - Reg. No. '.$rowj['regno'].' </td> <td align="center" class="borderclass">1</td> <td align="right"  class="borderclass" style="padding-right:3px;">'.number_format($row['amount'],0).'</td></tr>'; 
		}
}		
echo '<tr><td class="borderclass" colspan="3">Remarks :'.$row['rmks'].'</td></tr>';
echo '<tr><td align="right" style="padding-right:3px;" colspan="2">TOTAL</td> <td align="right"  class="borderclass" style="padding-right:3px;">'.number_format($row['amount'],0).'</td></tr>';		
echo '</table></td></tr>';    

echo '<tr><td colspan="2"></td><td align="left">Prepared By:&nbsp;'.$row['us'].' - '.$row['ts'].'</td></tr>';
echo '<tr><td align="right" colspan="3">&nbsp;&nbsp;</td></tr>';
echo '<tr><td>Terms strictly 30 days</td> <td colspan="2" align="left">Approved By:________________</td></tr>';
echo '<tr><td colspan="3"></td>&nbsp;</tr>'; 	echo '<tr><td colspan="3"></td>&nbsp;</tr>';
echo '<tr><td align="right" colspan="3"></td></tr></table>';
echo'</table></div>';

?>
</body>
<script type="text/javascript" src="js/jquery.PrintArea.js"></script>
<script type="text/javascript">
function invprint() {	
		var w = window.open('', '', 'width=800,height=600,resizeable,scrollbars');
	 w.document.write($("#inv").html());
	 w.document.close(); 										// needed for chrome and safari
	 javascript:w.print();
	 w.close();	
};
</script>
</html>