<?
session_start();
include("test.php");
include("opendb.php");
//include("includes/function.php");

$tbl2="stocksummary1".$brcode.$user;
$qry= mysqli_query($db,"select * from $tbl2 where  partname='$part'   and brcode='$brcode'");
$qry1= mysqli_query($db,"select * from $tbl2 where  partname='$part1'   and brcode='$brcode'");
$row=mysqli_fetch_array($qry);
$row1=mysqli_fetch_array($qry1);
if($row[5]=='spares')
 {

 	if($row[2]<$qty)
	{
	?>
	<input type='hidden' name='totalamt' id='totalamt' value='0'>
	<input type='hidden' name='untprice' id='untprice' value='0'>
	<input type='hidden' name='alertmsg' id='alertmsg' value='0'>
       <input type='hidden' name='typ_val' id='typ_val' value=''>
	
	<?
	}
	else
	{
	$tot_qty=$qty+$preqty;
	if($row[2]<$tot_qty)
 	 {
 	?>
	<input type='hidden' name='totalamt' id='totalamt' value='0'>
	<input type='hidden' name='untprice' id='untprice' value='0'>
	<input type='hidden' name='alertmsg' id='alertmsg' value='0'>
      <input type='hidden' name='typ_val' id='typ_val' value=''>
	
	<?
  	 }
 	 else
   	 {

	if($qty>=5)
	$upr=$row1[3];
	else
	$upr=$row1[4];
	$tot=($upr*$qty)-$dis;

	?>
	<input type='hidden' name='totalamt' id='totalamt' value='<? print $tot;?>'>
	<input type='hidden' name='untprice' id='untprice' value='<? print $upr;?>'>
	<input type='hidden' name='alertmsg' id='alertmsg' value='1'>
       <input type='hidden' name='typ_val' id='typ_val' value='<? echo $row[5];?>'>
	<?
	}
	}
 }
else
 {
       if($qty>=5)
	$upr=$row1[3];
	else
	$upr=$row1[4];
	$tot=($upr*$qty)-$dis;;

	?>
	<input type='hidden' name='totalamt' id='totalamt' value='<? print $tot;?>'>
	<input type='hidden' name='untprice' id='untprice' value='<? print $upr;?>'>
	<input type='hidden' name='alertmsg' id='alertmsg' value='1'>
       <input type='hidden' name='typ_val' id='typ_val' value='<? echo $row[5];?>'>
	<?



  }

	?>