<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

include_once '../config/database.php';
include_once '../objects/reservation.php';

$database = new Database();
$db = $database->getConnection();

$reservation = new Reservation($db);

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

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

if ($num > 0) {
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        extract($row);

        $item = array(
            $reservation_no,
            $agent_name,
            $guest_name,
            $adult . '/' . $child,  
            $room_no,
            $checkin_date,
            $checkout_date,
            $nights,
            number_format($total, 2, '.', ''),
            $date_time
        );

        array_push($response["records"], $item);
    }

    echo json_encode($response);
} else {
    echo json_encode(array("message" => "No check_ins found."));
}
?>
