<?
session_start();
$brcode = $_SESSION['brcode'];
include("../opendb.php");
include("../test.php");
$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
$kar=mysqli_fetch_array($ker);
$ordres=mysqli_query($db,"select max(orderno) from purorder_spare where brcode='$brcode'");
$ordrow=mysqli_fetch_row($ordres);
$ordnumber=$ordrow[0]+1;

?>

<link rel="stylesheet" href="../style.css" type="text/css" />
<script>
var pna=[];
var hand=[];
var price=[];
var disc=[];
function getname()
{
 if(document.f1.partcode.selectedIndex<=0)
 {
 document.f1.prtname.value="";
 document.f1.price.value="";
 //document.f1.discount.value="";
 document.f1.hand.value="";
 }
 else{
 //document.f1.prtname.value=pna[document.f1.partcode.selectedIndex];
 //document.f1.price.value=price[document.f1.partcode.selectedIndex];
 //document.f1.discount.value=disc[document.f1.partcode.selectedIndex];
 //document.f1.hand.value=hand[document.f1.partcode.selectedIndex];

var act=parseFloat(document.f1.price.value)*parseFloat(document.f1.qty.value);
 var hnd=parseFloat(act)*document.f1.hand.value/100;

 var act1=act*parseFloat(document.f1.discount.value)/100;

 document.f1.aprice.value=parseFloat(act+hnd-act1).toFixed(2);
 act=document.f1.aprice.value;

 var act2=parseFloat(document.f1.aprice.value);
  var cst=parseFloat(act2)*document.f1.cst.value/100;
  var gtot=parseFloat(act2+cst).toFixed(2);
  document.f1.tot.value=gtot;
 }
}
function calcamt()
{
var act=parseFloat(document.f1.price.value)*parseFloat(document.f1.qty.value);
 var hnd=parseFloat(act)*document.f1.hand.value/100;

 var act1=act*parseFloat(document.f1.discount.value)/100;

 document.f1.aprice.value=parseFloat(act+hnd-act1).toFixed(2);
 act=document.f1.aprice.value;

 var act2=parseFloat(document.f1.aprice.value);
  var cst=parseFloat(act2)*document.f1.cst.value/100;
  var gtot=parseFloat(act2+cst).toFixed(2);
  document.f1.tot.value=gtot;
}
function valid()
{
 if(document.f1.partcode.selectedIndex<=0)
 {
  alert('Invalid Item code');
  return false;
 }
/*
var x=document.getElementById("mselect")
 document.f1.partcode1.value=x.options[x.selectedIndex].text
x.remove(x.selectedIndex)
*/
}
</script>
<style>

#tbl	{
      margin-top:70px;
    	}

.cont
	{

	background:url(images/yellow_back2.jpg) repeat;
  	width: 100%;position: absolute ;
	height:100% auto;
    	/* Optional - just for DIV)*/
    	//border: solid 1px #000000;
	-moz-box-shadow: 0px 5px 5px #888;
	-webkit-box-shadow: 0px 5px 5px #888;
	box-shadow: 0px 5px 10px #888;
    
	}
body
	{
	background: url(images/yellow_back2.jpg) repeat;
	}
#txt
	 {
	font-size:13px;
	}

	#popup td 
	{
	border-bottom:1px solid #CCCCCC;border-left:1px solid #CCCCCC;
	}
.del 	{
    	border: none;
   	background: url('img/delete.png') no-repeat ;
	padding: 0px 25px 20px 0;
    
	}
.edit {
   	 border: none;
    	background: url('img/edit.gif') no-repeat ;
	padding: 0px 25px 12px 0;
    
	}
.tb
	{
	-moz-box-shadow:    inset 1px 10px 10px grey;
  	 -webkit-box-shadow: inset 1px 10px 10px grey;
   	box-shadow:         inset 1px 10px 10px grey;
	}
.tb1
	{
	-moz-box-shadow:    inset 1px 10px 10px #565155;
   	-webkit-box-shadow: inset 1px 10px 10px #565155;
  	 box-shadow:         inset 1px 10px 10px #565155;
	width:100%;
	height:50px;
	font-size:11px;
	background:#2C2C30;
	}
  .tb1 a
	 {
  	text-decoration: none;
  	color:black;
	font-family: Arial, Helvetica;
    	}
</style>
<title>ZF</title>
    <script type="text/javascript" src="../scripts/jquery-latest.js"></script>
	<link type="text/css" href="../includes/style.css" rel="stylesheet" />
<link href="../css/form.css" type="text/css" rel="stylesheet" media="screen"  />
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
<body background="../back_ground.jpg">

<?php include('top.php'); ?>
<?php include('logo1.php'); ?>
<center>
<form name='f1' action='purtempnew.php' method= 'post' onSubmit='return valid()'>

<input type=hidden name='partcode1'>
<table class='form'>
<th colspan=10><h3><font color="#006">ITEM PURCHASE ORDER (<?print $ordnumber?>)</font></h3></th>
<tr>
<td>Part Code</td><td><select name='partcode' id='mselect' onChange=getname();><option></option>
<?
$i=1;
$re=mysqli_query($db,"select * from partmaster order by partcode");
while($row=mysqli_fetch_array($re))
{
 print "<option value='$row[0]'>$row[0]</option>";
// print "\n<script> pna[$i]='$row[partname]'; hand[$i]='$row[hand_charge]';</script>";
/*
if($kar[0]=='Kerala') 
{  
$disres=mysqli_query($db,"select lstprice,discount from spareprmast where partcode='$row[0]' and brcode='ERA153' order by effectfrom desc");
$disrow=mysqli_fetch_array($disres);
}
else
{
$disres=mysqli_query($db,"select lstprice,discount from spareprmast where partcode='$row[0]' and brcode='BAN682' order by effectfrom desc");
$disrow=mysqli_fetch_array($disres);
}


 print "<script>price[$i]='$disrow[0]'; </script>";
 //disc[$i]='$disrow[1]'; </script>";
 $i++;
*/
}
?>
</select></td><td>Part Name </td><td COLSPAN=3><input type=text readonly  name='prtname' size=30></td></tr>
<tr><td>Qty</td><td><input type=text name='qty' size=3 value='1' onChange='calcamt()'></td>
  <td>Price </td><td><input type=text  name='price' size=10></td>
  <td>Disc% </td><td><select name='discount' onChange='calcamt()'> 
    <option value='19.49'>19.49</option>
    <option value='14.63'>14.63</option>
    <option value='0'>0</option>
</select>
Act Price <input type=text name='aprice' size=10>
</td></tr>
<tr><td>Hand Chrg%</td><td><input type=text name='hand' size=6 value='2.5'></td>
<?
 $cstres=mysqli_query($db,"select tax from taxmaster where type='cst'");
  $cstrow=mysqli_fetch_row($cstres);
?>
<td>CST%</td><td><input type=text name='cst'  size=6 value='<?print $cstrow[0]?>'></td>
<td>Total</td><td><input type=text name='tot'   size=16></td></tr>
<tr><td colspan=6 align=center bgcolor='steelblue'><input type=submit value='Add' name='add'></td></tr>
</table>
</form>

