<?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);

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

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

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

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

        $item = array(
            $room_no,
            $reservation_no,
            $folio_no,
            $agent_name,
            $guest_name,
            $reserve_date,
            $reserve_created_at,
            $room_rate,
            $extra_bed_charges,
            $extra_person_charges,
            $total_charges,
            number_format(round(($total_charges - ($total_charges / 1.07)), 2), 2, '.', ''),
            number_format(round($total_charges / 1.07, 2), 2, '.', ''),
            
        );

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

}

echo json_encode($response);
?>
