<?php
// array for JSON response
  $response= array();

    // include db connect class
		require_once __DIR__ . '/../DBConnect.php';

    if (isset($_POST['ClientID']) && isset($_POST['EventDate'])){
      $EventDate = $_POST['EventDate'];
	  $ClientID = $_POST['ClientID'];	
      $sql = "SELECT * FROM Booking WHERE EventDate = '$EventDate' AND ClientID = '$ClientID'";
  		$params = array();
  		$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
        $response["Bookings"] = array();

      	foreach($result as $row) { 
          $Bookings["BookingID"] = $row["BookingID"];
          $Bookings["ClientName"] = $row["ClientName"];
          $Bookings["ClientMobile"] = $row["ClientMobile"];
          $Bookings["ClientAddress"] = $row["ClientAddress"];
          $Bookings["ClientNic"] = $row["ClientNic"];
          $Bookings["EventName"] = $row["EventName"];
          $Bookings["BookingDate"] = $row["BookingDate"];
          $Bookings["EventDate"] = $row["EventDate"];
          $Bookings["ChargesTotal"] = $row["ChargesTotal"];
          $Bookings["Description"] = $row["Description"];
          $Bookings["ClientID"] = $row["ClientID"];
          $Bookings["ClientUserID"] = $row["ClientUserID"];
		  $Bookings["Shift"] = $row["Shift"];
		  $Bookings["SerialNo"] = $row["SerialNo"];
			
          // push single product into final response array
    			array_push($response["Bookings"], $Bookings);
        }

        // success
    		$response["success"] = 1;
        // echoing JSON response
    		echo json_encode($response);
      }else {
        // no products found
    		$response["success"] = 0;
    		$response["message"] = "Number Not Register";
        // echoing JSON response
    		echo json_encode($response);
      }

    }else if(isset($_POST['ClientID'])){
		
	  $ClientID = $_POST['ClientID'];
		
      $sql = "select * from Booking where ClientID= $ClientID";
  		$params = array();
  		$stmt = $conn->prepare($sql);
			$stmt->execute();
			$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	if($result!=null &&  $result>0){
        $response["Bookings"] = array();

        	foreach($result as $row) { 
     //     $Bookings["BookingID"] = $row["BookingID"];
       //   $Bookings["ClientName"] = $row["ClientName"];
       //   $Bookings["ClientMobile"] = $row["ClientMobile"];
       //   $Bookings["ClientAddress"] = $row["ClientAddress"];
       //   $Bookings["ClientNic"] = $row["ClientNic"];
       //   $Bookings["EventName"] = $row["EventName"];
       //   $Bookings["BookingDate"] = $row["BookingDate"];
       //   $Bookings["EventDate"] = $row["EventDate"];
       //   $Bookings["ChargesTotal"] = $row["ChargesTotal"];
       //   $Bookings["Description"] = $row["Description"];
       //   $Bookings["ClientID"] = $row["ClientID"];
       //   $Bookings["ClientUserID"] = $row["ClientUserID"];

			$Bookings["BookingID"] = $row["BookingID"];
          $Bookings["ClientName"] = $row["ClientName"];
          $Bookings["ClientMobile"] = $row["ClientMobile"];
          $Bookings["ClientAddress"] = $row["ClientAddress"];
          $Bookings["ClientNic"] = $row["ClientNic"];
          $Bookings["EventName"] = $row["EventName"];
          $Bookings["BookingDate"] = $row["BookingDate"];
          $Bookings["EventDate"] = $row["EventDate"];
		  $Bookings["ArrangePersons"] = $row["ArrangePersons"];
          $Bookings["ChargesTotal"] = $row["ChargesTotal"];
          $Bookings["Description"] = $row["Description"];
          $Bookings["ClientID"] = $row["ClientID"];
          $Bookings["ClientUserID"] = $row["ClientUserID"];
		  $Bookings["NetCode"] = $row["NetCode"];
          $Bookings["SysCode"] = $row["SysCode"];
          $Bookings["UpdatedDate"] = $row["UpdatedDate"];
		  $Bookings["Shift"] = $row["Shift"];
		  $Bookings["SerialNo"] = $row["SerialNo"];
		  
		  $current_date = date("Y-m-d H:i:s");	
		  $Bookings["SessionDate"] = $current_date;	
			
          // push single product into final response array
    			array_push($response["Bookings"], $Bookings);
        }

        // success
    		$response["success"] = 1;
        // echoing JSON response
    		echo json_encode($response);
      }else {
        // no products found
    		$response["success"] = 0;
    		$response["message"] = "Number Not Register";
        // echoing JSON response
    		echo json_encode($response);
      }
    }else {
        // success
        $response["success"] = 0;
        $response["message"] = "No Data Availaible";
        // echoing JSON response
    		echo json_encode($response);
      }
?>
