<?php
/*
  | Source Code Aplikasi Rental Mobil PHP & MySQL
  | 
  | @package   : rental_mobil
  | @file	   : cetak.php 
  | @author    : fauzan1892 / Fauzan Falah
  | @copyright : Copyright (c) 2017-2021 Codekop.com (https://www.codekop.com)
  | @blog      : https://www.codekop.com/products/source-code-aplikasi-rental-mobil-php-mysql-7.html 
  | 
  | 
  | 
  | 
 */
    require '../../koneksi/koneksi.php';
    session_start();
    if(empty($_SESSION['USER']))
    {
        echo '<script>alert("login dulu");window.location="index.php"</script>';
    }
    $kode_booking = $_GET['id'];
    $hasil = $koneksi->prepare("SELECT * FROM booking WHERE kode_booking = ?");
    $hasil->execute(array($kode_booking));
    $hasil = $hasil->fetch();

    $id_booking = $hasil['id_booking'];
    $hsl = $koneksi->prepare("SELECT * FROM pembayaran WHERE id_booking = ?");
    $hsl->execute(array($id_booking));
    $c = $hsl->rowCount();
    $hsl = $hsl->fetch();


    $id = $hasil['id_mobil'];
    $isi = $koneksi->prepare("SELECT * FROM mobil WHERE id_mobil = ?");
    $isi->execute(array($id));
    $isi = $isi->fetch();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Cetak Bukti Pembayaran - <?= $hasil['kode_booking'];?></title>
    <style>
        * {
            box-sizing: border-box;
            -moz-box-sizing: border-box;
        }
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #fff;
        }
        .container {
            width: 210mm;
            min-height: 297mm;
            padding: 15mm;
            margin: 10mm auto;
            border: 1px solid #D3D3D3;
            background: white;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
        }
        @page {
            size: A4;
            margin: 0;
        }
        @media print {
            body {
                background: none;
                margin: 0;
                padding: 0;
            }
            .container {
                margin: 0;
                border: none;
                box-shadow: none;
                width: 100%;
                min-height: auto;
            }
            .no-print {
                display: none;
            }
        }
        .header {
            text-align: center;
            border-bottom: 3px double #000;
            padding-bottom: 10px;
            margin-bottom: 20px;
        }
        .header h1 {
            margin: 0;
            text-transform: uppercase;
        }
        .header p {
            margin: 5px 0;
        }
        .content-title {
            text-align: center;
            text-decoration: underline;
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 20px;
        }
        .info-table {
            width: 100%;
            margin-bottom: 20px;
        }
        .info-table td {
            padding: 5px;
            vertical-align: top;
        }
        .data-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        .data-table th, .data-table td {
            border: 1px solid #000;
            padding: 10px;
            text-align: left;
        }
        .data-table th {
            background-color: #f2f2f2;
        }
        .footer-sign {
            margin-top: 50px;
            float: right;
            width: 200px;
            text-align: center;
        }
        .footer-sign p {
            margin-bottom: 80px;
        }
        .total-row td {
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="no-print" style="padding: 20px; text-align: center;">
        <button onclick="window.print()" style="padding: 10px 20px; cursor: pointer; background: #007bff; color: white; border: none; border-radius: 5px;">Cetak Sekarang</button>
        <a href="bayar.php?id=<?= $hasil['kode_booking'];?>" style="padding: 10px 20px; text-decoration: none; background: #6c757d; color: white; border-radius: 5px; margin-left: 10px;">Kembali</a>
    </div>

    <div class="container">
        <div class="header">
            <table style="width: 100%; border: none;">
                <tr>
                    <td style="width: 140px; border: none; vertical-align: middle;">
                        <?php if(!empty($info_web->logo)){?>
                            <img src="../../assets/image/<?= $info_web->logo;?>" style="width:130px;">
                        <?php }?>
                    </td>
                    <td style="text-align: center; border: none;">
                        <h1 style="margin:0; text-transform: uppercase;"><?= $info_web->nama_rental;?></h1>
                        <p style="margin:5px 0;"><?= $info_web->alamat ?? 'Alamat Tidak Tersedia';?></p>
                        <p style="margin:5px 0;">Telp: <?= $info_web->telp ?? '-';?> | Email: <?= $info_web->email ?? '-';?></p>
                    </td>
                    <td style="width: 100px; border: none;"></td>
                </tr>
            </table>
        </div>

        <div class="content-title">BUKTI PEMBAYARAN RENTAL MOBIL</div>

        <table class="info-table">
            <tr>
                <td width="150">Kode Booking</td>
                <td width="10">:</td>
                <td><strong><?= $hasil['kode_booking'];?></strong></td>
                <td width="150">Tanggal Cetak</td>
                <td width="10">:</td>
                <td><?= date('d F Y');?></td>
            </tr>
            <tr>
                <td>Nama Pelanggan</td>
                <td>:</td>
                <td><?= $hasil['nama'];?></td>
                <td>Telepon</td>
                <td>:</td>
                <td><?= $hasil['no_tlp'];?></td>
            </tr>
            <tr>
                <td>No. KTP</td>
                <td>:</td>
                <td><?= $hasil['ktp'];?></td>
                <td>Status Bayar</td>
                <td>:</td>
                <td><?= $hasil['konfirmasi_pembayaran'];?></td>
            </tr>
        </table>

        <table class="data-table">
            <thead>
                <tr>
                    <th>Detail Mobil</th>
                    <th>Tanggal Sewa</th>
                    <th>Lama Sewa</th>
                    <th>Harga / Hari</th>
                    <th>Total</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><?= $isi['merk'];?></td>
                    <td><?= $hasil['tanggal'];?></td>
                    <td><?= $hasil['lama_sewa'];?> Hari</td>
                    <td>Rp. <?= number_format($isi['harga']);?></td>
                    <td>Rp. <?= number_format($hasil['total_harga']);?></td>
                </tr>
                <tr class="total-row">
                    <td colspan="4" style="text-align: right;">Total Bayar</td>
                    <td>Rp. <?= number_format($hasil['total_harga']);?></td>
                </tr>
            </tbody>
        </table>

        <?php if($c > 0){?>
        <div style="margin-top: 20px;">
            <p><strong>Detail Pembayaran Transfer:</strong></p>
            <table class="info-table" style="border: 1px solid #ddd; padding: 10px;">
                <tr>
                    <td width="150">No. Rekening</td>
                    <td width="10">:</td>
                    <td><?= $hsl['no_rekening'];?></td>
                </tr>
                <tr>
                    <td>Atas Nama</td>
                    <td>:</td>
                    <td><?= $hsl['nama_rekening'];?></td>
                </tr>
                <tr>
                    <td>Nominal Transfer</td>
                    <td>:</td>
                    <td>Rp. <?= number_format($hsl['nominal']);?></td>
                </tr>
                <tr>
                    <td>Tanggal Transfer</td>
                    <td>:</td>
                    <td><?= $hsl['tanggal'];?></td>
                </tr>
            </table>
        </div>
        <?php }?>

        <div style="margin-top: 30px;">
            <p><em>* Harap tunjukkan bukti pembayaran ini saat pengambilan kendaraan.</em></p>
        </div>

        <div class="footer-sign">
            <p>Dicetak pada, <?= date('d/m/Y');?><br>Petugas Administrasi,</p>
            <strong>( ................................. )</strong>
        </div>
        <div style="clear: both;"></div>
    </div>

    <script>
        // window.print();
    </script>
</body>
</html>
