<?php include '../config/koneksi.php'; session_start(); if(!isset($_SESSION['admin_id'])){ header('Location: login.php'); exit; } ?>
<!DOCTYPE html>
<html>
<head>
    <title>Transaksi Berhasil - Admin</title>
    <link rel="stylesheet" type="text/css" href="style_admin.css">
</head>
<body>
<?php include 'header.php'; ?>
<?php include 'sidebar.php'; ?>
<div class="content">
    <div class="box">
        <h2 style="text-align:center;">Transaksi Berhasil</h2>
        <table>
            <tr>
                <th>ID</th>
                <th>Tgl</th>
                <th>Tipe</th>
                <th>Harga</th>
                <th>Jumlah</th>
                <th>Nama</th>
                <th>Telepon</th>
                <th>Kamar</th>
                <th>Tanggal Masuk</th>
                <th>Tanggal Keluar</th>
                <th>Lama</th>
                <th>Total</th>
            </tr>
            <?php
            $q = mysqli_query($conn, "SELECT p.*, u.nama, u.telepon, k.tipe, k.harga FROM pemesanan p JOIN user u ON p.id_user=u.id JOIN kamar k ON p.id_kamar=k.id WHERE p.status='lunas' ORDER BY p.id DESC");
            $noKamar = 1;
            while($d = mysqli_fetch_assoc($q)){
                $lama = (strtotime($d['tanggal_keluar'])-strtotime($d['tanggal_masuk']))/86400;
                $bulan = ceil($lama / 30); // Pembulatan ke atas, minimal 1 bulan
                echo '<tr>';
                echo '<td>ID'.str_pad($d['id'], 3, '0', STR_PAD_LEFT).'</td>';
                echo '<td>'.$d['tanggal_pesan'].'</td>';
                echo '<td>'.$d['tipe'].'</td>';
                echo '<td>Rp'.number_format($d['harga'],0,',','.').'</td>';
                echo '<td>1</td>';
                echo '<td>'.htmlspecialchars($d['nama']).'</td>';
                echo '<td>'.htmlspecialchars($d['telepon']).'</td>';
                echo '<td>Kamar '.$noKamar.'</td>';
                echo '<td>'.$d['tanggal_masuk'].'</td>';
                echo '<td>'.$d['tanggal_keluar'].'</td>';
                echo '<td>'.$lama.' Hari</td>';
                echo '<td>Rp'.number_format($d['harga']*$bulan,0,',','.').'</td>';
                echo '</tr>';
                $noKamar++;
            }
            ?>
        </table>
        <form method="post" action="cetak_laporan_sukses.php" target="_blank" style="text-align:center;">
            <button type="submit" class="btn">Cetak Laporan</button>
        </form>
    </div>
</div>
<?php include 'footer.php'; ?>
</body>
</html> 