Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //udah bener
- <?php
- $koneksi = new mysqli("localhost", "root","","db_perpustakaan");
- $filename = "transaksi_exel-(".date('d-m-y').").xls";
- header("content-disposition: attachment; filename='$filename'");
- header("content-type: application/vdn.ms-exel");
- ?>
- <h2>Laporan Transaksi</h2>
- <table border="1">
- <tr>
- <th>No</th>
- <th>Judul</th>
- <th>NIM</th>
- <th>Nama</th>
- <th>Tanggal Pinjam</th>
- <th>Tanggal Kembali</th>
- <th>Terlambat</th>
- <th>Status</th>
- </tr>
- <?php
- $no = 1;
- $sql = $koneksi->query("select * from db_transaksi where status='pinjam'");
- while ($data=$sql->fetch_assoc()) {
- ?>
- <tr>
- <td><?php echo $no++;?></td>
- <td><?php echo $data['judul'];?></td>
- <td><?php echo $data['nim'];?></td>
- <td><?php echo $data['nama'];?></td>
- <td><?php echo $data['tgl_pinjam'];?></td>
- <td><?php echo $data['tgl_kembali'];?></td>
- <td>
- <?php
- $denda = 1000;
- $tgl_dateline = $data['tgl_kembali'];
- $tgl_kembali = date('Y-m-d');
- $lambat = terlambat($tgl_dateline, $tgl_kembali);
- $denda1 = $lambat*$denda;
- if($lambat>0){
- echo "<font color='red'>$lambat hari<br>(Rp $denda1)</font>";
- }else{
- echo $lambat."Hari";
- }
- ?>
- </td>
- <td><?php echo $data['status'];?></td>
- </tr>
- <?php } ?>
- </table>
- <?php
- function terlambat($tgl_dateline, $tgl_kembali){
- $tgl_dateline_pecah = explode("-", $tgl_dateline);
- $tgl_dateline_pecah = $tgl_dateline_pecah[2]."-".$tgl_dateline_pecah[1]."-".$tgl_dateline_pecah[0];
- $tgl_kembali_pecah = explode("-", $tgl_kembali);
- $tgl_kembali_pecah = $tgl_kembali_pecah[2]."-".$tgl_kembali_pecah[1]."-".$tgl_kembali_pecah[0];
- $selisih = strtotime($tgl_kembali_pecah)-strtotime($tgl_dateline_pecah);
- $selisih = $selisih/86400;
- if($selisih>=1){
- $hasil_tgl = floor($selisih);
- }else{
- $hasil_tgl = 0;
- }
- return $hasil_tgl;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement