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

    session_start();
    date_default_timezone_set('Asia/Bangkok');

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

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

    $attendance = new Attendance($db);
	$data = json_decode(file_get_contents("php://input"));

    $attendance->date = $data->date;
    $attendance->staff_id = $data->staff_id;

    $attendance->getOneAttendance();
   
    $arr = array(
        "id" => $attendance->id,
        "duty_in_time" => $attendance->duty_in ? date('h:i A', strtotime($attendance->duty_in)) : "",
        "duty_out_time" => $attendance->duty_out ? date('h:i A', strtotime($attendance->duty_out)) : "",
        "second_duty_in_time" => $attendance->second_duty_in ? date('h:i A', strtotime($attendance->second_duty_in)) : "",
        "second_duty_out_time" => $attendance->second_duty_out ? date('h:i A', strtotime($attendance->second_duty_out)) : ""
    );
    
    echo json_encode($arr);
?>
