<?
session_start();
//if(strlen($brcode)<=0)
//{
 //print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 //return;
//}
include ("../opendb.php");
include ("../test_cummins.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);
if($jcrow[invno]>0)
{
?>
<title>ZF</title>
    <script type="text/javascript" src="../scripts/jquery-latest.js"></script>
	
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<body>
<?php //include('top.php'); ?>

<br><br><br>

<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);
?>
<TR><TD COLSPAN=3 ALIGN=CENTER ><BR>
<?print "PSN AUTOMOTIVE MARKETING PVT LTD" ?></u>
<br>CIN U50300KL1996PTC010841
<TR><TD COLSPAN=2 ALIGN=CENTER >
<tr><td colspan=10 align=center>
<font size=2>
<?
PRINT $brrow[braddr].' ,'.$brrow[brcity].' <br>Tin: '.$brrow[tin] .',<u>Phone: '.$brrow[brphone];
?>
<br>
</u>
<tr><td colspan=3>Reg. Off.:<br>35/189, NH, Palarivattom, Kochi-682025
<br>Ph:0484 2343754 Email :psnsales@eth.net Website:www.psn.in
</td></tr>
</font>
<?
if($jcrow[invtype]=='-')
 print " PENDING ";
?>
<tr><td colspan=3 align=CENTER>
JOB CARD RETAIL INVOICE 
<br>Form <?print strtoupper($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>
<td align=center width=40%>Invoice NO: <b>SER<?print $jcrow[invno]?></b><br>
Date: <b><?print datetohtml($jcrow[entrydate])?></b><br>
</td>
  <td>MSNO : <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>
<?
if($brcode=='BAN682' ||$brcode=='THU558'|| $brcode=='MYS543'|| $brcode=='HYD664'||$brcode =='DHA024')
{
?>
<th>Sno. <th>Part Code <th> Description <th>Quantity <th>Rate <th>Tax(5.5%) <th>Cess(0) 
<th>Serv Tx <th>Edu. Cess <th>Hr Edu Cess
<th>Total
<?
}
else
{
?>
<th>Sno. <th>Part Code <th> Description <th>Quantity <th>Rate <th>Total <th>Disc Amt <th>Before Tax <th>Tax(14.5%)<th>Net 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;
$rate_qty_tot=0;
$disc_tot = 0;
$bef_tax = 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>";
	}
	 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><td align=right>".$jprow[rate]*$jprow[qty]."</td>";
	$mdisc_amt = round($jprow[rate]*$jprow[qty]*$jprow[disc]/100,2);
	$mbef_tax = round(($jprow[rate]*$jprow[qty])-$mdisc_amt,2);
	 print "<td align=right>$mdisc_amt</td><td align=right>$mbef_tax</td>";
	 print "<td align=right>$jprow[taxamt] </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];
	$rate_qty_tot=$rate_qty_tot+($jprow[rate]*$jprow[qty]);
	$disc_tot = $disc_tot + $mdisc_amt;
	$bef_tax = $bef_tax + $mbef_tax;
}
print "<tr><td colspan=5 align=right><b>Total Parts</td><td align=right><b>".$rate_qty_tot."</td><td align=right><b>".$disc_tot."</td><td align=right><b>".$bef_tax."</td><td align=right><b>".putComa($taxtot)."</td><td align=right colspan=4><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=round(($jsrow[servamt]*$jsrow[servtx])/100,2);
	 print "<td></td><td align=right>".putcoma($servtx)."</td>";
	 $edutx=round(($servtx*$jsrow[edutx])/100,2);
	 print "<td align=right>".putcoma($edutx)."</td>";
	 $hredutx=round(($servtx*$jsrow[hredutx])/100,2);
	 print "<td></td>";
	 print "<td align=right>".putcoma($hredutx)."</td>";
	$tt=$ss+$servtx+$edutx+$hredutx;
	 print "<td></td>";
	 print "<td align=right>".putcoma(($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=5 align=right><b>Total Service</td><td align=right><b>".putComa(($totservtx))."</td><td align=right colspan=5><b>".putComa(($gt_serv))."</td></tr>";

?>
<tr><td colspan=11><hr></td></tr>

</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>
<?
if($jcrow[invno]>0)
{
?>
Amount in words: <?print word(round($gtot))?>
<p align=right>for PSN AUTOMOTIVE MARKETING PVT. LTD.,
<BR><BR><BR><BR><BR><BR>
Authorised signatory


</P>
Job Card No: JC-<?print $jcno?><br>
Customer Signature<br>
<?
}?>
 
