<script type="text/javascript" src="Chart/Chart.js"></script>
<?php 
mysql_select_db($database_sistem, $sistem);
$query_jumlah_penerimaan = "SELECT sum(debet)as Penerimaan, sum(kredit)as Pengeluaran FROM transaksi_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]'";
$jumlah_penerimaan = mysql_query($query_jumlah_penerimaan, $sistem) or die(mysql_error());
$row_jumlah_penerimaan = mysql_fetch_assoc($jumlah_penerimaan);
$totalRows_jumlah_penerimaan = mysql_num_rows($jumlah_penerimaan);

mysql_select_db($database_sistem, $sistem);
$query_saldo = "SELECT * FROM saldo_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]'";
$saldo = mysql_query($query_saldo, $sistem) or die(mysql_error());
$row_saldo = mysql_fetch_assoc($saldo);
$totalRows_saldo = mysql_num_rows($saldo);

mysql_select_db($database_sistem, $sistem);
$query_saldo4100 = "SELECT sum(debet)as ttl_dbt, sum(kredit)as ttl_krd FROM transaksi_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]' and transaksi='Kas' and akun='4100'";
$saldo4100 = mysql_query($query_saldo4100, $sistem) or die(mysql_error());
$row_saldo4100 = mysql_fetch_assoc($saldo4100);
$totalRows_saldo4100 = mysql_num_rows($saldo4100);

mysql_select_db($database_sistem, $sistem);
$query_saldo4200 = "SELECT sum(debet)as ttl_dbt, sum(kredit)as ttl_krd FROM transaksi_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]' and transaksi='Kas' and akun='4200'";
$saldo4200 = mysql_query($query_saldo4200, $sistem) or die(mysql_error());
$row_saldo4200 = mysql_fetch_assoc($saldo4200);
$totalRows_saldo4200 = mysql_num_rows($saldo4200);

mysql_select_db($database_sistem, $sistem);
$query_saldo4300 = "SELECT sum(debet)as ttl_dbt, sum(kredit)as ttl_krd FROM transaksi_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]' and transaksi='Kas' and akun='4300'";
$saldo4300 = mysql_query($query_saldo4300, $sistem) or die(mysql_error());
$row_saldo4300 = mysql_fetch_assoc($saldo4300);
$totalRows_saldo4300 = mysql_num_rows($saldo4300);

mysql_select_db($database_sistem, $sistem);
$query_saldo4400 = "SELECT sum(debet)as ttl_dbt, sum(kredit)as ttl_krd FROM transaksi_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]' and transaksi='Kas' and akun='4400'";
$saldo4400 = mysql_query($query_saldo4400, $sistem) or die(mysql_error());
$row_saldo4400 = mysql_fetch_assoc($saldo4400);
$totalRows_saldo4400 = mysql_num_rows($saldo4400);

