
<?php
session_start();
if( !isset($_SESSION["admin_login"])){
    header("Location: ../login/login.php");
}
require '../functions.php';
ob_start();
include "vendor/autoload.php"
?>

<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">


    <style>
    body {
        font-family: 'Poppins', sans-serif;
    }

    .villa {
        margin-top: 50px;

        
    }

    h2 {
        margin-bottom: 10px;
        text-align :center;
    }

    .sub {
        margin-top: 0;
        color: #777;
    }

    table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 20px;
        background-color: white;
    }

    th, td {
        padding: 8px;
        text-align: center;
        border: 1px solid #ccc;
    }

    th {
        font-weight: bold;
    }

    p{
        text-align : center;
    }
    .total-row td:first-child {
        font-weight: bold;
        text-align: right;
    }

    .total-row td:last-child {
        font-weight: bold;
    }
</style>


</head>
<body ><!-- onload="print()" -->
    <!-- villa table -->
    <section class="villa">
        <div class="container">
           
            <?php
            $dari_tgl = @$_GET['dari_tgl'];
            $sampai_tgl = @$_GET['sampai_tgl'];
            if (isset($_POST['filter'])) {
                $dari_tgl = mysqli_real_escape_string($conn, $_POST['dari_tgl']);
                $sampai_tgl = mysqli_real_escape_string($conn, $_POST['sampai_tgl']);
                echo "Data Booking Dari Tanggal " . $dari_tgl . " Sampai Tanggal " . $sampai_tgl;
            }
            ?>

            <div class="col-md-12">
                <h2>Laporan Data Booking</h2>
                <?php if (!empty($dari_tgl) && !empty($sampai_tgl)) { ?>
                    <p class="sub">Dari tanggal <?= strftime('%d-%m-%Y', strtotime($dari_tgl)) ?> Sampai tanggal <?= strftime('%d-%m-%Y', strtotime($sampai_tgl)) ?></p>
                <?php } ?>
            </div>


            <div class="row mb-5">
                <div class="col-md-12">
                    <table class="table table-striped table-hover">
                        <thead class="thead-dark text-center">
                            <tr>
                                <th scope="col">No.</th>
                                <th scope="col">Name</th>
                                <th scope="col">Email</th>
                                <th scope="col">Phone Number</th>
                                <th scope="col">Check-in</th>
                                <th scope="col">Check-out</th>
                                <th scope="col">Jumlah Bayar</th>
                                <!-- <th scope="col">villa Id</th> -->
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                        $dari_tgl = @$_GET['dari_tgl'];
                        $sampai_tgl = @$_GET['sampai_tgl'];
                        $i = 1;
                        if(empty($dari_tgl) or empty($sampai_tgl)) {
                            $book_log = mysqli_query($conn, "SELECT * FROM tb_booklog JOIN tb_payments ON tb_payments.user_id = tb_booklog.user_id ");
                            $total_transaksi =0;
                        }else{
            
                            $book_log = mysqli_query($conn,"SELECT * FROM tb_booklog JOIN tb_payments ON tb_payments.user_id = tb_booklog.user_id WHERE tanggal_pesan BETWEEN '$dari_tgl' AND '$sampai_tgl' ");
                            $url_cetak = "print.php?dari_tgl=".$dari_tgl."&samapai_tgl=".$sampai_tgl;
                            $total_transaksi =0;
                        }
                        while ($book = mysqli_fetch_array($book_log)) {
                        $total_transaksi+=$book['jumlah_bayar'];
                        ?> 
                            <tr>
                                <th class="text-center" scope="row"><?= $i++; ?></th>
                                <td class="text-center"><?= $book["nama"] ?></td>
                                <td class="text-center"><?= $book["email"] ?></td>
                                <td class="text-center"><?= $book["nomer"] ?></td>
                                <td class="text-center"><?= strftime('%d-%m-%Y', strtotime($book["tanggal_pesan"])) ?></td>
                                <td class="text-center"><?= strftime('%d-%m-%Y', strtotime($book["tanggal_pulang"])) ?></td>
                                <td class="text-center">Rp. <?= $book["jumlah_bayar"] ?></td>
                                
                            </tr>
                        <?php } ?>
                            <tr>
                                <td class="text-center"></td>
                                <td class="text-center"></td>
                                <td class="text-center"></td>
                                <td class="text-center"></td>
                                <td class="text-center"></td>
                                <td class="text-center">Total Transaksi</td>
                                <td class="text-center" style= bacground-color : whitesmoke;"align=center">Rp. <?php echo ($total_transaksi); ?></td>
                                

                            </tr>
                       
                        </tbody>
                    </table>
                </div>
            </div>
        </div>        
    </section>
    <!-- end of table -->
    
    

    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
    <!-- <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script> -->

    <!-- Option 2: jQuery, Popper.js, and Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
</body>
</html>
<?php
$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => 'A4','margin_top' => 25, 'margin_bottom' => 25, 'margin_left' => 25, 'margin_right' => 25]);

//Memasukkan output yang diambil dari output buffering ke variabel html
$html = ob_get_contents();

//Menghapus isi output buffering
ob_end_clean();

$mpdf->WriteHTML(utf8_encode($html));

//Membuat output file
$content = $mpdf->Output("Laporan Pemesanan.pdf", "D");
?>


