Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_host = 'localhost';
- $db_port = '3306';
- $db_name = 'krida-sysco';
- $db_user = 'root';
- $db_pass = '';
- try {
- $pdo = new PDO( 'mysql:host='.$db_host.';port='.$db_port.';dbname='.$db_name , $db_user, $db_pass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1) );
- $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e)
- {
- $errMessage = 'Gagal terhubung dengan MySQL' . ' # MYSQL ERROR:' . $e->getMessage();
- die($errMessage);
- }
- if(isset($_GET['Cetak'])){
- $aa=$_GET['tgl_a'];
- $ab=$_GET['tgl_b'];
- $cb=$_GET['cabang'];
- $sql = ' select a.ket,a.cabang,a.idp,a.tgl,a.jam,a.km,a.liter,a.total,sum(a.total) AS jml_byr,b.nik,b.nama, c.nopol,c.jenis,c.fungsi,d.bbm,d.harga from voucher a, staff b,kendaraan c,subsidi d where a.nik=b.nik and a.nopol=c.nopol and a.bbm=d.bbm and a.cabang ='$cb' and a.tgl>='$aa' and a.tgl<='$ab' GROUP BY c.fungsi';
- $stmt = $pdo->prepare($sql);
- $stmt->execute();
- echo '<html>
- <head>
- <title>CLAIM TAGIHAN BBM TOYOTA</title>
- <style>
- body {font-family:tahoma, arial}
- table {border-collapse: collapse}
- th, td {font-size: 13px; border: 1px solid #DEDEDE; padding: 3px 5px; color: #303030}
- th {background: #CCCCCC; font-size: 12px; border-color:#B0B0B0}
- .subtotal td {background: #F8F8F8}
- .right{text-align: right}
- </style>
- </head>
- <body>';
- function format_ribuan ($nilai){
- return number_format ($nilai, 0, ',', '.');
- }
- // Ubah hasil query menjadi associative array dan simpan kedalam variabel result
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
- echo '<table>
- <thead>
- <tr>
- <th>Voucher</th>
- <th>Tanggal</th>
- <th>Supir</th>
- <th>Nopol</th>
- <th>Kendaraan</th>
- <th>Subsidi</th>
- <th>Liter</th>
- <th>Harga</th>
- <th>Total</th>
- </tr>
- </thead>
- <tbody>';
- $subtotal_thn = $total = 0;
- foreach ($result as $key => $row)
- {
- //$subtotal_plg += $row['jml_byr'];
- $subtotal_fungsi += $row['jml_byr'];
- echo '<tr>
- <td>'.$row['idp'].'</td>
- <td>'.$row['tgl'].'</td>
- <td>'.$row['nama'].'</td>
- <td>'.$row['nopol'].'</td>
- <td>'.$row['fungsi'].'</td>
- <td>'.$row['bbm'].'</td>
- <td>'.$row['harga'].'</td>
- <td class="right">'.format_ribuan($row['jml_byr']).'</td>
- </tr>';
- /* SUB TOTAL per id_pelanggan
- if (@$result[$key+1]['id_pelanggan'] != $row['id_pelanggan']) {
- echo '<tr class="subtotal">
- <td></td>
- <td>SUB TOTAL</td>
- <td></td>
- <td class="right">'.format_ribuan($subtotal_plg).'</td>
- </tr>';
- $subtotal_plg = 0;
- }
- */// SUB TOTAL per thn_br
- if (@$result[$key+1]['fungsi'] != $row['fungsi']) {
- echo '<tr class="subtotal">
- <td></td>
- <td>SUB TOTAL ' . $row['fungsi'] . '</td>
- <td></td>
- <td class="right">'.format_ribuan($subtotal_fungsi).'</td>
- </tr>';
- $subtotal_fungsi = 0;
- }
- $total += $row['jml_byr'];
- }
- echo '<tr class="total">
- <td></td>
- <td>GRAND TOTAL</td>
- <td></td>
- <td class="right"> ' . format_ribuan($total) . '</td>
- </tr>
- </tbody>
- </table>
- </body>
- </html>';
- }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement