gundambison

koding perbaikan 34

Jan 20th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //harusnya udah bener
  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.  $denda = 1000;
  34.  
  35.            $tgl_dateline = $data['tgl_kembali'];
  36.            $tgl_kembali = date('Y-m-d');
  37.  
  38.            $lambat = terlambat($tgl_dateline, $tgl_kembali);
  39.            $denda1 = $lambat*$denda;
  40.  
  41.            if($lambat>0){
  42.              $status= "<font color='red'>$lambat hari<br>(Rp $denda1)</font>";
  43.            }else{
  44.              $status=  $lambat."Hari";
  45.            }
  46.  
  47.     $content .='
  48.    <tr>
  49.      <td>'.$no++.'</td>
  50.      <td>'.$data['judul'].'</td>
  51.      <td>'.$data['nim'].'</td>
  52.      <td>'.$data['nama'].'</td>
  53.      <td>'.$data['tgl_pinjam'].'</td>
  54.      <td>'.$data['tgl_kembali'].'</td>
  55.      <td>
  56.        '.
  57.           $status
  58.         .'
  59.      </td>
  60.      <td>'.$data['status'].'</td>
  61.    </tr>
  62.    ';
  63.  
  64.   }
  65.   $content.='
  66.    </table>
  67.  
  68.  </page>';
  69.  
  70.       require_once('../assets/html2pdf/html2pdf.class.php');
  71.       $html2pdf = new HTML2PDF('P','A4', 'fr');
  72.       $html2pdf->WriteHTML($content);
  73.       $html2pdf->Output('exemple.pdf');
  74.  
  75. ?>
  76.  
  77. <?php
  78.  
  79.   function terlambat($tgl_dateline, $tgl_kembali){
  80.     $tgl_dateline_pecah = explode("-", $tgl_dateline);
  81.     $tgl_dateline_pecah = $tgl_dateline_pecah[2]."-".$tgl_dateline_pecah[1]."-".$tgl_dateline_pecah[0];
  82.  
  83.     $tgl_kembali_pecah = explode("-", $tgl_kembali);
  84.     $tgl_kembali_pecah = $tgl_kembali_pecah[2]."-".$tgl_kembali_pecah[1]."-".$tgl_kembali_pecah[0];
  85.  
  86.     $selisih = strtotime($tgl_kembali_pecah)-strtotime($tgl_dateline_pecah);
  87.  
  88.     $selisih = $selisih/86400;
  89.  
  90.     if($selisih>=1){
  91.       $hasil_tgl = floor($selisih);
  92.     }else{
  93.       $hasil_tgl = 0;
  94.     }
  95.   return $hasil_tgl;
  96.  
  97.  
  98.   }
  99.  
  100. /*
  101. ---------------------
  102. jalanin query dalam fungsi
  103. nb: tidak disarankan walau ini jalan
  104. */
  105. function coba_query(){
  106. global $koneksi;
  107. $query = $koneksi->query("select * from db_transaksi where status='pinjam'");
  108.  
  109. return  $data=$query->fetch_assoc();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment