<?php
// File: API_KONEKSI/admin/list_sesi_mendatang.php
header('Content-Type: application/json');
include '../config/koneksi.php';

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    // Mengambil jadwal yang >= hari ini (bisa disesuaikan jika ingin > hari ini saja)
    $query = "SELECT r.reservasi_id, r.booking_tgl, r.booking_jam, r.final_harga, r.reservasi_st, 
                     u.lengkap_nm, p.paket_nm 
              FROM dat_reservasi r
              JOIN mst_user u ON r.user_id = u.user_id
              JOIN mst_paket p ON r.paket_id = p.paket_id
              WHERE r.booking_tgl >= CURDATE() AND r.reservasi_st NOT IN ('Dibatalkan', 'Batal') AND r.deleted_st = 0
              ORDER BY r.booking_tgl ASC, r.booking_jam ASC";

    $result = $conn->query($query);
    $data = [];

    while ($row = $result->fetch_assoc()) {
        // Format Invoice
        $row['invoice'] = $row['reservasi_id'];
        
        $data[] = $row;
    }

    if (count($data) > 0) {
        echo json_encode(["status" => "sukses", "pesan" => "Data ditemukan", "data" => $data]);
    } else {
        echo json_encode(["status" => "kosong", "pesan" => "Belum ada jadwal", "data" => []]);
    }
}
$conn->close();
?>