<?php
// session_start();
include ('../config/conn.php');
include ('../config/function.php');
?>
<html>

<head>
    <style>
    h2 {
        padding: 0px;
        margin: 0px;
        font-size: 14pt;
    }

    h4 {
        font-size: 12pt;
    }

    text {
        padding: 0px;
    }

    table {
        border-collapse: collapse;
        border: 1px solid #000;
        font-size: 11pt;
    }

    th,
    td {
        border: 1px solid #000;
        padding: 5px;
    }

    table.tab {
        table-layout: auto;
        width: 100%;
    }
    </style>
    <title>Cetak Laporan Peminjaman</title>
</head>

<body>
    <?php
    $now = date('Y-m-d'); 
    $query = mysqli_query($con, "SELECT x.*,x1.nama_barang,x3.nama_konsumen,x4.nama_divisi
    FROM peminjaman x 
    JOIN barang x1 ON x1.idbarang=x.barang_id 
    JOIN konsumen x3 ON x3.id_konsumen = x.konsumen_id
    JOIN divisi x4 ON x4.id_divisi = x.divisi_id
    WHERE x.tgl_pinjam='$now'  ORDER BY x.id_peminjaman DESC")or die(mysqli_error($con));
    
    ?>
    <div style="page-break-after:always;text-align:center;margin-top:5%;">
        <div style="line-height:5px;">
            <h2>LAPORAN PEMINJAMAN</h2>
            <h4>SEMUA PEMINJAMAN HARI INI</h4>
        </div>
        <hr style="border-color:black;">
        <table class="tab">
            <tr>
                <th width="20">No</th>
                <th>Nama Barang</th>
                <th>Jumlah</th>
                <th>Tanggal Pinjam</th>
                <th>Tanggal Kembali</th>
                <th>Nama Konsumen</th>
                <th>Nama Divisi</th>
            </tr>
            <?php $n=1; while($row = mysqli_fetch_array($query)): ?>
            <tr>
                <td align="center"><?= $n++.'.'; ?></td>
                <td><?= $row['nama_barang']; ?></td>
                <td><?= $row['jumlah']; ?></td>
                <td><?= date('d-m-Y',strtotime($row['tgl_pinjam'])); ?></td>
                <td><?= $row['tgl_kembali']; ?></td>
                <td><?= $row['nama_konsumen']; ?></td>
                <td><?= $row['nama_divisi']; ?></td>
            </tr>
            <?php endwhile; ?>
        </table>
    </div>
</body>

</html>

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