<?php
	session_start();
    date_default_timezone_set('Asia/Colombo');
$currentDate = date('Y-m-d H:i:s');
	require_once 'db_connection.php'; 
	$product = $_POST['product'];
	$qty = $_POST['qty'];
    $user_id = $_SESSION['user_id'];
    $branch_id = $_SESSION['branch_id'];
$sql1 = "SELECT * FROM mobileproducts WHERE prid='$searchbarcode' AND status=1";
$result1 = $conn->query($sql1);
$r = mysqli_fetch_assoc($result1);
$expiredate = $r['expdate'];
$today = date('Y-m-d');


//if ($expiredate <= $today && $expiredate != "0000-00-00") {
	
//	echo "Sorry, product has expired on ".$expiredate;
	
//}else{
    $user_qury_03 = mysqli_query($conn, "SELECT * FROM tbl_stock WHERE prid = '$product'");
		$user_res1 = mysqli_fetch_assoc($user_qury_03);
		$sqty = $user_res1['qty'];
		
		if($sqty > 0){
            $sqll = "INSERT INTO `mobiletemporarycart`(`tempid`, `orderid`, `proid`, `pro_price`, `pro_dis`, `pro_qty`, `user_id`, `return_qty`, `return_date`, `return_user`, `hold`, `branch_id`, `freeitem`) VALUES (null,0,'$product','0','0','$qty','$user_id',0,'$currentDate',0,0,'$branch_id',1)";
            if ($conn->query($sqll) === TRUE) {
                echo 1;
            }else{
                echo 0;
            }
        }else{
            echo "Sorry, The product has no quantity";
        }
//}



?>