<?
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 PENDING FROM TELCON</H3>
</TD></TR>
</TABLE>
<?
$brres11=mysqli_query($db,"select brname,brcode from branch order by brname");
while($brrow=mysqli_fetch_array($brres11))
{
 $tprice=0;
print "<fieldset><legend>$brrow[0]</legend>";
$s="select distinct warno,cust,msno,brcode,cssno,notifno,sum(psnqty),stono from warsparetransout where tobr='ser516' and brcode='$brrow[1]' and psnqty>0 group by warno,brcode";

$res=mysqli_query($db,$s)or die(mysqli_error());
print "<table border=1 bgcolor='ivory'>";
print "<th>War No <th>Customer <th>MSNO <th>CSS No <th>Notif<th>Sto No<th>Part Code <th>Part Name";
print "<th>Qty<th>Date <th>Price <th>Amount";
if(mysqli_num_rows($res)>0)
{
while($ro=mysqli_fetch_array($res))
{
  $brres=mysqli_query($db,"select brname from branch where brcode='$ro[brcode]'");
  $brrow=mysqli_fetch_array($brres);
$s="select * from warsparetransout where warno='$ro[0]' and brcode='$ro[brcode]'";

 $res1=mysqli_query($db,$s);
$i=1;
  while($row=mysqli_fetch_array($res1))
 {
$sq="select psnqty,sum(recqty) from sparetrinwarph where warno='$ro[0]' and frombr='$brrow[0]' 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 "<tr><td>$ro[0]</td><td>$row[cust]</td><td>$ro[msno]</td>";
print "<td>$ro[cssno]</td><td>$ro[notifno]</td><td>$ro[stono]</td>";
print"<td>$row[1]</td><td>$row[2]</td><td>$row[psnqty]</td><td>".
datetohtml($row[date])."</td><td align=right>$row[price]</td>";
$amt=($row[psnqty]*$row[price]);
print "<td align=right>".putcoma($amt)."</td></tr>";
$tprice+=$amt;
 }// end if
}
  //print "<tr><th colspan=12> <input type=submit value='Save this warranty data'></th>";

}
print "<tr><td colspan=11 align=right><b>Total </td><td align=right>".putComa($tprice)."</td></tr>";
$tq+=$tprice;

}
print " </table></fieldset>";
}
print "<h2>Grand Total :".putComa($tq)."</h2>";
print "<table border=1>";
$opres=mysqli_query($db,"select * from spareopstock where brcode='ser516'");
while($row=mysqli_fetch_array($opres))
{
 print "<tr><td>$row[itemcode]</td><td>$row[itemname]</td><td>$row[qty]</td>";
 $prres=mysqli_query($db,"select lstprice from spareprmast where partcode='$row[itemcode]' order by effectfrom limit 1");
 $prrow=mysqli_fetch_array($prres);
 $amt=($prrow[0]*$row[qty]);
 print "<td align=right>$amt</td>";
 $tamt+=$amt;
}
print "<tr><td colspan=3>Total</td><td align=right>".putComa($tamt)."</td></tr>";
?>


