<?php
$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
mysql_selectDB("wauhaha_karaoke",$login);


$ProID = $_GET['ProID'];
$TID = $_POST['TID'];
$AddQuan1 = $_POST['AddQuan1'];
$TQuan1 = $_POST['TQuan1'];
$UPrice1 =$_POST['UPrice1'];
$TPrice1 =$_POST['TPrice1'];
$time= $_POST['time'];

$result=mysql_query("select * from stock where ProID='$ProID'");
$row =mysql_fetch_array($result);
$SupID = $row['SupID'];
$ProRQuan=$row['ProRQuan'];
$ProName=$row['ProName'];
$result2=mysql_query("select * from supplier where SupID='$SupID'");
$row2 =mysql_fetch_array($result2);
$SupName =$row2['SupName'];
$result3=mysql_query("select * from stockuse where ProID='$ProID'");
$row4=mysql_fetch_array($result3);
$Remain = $row4['ProRemain'];
$Used = $row4['ProUsed'];

$Remain1 = $TQuan1 - $Used;
$query3=mysql_query("UPDATE stockuse Set ProQuan='$TQuan1',ProRemain='$Remain1' where ProID='$ProID'");
$query=mysql_query("UPDATE stock SET ProRQuan ='$TQuan1' where ProID='$ProID'");
$query2=mysql_query("INSERT INTO stocktran(TID,ProID,SupID,SupName,ProName,ProRQuan,ProAddQuan,ProTQuan,ProPrice,ProTPrice,Date)VALUE('$TID','$ProID','$SupID','$SupName','$ProName','$ProRQuan','$AddQuan1','$TQuan1','$UPrice1','$TPrice1','$time')");
if($query2){
	echo "<script language=javascript>alert('Add successful!!');window.location='http://www.wauhaha.com/karaoke/addstock.php?SupID=$SupID'</script>";
}
echo "<script language=javascript>alert('Add fail!!');window.location='http://www.wauhaha.com/karaoke/addstock.php?SupID=$SupID '</script>";
?>