SHOW:
|
|
- or go back to the newest paste.
| 1 | - | //masih salah |
| 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 | - | $denda = 1000; |
| 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 | - | echo "<font color='red'>$lambat hari<br>(Rp $denda1)</font>"; |
| 53 | + | |
| 54 | <td>'.$data['tgl_kembali'].'</td> | |
| 55 | - | echo $lambat."Hari"; |
| 55 | + | |
| 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 | - | ?> |
| 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 | } |