<? 
session_start();
include("test.php");
include("opendb.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>World Wide Automotive Center</title>
<script type="text/javascript" src="number_to_word.js"></script>

<script>

var regno=[];
var jcno=[];
var cnt2=1;



  /*  below code is to get jcno when regno select ***/

 function get_jobno(str)
  {

  var list="<select name='jcno' id='jcno_list'><option>-Select JobNo-</option>";

  var j;
  for(j=1;j<cnt2;j++){

     if(str==regno[j]){
       
        list+="<option>"+jcno[j]+"</option>"; 
     }
 }
  
   list+="</select>";
   
   document.getElementById("job_list").innerHTML=list;   
}

</script>


<style>
hr{
color:#F3F3EC;
}

table,td,th{
border:1px solid #DADACE;
border-collapse:collapse;
}
#myTable td th
{
border:1px solid #DADACE;
border-collapse:collapse;
}

#myTable tr:nth-child(odd){ background-color:#EBEBEB; }
#myTable tr:nth-child(even)    { background-color:#F3F3F3; }
#myTable{border:0px}
</style>




<body  bgcolor='#3b5998'  >


<div id='outPopUp' align="center" style=" margin:0 250px 0 250px; background-color:white; height:1000px;">

<div style='background-color:#F0F1F1;'>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#FAFAFA;'>

<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

Select Jobcard No. <select name='invno' style="width:145px;"><option>--Select--</option>
<?
$re=mysqli_query($db,"select distinct(invno),jcno from jcardinvoice where brcode='$brcode' order by invno asc");
while($row=mysqli_fetch_row($re))
{
 print "<option value='$row[0]'>".$row[0]."--".$row[1]."</option>";
}
?>
</select>

<input type=submit value='Show' name='show'>

</form>
</div>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#F6F6F6;'>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

Enter Jobcard No. <input name='jcno' type='text'  placeholder='Jobcard No Here...' >

<input type=submit value='Show' name='show1'>

</form>
</div>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
<div style='background-color:#FAFAFA;'>

<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

<table><tr><td>Enter Register No. <input name='regno' type='text' placeholder='Register No Here...' onkeyup='get_jobno(this.value)' autocomplete='off' ></td>

<td id='job_list'></td><td><input type=submit value='Show ->' name='show2'></td></tr></table>


</form>
</div>
<div style='color:#B6B8B8;'>------------------------------------------------------------------------------------------------------------------------------------------------------</div>
</div>


<?

 $qry=mysqli_query($db,"select *  from gateentry where brcode='$brcode' ");
$i=1;
 while($qry1=mysqli_fetch_array($qry)){

 print "<script>regno[$i]='$qry1[4]';jcno[$i]='$qry1[1]';cnt2++;</script>";
 $i++; 
 }  


if($show)
{
$qry=mysqli_query($db,"select * from jcardinvoice where invno='$invno' and brcode='$brcode'");
}

if($show1)
{
$qry=mysqli_query($db,"select * from jcardinvoice where jcno='$jcno' and brcode='$brcode'");
$r1=mysqli_fetch_row($qry);
$invno=$r1[0];
if(mysqli_num_rows($qry)<=0)
   {
    print "<script>alert ('Invalid Jobcard Number');</script>";
   }
}

if($show2)
{
  $res=mysqli_query($db,"select * from gateentry where regno='$regno' and jcno='$jcno' and brcode='$brcode' ");
  if(mysqli_num_rows($res)<=0)
   {
    print "<script>alert ('Invalid Register Number');</script>";
   }
}

$qry1=mysqli_query($db,"select * from jcardinvoice where invno='$invno' and brcode='$brcode'");
$row=mysqli_fetch_array($qry);   
?>
<img  src="xpress/head1.jpg" width="745" height="110"  alt="login" title="logo" border='0'/>

 <h2 align='center'>INVOICE</h2>
<p align='right'><a href='edit_jobinv.php?invno=<? echo $invno; ?>'/><img src='images/edit.png' width='20' height='20' title='Click to Edit' /></a>

<a href='printjobinv.php?invno=<? echo $invno; ?>'/>Print Duplicate</a>
</p>

<table  id='tbl' bgcolor='#E8E8E6' id='tbl' align='center' width=95% border='0' style="border-collapse:collapse;">
<tr><td colspan='5' align='center' >JC NO:<? echo $row[jcno]; ?></td></tr>
<tr><td align='left'><b>Ins. Company/Customer:</b><br></td><td align='left'><? echo $row[2];?></td>
<td rowspan='5'  width=30%></td><td ><b>Invoice No: </b><br></td><td ><? echo $invno;?></td></tr>

<tr><td align='left'><b>Lpo No:</b><br></td><td align='left'><? echo $row[8]; ?> </td>
<td ><b>Date : </b><br></td><td ><? echo $row[1]; ?></td></tr>
<tr><td align='left'><b>File No:</b><br></td><td align='left'><? echo $row[3]; ?></td>
<td><b>A/c No:</b><br></td><td ><? echo $row[4]; ?></td></tr>

<tr><td align='left'><b>Vehicle:</b><br></td><td align='left' ><? echo $row[5]; ?></td>
<td ><b>Register No: </b><br></td><td ><? echo $row[6]; ?></td></tr>
<tr><td align='left'><b>Body Type:</b><br></td><td align='left'><? echo $row[7]; ?></td></tr>
<tr><td  colspan='5'>

</td></tr>

<tr><td colspan='5' >
<table id='myTable' border='1' style="border-collapse:collapse;" width=100%>
<th>Sl No.<th width='30%'>Description  <th>Qty<th>Amount
<?
$i=1;
$tot=0;
while($row1=mysqli_fetch_array($qry1))
{
print "<tr><td>".$i."</td><td>".$row1[14]."</td><td>".$row1[9]."</td><td>".$row1[10]."</td></tr>";
$tot+=$row1[10];
$i++;

}

?>
</table>
</td></tr>
<tr><td colspan='5' ></td></tr>


<tr><td colspan='4' align='right'>Total:</td><td id='tot' ><? echo $tot; ?></td></tr>
<tr><td>
<?
if($row[15]!='')
{
?>
<font color='red'> * </font> Remark: <?echo $row[15];
}
$ntot=$tot-$row[17];
?>
</td>
<td align='right' colspan='3'> Dep:</td><td id='depr' ><? echo $row[17]; ?></td></tr>
<tr><td  height=60 id='totwd'>
<? print "<script>document.write(toWords($ntot));</script> only";
?>
<td align='right' colspan='3'> Net Total:</td><td id='ntot' ><? echo $ntot; ?>
</td></tr></table>

</div>

