<?
session_start();
include("test.php");
include("opendb.php");
include("includes/function.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}


        
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>World Wide Automotive Center</title>
</head>
<style type="text/css">
table,tr,td{border-collapse:collapse;border:1px solid grey;padding:5px;}
body{font-family:Arial, Helvetica, sans-serif;font-size:13px;}

tr:nth-child(odd)    { background-color:#f3f3f3; }
tr:nth-child(even)    { background-color:#fff; }
select,input[type=text], textarea{  
background: #eeeeee; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjIzJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, #eeeeee 0%, #ffffff 23%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(23%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* IE10+ */
background: linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#ffffff',GradientType=0 ); /* IE6-8 */
border:1px solid #999; padding:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;


}
#tbb
{
border:0px solid white;
}
#tbb td
{
border:0px solid white;
}
</style>
<script>
function editfun()
{
var estno=document.f2.estno.value;
document.location='editest.php?estno='+estno;
}
</script>


<?
if($show)
{

$qry=mysqli_query($db,"select * from jcard_est where brcode='$brcode' and estno='$estno'");
$row=mysqli_fetch_row($qry);
$jcno=$row[1];

}

if($show1)
{

$qry=mysqli_query($db,"select * from jcard_est where brcode='$brcode' and jcno='$jcno'");
$row=mysqli_fetch_row($qry);
$jcno=$row[1];

}

if($show2)
{
$jcno='';
$r=mysqli_query($db,"select * from gateentry where brcode='$brcode' and regno='$regno' order by jcno");
if(mysqli_num_rows($r)<1)
{
print "<script>alert ('Invalid Register no.');document.location='printjobest.php';</script>";
}
while($r1=mysqli_fetch_array($r))
{
$qry=mysqli_query($db,"select * from jcard_est where brcode='$brcode' and jcno='$r1[jcno]' ");
if(mysqli_num_rows($qry)>0)
{
$row=mysqli_fetch_row($qry);
$jcno=$row[1];
}
}
if($jcno=='')
{
print "<script>alert ('There is no estimation created for this Register no.');document.location='printjobest.php';</script>";
}

}
if(($show) ||($show1) ||($show2) )
{
$qry1=mysqli_query($db,"select * from gateentry where brcode='$brcode' and jcno='$jcno'");
$row4=mysqli_fetch_row($qry1);

?>
<body onload='window.print()'>
<form action="" method="post">
<table width="100%" border="1" align="center" cellpadding="1" cellspacing="1">
  <tr>
    <td colspan="8" bgcolor="#fff">
<table  width='100%'  id='tbb'>
<tr>
<td align='left' width='33%'> 
<?
$qry1=mysqli_query($db,"select * from company_master where brcode='$brcode'");
$row1=mysqli_fetch_array($qry1);
print $row1[2]."<br>".$row1[4]."<br>".$row1[5]."<br>".$row1[6]."<br>Tel: ".$row1[7]."/ Fax: ".$row1[8]."<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%'></td>
<td align='right'  width='33%'> <img src="images/logo.gif" width="70" height="70" />  </td></tr>
<tr><td colspan='3' align='right'>Finance Code:<? echo $row1[13]; ?></td></tr></table>
</td>
    </tr>
  <tr>
    <td width="120"><strong>ESTIMATE NO</strong></td>
    <td width="148"><? echo $row[2]; ?> </td>
    <td width="132"><strong>DATE</strong></td>
    <td width="148"><? print datetohtml( $row4[11]);?></td>
    <td width="96"><strong>CAR NO.</strong></td>
    <td colspan="3"><? echo $row4[4]; ?></td>
    </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td COLSPAN='2'><strong>E-MAIL:&nbsp;</strong><? echo $row4[22]; ?></td>
    <td><strong>MAKE</strong></td>
    <td colspan="3"><? echo $row4[2]; ?></td>
    </tr>
  <tr>
    <td><strong>TO</strong></td>
    <td><? echo $row4[8]; ?></td>
    <td><strong>FAX NO.</strong></td>
    <td>&nbsp;</td>
    <td><strong>MODEL</strong></td>
    <td colspan="3"><? echo $row4[3]; ?></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td><strong>FILE NO.</strong></td>
    <td colspan="3"><? echo $row1[23]; ?></td>
    </tr>
  <tr>
    <td><strong>POLICE REPORT</strong></td>
    <td>CHECKED</td>
    <td><strong>DATE OF ACCIDENT</strong></td>
    <td><? echo datetohtml($row4[28]); ?></td>
    <td><strong>POLICE REP. NO.</strong></td>
    <td colspan="3"><? echo $row4[6]; ?></td>
    </tr>
  <tr>
    <td colspan="2"><strong>ACCIDENT DETAILS</strong></td>
    <td colspan="6"><? echo $row4[34]; ?></td>
    </tr>
  <tr>
    <td colspan="2"><strong>ADD JOBS NOT RELATED TO ACCIDENT</strong></td>
    <td colspan="6">&nbsp;</td>
    </tr>
<?
$qry2=mysqli_query($db,"select * from jcard_estparts where brcode='$brcode' and estno='$estno'");
?>
  <tr>
    <td width='6%'><strong>SL.NO.</strong></td>
    <td width='35%'><strong>PARTS NAME</strong></td>
    <td width='10%'><p><strong>BODY=B,MECH=M,</strong></p>
      <p><strong>DEPRECIATABLE=D</strong></p></td>
    <td width='12%'><strong>CHANGE=C,REPAIR=R</strong></td>
    <td width='10%'><strong>ORIGINAL PARTS</strong></td>
    <td width='10%'><p><strong>SECOND HAND PARTS</strong></p></td>
    <td width='10%'><p><strong>COMMERCIAL </strong><strong>PARTS</strong></p></td>
    <td width='8%'><strong >OTHER SOURCES</strong></td>
  </tr>
<?
$i=1;
$tot1=0;
$tot2=0;
$tot3=0;
$tot4=0;
$tot5=0;
$gtot=0;
while($row2=mysqli_fetch_array($qry2))
{

 print "<tr><td height='20'>".$i."</td><td>".$row2[4]."</td>";
 print "<td >";
if($row2[5]=='B-M-D'){echo $row2[10];
$tot1+=$row2[10];}
print "</td> <td>";
if($row2[5]=='Change and Repair'){echo $row2[10];
$tot2+=$row2[10];}
print "</td><td>";
if($row2[5]=='Original'){echo $row2[10];
$tot3+=$row2[10];}
print "</td> ";
print "<td>";
if($row2[5]=='Used'){echo $row2[10];
$tot4+=$row2[10];}
print "</td><td>";
if($row2[5]=='Commercial'){echo $row2[10];
$tot5+=$row2[10];}
print "</td></tr>";
$i++;
 }
for($j=$i;$j<11;$j++){
  print "<tr><td height='20'></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; 

}
$gtot+=$tot1+$tot2+$tot3+$tot4+$tot5;
?> 

  <tr>
    <td>&nbsp;</td>
    <td><b>TOTAL SP</b></td>
    <td><b><? echo putcoma($tot1); ?></b></td>
    <td><b><? echo putcoma($tot2); ?></b></td>
    <td><b><? echo putcoma($tot3); ?></b></td>
    <td><b><? echo putcoma($tot4); ?></b></td>
    <td><b><? echo putcoma($tot5); ?></b></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height='25'></td>
    <td><b>GRAND SP TOTAL</b></td>
    <td colspan='6'><b><? echo putcoma($gtot); ?></b></td>
    
  </tr>
<tr>
    <td>a</td>
    <td>a/c gas</td>
    <td><? echo $row[5]; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>b</td>
    <td>others</td>
    <td><? echo $row[6]; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
<?
$servtot=0;
$qry3=mysqli_query($db,"select * from jcard_estserv where brcode='$brcode' and estno='$estno'");
while($row3=mysqli_fetch_array($qry3))
{
$servtot+=$row3[5];
}
?>
    <td>c</td>
    <td>labour</td>
    <td><? echo putcoma($servtot); ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>d</td>
    <td>miscellaneous</td>
    <td><? echo $row[7]; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>collection:excess:</td>
    <td><? echo $row[8]; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
<?
$ntot=0;
$ntot=$gtot+$servtot+$row[5]+$row[6]+$row[7]+$row[8];
?>
    <td height='25'>&nbsp;</td>
    <td><b>GRAND TOTAL:</b></td>
    <td><b><? echo putcoma($ntot); ?></b></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td rowspan="2" height='75'>&nbsp;</td>
    <td rowspan="2" align='left' valign='top'><strong>SIGNATURE</b></td>
    <td colspan="4" rowspan="2">&nbsp;</td>
   <td  colspan="2" rowspan="2" valign='top'><strong>STAMP</strong></td>
    </tr>
  <tr>
    
  </tr>
</table>

	

</form>
<?
}
else
{
?>
<table>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

<tr><td>Select Estimation No. <select name='estno'><option>--Select--</option>
<?
$re=mysqli_query($db,"select estno,jcno from jcard_est where brcode='$brcode' order by jcno desc");
while($row=mysqli_fetch_row($re))
{
 print "<option value='$row[0]'>$row[0]-$row[1]</option>";
}
?>
</select>

<input type=submit value='Show ->' name='show' ></td>
</form>
<td>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

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

<input type=submit value='Show ->' name='show1'>
</td>
</form>
<td>
<form name=f2 action='<?print $PHP_SELF?>' method='post' onSubmit='return valid1()'>

Enter Register No. <input name='regno' type='text'>

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


<?
}
?>
</body>
</html>
