<?php 
require_once('Connections/localhost.php'); 
mysql_select_db($database_localhost,$localhost);


//$productID = 'P001.N00001';
//$exp = '2012-01-05';
//$quan = '50';
//$own = 'O002';
$productID = $_POST['proID'];
$exp = $_POST['exp'];
$quan = $_POST['quan'];
$own = $_POST['own'];
//$codeNum = $_POST['codeNum'];

$idSub = substr($productID, -11, 4);
$codeSub = substr($productID, -6, 6);

date_default_timezone_set('Etc/GMT-8');
$dateToday = date('Y-m-d', time());
//$timeNow = date('h:i:s a', time());
$wareH = $_POST['wareHouse'];
$Nowlocation = $_POST['location'];
$action = "Add";

//$wareH = "A";
//$Nowlocation = "L001";
//$quantity = 30;

$query = "select * from tbl_location where wareHouse = '$wareH' and location = '$Nowlocation'";
$query_exec = mysql_query($query) or die(mysql_error());
$row3 = mysql_fetch_array($query_exec);
$storeQ = $row3['numStore'];
$totalQuan = $storeQ + $quan;

if($totalQuan > 100){
	echo "N";
}
else{
echo "Y";
	$query_search = "select * from tbl_introprod where product_ID = '$idSub' and codeNum = '$codeSub'";
	$query_search2 = "select * from tempid";
	$query_exec = mysql_query($query_search) or die(mysql_error());
	$query_exec2 = mysql_query($query_search2) or die(mysql_error());
	$rows = mysql_num_rows($query_exec);
	$row = mysql_fetch_array($query_exec);
	$row2 = mysql_fetch_array($query_exec2);
	

$intime = $row['timeToIn'];
$expire = $row['expireDay'];
$hs = $row2['user_ID'];
$owID = $row['OWNER'];
$allQuan = $row['product_QUANTITY'];
$receiver = $row['personForHander'];

$result0 = mysql_query("insert into tbl_history (product_ID,Intime,Outtime,expireD,handStaff,quantity,ownerID,codeNum,action,receiver) value ('$idSub','$intime','$dateToday','$expire','$hs','$quan','$owID','$codeSub','$action','$receiver')");
	$result = mysql_query("insert into tbl_introprod (product_ID,timeToIn,product_QUANTITY,expireDay,personForHander,OWNER,codeNum,wareHouse,location) value ('$idSub','$dateToday','$quan','$exp','$hs','$own','$codeSub','$wareH','$Nowlocation')");
	$result1 = mysql_query("update tbl_location SET numStore='$totalQuan' where wareHouse = '$wareH' and location = '$Nowlocation'");
}

?>