endang_nuradi

laporan_transaksi_pdf

Jan 20th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. //masih salah
  2. <?php
  3. $koneksi = new mysqli("localhost","root","","db_perpustakaan");
  4. $content = '
  5. <style type="text/css">
  6. .tabel{border-collapse: collapse;}
  7. .tabel th{padding: 8px 5px; background-color: #cccccc;}
  8. .tabel td{padding: 8px 5px;}
  9.  
  10. </style>
  11. ';
  12.  
  13. $content .= '
  14.  
  15. <page>
  16. <h2> Laporan Data Transaksi </h2>
  17. <table border="1" class="tabel">
  18. <tr>
  19. <th>No</th>
  20. <th>Judul</th>
  21. <th>NIM</th>
  22. <th>Nama</th>
  23. <th>Tanggal Pinjam</th>
  24. <th>Tanggal Kembali</th>
  25. <th>Terlambat</th>
  26. <th>Status</th>
  27. </tr>';
  28.  
  29. $no = 1;
  30. $sql = $koneksi->query("select * from db_transaksi where status='pinjam'");
  31.  
  32. while ($data=$sql->fetch_assoc()) {
  33.  
  34. $content .='
  35. <tr>
  36. <td>'.$no++.'</td>
  37. <td>'.$data['judul'].'</td>
  38. <td>'.$data['nim'].'</td>
  39. <td>'.$data['nama'].'</td>
  40. <td>'.$data['tgl_pinjam'].'</td>
  41. <td>'.$data['tgl_kembali'].'</td>
  42. <td>
  43. '.
  44. $denda = 1000;
  45.  
  46. $tgl_dateline = $data['tgl_kembali'];
  47. $tgl_kembali = date('Y-m-d');
  48.  
  49. $lambat = terlambat($tgl_dateline, $tgl_kembali);
  50. $denda1 = $lambat*$denda;
  51.  
  52. if($lambat>0){
  53. echo "<font color='red'>$lambat hari<br>(Rp $denda1)</font>";
  54. }else{
  55. echo $lambat."Hari";
  56. }
  57. .'
  58. </td>
  59. <td>'.$data['status'].'</td>
  60. </tr>
  61. ';
  62.  
  63. }
  64. $content.='
  65. </table>
  66.  
  67. </page>';
  68.  
  69. require_once('../assets/html2pdf/html2pdf.class.php');
  70. $html2pdf = new HTML2PDF('P','A4', 'fr');
  71. $html2pdf->WriteHTML($content);
  72. $html2pdf->Output('exemple.pdf');
  73.  
  74. ?>
  75.  
  76. <?php
  77.  
  78. function terlambat($tgl_dateline, $tgl_kembali){
  79. $tgl_dateline_pecah = explode("-", $tgl_dateline);
  80. $tgl_dateline_pecah = $tgl_dateline_pecah[2]."-".$tgl_dateline_pecah[1]."-".$tgl_dateline_pecah[0];
  81.  
  82. $tgl_kembali_pecah = explode("-", $tgl_kembali);
  83. $tgl_kembali_pecah = $tgl_kembali_pecah[2]."-".$tgl_kembali_pecah[1]."-".$tgl_kembali_pecah[0];
  84.  
  85. $selisih = strtotime($tgl_kembali_pecah)-strtotime($tgl_dateline_pecah);
  86.  
  87. $selisih = $selisih/86400;
  88.  
  89. if($selisih>=1){
  90. $hasil_tgl = floor($selisih);
  91. }else{
  92. $hasil_tgl = 0;
  93. }
  94. return $hasil_tgl;
  95.  
  96.  
  97. }
  98.  
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment