<?php
    // required headers
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    header("Access-Control-Allow-Methods: POST");
    header("Access-Control-Max-Age: 3600");
    header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
     
    // include database and object files
    include_once '../config/database.php';
    include_once '../objects/reservation.php';
     
    // instantiate database
    $database = new Database();
    $db = $database->getConnection();
     
    // initialize object
    $reservation = new Reservation($db);
    $data = json_decode(file_get_contents("php://input"));

    $reservation->df = isset($_GET['df']) ? $_GET['df'] : null;
    $reservation->dt = isset($_GET['dt']) ? $_GET['dt'] : null;

    $stmt = $reservation->searchGuest();
    $num = $stmt->rowCount();

    $arr=array();
    $arr["records"]=array();

    $total=0;
    if($num>0){
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            extract($row);
            $ex=array(
                $guest_id,
                $guest_name,
                $contact_number,
                $email,
                $country,
                $ppnrc,
                $address,
                $room_no,
				($checkin)?$checkin:"",
                ($checkout_date)?$checkout_date:"",
            );
            // $total += ($checkout_date)?$charges:0;
            array_push($arr["records"], $ex);
        }
        $arr["total"] = number_format($total, 2, '.', '');
        
    }
    echo json_encode($arr);
?>