<?php
require("lib/config.php");
require_once 'vendor/eway/eway-rapid-php/include_eway.php';
// =============== Get customer user api ===================================
$data  = $_REQUEST;
$sql = "SELECT * FROM `booking` where `email` = '".$_REQUEST['email']."' AND status <> 'completed' AND status <> 'cancelled' AND status <> 'expired'";
$result = $conn->query($sql);
if ($result->num_rows > 0) 
{
	while($row_details = $result->fetch_assoc()) 
	{
		$format = 'Y-m-d';
            $datetime = DateTime::createFromFormat($format, $row_details["booking_date"]);
            $bookingdate = $datetime->getTimestamp();
            
	    if($bookingdate < strtotime("yesterday")) {
	        
	        $sql1 = "UPDATE `booking` SET `status` = 'expired' WHERE `id` = '".$row_details['id']."'";
	        $result1 = $conn->query($sql1);
	        if(!$result1) {
	            error_log($conn->error);
	        }
	        
	    } else {
	    
		$booking_detail[] = $row_details;
		
	    }
	}
	
	
	
	error_log(json_encode($booking_detail, true));
	if(count($booking_detail) > 0) {
	$Res["data"] = $booking_detail;
	$Res["message"] = "Bookings Found"; 
	$Res["status"] = "OK"; 
	} else {
	   $Res["message"] = "No Open Bookings Found"; 
	    $Res["status"] = "no";  
	    
	}
	
}
else
{
	$Res["message"] = "No Open Bookings Found"; 
	$Res["status"] = "no"; 
}


echo json_encode(new ArrayObject($Res)); 

				
