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

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
    $reservasi_id = $_GET['reservasi_id'] ?? '';

    $stmt = $conn->prepare("
        SELECT r.*, u.lengkap_nm, u.whatsapp_no, p.paket_nm, 
               bayar.transfer_bukti, bayar.validasi_st
        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
        LEFT JOIN dat_pembayaran bayar ON r.reservasi_id = bayar.reservasi_id
        WHERE r.reservasi_id = ? AND r.deleted_st = 0
    ");
    $stmt->bind_param("s", $reservasi_id);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($row = $result->fetch_assoc()) {
        $row['invoice'] = $row['reservasi_id'];

        echo json_encode(["status" => "sukses", "pesan" => "Data ditemukan", "data" => [$row]]);
    } else {
        echo json_encode(["status" => "gagal", "pesan" => "Transaksi tidak ditemukan", "data" => []]);
    }
    $stmt->close();
}
$conn->close();
?>