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

//check for required fields
if ( isset($_POST['ClientID']) ) {
		
		
		$BookingID = $_POST['BookingID'];
		$VehicleID = $_POST['VehicleID'];
  		$BookingDate = $_POST['BookingDate'];
		$BookingDetail = $_POST['BookingDetail'];
  		$BookingCharges = $_POST['BookingCharges'];
		$SerialNo = $_POST['SerialNo'];
  		$UpdatedDate = $_POST['UpdatedDate'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
  		$SysCode = $_POST['SysCode'];
		

      // include db connect class
      require_once __DIR__ . '/../DBConnect.php';
               $parm=array();
	           $query="select max(BookingID) as maxid from Vehicle3Booking where ClientID =".$ClientID;
			   
	          

			     try {
        // $result=$conn->query($sql);
        $stmt = $conn->prepare($query);
        
        // execute the query
        $stmt->execute();
        $users = $stmt->fetchAll();
		$BookingID = 0;
        foreach ($users as $user) {
          
			$BookingID = $user['maxid'] + 1;
        }
        // echo a message to say the UPDATE succeeded
       // $result = $stmt->rowCount(); // . " records UPDATED successfully";
    }
    catch (PDOException $e) {
        echo $sql . "<br>" . $e->getMessage();
    }
	                  
			    $UpdatedDate = date("Y-m-d H:i:s");
          $sql = "INSERT INTO Vehicle3Booking (BookingID, VehicleID, BookingDate, BookingDetail, BookingCharges, SerialNo, ClientID, ClientUserID, UpdatedDate, NetCode, SysCode) VALUES ('$BookingID', '$VehicleID', '$BookingDate', '$BookingDetail', '$BookingCharges', '$SerialNo', '$ClientID', '$ClientUserID', '$UpdatedDate', '$NetCode', '$SysCode');";
      		
      		try {
		   $result= $conn->exec($sql);		   
				if( $result === false ) {
				/////////////not inserted
					$response["success"] = 0;  
					$response["message"] = "User Not Register";
				echo json_encode($response);
				}else{
					/////////////inserted
				$response["success"] = 1;
				$response["BookingID"] = $BookingID;
				$response["UpdatedDate"] = $UpdatedDate;
				$response["message"] = "User Register";
				echo json_encode($response);
				}
			}
		catch (PDOException $e) {
			echo $sql . "<br>" . $e->getMessage();
		}
		 
		 
        } else{
      // success
      $response["success"] = 0;
      $response["message"] = "Send All Required Fields ";
      // echoing JSON response
      echo json_encode($response);
    }
?>
