<?php
include "koneksi.php";
$id = (int) $_GET['id'];

// Ambil transaksi
$trx = $conn->query("SELECT * FROM tabel_transaksi WHERE id=$id")->fetch_assoc();

// Ambil detail
$detail = $conn->query("
    SELECT d.*, p.nama_produk 
    FROM tabel_transaksi_detail d 
    JOIN tabel_produk p ON d.produk_id = p.id
    WHERE d.transaksi_id=$id
");
?>

<div class="container mt-4">
    <h3>Detail Transaksi</h3>
    <p><b>No Transaksi:</b> <?= $trx['no_transaksi'] ?></p>
    <p><b>Tanggal:</b> <?= date('d-m-Y', strtotime($trx['tanggal'])) ?></p>
    <p><b>Customer:</b> <?= $trx['customer'] ?></p>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Produk</th>
                <th>Harga</th>
                <th>Qty</th>
                <th>Subtotal</th>
            </tr>
        </thead>
        <tbody>
            <?php while($d = $detail->fetch_assoc()): ?>
            <tr>
                <td><?= $d['nama_produk'] ?></td>
                <td>Rp <?= number_format($d['harga'],0,',','.') ?></td>
                <td><?= $d['qty'] ?></td>
                <td>Rp <?= number_format($d['subtotal'],0,',','.') ?></td>
            </tr>
            <?php endwhile; ?>
        </tbody>
    </table>

    <h5>Total: Rp <?= number_format($trx['total'],0,',','.') ?></h5>
    <h5>Grand Total: Rp <?= number_format($trx['grand_total'],0,',','.') ?></h5>

    <a href="index.php?page=transaksi" class="btn btn-secondary">Kembali</a>
</div>
