<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
th{background-color:steelblue;color:white}
</style>
<center>
<h3>JOB CARD REPORT </H3>
<?
if($show)
{
include("../opendb.php");
include("../test.php");
 $dfrom=$y1.'-'.$m1.'-'.$d1;
 $dto=$y2.'-'.$m2.'-'.$d2;
$sql="select * from jobcard where brcode='$brcode' and (entrydate>='$dfrom' and entrydate<='$dto' or entrydate is null)";
$res=mysqli_query($db,$sql);
print "<table border=0 bgcolor=black cellspacing=1 cellpadding=1><th>No <th> JC No <th>Inv No <th>Date <th>Customer <th>MSNO <th>Engineer";
print "<th>Amount<br>Parts<th>VAT <th>Cess <th>Amount<br>Service<th>Serv Tx<th>Edu <th>HR Edu <th>Total <br>Accounted<th>Not Accounted";
$i=1;
while($row=mysqli_fetch_array($res))
{
$rowtot=0;
$price=0;
$vatamt=0;
$cessamt=0;
$pr=0;
$servtx=0;
$edu=0;
$hredu=0;
$servamt=0;

 if($row[jvno]>0)
 {
	 print "<tr bgcolor='ivory'>";
}
 else
{
	 print "<tr bgcolor='pink'>";
}  
$sq="select sum(dramt) from journal2 where jvno='$row[jvno]' and no='$row[jcno]' and brcode='$brcode'";

   $amtres=mysqli_query($db,$sq);
    $amtrow=mysqli_fetch_row($amtres);
    $amt=$amtrow[0];
  $jtxres=mysqli_query($db,"select sum(amt),sum(taxamt),sum(cessamt) from jcardparts where jcno='$row[jcno]' and brcode='$brcode'")or die(mysqli_error());
  $jtxrow=mysqli_fetch_array($jtxres);
   $price=$jtxrow[0];
   $vatamt=$jtxrow[1];
   $cessamt=$jtxrow[2];
$sq="select sum(servamt),sum((servamt*servtx)/100),sum((servamt*servtx)/100)*edutx/100,sum((servamt*servtx)/100)*hredutx/100 from jcardserv where jcno='$row[jcno]' and brcode='$brcode'";

  $jstxres=mysqli_query($db,$sq)or die('err'.mysqli_error());
  $jstxrow=mysqli_fetch_array($jstxres);

  $pr=$price+$jstxrow[0]; 
  $servtx=$jstxrow[1];
  $edu=$jstxrow[2];
  $hredu=$jstxrow[3];
  $servamt=$jstxrow[0];


  $totserve+=$servamt;
  $tpr+=$price; 
  $tvat+=$vatamt;
  $tcess+=$cessamt;

  $tservtx+=$jstxrow[1];
  $tedu+=$jstxrow[2];
  $thredu+=$jstxrow[3];

// }
/* else
 {
	 print "<tr bgcolor='pink'>";
   	 $amt=0;
  $pr=0; 
  $price=0;
  $servtx=0;
  $edu=0;
  $hredu=0;
   $vatamt=0;
   $cessamt=0;
   $servamt=0;

 }*/
 print "\n<td>".$i++."</td><td>$row[jcno]</td><td  align=right>$row[invno]</td><td>".datetohtml($row[date])."</td><td>$row[cname]</td>";
 print "<td>$row[msno]</td><td>$row[engineer]</td>";
 print "<td align=right>".putComa($price)."</td>";

 print "<td align=right>".putComa($vatamt)."</td>";
 print "<td align=right>".putComa($cessamt)."</td>";
 print "<td align=right>".putComa($servamt)."</td>";

 printf("<td align=right>%.2f</td>",$servtx);
 printf("<td align=right>%.2f</td>",$edu);

// print "<td align=right>".putComa($edu)."</td>";
 printf("<td align=right>%.2f</td>",putComa($hredu));

// print "<td align=right>".putComa($hredu)."</td>";
 print "<td align=right>".putComa($amt)."</td>";
if($row[jvno]<=0)
 {
$rowtot=($price+$vatamt+$cessamt+$servtx+$edu+$hredu+$servamt);
  print "<td align=right>".putComa($rowtot)."</td>";
  $trowtot+=$rowtot;
 }
else
  print "<td></td>";
  $tamt+=$amt;
 print "</tr>";
}
print "\n<tr bgcolor='white'><td colspan=7 align=right><b>Total</td>";
 print "<td>".putComa($tpr)."</td>";
 print "<td>".putComa($tvat)."</td>";
 printf("<td>%.2f</td>",$tcess);
// sprintf ("<td>%.2f</td>",$tservtx);
   //$tservtx=number_format($tservtx, 2, '.', '');
 print "<td>".putComa($totserve)."</td>";


 printf("<td align=right>%.2f</td>",$tservtx);

  print "<td>".putComa($tedu)."</td>";
 print "<td>".putComa($thredu)."</td>";
 print "<td>".putComa($tamt)."</td>";
print "<td align=right>".putComa($trowtot)."</tr>";
return;
}
?>
</table>

<form action='<?Print $PHP_SELF?>' method='post'>
<table cellspacing=1 cellpadding=1 bgcolor='steelblue'>
<tr><td bgcolor='white' align=center>
<table class=noprint>
<tr><td>Date from </td><td>dd <input type=text name='d1' size=2 value='<?print date("d")?>'>
mm <input type=text name='m1' size=2 value='<?print date("m")?>'>
yy <input type=text name='y1' size=4 value='<?print date("Y")?>'></td></tr>

<tr><td align=right>to </td><td>dd <input type=text name='d2' size=2 value='<?print date("d")?>'>
mm <input type=text name='m2' size=2 value='<?print date("m")?>'>
yy <input type=text name='y2' size=4 value='<?print date("Y")?>'>
</td></tr>

<tr><td colspan=2 align=center bgcolor='lightsteelblue'><input type=submit value='Show' name='show'></td></tr>
</table>
</td></tr>
</table>
</form>

