<?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/reservation.php';
include_once '../objects/reservation_detail.php';
include_once '../objects/deposit.php';

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

$reservation = new Reservation($db);
$reservation_detail = new ReservationDetail($db);
$deposit = new Deposit($db);
$data = json_decode(file_get_contents("php://input"));

$reservation->reservation_no = $data->reservation_no;
$reservation->room_no = $data->room_no;
$reservation_detail->reservation_no = $data->reservation_no;
$deposit->reservation_no = $data->reservation_no;

$db->beginTransaction();

if ($deposit->DeleteReservation() && $reservation_detail->DeleteReservation() && $reservation->DeleteReservation()) {
    $db->commit();
    echo json_encode(array("message" => "deleted"));
} else {
    $db->rollBack();
    echo json_encode(array("message" => "error")); 
}
?>
