Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_host = 'localhost';
- $db_port = '3306';
- $db_name = 'sista';
- $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);
- }
- ?>
- <?php
- if(isset($_GET['Cetak'])){
- $aa=$_GET['tgl_a'];
- $ab=$_GET['tgl_b'];
- $sql = " select a.idmemo,b.nokwitansi,b.total,a.ket_memo,b.keterangan,a.tgl_memo,a.bayar,b.saldo,sum(b.total) AS tot_bayar,sum(b.saldo) AS tot_saldo ,sum(a.bayar) AS jml_byr from tagihan b, memorial a where a.nokwitansi=b.nokwitansi and a.tgl_memo>='$aa' and a.tgl_memo<='$ab' GROUP BY b.nokwitansi,a.idmemo";
- $stmt = $pdo->prepare($sql);
- $stmt->execute();
- echo '<html>
- <head>
- <title>Laporan Tagihan</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>#</th>
- <th>Tanggal</th>
- <th>No-Kwitansi</th>
- <th>Nama Tagihan</th>
- <th>Keterangan</th>
- <th>Total Tagihan</th>
- <th>Total Bayar</th>
- <th>Sisa Tagihan</th>
- </tr>
- </thead>
- <tbody>';
- $subtotal_fungsi = $total1 = 0;
- $subtotal_fungsi = $total2 = 0;
- $subtotal_fungsi = $total3 = 0;
- foreach ($result as $key => $row)
- {
- //$subtotal_plg += $row['jml_byr'];
- $subtotal_fungsi += $row['jml_byr'];
- $a2 = $row['bayar'];
- $a1 = $row['total'];
- $saldo = $row['saldo'];
- echo '<tr>
- <td align=right>'.$row['idmemo'].'</td>
- <td align=right>'.$row['tgl_memo'].'</td>
- <td align=right>'.$row['nokwitansi'].'</td>
- <td align=right>'.$row['ket_memo'].'</td>
- <td align=right></td>
- <td align=right>'.format_ribuan($a2).'</td>
- <td></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]['nokwitansi'] != $row['nokwitansi']) {
- echo '<tr class="subtotal">
- <td colspan="5"><b>SUB TOTAL</b> : ' . $row['nokwitansi'] . ' - ' . $row['keterangan'].'</td>
- <td class="right">'.format_ribuan($a1).'</td>
- <td class="right">'.format_ribuan($subtotal_fungsi).'</td>
- <td class="right">'.format_ribuan($saldo).'</td>
- </tr>';
- $subtotal_fungsi = 0;
- }
- $total1 += $row['jml_byr'];
- $total2 += $row['tot_bayar'];
- $total3 += $row['tot_saldo'];
- }
- echo '<tr class="total">
- <td colspan="5"><B>GRAND TOTAL</B></td>
- <td class="right"> ' . format_ribuan($total2) . '</td>
- <td class="right"> ' . format_ribuan($total1) . '</td>
- <td class="right"> ' . format_ribuan($total3) . '</td>
- </tr>
- </tr>
- </tbody>
- </table>
- </body>
- </html>';
- }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement