<html>
<head>
<title>Add Stock</title>
</head>
<body style="background-color: #ffffff;background-image:url(rail.jpg);background-repeat: repeat-y">
<center>
<?php include('link.php');?>
</center>
<center><h1><u>Admin In Stock</u></h1>
<a href="http://www.wauhaha.com/karaoke/kinstock.php">Back</a></center>


<?php


$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
mysql_selectDB("wauhaha_karaoke",$login);
$time_offset ="240"; 
$time_a = ($time_offset * 120);
$time = date("Y-m-d");
$po = $_POST['po'];
$inv= $_POST['inv'];
$c = $_POST['c'];

$result4 = mysql_query("select PoID from kporder where PoID='$po'");
$w = mysql_num_rows($result4);
for($i=1;$i<=$c;$i++){
$po1 = $_POST['po'.$i];
$result6 = mysql_query("select PoID from kporder where PoID='$po1'");
$e = mysql_num_rows($result6);
break;
}
$g =$w + $e;

$result = mysql_query("Select * from kporder where PoID='$po' OR PoID='$po1'");
$result2 = mysql_query("Select * from kporder where PoID='$po' ");
$row=mysql_fetch_array($result2);
$PoNum = $row['PoNum'];
$SupName = $row['SupName'];
$result1 = mysql_query("Select * from ksupplier where SupName='$SupName' ");
$row1=mysql_fetch_array($result1);
$a = 0;

echo "<form method=post action=kinstock1.php>

<table align=center style='font-size:14pt;font-family:verdana'>

<tr>
	<td align=right>Inv ID:</td>
	<td>&nbsp; $inv <input  type=hidden name=inv value=$inv><input type=hidden name=g value=$g></td>
</tr>
<tr>
	<td align=right>Supplier Company:</td>
	<td>&nbsp; $SupName </td>
</tr>
<tr>
	<td align=right>Date:</td>
	<td>&nbsp; $time</td>
</tr>
</table>


<table align=center>
	<tr>
		<th width=100 align=center bgcolor=lightblue>PO No</th>
		<th width=100 align=center bgcolor=lightblue>Product Name</th>
		<th width=100 align=center bgcolor=lightblue>Order Quantity</th>
		<th width=100 align=center bgcolor=lightblue>Buy Quantity</th>
		<th width=100 align=center bgcolor=lightblue>Price</th>
		<th width=100 align=center bgcolor=lightblue>Sub Total</th>
		
		

		
		
	</tr>";
	

while($row=mysql_fetch_array($result)){


echo "<tr>
		<td align=center>".$row['PoID']." <input type=hidden name=po$a value=".$row['PoID']." ></td>
		<td align=center>".$row['ProName']." <input type=hidden name=p$a value=".$row['ProName']."></td>
		<td align=center>".$row['ProRQuan']."</td>
		<td align=center><input type=text name=q$a value='' size=5 onchange='multiply(q$a.value,pr$a.value,t$a,total,t$a.value,total.value,oldquantity$a,oldquantity$a.value)'></td>
		<td align=center><input type=text name=pr$a value=".$row['price']." readonly size=5 onchange='multiply(q$a.value,pr$a.value,t$a,total,t$a.value,total.value,oldquantity$a,oldquantity$a.value)'></td>
		<td align=center>RM<input type=text name=t$a value='' size=5><input type='hidden' id=oldquantity$a name=oldquantity$a value=0></td>


</tr>";


$a ++;
}	
	

	
	
echo "
<tr>
	<td bordercolor=white></td>
	<td></td>
	<td></td>
	<td></td>
	<td align=right>Total</td>
	<td align=center>RM<input type=text name=total value='' readonly size=5></td>
</tr>
<tr>
	<td colspan=5 align=center><input type=submit value=Add></td>
</tr>
</table>";
?>
<script language="javascript" type="text/javascript">
	function multiply(q,p,s,t,l,v,h,x){
	
	var c = s;
	c.value=((q*p).toFixed(2));
	
	var d = t;
	d.value = ((v-l+(q*p)).toFixed(2));
	
	var e = y;
	e.value = parseInt(a)+parseInt(q)-parseInt(x);
	
	var f = h;
	f.value = q;
	}
	</script>




