<?
require("config.inc");
date_default_timezone_set('Etc/GMT-8');
$dateToYear = date('Y', time());
$dateToMonth = date('m', time());
$dateToday = date('d', time());
$query1 = mysql_query("select * from tbl_introprod");
//echo "<script>alert('".$productType."');</script>";
while ($row=mysql_fetch_array($query1))
{
	$expireDate = $row['expireDay'];
	$expireYear = substr(".$expireDate.", -11, 4);
	$expireMonth = substr(".$expireDate.", -6, 2);
	$expireDay = substr(".$expireDate.", -3, 2);
	if($expireYear < $dateToYear){
		$productID = $row['product_ID'];
		$quantity = $row['product_QUANTITY'];
		$intime = $row['timeToIn'];
		$exp = $row['expireDay'];
		$PFH = $row['personForHander'];
		$owner = $row['OWNER'];
		$code = $row['codeNum'];

		$result = mysql_query("insert into tbl_outstock (product_ID,product_QUANTITY,timeToIn,expireDay,personForHander,OWNER,codeNum) value ('$productID','$quantity','$intime','$exp','$PFH','$owner','$code')");
		mysql_query("delete from tbl_introprod where expireDay='$expireDate'");
	}
	else if($expireYear == $dateToYear){
		if($expireMonth < $dateToMonth){
			$productID = $row['product_ID'];
			$quantity = $row['product_QUANTITY'];
			$intime = $row['timeToIn'];
			$exp = $row['expireDay'];
			$PFH = $row['personForHander'];
			$owner = $row['OWNER'];
			$code = $row['codeNum'];
			echo "<script>alert('".$productID."');</script>";
			$result = mysql_query("insert into tbl_outstock (product_ID,product_QUANTITY,timeToIn,expireDay,personForHander,OWNER,codeNum) value ('$productID','$quantity','$intime','$exp','$PFH','$owner','$code')");
			mysql_query("delete from tbl_introprod where expireDay='$expireDate'");
		}
		else if($expireMonth == $dateToMonth){
			if($expireDay < $dateToday){
				$productID = $row['product_ID'];
				$quantity = $row['product_QUANTITY'];
				$intime = $row['timeToIn'];
				$exp = $row['expireDay'];
				$PFH = $row['personForHander'];
				$owner = $row['OWNER'];
				$code = $row['codeNum'];

				$result = mysql_query("insert into tbl_outstock (product_ID,product_QUANTITY,timeToIn,expireDay,personForHander,OWNER,codeNum) value ('$productID','$quantity','$intime','$exp','$PFH','$owner','$code')");
				mysql_query("delete from tbl_introprod where expireDay='$expireDate'");
			}
			else if($expireDay == $dateToday){
				
			}
			else{}
		}
		else{
		
		}
	}
	else{
		
	}
}
echo "<script>window.location='intro.php';</script>";
?>