<?
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>PHYSICAL STOCK TRANSFER IN (WARRANTY)</H3>
</TD></TR>
</TABLE>
<form action='<?print $PHP_SELF?>'>
<table>
<tr><td>Select Branch:</td><td>
<select name='br'>
<?
$brr=mysqli_query($db,"select brname,brcode from branch order by brname");
while($br1=mysqli_fetch_array($brr))
{
 print "<option value='$br1[1]'>$br1[0]</option>";
}
?>
</select></td>
<td><input type=submit value='Show' name='show'></td></tr>
</table>
</form>
<HR>
<?
if($show)
{
print "<script> window.open('prnsparetrinwarph.php?br=$br'); </script>";
}
$res=mysqli_query($db,"select distinct warno,cust,msno,brcode,cssno,notifno,sum(psnqty) from warsparetransout where tobr='$brcode' and brcode='$br' and psnqty>0 group by warno,brcode");
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);
?>
<fieldset width=110%> <legend> Warranty No : <b><?print $ro[0]?> </b>
Customer : <font color=blue><?print $ro[cust]."</font> MSNO :<font color=blue>".$ro[msno]."</font> From Branch: <font color=red>$brrow[0]</font> [<a href='edsptrinwar.php?warno1=$ro[0]&br=$ro[brcode]' target='ed' style='color:blue'>Edit/View More</a>]" ?></legend>
<form action='svsparetrinwarph.php' onSubmit="return valid()">
<input type=hidden name='warno' value='<?print $ro[0]?>'> 
<input type=hidden name='frombr' value='<?print $brrow[0]?>'> 
<input type=hidden name='msno' value='<?print $ro[msno]?>'> 
<input type=hidden name='cust' value='<?print $ro[cust]?>'>

<table border=0 width=100%>
<tr><td colspan=5 bgcolor=yellow>Entrydate dd <input type=text name=ed size=2 value='<?print date('d')?>'>
mm <input type=text name=em size=2 value='<?print date('m')?>'>
yy <input type=text name=ey size=4 value='<?print date('Y')?>'>
</td></tr>
<tr><td colspan=2>CSS No </td><td><?print $ro[cssno]?></td></tr>
<tr><td colspan=2>Notif No </td><td><?print $ro[notifno]?></td></tr>
<th>No <th>Part Code <th>Part Name <th>PSN Qty <th>Tel Qty <th>Rec Qty<th>Acc Qty<th>Price <th> Date
<th><font color='dark brown'><b>*</b></font> STO No.
<th><font color='dark brown'><b>*</b></font> Preq No. <th>Inv No. <th>Serv Ord<th>Inv Date <th>Status

<?
 $res1=mysqli_query($db,"select * from warsparetransout where warno='$ro[0]' and brcode='$ro[brcode]'");
$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]' and cust='$row[cust]' and msno='$row[msno]' group by partcode";

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

  if($inrow[1]<$inrow[0]||mysqli_num_rows($inres)<=0)
  {
   print "\n<tr><td>".$i++."</td><td><input type=text name='partcode[]' value='$row[1]' size=10>";
  print "</td><td><input type=text name='partname[]' value='$row[2]'></td>";
  print "\n<td align=right><input type=text readonly name='psnqty[]' id='$i' value='$row[psnqty]' size=4></td>";
   print "<td align=right>$row[telcqty]</td>";
print "\n<td align=right><input type=text name='recqty[]' id='recqty$i' value='0' size=4 onChange=chkqty($i);></td>";

  $reqres=mysqli_query($db,"select sum(recqty) from sparetrinwarph where warno='$ro[0]' and partcode='$row[partcode]' and frombr='$brrow[0]' and cust='$row[cust]' and msno='$row[msno]'")or die(mysqli_error($db));
   $reqrow=mysqli_fetch_row($reqres);
   if($reqrow[0]>0)
     $acc=$reqrow[0];
   else
     $acc=0;
print "<td align=CENTER BGCOLOR='YELLOW'><b>$acc</td>";

 
print "<td align=right>$row[price]</td>";

   print "<td align=right>".datetohtml($row[date])."</td>";

   print "<td><center><input type=text name='stono[]' size=10 title='Enter for closing only' style={background-color:pink} value='$row[stono]'></td>";
   print "<td><center><input type=text name='preqno[]' size=10 value='$row[preqno]'></td>";
   print "<td><center><input type=text name='invno[]' size=10 value='$row[invno]'></td>";
   print "<td><center><input type=text name='servord[]' size=10 value='$row[servord]'></td>";

   print "<td><center>dmy<input type=text name='invdate[]' size=10 value='".date("d-m-Y")."'</td>";
   print "<td><center><input type=text name='stat[]' size=10 value='$row[stat]'></td>";
 }// end if
}

  print "<tr><th colspan=12> <input type=submit value='Save this warranty data'></th>";

print "</table></form> </fieldset><br>";
}
}
?>

