<?php
//open connection
include 'db_Connection.php';

//update timestamp
//$cek_uid =$_SESSION['username'];  
$timezone = "Asia/Jakarta";
date_default_timezone_set($timezone);  
$datetime = new DateTime(date("Y-m-d H:i:s"));
$str_datetime = $datetime->format("Y-m-d H:i:s");
//$sql  = ("UPDATE usr_profile SET last_activity = '$str_datetime' WHERE user_id = '$cek_uid'");
//$query = mysqli_query($conn, $sql);

//get parameters
$data_post = $_POST['data_post'];

//get array value
$json = $data_post;
$array = json_decode($json, true);
$cekStock = $array['cekStock'];
$product_code = $array['product_code'];
$qty = $array['qty'];

// cek quantity stock    
    $sql = "SELECT Quantity FROM stock WHERE Product_Code ='$product_code'";
    $rs_result = $conn->query($sql);
	$row = $rs_result->fetch_assoc();
	$cek = $row['Quantity'];
	
	

    
if($cek >= $qty){	        	        
        $message = "past";    
        $res = array("result" => $message);
        echo json_encode($res);
}
else{
		$message = "outofstock";    
        $res = array("result" => $message);
        echo json_encode($res);
}
?>
