<?php $now = date('Y-m-d'); ?>
<!-- Begin Page Content -->
<div class="container-fluid">
<style>
.button {
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  padding: 16px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #4CAF50;
}

.button1:hover {
  background-color: #4CAF50;
  color: white;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #008CBA;
}

.button2:hover {
  background-color: #008CBA;
  color: white;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #f44336;
}

.button3:hover {
  background-color: #f44336;
  color: white;
}


.button5 {
  background-color: white;
  color: black;
  border: 2px solid #CC9544;
}

.button5:hover {
  background-color: #CC9544;
  color: white;
}
</style>
    <!-- Page Heading -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Beranda </h1>
    </div>
    <button class="button button2" id="b1">Barang Masuk</button>
    <button class="button button3" id="b2">Barang Keluar</button>
    <button class="button button5" id="b3">Peminjaman</button>
    <!-- DataTales Example -->
    <div class="card shadow mb-4" id="one" style="display:block">
        <div class="card-header py-sm-5">
            <h4 class="float-left">Barang Masuk Hari Ini</h4>
            <a href="<?=base_url();?>process/cetak_barang_masuk_today.php" target="_blank"
                class="btn btn-info btn-icon-split btn-sm float-right">
                <span class="icon text-white-50">
                    <i class="fas fa-print"></i>
                </span>
                <span class="text">Cetak</span>
            </a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                        <th width="20">No</th>
                            <th>Tanggal</th>
                            <th>Tanggal PO</th>
                            <th>No PO</th>
                            <th>Project Name</th>
                            <th>Nama Barang</th>
                            <th>Merek</th>
                            <th>Tipe</th>
                            <th>Jumlah Masuk</th>
                            <th>Satuan</th>
                            <th>Keterangan</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $n=1;
                        $query = mysqli_query($con,"SELECT x.*,x1.nama_barang,x1.tipe,x2.nama_merek,x3.nama_satuan
                        FROM barang_masuk x JOIN barang x1 ON x1.idbarang=x.barang_id 
                        JOIN merek x2 ON x2.idmerek=x1.merek_id 
                        JOIN satuan x3 ON x3.id_satuan=x.satuan_id
                        WHERE x.tanggal='$now' ORDER BY x.idbarang_masuk DESC")or die(mysqli_error($con));
                        while($row = mysqli_fetch_array($query)):
                        ?>
                        <tr>
                        <td><?= $n++; ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tanggal'])); ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tanggal_po'])); ?></td>
                            <td><?= $row['no_po']; ?></td>
                            <td><?= $row['project_name']; ?></td>
                            <td><?= $row['nama_barang']; ?></td>
                            <td><?= $row['nama_merek']; ?></td>
                            <td><?= $row['tipe']; ?></td>
                            <td><?= $row['jumlah']; ?></td>
                            <td><?= $row['nama_satuan']; ?></td>
                            <td><?= $row['keterangan']; ?></td>
                        </tr>
                        <?php endwhile; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- DataTales Example -->
    <div class="card shadow mb-4" id="two" style="display:none">
        <div class="card-header py-5">
            <h4 class="float-left">Barang Keluar Hari Ini</h4>
            <a href="<?=base_url();?>process/cetak_barang_keluar_today.php" target="_blank"
                class="btn btn-info btn-icon-split btn-sm float-right">
                <span class="icon text-white-50">
                    <i class="fas fa-print"></i>
                </span>
                <span class="text">Cetak</span>
            </a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th width="20">No</th>
                            <th>Tanggal</th>
                            <th>Nama Barang</th>
                            <th>Merek</th>
                            <th>Tipe</th>
                            <th>Keterangan</th>
                            <th>Jumlah Keluar</th>
                            <th>Tanggal BAST</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $n=1;
                        $query = mysqli_query($con,"SELECT x.*,x1.nama_barang,x1.tipe,x2.nama_merek 
                        FROM barang_keluar x 
                        JOIN barang x1 ON x1.idbarang=x.barang_id 
                        JOIN merek x2 ON x2.idmerek=x1.merek_id 
                        WHERE x.tanggal='$now' ORDER BY x.idbarang_keluar DESC")or die(mysqli_error($con));
                        while($row = mysqli_fetch_array($query)):
                        ?>
                        <tr>
                            <td><?= $n++; ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tanggal'])); ?></td>
                            <td><?= $row['nama_barang']; ?></td>
                            <td><?= $row['nama_merek']; ?></td>
                            <td><?= $row['tipe']; ?></td>
                            <td><?= $row['keterangan']; ?></td>
                            <td><?= $row['jumlah']; ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tanggal_bast'])); ?></td>
                        </tr>
                        <?php endwhile; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="card shadow mb-4" id="three" style="display:none">
        <div class="card-header py-5">
            <h4 class="float-left">Peminjaman Hari Ini</h4>
            <a href="<?=base_url();?>process/cetak_peminjaman_today.php" target="_blank"
                class="btn btn-info btn-icon-split btn-sm float-right">
                <span class="icon text-white-50">
                    <i class="fas fa-print"></i>
                </span>
                <span class="text">Cetak</span>
            </a>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th width="20">No</th>
                            <th>Id Peminjaman</th>
                            <th>Nama Barang</th>
                            <th>Jumlah</th>
                            <th>Tanggal Pinjam</th>
                            <th>Tanggal Kembali</th>
                            <th>Konsumen</th>
                            <th>Divisi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $n=1;
                        $query = mysqli_query($con,"SELECT x.*,x1.nama_barang,x2.nama_konsumen,x3.nama_divisi
                        FROM peminjaman x JOIN barang x1 ON x1.idbarang=x.barang_id 
                        JOIN konsumen x2 ON x2.id_konsumen=x.konsumen_id 
                        JOIN divisi x3 ON x3.id_divisi=x.divisi_id
                        WHERE x.tgl_pinjam='$now' ORDER BY x.id_peminjaman DESC")or die(mysqli_error($con));
                        while($row = mysqli_fetch_array($query)):
                        ?>
                        <tr>
                            <td><?= $n++; ?></td>
                            <td><?= $row['id_peminjaman']; ?></td>
                            <td><?= $row['nama_barang']; ?></td>
                            <td><?= $row['jumlah']; ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tgl_pinjam'])); ?></td>
                            <td><?= date('d-m-Y',strtotime($row['tgl_kembali'])); ?></td>
                            <td><?= $row['nama_konsumen']; ?></td>
                            <td><?= $row['nama_divisi']; ?></td>
                        </tr>
                        <?php endwhile; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<!-- /.container-fluid -->
<script>
function swap(one, two, three) {
    document.getElementById(one).style.display = 'block';
    document.getElementById(two).style.display = 'none';
    document.getElementById(three).style.display = 'none';
}
document.getElementById('b1').addEventListener('click',function(e){
    swap('one','two','three');
});
document.getElementById('b2').addEventListener('click',function(e){
    swap('two','three','one');
});
document.getElementById('b3').addEventListener('click',function(e){
    swap('three','one','two');
});
</script>