<?
session_start();

include("../../opendb.php");
include("../../test.php");
?>
<link rel="stylesheet" href="../../style.css" type="text/css" />
<style>
	th{background-color:#6595A1;color:white}
.right{text-align:right}
</style>
<script>
 function valid()
 {
   if(confirm('Do you want to save?'))
    return true;
   else
    return false;
 }
function chkqty(x)
{
 var psnqtyele=x;
 var recqtyele='recqty'+x;
 pval=parseFloat(document.getElementById(psnqtyele).value);
 recval=parseFloat(document.getElementById(recqtyele).value);
 if(recval>pval)
  {
    alert('Invalid Quantity');
	document.getElementById(recqtyele).value=0;
  }
}
</script>

<center>
<TABLE WIDTH=100%>
<TR><TD BGCOLOR='#71A7B4'><CENTER><h3>WARRANTY STATUS REPORT</H3>
</TD></TR>
</TABLE>

<?
$brres=mysqli_query($db,"select distinct brcode from warsparetransout order by brcode")or die(mysqli_error());
while($brrow=mysqli_fetch_array($brres))
{
 print "<fieldset><legend>WARRANTY STATUS - ".getbrname($brrow[brcode])."</legend>";

$res=mysqli_query($db,"select distinct warno,cust,msno,brcode,cssno,notifno,sum(psnqty) from warsparetransout where  brcode='$brrow[brcode]' and psnqty>0 group by warno,brcode")or die(mysqli_error());
if(mysqli_num_rows($res)>0)
{
$i=1;
print "<table cellspacing=1 cellpadding=3 bgcolor='gray'>";
print "<th>No <th>Customer <th>Part Code<th>Qty<th>Price<th>Amount<th>STO No <th>War NO <th>Acc";
print "<th>Amount";
while($ro=mysqli_fetch_array($res))
{
?>
<?
 $res1=mysqli_query($db,"select * from warsparetransout where warno='$ro[0]' and brcode='$brrow[brcode]'");

  while($row=mysqli_fetch_array($res1))
 {
?>
<tr bgcolor='white'><td><?print $i++?></td><td><?print $ro[cust]?></td>
<?
$sq="select psnqty,sum(recqty) from sparetrinwarph where warno='$ro[0]' and frombr='$brrow[brcode]' and partcode='$row[1]' group by partcode";

$inres=mysqli_query($db,$sq);//or die('Err:'.mysqli_error());
$inrow=mysqli_fetch_array($inres);

  if($inrow[1]<$inrow[0]||mysqli_num_rows($inres)<=0)
  {
   print "\n<td>$row[1] </td>";
  print "\n<td align=right>$row[psnqty]</td>";
$tq+=$row[psnqty];
  $reqres=mysqli_query($db,"select sum(recqty) from sparetrinwarph where warno='$ro[0]' and partcode='$row[partcode]'")or die(mysqli_error());
   $reqrow=mysqli_fetch_row($reqres);
   if($reqrow[0]>0)
     $acc=$reqrow[0];
   else
     $acc=0;
 $tacc+=$acc;
print "<td align=right>$row[price]</td>";
$amt=($row[price]*$row[psnqty]);
$tamt+=$amt;
print "<td align=right>".putComa($amt)."</td>";
   print "<td><center>$row[stono]</td>";
   print "<td><center>$ro[0]</td>";

 if($acc<$row[psnqty])
print "<td align=CENTER BGCOLOR='pink'><b>$acc</td>";
else if($acc>$row[psnqty])
print "<td align=CENTER BGCOLOR='red'><b>$acc</td>";
else
print "<td align=CENTER BGCOLOR='yellow'><b>$acc</td>";
$amt2=($row[price]*$acc);
$tamt2+=$amt2;
print "<td align=right>".putComa($amt2)."</td>";

 }// end if
}

}
print "<tr bgcolor='silver'><td colspan=3 align=center><b>Total</td>";
print "<td align=right>".putComa($tq)."</td><td></td>";
print "<td align=right>".putComa($tamt)."</td>";
print "<td></td><td></td><td align=right>$tacc</td><td align=right>".putComa($tamt2)."</td></tr></table>";
}
print "</fieldset><br>";
}
?>

