<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
include ("../opendb.php");
include ("../test.php");
$re=mysqli_query($db,"select * from jobcard where jcno='$jcno' and brcode='$brcode'");
if(mysqli_num_rows($re)<=0)
 {
    print "Jobcard does not exist";
    return;
 }
$jcrow=mysqli_fetch_array($re);

?>
<style>
 td,body{font-family:'arial narrow';font-size:14;letter-spacing:1}
</style>

<table width=100% border=0>
<th colspan=3>
<?
 $brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
 $brrow=mysqli_fetch_array($brres);
?>

PSN AUTOMOBILES PVT. LTD., <br>
</th>
<tr><td colspan=10 align=center>
<font size=2>
<?PRINT $brrow[braddr].' ,'.$brrow[brcity].' <br>Tin: '.$brrow[tin] .',<u>Phone: '.$brrow[brphone]?>
</u>

<br><br>
</font>
<?
if($jcrow[invtype]=='-')
 print " PENDING ";
?>
JOB CARD RETAIL INVOICE 
<br>Form <?print $jcrow[invtype]?>

<hr><TH>
<tr><td width=310>
Customer Name and Address: <br>
<?
$cusres=mysqli_query($db,"select * from customer where acname='$jcrow[cname]'");
$cusrow=mysqli_fetch_array($cusres);
print $jcrow[cname]."<br>".$cusrow[addr1].", ".
$cusrow[dist1].", ".$cusrow[state1].", ".$cusrow[pin1];
?>
</td>
<?
if($brcode == 'PSN328')
{
?>
 	<td align=center width=40%>Invoice NO: <b>HSMDJC<?print $jcrow[invno]?></b><br>
<?
}
elseif($brcode == 'PSN481')
{
?>
  	<td align=center width=40%>Invoice NO: <b>HSTRJC<?print $jcrow[invno]?></b><br>
<?
}
?> 

Date: <b><?print datetohtml($jcrow[entrydate])?></b><br>
</td>
  <td>TSNO : <B><?print $jcrow[msno]?></b> <br>
      Model : <?Print $jcrow[model]?> <br>
      Serv Type : <?print $jcrow[servtype]?>
</td>
</tr>
</table>
<hr>
<table border=0 width=95% >
<font size:10>
<th>Sno. <th>Part Code <th> Description <th>Quantity <th>Rate <th>Tax(13.5) <th>Cess(1%) 
<th>Serv Tx <th>Edu. Cess <th>Hr Edu Cess
<th>Total
<tr><td><b>Parts</td></tr>
<?
$jpres=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
$i=1;
$ratetot=0;
$gtot=0;
$taxtot=0;
$cesstot=0;
while($jprow=mysqli_fetch_array($jpres))
{
if($jprow[gtot]<=0)
{
 print "<script> alert('Invalid Entry Total')</script>";
 print "<h1>Error</h1>";
}
if($jprow[taxamt]<=0)
{
 print "<script> alert('Invalid Entry Tax')</script>";
 print "<h1>Error</h1>";
}
/*
if($jprow[cessamt]<=0)
{
 print "<script> alert('Invalid Entry Cess')</script>";
 print "<h1>Error</h1>";
}
*/
 print "<tr><td align=center>".$i++."</td><td>$jprow[2]</td><td>$jprow[3]</td>";
 print "<td align=right>$jprow[qty]</td><td align=right>$jprow[rate]</td>";
 print "<td align=right>$jprow[taxamt] </td><td align=right>$jprow[cessamt]</td>";
 print "<td></td><td></td><td></td>";
 print "<td align=right>$jprow[gtot]</td></tr>";
 $ratetot+=$jprow[rate];
 $gtot+=$jprow[gtot];
 $taxtot+=$jprow[taxamt];
 $txp+=$jprow[cessp];
$cesstot+=$jprow[cessamt];
$tot_g+=$jprow[gtot];
}
print "<tr><td colspan=10 align=right><b>Total Parts</td><td align=right><b>".putComa($tot_g)."</td></tr>";
?>
</table>
<table border=0 width=95% >
<tr><td><b>Service</td></tr>
<?
$jsres=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
$i=1;
while($jsrow=mysqli_fetch_array($jsres))
{
 print "<tr><td align=center>".$i++."</td><td>$jsrow[2]</td>";
 print "<td align=center>$jsrow[servamt]</td>";
$ss=$jsrow[servamt];
// print "<td>".(($jsrow[servamt]*12.5)/100)."</td>";
 print "<td></td>";
 $servtx=(($jsrow[servamt]*$jsrow[servtx])/100);
 print "<td></td><td align=right>".putcoma(($jsrow[servamt]*$jsrow[servtx])/100)."</td>";
 $edutx=(($servtx*$jsrow[edutx])/100);
 print "<td align=right>".(($servtx*$jsrow[edutx])/100)."</td>";
 $hredutx=(($servtx*$jsrow[hredutx])/100);
 print "<td></td>";
 print "<td align=right>".putcoma(($servtx*$jsrow[hredutx])/100)."</td>";
$tt=$ss+$servtx+$edutx+$hredutx;
 print "<td></td>";
 print "<td align=right>$tt</td></tr>";
 $ratetot+=$jsrow[servamt];
 $gtot+=$tt;
 //$taxtot+=(($jsrow[servamt]*$jsrow[servtx])/100);
 $txp+=($jsrow[edutx]+$jsrow[hredutx]);
 //$cesstot=($taxtot*$txp)/100;
 $totservtx+=$servtx;
 $totedutx+=$edutx;
 $tothredutx+=$hredutx;
 $gt_serv+=$tt;
}
print "<tr><td colspan=10 align=right><b>Total Service</td><td align=right><b>".putComa($gt_serv)."</td></tr>";

?>
<tr><td colspan=11><hr></td></tr>
<tr><td colspan=4 align=right><b>Total &nbsp;</td><td align=center><?
//print putcoma($ratetot)
?></td>
<td align=right><?print ($taxtot)?></td>
<td align=right><?print ($cesstot)?></td>
<td align=right><?print ($totservtx)?></td>
<td align=right><?print ($totedutx)?></td>
<td align=right><?print ($tothredutx)?></td>
</tr>
<tr>
<td align=right colspan=11>
<?
print putcoma($gtot);
$rnd=round($gtot);
$dif=round(($rnd-$gtot),2);
print "</td></tr><tr><td colspan=10 align=right>Round Off </td><td align=right>".putComa($dif);

?></td></tr>
<tr><td colspan=10 align=right><b>Grand Total</td><td align=right><b><?print putComa(round($gtot))?></td></tr>
<tr><td colspan=11><hr></td></tr>
</table>
<br>
Amount in words: <?print word(round($gtot))?>
<p align=right>for PSN AUTOMOBILES PVT. LTD.,
<BR><BR><BR><BR><BR><BR>
Authorised signatory
</P>
Job Card No: JC-<?print $jcno?><br>
TAX-14.50%, CESS1%, SERVICE TAX-10%, ED.CESS-2% and HR.SEC CESS-1 %
 
