Advertisement
Ikki_wrs

tanya

Feb 4th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. <?php
  2. $db_host = 'localhost';
  3. $db_port = '3306';
  4. $db_name = 'sista';
  5. $db_user = 'root';
  6. $db_pass = '';
  7.  
  8. try {
  9. $pdo = new PDO( 'mysql:host='.$db_host.';port='.$db_port.';dbname='.$db_name , $db_user, $db_pass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1) );
  10. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. }
  12. catch(PDOException $e)
  13. {
  14. $errMessage = 'Gagal terhubung dengan MySQL' . ' # MYSQL ERROR:' . $e->getMessage();
  15. die($errMessage);
  16. }
  17. ?>
  18. <?php
  19. if(isset($_GET['Cetak'])){
  20. $aa=$_GET['tgl_a'];
  21. $ab=$_GET['tgl_b'];
  22. $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";
  23. $stmt = $pdo->prepare($sql);
  24. $stmt->execute();
  25.  
  26. echo '<html>
  27. <head>
  28. <title>Laporan Tagihan</title>
  29. <style>
  30. body {font-family:tahoma, arial}
  31. table {border-collapse: collapse}
  32. th, td {font-size: 13px; border: 1px solid #DEDEDE; padding: 3px 5px; color: #303030}
  33. th {background: #CCCCCC; font-size: 12px; border-color:#B0B0B0}
  34. .subtotal td {background: #F8F8F8}
  35. .right{text-align: right}
  36. </style>
  37. </head>
  38. <body>';
  39.  
  40. function format_ribuan ($nilai){
  41. return number_format ($nilai, 0, ',', '.');
  42.  
  43. }
  44.  
  45. // Ubah hasil query menjadi associative array dan simpan kedalam variabel result
  46. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  47.  
  48. echo '<table>
  49. <thead>
  50. <tr>
  51. <th>#</th>
  52. <th>Tanggal</th>
  53. <th>No-Kwitansi</th>
  54. <th>Nama Tagihan</th>
  55. <th>Keterangan</th>
  56. <th>Total Tagihan</th>
  57. <th>Total Bayar</th>
  58. <th>Sisa Tagihan</th>
  59. </tr>
  60. </thead>
  61. <tbody>';
  62.  
  63. $subtotal_fungsi = $total1 = 0;
  64. $subtotal_fungsi = $total2 = 0;
  65. $subtotal_fungsi = $total3 = 0;
  66. foreach ($result as $key => $row)
  67. {
  68. //$subtotal_plg += $row['jml_byr'];
  69. $subtotal_fungsi += $row['jml_byr'];
  70. $a2 = $row['bayar'];
  71. $a1 = $row['total'];
  72. $saldo = $row['saldo'];
  73.  
  74. echo '<tr>
  75. <td align=right>'.$row['idmemo'].'</td>
  76. <td align=right>'.$row['tgl_memo'].'</td>
  77. <td align=right>'.$row['nokwitansi'].'</td>
  78. <td align=right>'.$row['ket_memo'].'</td>
  79. <td align=right></td>
  80. <td align=right>'.format_ribuan($a2).'</td>
  81. <td></td>
  82. </tr>';
  83.  
  84. /* SUB TOTAL per id_pelanggan
  85. if (@$result[$key+1]['id_pelanggan'] != $row['id_pelanggan']) {
  86. echo '<tr class="subtotal">
  87. <td></td>
  88. <td>SUB TOTAL</td>
  89. <td></td>
  90. <td class="right">'.format_ribuan($subtotal_plg).'</td>
  91. </tr>';
  92. $subtotal_plg = 0;
  93. }
  94.  
  95. */// SUB TOTAL per thn_br
  96. if (@$result[$key+1]['nokwitansi'] != $row['nokwitansi']) {
  97. echo '<tr class="subtotal">
  98. <td colspan="5"><b>SUB TOTAL</b> : ' . $row['nokwitansi'] . ' - ' . $row['keterangan'].'</td>
  99. <td class="right">'.format_ribuan($a1).'</td>
  100. <td class="right">'.format_ribuan($subtotal_fungsi).'</td>
  101. <td class="right">'.format_ribuan($saldo).'</td>
  102. </tr>';
  103. $subtotal_fungsi = 0;
  104. }
  105. $total1 += $row['jml_byr'];
  106. $total2 += $row['tot_bayar'];
  107. $total3 += $row['tot_saldo'];
  108.  
  109.  
  110. }
  111.  
  112. echo '<tr class="total">
  113. <td colspan="5"><B>GRAND TOTAL</B></td>
  114. <td class="right"> ' . format_ribuan($total2) . '</td>
  115. <td class="right"> ' . format_ribuan($total1) . '</td>
  116. <td class="right"> ' . format_ribuan($total3) . '</td>
  117. </tr>
  118. </tr>
  119.  
  120. </tbody>
  121. </table>
  122. </body>
  123. </html>';
  124. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement