Advertisement
endang_nuradi

laporan_transaksi_excel

Jan 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. //udah bener
  2. <?php
  3.  
  4. $koneksi = new mysqli("localhost", "root","","db_perpustakaan");
  5.  
  6. $filename = "transaksi_exel-(".date('d-m-y').").xls";
  7.  
  8. header("content-disposition: attachment; filename='$filename'");
  9. header("content-type: application/vdn.ms-exel");
  10. ?>
  11.  
  12. <h2>Laporan Transaksi</h2>
  13.  
  14. <table border="1">
  15. <tr>
  16. <th>No</th>
  17. <th>Judul</th>
  18. <th>NIM</th>
  19. <th>Nama</th>
  20. <th>Tanggal Pinjam</th>
  21. <th>Tanggal Kembali</th>
  22. <th>Terlambat</th>
  23. <th>Status</th>
  24. </tr>
  25. <?php
  26. $no = 1;
  27. $sql = $koneksi->query("select * from db_transaksi where status='pinjam'");
  28.  
  29. while ($data=$sql->fetch_assoc()) {
  30.  
  31. ?>
  32. <tr>
  33. <td><?php echo $no++;?></td>
  34. <td><?php echo $data['judul'];?></td>
  35. <td><?php echo $data['nim'];?></td>
  36. <td><?php echo $data['nama'];?></td>
  37. <td><?php echo $data['tgl_pinjam'];?></td>
  38. <td><?php echo $data['tgl_kembali'];?></td>
  39. <td>
  40. <?php
  41. $denda = 1000;
  42.  
  43. $tgl_dateline = $data['tgl_kembali'];
  44. $tgl_kembali = date('Y-m-d');
  45.  
  46. $lambat = terlambat($tgl_dateline, $tgl_kembali);
  47. $denda1 = $lambat*$denda;
  48.  
  49. if($lambat>0){
  50. echo "<font color='red'>$lambat hari<br>(Rp $denda1)</font>";
  51. }else{
  52. echo $lambat."Hari";
  53. }
  54. ?>
  55. </td>
  56. <td><?php echo $data['status'];?></td>
  57. </tr>
  58.  
  59. <?php } ?>
  60. </table>
  61.  
  62. <?php
  63.  
  64. function terlambat($tgl_dateline, $tgl_kembali){
  65. $tgl_dateline_pecah = explode("-", $tgl_dateline);
  66. $tgl_dateline_pecah = $tgl_dateline_pecah[2]."-".$tgl_dateline_pecah[1]."-".$tgl_dateline_pecah[0];
  67.  
  68. $tgl_kembali_pecah = explode("-", $tgl_kembali);
  69. $tgl_kembali_pecah = $tgl_kembali_pecah[2]."-".$tgl_kembali_pecah[1]."-".$tgl_kembali_pecah[0];
  70.  
  71. $selisih = strtotime($tgl_kembali_pecah)-strtotime($tgl_dateline_pecah);
  72.  
  73. $selisih = $selisih/86400;
  74.  
  75. if($selisih>=1){
  76. $hasil_tgl = floor($selisih);
  77. }else{
  78. $hasil_tgl = 0;
  79. }
  80. return $hasil_tgl;
  81.  
  82.  
  83. }
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement