Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //harusnya udah bener
- <?php
- $koneksi = new mysqli("localhost","root","","db_perpustakaan");
- $content = '
- <style type="text/css">
- .tabel{border-collapse: collapse;}
- .tabel th{padding: 8px 5px; background-color: #cccccc;}
- .tabel td{padding: 8px 5px;}
- </style>
- ';
- $content .= '
- <page>
- <h2> Laporan Data Transaksi </h2>
- <table border="1" class="tabel">
- <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>';
- $no = 1;
- $sql = $koneksi->query("select * from db_transaksi where status='pinjam'");
- while ($data=$sql->fetch_assoc()) {
- $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){
- $status= "<font color='red'>$lambat hari<br>(Rp $denda1)</font>";
- }else{
- $status= $lambat."Hari";
- }
- $content .='
- <tr>
- <td>'.$no++.'</td>
- <td>'.$data['judul'].'</td>
- <td>'.$data['nim'].'</td>
- <td>'.$data['nama'].'</td>
- <td>'.$data['tgl_pinjam'].'</td>
- <td>'.$data['tgl_kembali'].'</td>
- <td>
- '.
- $status
- .'
- </td>
- <td>'.$data['status'].'</td>
- </tr>
- ';
- }
- $content.='
- </table>
- </page>';
- require_once('../assets/html2pdf/html2pdf.class.php');
- $html2pdf = new HTML2PDF('P','A4', 'fr');
- $html2pdf->WriteHTML($content);
- $html2pdf->Output('exemple.pdf');
- ?>
- <?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;
- }
- /*
- ---------------------
- jalanin query dalam fungsi
- nb: tidak disarankan walau ini jalan
- */
- function coba_query(){
- global $koneksi;
- $query = $koneksi->query("select * from db_transaksi where status='pinjam'");
- return $data=$query->fetch_assoc();
- }
Advertisement
Add Comment
Please, Sign In to add comment