<? 
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");
include("calstock.php");

if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Repair Invoice</title>


<style>

#printable{ 
      page-break-before: always;

      margin-top:30px;
    }
.tbl
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:12px;
text-transform:uppercase;
}
.tbl td
{
border: 0px solid black;
}
#tbl
{
border: 1px solid black;

}
.tble 
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:12px;
border-collapse:collapse;
text-transform:uppercase;

}
.tble  td{
height:18px;
margin-left:10px;
margin-right:10px;
padding-left:10px;
padding-right:10px;
}

.tble th
{
border:1px solid black;
}
.tbl1{
border: 1px solid black;
border-bottom:0px solid white;
font-size:12px;
border-collapse:collapse;
text-align:right;
text-transform:uppercase;
}
.tbl1 td{
border-bottom:1px solid black;
height:10px;
}

#add_td{
font-size:12px;
height:15px;
}
#add_td br{
margin:0px;
padding:0px;
}
.tot_td{
border-bottom:0px solid black;
}
.tot_td1{
border-top:0px solid black;
}
#tot_tbl td{
border:1px solid black;
border-collapse:collapse;
}
body
 {font-family:Arial;}
</style>
<body onload='window.print()'>
<?
$qry=mysqli_query($db,"select * from gateentry where jcno='$jcno' and brcode='$brcode'");

$row=mysqli_fetch_array($qry);       
$date = $row['estdate'];
$newDate = date("d-m-Y", strtotime($date));

?>

<table border='0' width='100%'>
<tr>
<td align='left' width='33%' id='add_td'> 
<?
$qry1=mysqli_query($db,"select * from company_master where brcode='$brcode'");

$row1=mysqli_fetch_array($qry1);
print "<font size='2'><b>".$row1[2]."</b></font><br>".$row1[4]."<br>".$row1[5].",".$row1[6];
if(($row1[7]>0)&&($row1[7]!=''))
    print "<br>Tel: ".$row1[7];
 if(($row1[8]>0)&&($row1[8]!=''))
   print " Fax: ".$row1[8];
print "<br>Email: ".$row1[10];
if($row1[11]!='')
print ",<br>".$row1[11]."<br>Web: ".$row1[12];
else
print "<br>Web: ".$row1[12];
?>
</td>
<td align='center'  width='33%'><h4 style='border:1px solid black;background-color:grey;'>REPAIR INVOICE</h4></td>
<td align='right'  width='33%'> <img src="images/logo.gif" width="80" height="80" /> 
<br>
<br>
 Finance Code:<? echo $row1[13]; ?></td></tr></table>
<table width=100% class='tbl' >

<tr><td align='left' style="width:60px;"><b>Payer</b></td><td ><b>:</b></td><td align='left' colspan='2' style="min-width:50%;" ><? echo $row['owner']; ?></td><td align='left'><b>Tel</b></td><td><b> :</b></td><td align='left'><? echo $row['telephone']; ?></td></tr>
<tr><td align='left'><b>Address</b></td><td ><b>:</b></td><td align='left' colspan='2'><? echo $row['address']; ?></td><td align='left'><b>Mobile </b></td><td><b> :</b></td><td align='left'><? echo $row['mobile']; ?></td></tr>
<tr><td align='left'><b>User Name</b></td><td ><b>:</b></td><td align='left' colspan='2'>--</td><td align='left'><b>Email</b></td><td><b> :</b></td><td align='left'><? echo $row['email']; ?></td></tr>
</table>
<table width=100% class='tbl' height='40'>
<tr><td  ><b>Insurance Claim No:</b></td><td >--</td><td ><b>Date:</b></td><td ><? echo $newDate; ?></td><td rowspan='3' style="border-left:1px solid black;border-collapse:collapse;border-style:dotted;width:0px"></td><td ><b>Repair Invoice: </b></td><td><? echo $row['invno']; ?></td><td ><b>Date:</b></td><td><? echo $newDate; ?></td></tr>
<tr><td colspan='4' style="border-bottom:0px solid black;border-collapse:collapse;"></td><td ><b>Repair Order: </b></td><td><? echo (int)$row[0]; ?></td><td ><b>Date:</b></td><td><? echo $newDate; ?></td></tr>
<tr><td ><b>Counter Reading:</b></td><td ><? echo (int)$row['kms']; ?></td><td ></td><td ></td><td ><b>Assignment No: </b></td><td>--</td><td ></td><td></td></tr>
</table>
<table width=100% class='tbl'>
<tr><td ><b>Reg No:</b></td><td ><? echo $row['regno']; ?></td><td ><b>Model Code:</b></td><td ><? echo $row['model']; ?></td><td ><b>VIN No: </b></td><td><? echo $row['chasisno']; ?></td></tr>
<tr><td ><b>Model Name:</b></td><td ><? echo $row['vehiclename']; ?></td><td ><b>Sale Date:</b></td><td >--</td><td ><b>Cust. Name: </b></td><td><? echo $row['owner']; ?></td></tr>
</table>
<table width=100% class='tbl' >
<tr><td align='left'><b>LPO No</b></td><td ><b>:</b></td><td align='left'>--</td><td width=50%></td><td align='left'><b>Date </b></td><td><b> :</b></td><td align='left'><? echo $newDate; ?></td></tr>
<tr><td align='left'><b>Estimate No</b></td><td ><b>:</b></td><td align='left'>--</td><td width=40%></td><td align='left'><b>Date </b></td><td><b> :</b></td><td align='left'><? echo $newDate; ?></td></tr>
</table>
<table width=100% class='tble'  border='1'  FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS style='border-bottom:1px solid black;'>
<tr><th>JobNo<th>Code<th >Repairs Carried Out  <th> Qty <th> Amount</tr>

<?

$ptot=0;
$pdisctot=0;
$ltot=0;
$subtot=0;
$i=1;
$flg=0;
$k=1;

$res=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
while($res1=mysqli_fetch_array($res))
{

if(($k>=15)&&($flg==0)){
$i=-5;
print "</table><p >continued on page 2..</p><p  id='printable'>continued from page 1..</p>";
?>
<table border='0' width='100%'>
<tr>
<td align='left' width='33%' id='add_td'> 
<?
$qry1=mysqli_query($db,"select * from company_master where brcode='$brcode'");

$row1=mysqli_fetch_array($qry1);
print "<font size='2'><b>".$row1[2]."</b></font><br>".$row1[4]."<br>".$row1[5].",".$row1[6];
if(($row1[7]>0)&&($row1[7]!=''))
    print "<br>Tel: ".$row1[7];
 if(($row1[8]>0)&&($row1[8]!=''))
   print " Fax: ".$row1[8];
print "<br>Email: ".$row1[10];
if($row1[11]!='')
print ",<br>".$row1[11]."<br>Web: ".$row1[12];
else
print "<br>Web: ".$row1[12];
?>
</td>
<td align='center'  width='33%'><h4 style='border:1px solid black;background-color:grey;'>REPAIR INVOICE</h4></td>
<td align='right'  width='33%'> <img src="images/logo.gif" width="80" height="80" /> 
<br>
<br>
 Finance Code:<? echo $row1[13]; ?></td></tr></table>
<?
print "<table width=100% class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS>";

print "<tr><th>JobNo<th>Code<th >Repairs Carried Out  <th> Qty <th> Amount</tr>";
$flg=1;

}

print "<tr><td width='6%' height='20' >".$k."</td><td>spare</td><td >".$res1['partname']."</td><td>".$res1['qty']."</td><td align='right'>".$res1['gtot']."</td></tr>";
$ptot+=$res1['gtot'];
$pdisctot+=$res1['disc'];
$i++;
$k++;
}


$res2=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
while($res3=mysqli_fetch_array($res2))
{

if(($k>=15)&&($flg==0)){
$i=-5;
print "</table><p >continued on page 2..</p><p  id='printable'>continued from page 1..</p>";
?>
<table border='0' width='100%'>
<tr>
<td align='left' width='33%' id='add_td'> 
<?
$qry1=mysqli_query($db,"select * from company_master where brcode='$brcode'");

$row1=mysqli_fetch_array($qry1);
print "<font size='2'><b>".$row1[2]."</b></font><br>".$row1[4]."<br>".$row1[5].",".$row1[6];
if(($row1[7]>0)&&($row1[7]!=''))
    print "<br>Tel: ".$row1[7];
 if(($row1[8]>0)&&($row1[8]!=''))
   print " Fax: ".$row1[8];
print "<br>Email: ".$row1[10];
if($row1[11]!='')
print ",<br>".$row1[11]."<br>Web: ".$row1[12];
else
print "<br>Web: ".$row1[12];
?>
</td>
<td align='center'  width='33%'><h4 style='border:1px solid black;background-color:grey;'>REPAIR INVOICE</h4></td>
<td align='right'  width='33%'> <img src="images/logo.gif" width="80" height="80" /> 
<br>
<br>
 Finance Code:<? echo $row1[13]; ?></td></tr></table>
<?
print "<table width=100% class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS>";

print "<tr><th>JobNo<th>Code<th >Repairs Carried Out  <th> Qty <th> Amount</tr>";
$flg=1;

}


print "<tr><td width='4%' height='20'  >".$k."</td><td>labour</td><td >".$res3['service']."</td><td>1.00</td><td align='right'>".$res3['servamt']."</td></tr>";
$ltot+=$res3['servamt'];
$subtot+=$res3['subamt'];
$i++;
$k++;
}




$gtot=$ptot+$ltot;
$ntot1=$gtot-$pdisctot;
$ntot=$ntot1-$row['adv_amt'];
for($j=$i;$j<15;$j++){

print "<tr><td width='4%' height='20' ></td><td></td><td ></td><td></td><td ></td></tr>";
}
?>

</table>
<?
$qry1=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
$row1=mysqli_fetch_array($qry1);
$qry2=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
$row2=mysqli_fetch_array($qry2);
$qry3=mysqli_query($db,"select * from jcardserv where subamt>'0' and jcno='$jcno' and brcode='$brcode'");

?>
<?
$sql=mysqli_query($db,"select sum(jcardparts.gtot) from jcardparts INNER JOIN newpartmaster ON jcardparts.partcode=newpartmaster.partcode where (newpartmaster.subgroup='PARTS' or newpartmaster.subgroup='FILTER') and jcardparts.jcno='$jcno' and jcardparts.brcode='$brcode'");
$rr=mysqli_fetch_array($sql);
$sql1=mysqli_query($db,"select sum(jcardparts.gtot) from jcardparts INNER JOIN newpartmaster ON jcardparts.partcode=newpartmaster.partcode where newpartmaster.subgroup='TYRE' and jcardparts.jcno='$jcno' and jcardparts.brcode='$brcode'");
$rr1=mysqli_fetch_array($sql1);
$sql2=mysqli_query($db,"select sum(jcardparts.gtot) from jcardparts INNER JOIN newpartmaster ON jcardparts.partcode=newpartmaster.partcode where newpartmaster.subgroup='OIL' and jcardparts.jcno='$jcno' and jcardparts.brcode='$brcode'");
$rr2=mysqli_fetch_array($sql2);
?>
<table  width=100% class='tbl1' id='tbl' border='1' style='height:50px;'>
<tr><td align='left'  width='30%' ><b>Prepared by:</b><? echo $pre_by; ?></td><td align='left' width='30%'><b>Verified by:</b>--</td><td rowspan='4'>

           <table width='100%' style='border:0px solid black;border-collapse:collapse;margin:0px' border=0 id='tot_tbl'>
    	   <tr><td colspan=2 class='tot_td1'>Accounts</td></tr>
 	   <tr><td align='right'>Labour</td><td ><? echo putcoma($ltot); ?></td></tr>
	   
          <tr><td  align='right' height='10'>Parts & Filter</td><td ><? echo $rr[0]; ?></td></tr>
	   <tr><td align='right'>Tyre</td><td ><? echo $rr1[0]; ?></td></tr>
	   <tr><td  align='right'>Gas & Oil</td><td ><? echo $rr2[0]; ?></td></tr>
   	   <tr><td align='right'>Consumables</td><td></td></tr>
	   <tr><td  align='right'>Sublet</td><td><? echo putcoma($subtot); ?></td></tr>
	   <tr><td align='right'>Total</td><td ><? echo putcoma($gtot); ?></td></tr>
	   <tr> <td  align='right'>Advance</td><td ><? echo $row['adv_amt'];?></td></tr>
	   <tr><td align='right'>Labour disc</td><td></td></tr>
	   <tr><td align='right'>Parts disc</td><td ><? echo putcoma($pdisctot); ?> </td></tr>
                     <tr><td align='right'>Round off</td><td ></td></tr>
                     <tr><td align='right' class='tot_td' >Net Amount</td><td class='tot_td'><? echo putcoma($ntot); ?></td></tr>
          </table>






</td></tr>



<tr><td align='left' colspan='2'  height=20><b>Advance:</b><? echo $row['adv_amt'];?></td></tr>

<tr><td align='left' colspan='2'  height=20><b>Sublet Name	:</b>
<?
while($row3=mysqli_fetch_array($qry3))
{
print $row3['subnm'].",";
}
?>
</td></tr>

<tr><td colspan=2>
<table border=0 style='border:0px solid white; ' width=100%><tr>
<td style='border:0px solid white;text-align:left'>Company accepts no responsibility for money paid against this invoice unless cash stamp affixed and signed AND/OR evidenced by an offical receipt of the company .
</td><td style='border:0px solid white; text-align:right;'> <img src='images/est21.png' /></td></tr>
<tr><td style='border:0px solid white;text-align:left'> Received vehicle to my entire satisfaction with all tools and accessories complete.</br>

SIGNATURE OF CUSTOMER.</td><td style='border:0px solid white; text-align:right;'>
<img src='images/est22.png' /></td></tr></table>


</td>

</tr></table>



