<?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/check_in.php';
include_once '../objects/validate.php';
 
$database = new Database();
$db = $database->getConnection();

$checkin = new checkin($db);
$validate = new Validate($db);

$data = json_decode(file_get_contents("php://input"));  
$checkin->id = $data->checkin_id;
$checkin->getOneRow();

$validate->checkin_id = $data->checkin_id;

$checkin_items = array();
$stmt = $validate->getcheckinDetail();

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

		$item=array(
            "date" => $date,            
            "room_rate" => $room_rate,
            "extra_bed" => $extra_bed,
            "extra_bed_rate" => $extra_bed_rate,
            "extra_person" => $extra_person,
            "extra_person_rate" => $extra_person_rate,
            "total" => $room_rate+($extra_bed*$extra_bed_rate)+($extra_person*$extra_person_rate)
        );
        array_push($checkin_items, $item);
    }
}

$checkin = array(
    "reservation_no" => $checkin->reservation_no,
    "agent_id" => $checkin->agent_id,
    "agent_name" => $checkin->agent_name,
    "guest_id" => $checkin->guest_id,	
    "guest_name" => $checkin->guest_name,	
    "remark" => $checkin->remark,
    "room_type" => $checkin->room_type,
    "bed_type" => $checkin->bed_type,
    "room_no" => $checkin->room_no,
    "adult" => $checkin->adult,
    "child" => $checkin->child,
    "checkin_items" => $checkin_items
);
echo json_encode($checkin);
?>