<?
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>
<?
  $brres11=mysqli_query($db,"select brname from branch where brcode='$br'");
  $brrow=mysqli_fetch_array($brres11);

?>
<TABLE WIDTH=100%>
<TR><TD BGCOLOR='#71A7B4'><CENTER>
<h3>PHYSICAL STOCK TRANSFER IN (WARRANTY)- <?print $brrow[0];?></H3>
</TD></TR>
</TABLE>
<?
$res=mysqli_query($db,"select distinct warno,cust,msno,brcode,cssno,notifno,sum(psnqty) from warsparetransouto where tobr='$brcode' and brcode='$br' and psnqty>0 group by warno,brcode");
print "<table border=1 bgcolor='ivory'>";
print "<th>War No <th>Customer <th>MSNO <th>CSS No <th>Notif<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);

 $res1=mysqli_query($db,"select * from warsparetransouto where warno='$ro[0]' and brcode='$ro[brcode]'");
$i=1;
  while($row=mysqli_fetch_array($res1))
 {
$sq="select psnqty,sum(recqty) from sparetrinwarpho 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>";
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=10 align=right><b>Total </td><td align=right>".putComa($tprice)."</td></tr>";

}
?>

