Advertisement
Ikki_wrs

Untitled

Dec 17th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <?php
  2. $db_host = 'localhost';
  3. $db_port = '3306';
  4. $db_name = 'krida-sysco';
  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. if(isset($_GET['Cetak'])){
  19. $aa=$_GET['tgl_a'];
  20. $ab=$_GET['tgl_b'];
  21. $cb=$_GET['cabang'];
  22. $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';
  23. $stmt = $pdo->prepare($sql);
  24. $stmt->execute();
  25.  
  26. echo '<html>
  27. <head>
  28. <title>CLAIM TAGIHAN BBM TOYOTA</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. // Ubah hasil query menjadi associative array dan simpan kedalam variabel result
  45. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  46.  
  47. echo '<table>
  48. <thead>
  49. <tr>
  50. <th>Voucher</th>
  51. <th>Tanggal</th>
  52. <th>Supir</th>
  53. <th>Nopol</th>
  54. <th>Kendaraan</th>
  55. <th>Subsidi</th>
  56. <th>Liter</th>
  57. <th>Harga</th>
  58. <th>Total</th>
  59. </tr>
  60. </thead>
  61. <tbody>';
  62.  
  63. $subtotal_thn = $total = 0;
  64. foreach ($result as $key => $row)
  65. {
  66. //$subtotal_plg += $row['jml_byr'];
  67. $subtotal_fungsi += $row['jml_byr'];
  68. echo '<tr>
  69. <td>'.$row['idp'].'</td>
  70. <td>'.$row['tgl'].'</td>
  71. <td>'.$row['nama'].'</td>
  72. <td>'.$row['nopol'].'</td>
  73. <td>'.$row['fungsi'].'</td>
  74. <td>'.$row['bbm'].'</td>
  75. <td>'.$row['harga'].'</td>
  76. <td class="right">'.format_ribuan($row['jml_byr']).'</td>
  77. </tr>';
  78.  
  79. /* SUB TOTAL per id_pelanggan
  80. if (@$result[$key+1]['id_pelanggan'] != $row['id_pelanggan']) {
  81. echo '<tr class="subtotal">
  82. <td></td>
  83. <td>SUB TOTAL</td>
  84. <td></td>
  85. <td class="right">'.format_ribuan($subtotal_plg).'</td>
  86. </tr>';
  87. $subtotal_plg = 0;
  88. }
  89.  
  90. */// SUB TOTAL per thn_br
  91. if (@$result[$key+1]['fungsi'] != $row['fungsi']) {
  92. echo '<tr class="subtotal">
  93. <td></td>
  94. <td>SUB TOTAL ' . $row['fungsi'] . '</td>
  95. <td></td>
  96. <td class="right">'.format_ribuan($subtotal_fungsi).'</td>
  97. </tr>';
  98. $subtotal_fungsi = 0;
  99. }
  100. $total += $row['jml_byr'];
  101. }
  102.  
  103. echo '<tr class="total">
  104. <td></td>
  105. <td>GRAND TOTAL</td>
  106. <td></td>
  107. <td class="right"> ' . format_ribuan($total) . '</td>
  108. </tr>
  109. </tbody>
  110. </table>
  111. </body>
  112. </html>';
  113. }?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement