<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<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='-'";
$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='-'";
$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_unit = "SELECT * FROM user_tb WHERE user_tb.`level`='Unit'";
$unit = mysql_query($query_unit, $sistem) or die(mysql_error());
$row_unit = mysql_fetch_assoc($unit);
$totalRows_unit = mysql_num_rows($unit);
?>
 <table width="90%" border="0" align="center" cellpadding="5" cellspacing="5" class="form_body">
   <tr>
     <td align="center" valign="bottom"><div style="width: 600px; height:400px; 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>
              
       Diagram 1</p>
       </div>       </td>
   </tr>
   <tr>
     <td align="center">&nbsp;
       <table width="80%" border="0" cellpadding="2" cellspacing="2" class="form_body">
         <tr align="center">
           <td>kode unit</td>
           <td>nama unit</td>
           <td>alamat</td>
           <td>telp</td>
           <td>email</td>
           <td>direktur</td>
           <td>bendahara</td>
           <td>nama admin</td>
         </tr>
         <tr align="center">
           <td colspan="8"><hr></td>
         </tr>
         <?php do { ?>
           <tr align="center">
             <td><a href="?section=Setting&module=show&kodenya=<?php echo $row_unit['kode_unit'];?>"><?php echo $row_unit['kode_unit']; ?></a></td>
             <td><?php echo $row_unit['nama_unit']; ?></td>
             <td><?php echo $row_unit['alamat']; ?></td>
             <td><?php echo $row_unit['telp']; ?></td>
             <td><?php echo $row_unit['email']; ?></td>
             <td><?php echo $row_unit['direktur']; ?></td>
             <td><?php echo $row_unit['bendahara']; ?></td>
             <td><?php echo $row_unit['nama_admin']; ?></td>
           </tr>
           <?php } while ($row_unit = mysql_fetch_assoc($unit)); ?>
     </table></td>
   </tr>
 </table>
<p>&nbsp;</p>
 <?php
mysql_free_result($unit);
?>