mysql_select_db($database_sistem, $sistem);
$query_saldo4500 = "SELECT sum(debet)as ttl_dbt, sum(kredit)as ttl_krd FROM transaksi_tb where bulan='$bulan' and tahun='$tahun' and kode_unit='$_SESSION[kode]' and transaksi='Kas' and akun='4500'";
$saldo4500 = mysql_query($query_saldo4500, $sistem) or die(mysql_error());
$row_saldo4500 = mysql_fetch_assoc($saldo4500);
$totalRows_saldo4500 = mysql_num_rows($saldo4500);
?>
 <table width="100%" border="0" align="center" cellpadding="2" cellspacing="2"  class="form_body">
   <tr>
     <td width="35%" rowspan="2" align="left" valign="bottom"><div style="width: 400px; height:300px; position:inherit;">
              <p>
              <canvas id="myChart"></canvas>
            </p>  
     <script>
		var ctx = document.getElementById("myChart").getContext('2d');
		var myChart = new Chart(ctx, {
    type: 'bar',
			data: {
				labels: ["Penerimaan", "Pengeluaran"],
				datasets: [{
					label: '',
					data: [<?php echo $row_jumlah_penerimaan['Penerimaan'].','.$row_jumlah_penerimaan['Pengeluaran'];?>],
					backgroundColor: [
					'rgba(54, 162, 235, 0.2)',
					'rgba(255, 99, 132, 0.2)',
					'rgba(721, 710, 140, 0.2)'
					],
					borderColor: [
					'rgba(54, 162, 235, 1)',
					'rgba(255,99,132,1)',
					'rgba(74, 112, 35, 1)'
					],
					borderWidth: 1
				}]
			},
			options: {
				scales: {
					yAxes: [{
						ticks: {
							beginAtZero:true
						}
					}]
				}
			}
		});
	          </script></div></td>
     <td align="left" valign="top"><h4 style="color:#063">Penerimaan Kas (Recent)</h4></td>
   </tr>
   <tr>
     <td width="50%" align="left" valign="top">
       <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css">
       
       <script src="media/js/jquery.dataTables.js"></script>
       
       <script type="text/javascript" charset="utf-8">
          $(document).ready(function(){
            $('#transaksi, #transaksi2').dataTable({
					     "oLanguage": {
						      "sLengthMenu": "Tampilkan _MENU_ data per halaman",
						      "sSearch": "Pencarian: ", 
						      "sZeroRecords": "Maaf, tidak ada data yang ditemukan",
						      "sInfo": "Menampilkan _START_ s/d _END_ dari _TOTAL_ data",
						      "sInfoEmpty": "Menampilkan 0 s/d 0 dari 0 data",
						      "sInfoFiltered": "(di filter dari _MAX_ total data)",
						      "oPaginate": {
						          "sFirst": "<<",
						          "sLast": ">>", 
						          "sPrevious": "<", 
						          "sNext": ">"
					       }
				      },
              "sPaginationType":"full_numbers",
              "bJQueryUI":true
            });
          })    
        </script>
       <table  id="transaksi2" class="display" width="100%" border="0" align="left" cellpadding="1" cellspacing="1">
         <thead>
           <tr height="40" class="form_body">
             <th width="20" height="30" align="center">No</th>
             <th width="40" align="center">Tgl</th>
             <th width="100" align="center">Keterangan</th>
             <th width="20" align="center">Ref (D)</th>
             <th width="20" align="center">Ref (K)</th>
             <th width="30" height="30" align="center">Debet</th>
             <th width="30" height="30" align="center">Kredit</th>
           </tr>
         </thead>
         <tbody>
           <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * FROM transaksi_tb WHERE bulan='$bulan' AND tahun='$tahun' AND kode_unit='$_SESSION[kode]' and jenis_rincian='Pendapatan' order by waktu_catat desc");
					       
                     ($r = mysql_fetch_array($sql));
					 
						                       echo "
		  <tr height='30' class='isi_tabel'> 									   
          <td align='center'>1(a)</td>
          <td align='center'>$r[tgl_update]</td>
          <td align='left'>Penerimaan Kas diterima</td>
          <td align='center'>1110</td>
          <td align='center'>-</td>
          <td align='right'>";?><?php echo formatRupiah($r['debet']);?><?php echo "</td>
          <td align='right'>-</td>
          </tr>
		   <tr height='30' class='isi_tabel'> 									   
          <td align='center'>1(b)</td>
          <td align='center'></td>
          <td align='left'>$r[keterangan]</td>
          <td align='center'>-</td>
          <td align='center'>$r[no_perkiraan]</td>
          <td align='right'>-</td>
          <td align='right'>";?><?php echo formatRupiah($r['debet']);?><?php echo "</td>
          </tr>";
                    ?>
         </tbody>
       </table>
     </td>
   </tr>
   <tr>
     <td rowspan="2" align="left"><div style="width: 400px; height:300px; position:inherit;">
       <p>
         <canvas id="myChart1"></canvas>
        </p>
       <script>
		var ctx = document.getElementById("myChart1").getContext('2d');
		var myChart = new Chart(ctx, {
    type: 'bar',
			data: {
				labels: ["4100", "4200", "4300", "4400", "4500"],
				datasets: [{
					label: '',
					data: [<?php echo $row_saldo4100['ttl_dbt'].','.$row_saldo4200['ttl_dbt'].','.$row_saldo4300['ttl_dbt'].','.$row_saldo4400['ttl_dbt'].','.$row_saldo4500['ttl_dbt'];?>],
					backgroundColor: [
					'rgba(54, 162, 235, 0.2)',
					'rgba(255, 99, 132, 0.2)',
					'rgba(54, 162, 235, 0.2)',
					'rgba(721, 710, 140, 0.2)',
					'rgba(255, 99, 132, 0.2)'
					],
					borderColor: [
					'rgba(54, 162, 235, 1)',
					'rgba(255,99,132,1)',
					'rgba(74, 112, 35, 1)',
					'rgba(54, 162, 235, 1)'
					],
					borderWidth: 1
				}]
			},
			options: {
				scales: {
					yAxes: [{
						ticks: {
							beginAtZero:true
						}
					}]
				}
			}
		});
	        </script>
     </div></td>
     <td align="left"><h4 style="color:#063">Pengeluaran Kas (Recent)</h4></td>
   </tr>
   <tr>
     <td align="left" valign="top"><table  id="transaksi" class="display" width="100%" border="0" align="left" cellpadding="1" cellspacing="1">
       <thead>
         <tr height="40" class="form_body">
           <th width="20" height="30" align="center">No</th>
           <th width="40" align="center">Tgl</th>
           <th width="100" align="center">Keterangan</th>
           <th width="20" align="center">Ref (D)</th>
           <th width="20" align="center">Ref (K)</th>
           <th width="30" height="30" align="center">Debet</th>
           <th width="30" height="30" align="center">Kredit</th>
          </tr>
        </thead>
       <tbody>
         <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * FROM transaksi_tb WHERE bulan='$bulan' AND tahun='$tahun' AND kode_unit='$_SESSION[kode]' and jenis_rincian='Pengeluaran' order by waktu_catat desc");
					       
                     ($r = mysql_fetch_array($sql));
					 
						                       echo "
		  <tr height='30' class='isi_tabel'> 									   
          <td align='center'>1(a)</td>
          <td align='center'>$r[tgl_update]</td>
          <td align='left'>Pengeluaran Kas</td>
          <td align='center'>-</td>
          <td align='center'>1110</td>
          <td align='right'>-</td>
          <td align='right'>";?>
         <?php echo formatRupiah($r['kredit']);?><?php echo "</td>          
          </tr>
		   <tr height='30' class='isi_tabel'> 									   
         <td align='center'>1(b)</td>
          <td align='center'></td>
          <td align='left'>$r[keterangan]</td>
          <td align='center'>$r[no_perkiraan]</td>
          <td align='center'>-</td>
          <td align='right'>";?><?php echo formatRupiah($r['kredit']);?><?php echo "</td>
          <td align='right'>-</td>
          </tr>";
                    ?>
        </tbody>
     </table></td>
   </tr>
   <tr>
     <td align="left"></td>
     <td align="left"></td>
   </tr>
   <tr>
     <td align="center">  </td>
     <td align="center">&nbsp;</td>
   </tr>
 </table>
 <p>&nbsp;</p>
 