<?php
// array for JSON response
$response = array();
//check for required fields
if (  isset($_POST['ClientName'])                                          
 && isset($_POST['ClientMobile'])                                        
 && isset($_POST['ClientAddress'])                                       
 && isset($_POST['ClientNic'])                                           
 && isset($_POST['EventName'])                                           
 && isset($_POST['BookingDate'])  
 && isset($_POST['EventDate'])   
 && isset($_POST['ArrangePersons'])                                      
 && isset($_POST['ChargesTotal'])  
 && isset($_POST['Description']) 
 && isset($_POST['ClientID'])     
 && isset($_POST['ClientUserID'])  
 && isset($_POST['NetCode'])                                             
 && isset($_POST['SysCode'])                                                       
 && isset($_POST['Shift'])                                             
 && isset($_POST['SerialNo']) ) {

      $ClientName = $_POST['ClientName'];
  		$ClientMobile = $_POST['ClientMobile'];
  		$ClientAddress = $_POST['ClientAddress'];
  		$ClientNic = $_POST['ClientNic'];
  		$EventName = $_POST['EventName'];
  		$Booking_Date = $_POST['BookingDate'];
  		$Event_Date = $_POST['EventDate'];
  		$ArrangePersons = $_POST['ArrangePersons'];
  		$ChargesTotal = $_POST['ChargesTotal'];
  		$Description = $_POST['Description'];
  		$ClientID = $_POST['ClientID'];
  		$ClientUserID = $_POST['ClientUserID'];
  		$NetCode = $_POST['NetCode'];
  		$SysCode = $_POST['SysCode'];
      	$DebitAccount = $_POST['DebitAccount'];
  		$CreditAccount = $_POST['CreditAccount'];
  		$Amount = $_POST['Amount'];
		$Shift = $_POST['Shift'];
	    $SerialNo = $_POST['SerialNo'];
	
		$BookingDate = date("Y-m-d", strtotime($Booking_Date));
		$EventDate = date("Y-m-d", strtotime($Event_Date));
	
      // include db connect class
  		require_once __DIR__ . '/../DBConnect.php';

      $Dat = date("Y-m-d H:i:s");
		$MAX_ID;
			$sqll="Select max(BookingID) as maxid from Booking ";
			
			   try {
        // $result=$conn->query($sql);
        $stmt = $conn->prepare($sqll);
        
        // execute the query
        $stmt->execute();
        $users = $stmt->fetchAll();
		$MAX_ID = 0;
        foreach ($users as $user) {
          
			$MAX_ID = $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();
    }
			 
			 
			 
			////////////////////////////////////////////////////////////////
      $sql = "INSERT INTO Booking (BookingID,ClientName, ClientMobile, ClientAddress, ClientNic, EventName, BookingDate, EventDate, ArrangePersons, ChargesTotal, Description, ClientID, ClientUserID, NetCode, SysCode, UpdatedDate, Shift, SerialNo) VALUES ('$MAX_ID','$ClientName', '$ClientMobile', '$ClientAddress', '$ClientNic', '$EventName', '$BookingDate', '$EventDate', '$ArrangePersons', '$ChargesTotal', '$Description', '$ClientID', '$ClientUserID', '$NetCode', '$SysCode', '$Dat', '$Shift', '$SerialNo');";
	
			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"] = $MAX_ID;
				$response["UpdatedDate"] = $Dat;
				$response["message"] = "User Register";
				echo json_encode($response);
				}
			}
		catch (PDOException $e) {
			echo $sql . "<br>" . $e->getMessage();
		}
		
		
		
      }else {
          $response["success"] = 0;
		
          $response["message"] = "Send All Parameter(ClientName, ClientMobile, ClientAddress, ClientNic, EventName, BookingDate, EventDate, ArrangePersons, ChargesTotal, Description, ClientID, ClientUserID, NetCode, SysCode,  Shift, SerialNo)";
			// echoing JSON response
    		echo json_encode($response);
        }

   

?>
