<?php
    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_once '../config/database.php';
    include_once '../objects/room.php';

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

    $room = new Room($db);
    $data = json_decode(file_get_contents("php://input"));

    $room->start_date = $data->start_date;
    $room->end_date = $data->end_date;

    $stmt = $room->getRoomStatusByDate();
	$num = $stmt->rowCount();
    $arr=array();
	$arr["records"]=array();
	if($num>0){
		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);

			$item=array(
                "room_no" => $room_number,
				"name" => ($name)?$name:"",
				"checkin_id" => $checkin_id,
                "reservation_no" => $reservation_no,
                "invoice_no" => $folio_no,
				"date" => $date,
                "status" => $c_status,
                "room_income" => $room_income,
                "room_type" => $room_type,
                "bed_type" => $bed_type,
                "max_occupancy" => $max_occupancy,
                "room_rate" => $room_rate,
                "remark" => $remark,
                "from_to_date" => $from_to_date,
                "total_days" => $total_days,
                "total_amount" => number_format($total_amount,2),
                "agent_name" => $agent_name,
			);
			array_push($arr["records"], $item);
		}
	}
    echo json_encode($arr);
?>
