<?php
include 'config/koneksi.php';
date_default_timezone_set('Asia/Jakarta');

if (!isset($_GET['id'])) {
    die("ID transaksi tidak ditemukan");
}

$id = $_GET['id'];
$q = mysqli_query($conn, "SELECT * FROM transaksi WHERE id='$id'");
$d = mysqli_fetch_assoc($q);
$qty = $d['qty'] ?? 1;

if (!$d) {
    die("Data invoice tidak ditemukan");
}

if (isset($_GET['download'])) {
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=invoice-".$_GET['id'].".html");
}
?>



<!DOCTYPE html>
<html>
<head>
<title>Invoice</title>
<!-- Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
<style>
body{
    font-family: 'Poppins', sans-serif;
    background:#f5f5f5;
}
.container{
    width:800px;
    margin:40px auto;
    background:white;
    padding:30px;
    border-radius:10px;
}
.header{
    display:flex;
    justify-content:space-between;
}

.navbar {
            position: sticky;
            top: 0;
            z-index: 999;
            background: rgba(63,93,80,0.95) !important;
            backdrop-filter: blur(6px);
        }
        .navbar .navbar-brand {
            font-size: 28px;   /* BESARKAN */
            font-weight: 700;  /* BOLD */
            letter-spacing: 1px; /* biar keren */
        }
        .navbar .navbar-brand span {
            color: #F9BF29;
        }
        .nav-link {
            color: white !important;
             position: relative;
        }
        .navbar .nav-link {
            font-size: 25px;   /* BESARIN FONT */
            font-weight: 500;  /* AGAK TEBAL */
            margin: 0 10px;

        }

        .navbar .nav-link::after {
            content: "";
            position: absolute;
            width: 0%;
            height: 2px;
            background: #F9BF29;
            left: 0;
            bottom: -5px;
            transition: 0.3s;
        }

        .navbar .nav-link:hover::after {
            width: 100%;
        }

        .nav-icons a {
            color: white;
            font-size: 25px;
            margin-left: 25px;
            transition: 0.3s;
        }

        .nav-icons a:hover {
            color: #F9BF29;
            transform: scale(1.2);
        }
.title{
    font-size:40px;
    font-weight:bold;
}
.section{
    margin-top:20px;
}
.table{
    width:100%;
    border-collapse:collapse;
    margin-top:20px;
}
.table th{
    background:#1abc9c;
    color:white;
    padding:10px;
    text-align:left;
}
.table td{
    padding:10px;
    border-bottom:1px solid #ddd;
}
.total{
    text-align:right;
    margin-top:20px;
}
.total h2{
    color:#1abc9c;
}
</style>
</head>

<body>

<nav class="navbar navbar-expand-lg navbar-dark px-5">
    <div class="container-fluid">

        <a class="navbar-brand fw-bold text-white" href="index.php">F3F3.</a>

        <div class="d-flex align-items-center nav-icons">

            <!-- Unduh -->
            <a href="invoice.php?id=<?= $_GET['id']; ?>&download=1" 
                class="btn btn-sm text-white" 
                style="border:1px solid white; border-radius:20px;">
                
                ⬇ Unduh
            </a>

        </div>

    </div>
</nav>

<div class="container">

<!-- HEADER -->
<div class="header">
    <div>
        <h2>F3F3 Furniture</h2>
        <p><p>Solusi Furniture Modern untuk Hunian Nyaman</p></p>
    </div>
    <div class="title">INVOICE</div>
</div>

<hr>

<!-- INFO -->
<div class="section">
    <b>Tagihan Kepada:</b><br>
    <?= $d['nama'] ?? 'Customer'; ?><br>
    <?= $d['no_hp'] ?? '-'; ?><br>
    <?= $d['alamat'] ?? '-'; ?>
</div>

<div class="section">
    <b>Invoice #:</b> INV-<?= $d['id']; ?><br>
    <b>Tanggal:</b> <?= date('d M Y, H:i'); ?><br>
</div>

<!-- TABLE -->
<table class="table">
<tr>
    <th>Deskripsi</th>
    <th>Harga</th>
    <th>Qty</th>
    <th>Total</th>
</tr>

<tr>
    <td><?= $d['nama_jasa']; ?></td>
    <td>Rp <?= number_format($d['harga']); ?></td>
    <td><?= $qty ?></td>
    <td>Rp <?= number_format($d['total']); ?></td>
</tr>
</table>

<!-- TOTAL -->
<div class="total">
    <p>Subtotal: Rp <?= number_format($d['total']); ?></p>
    <p>Pajak (11%): Rp <?= number_format($d['total'] * 0.11); ?></p>
    <h2>Total: Rp <?= number_format($d['total'] * 1.11); ?></h2>
</div>

<hr>

<!-- PAYMENT -->
<p><b>Metode:</b> <?= $d['metode']; ?></p>

<?php if(trim($d['metode']) == 'QRIS'){ ?>
    <div style="text-align:center">
        <p>QRIS ke F3F3 Furniture</p>
    </div>
<?php } else { ?>
    <p>
        Transfer ke:<br>
        <b>BCA 123456789</b><br>
        a.n F3F3 Furniture
    </p>
<?php } ?>

<br>

<p>Terima kasih telah menggunakan jasa kami 🙏</p>

</div>

</body>
</html>