<? session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../ind.php'; </script>";
 return;
}
include("../opendb.php");
$sql="select a.code,a.item_code,b.itname,a.taxp,a.uni_amt,a.gross,a.disc,a.net,a.taxamt,a.gtot, a.chasis from item_purchase a,itemmaster b where a.item_code=b.code and a.brcode='$brcode' and (a.qty-a.sale_count)>0 group by a.chasis order by b.itname";

$result=mysqli_query($db,$sql)or die("Retrieve err:".mysqli_error());
?>
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
tr{background-color:c1d7bb}
.mnu{margin-left:5}
</style>
<script>
var taxrate=[];
var unit=[];
var item_code1=[];
var taxamt=[];
var net=[];
function setval()
{
  var x=document.f1.item.selectedIndex; 
  var qty=document.f1.qty.value;
  if(x>0)
   {
     document.f1.taxp.value=taxrate[x];
     document.f1.uni_amt.value=unit[x];
     document.f1.gross.value=unit[x];
     document.f1.taxamt.value=taxamt[x];
     document.f1.gtot.value=unit[x];

     document.f1.net.value=net[x];
     document.f1.item_code.value=item_code1[x];
   }
  else
   {
     document.f1.uni_amt.value='';
     document.f1.item_code.value='';
     document.f1.taxp.value='';
   }
}
function clrval()
{
     document.f1.uni_amt.value='';
     document.f1.item_code.value='';
     document.f1.taxp.value='';
}

function validate()
{
 var qty=document.f1.qty.value;
 var sub="true";
 if(qty.length<=0)
 {
   alert('Invalid Entry'); 
   sub="false";
 }
if(document.f1.gtot.value<=0)
 {
   alert('Invalid Grand Total'); 
   sub="false";
 }

 if(sub=="false")
  return false;
 else
  return true;
}
</script>
<BODY BGCOLOR='IVORY'>
<base target='main1'>
<center>
<b>SELECT ITEMS
<FORM name='f1' ACTION='inv_items.php' METHOD='POST' onSubmit='return validate()'>
<input type=hidden name='item_code'>
<table>
<tr> <td colspan=10 align=center>
Item <select name='item' onChange=setval()>
<option></option>
<?
$i=1;
 while($row=mysqli_fetch_row($result))
 {
  print "\n<option value='$row[0]-$row[2]'>$row[2]-$row[10]</option>";
  print "<script> taxrate[$i]='$row[3]'; </script>";
  print "<script> taxamt[$i]='$row[8]'; </script>";
  print "<script> net[$i]='$row[7]'; </script>";

  print "<script> unit[$i]='$row[4]'; </script>";
  print "\n<script> item_code1[$i]='$row[0]'; </script>";
  $i++;
 }

?>
</select>
</td></tr>
<tr>
  <th>Tax Rate <th><font color=red>Unit Price <th><font color=red> Qty  <th>Gross Value   <th><font color=red>Before Tax<th>Tax Amt. <th><font color=red>Grant Total  
</tr><tr>
<td>
 <input type=text name='taxp' size=5></td>
<td><input type=text name='uni_amt' size=12 onChange=calcgross() style={text-align:right}></td>
<td><input type=text size=4 name='qty' value='1' ></td>
<td><input type=text name='gross' size=12></td>
<td><input type=text name='net' size=10></td>
<td><input type=text name='taxamt' size=10></td>
<td><input type=text name='gtot' size=10></td>

</table>
</td></tr>
<tr><td align=center bgColor='lightsteelblue'><input name='submit' type=submit value='   ADD   '></td></tr>
</table>
</td></tr>
</table>
</form>
