<?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;
}
}

mysql_select_db($database_sistem, $sistem);
$query_unit = "SELECT * FROM user_tb where level='Unit' group by kode_unit order by kode_unit asc";
$unit = mysql_query($query_unit, $sistem) or die(mysql_error());
$row_unit = mysql_fetch_assoc($unit);
$totalRows_unit = mysql_num_rows($unit);


?>

<table id="myTable1" width="90%" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td colspan="2">Nama Unit</td>
    <td width="150"><img src="images/kas.png" width="40" height="40"></td>
    <td width="150"><img src="images/arus_kas.png" width="40" height="40"></td>
    <td width="150"><img src="images/laba_rug.png" width="40" height="40"></td>
    <td width="150"><img src="images/banks.png" width="40" height="40"></td>
    <td width="150"><img src="images/neraca.png" width="40" height="40" /></td>
  </tr>
  <tr>
    <td colspan="7"><hr></td>
  </tr>
  <?php do { ?>
    <tr>
      <td width="100" align="center"><?php echo $row_unit['kode_unit'];?></td>
      <td align="center"><?php echo $row_unit['alamat'];?></td>
      <td align="center"><a href="?section=Report&module=kas_unit&kodenya=<?php echo $row_unit['kode_unit'];?>&nama=<?php echo $row_unit['nama_unit'];?>">Laporan Kas</a></td>
      <td align="center"><a href="?section=Report&module=akb_unit&kodenya=<?php echo $row_unit['kode_unit'];?>&nama=<?php echo $row_unit['nama_unit'];?>">Laporan Arus Kas &amp; Bank</a></td>
      <td align="center"><a href="?section=Report&module=labarug_unit&kodenya=<?php echo $row_unit['kode_unit'];?>&nama=<?php echo $row_unit['nama_unit'];?>">Laba Rugi</a></td>
      <td align="center"><a href="?section=Report&module=bank_unit&kodenya=<?php echo $row_unit['kode_unit'];?>&nama=<?php echo $row_unit['nama_unit'];?>">Laporan Bank</a></td>
      <td align="center"><a href="?section=Report&amp;module=neraca_unit&amp;kodenya=<?php echo $row_unit['kode_unit'];?>&amp;nama=<?php echo $row_unit['nama_unit'];?>">Laporan Neraca</a></td>
    </tr>
    <?php } while ($row_unit = mysql_fetch_assoc($unit)); ?>
    <tr>
      <td colspan="7" align="center"><hr /></td>
    </tr>
    
</table>
<p>
  <?php
mysql_free_result($unit);
?></p>


<?php
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);

mysql_select_db($database_sistem, $sistem);
$query_unit_a = "SELECT * FROM user_tb WHERE user_tb.`kode_unit`='$_GET[kodenya]'";
$unit_a = mysql_query($query_unit_a, $sistem) or die(mysql_error());
$row_unit_a = mysql_fetch_assoc($unit_a);
$totalRows_unit_a = mysql_num_rows($unit_a);
?>
<script type="text/javascript" charset="utf-8">
          $(document).ready(function(){
            $('#bbkas').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>

<p>&nbsp;</p>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="400" class="isi_tabel">
      <tr>
        <td colspan="3"><h1 style="color:#033">Index Buku Bank</h1></td>
      </tr>
      <tr>
        <td width="159">Bulan/ Tahun Lapor</td>
        <td width="10">:</td>
        <td width="215"><?php echo $bulan.'/ '.$tahun;?></td>
      </tr>
      <tr>
        <td>Unit</td>
        <td>:</td>
        <td><?php echo $row_unit_a['nama_unit'];?></td>
      </tr>
      <tr>
        <td>Tanggal</td>
        <td>:</td>
        <td><?php echo date('d-M-Y');?></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="90%" align="center"  bgcolor="#FFFFFF" class="display" id="bbkas">
      <thead>
        <tr height="30" class="form_body">
          <th align="center" width="100">No</th>
          <th align="center">Kode Bank</th>
          <th align="center">No.Rekening</th>
          <th align="center">Nama Bank</th>
          <th align="center">Saldo Awal</th>
          <th align="center">Saldo Akhir</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where kode_unit='$_GET[kodenya]' and jenis='Bank' order by kode_unit, kode_bank asc");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "<tr height='25'>
          <td align='center'>$no</td>
		  <td align='center'>$r[kode_bank]</td>";?>
          <?php
			if($r['kode_bank']=='Bank 1'){
		  $saldo=$row_saldo_awal['col_1120a'];
			}
			elseif($r['kode_bank']=='Bank 2'){
		  $saldo=$row_saldo_awal['col_1120b'];
			}
			elseif($r['kode_bank']=='Bank 3'){
		  $saldo=$row_saldo_awal['col_1120c'];
			}
			elseif($r['kode_bank']=='Bank 4'){
		  $saldo=$row_saldo_awal['col_1120d'];
			}
			else{
		  $saldo=$row_saldo_awal['col_1120e'];
			}
			?>
		  <?php echo
            "<td align='center'>";?><a href="?section=Report&module=bb_bank&no_rek=<?php echo $r['no_rek'];?>&saldo=<?php echo $saldo;?>&nama=<?php echo $_GET['nama'];?>"><?php echo $r['no_rek'];?></a><?php echo"</td>
			<td align='center'>$r[nama_bank]</td>
			<td align='right'>";?>
			<?php
			if($r['kode_bank']=='Bank 1'){
		  $saldo=$row_saldo_awal['col_1120a'];
		  echo formatRupiah($saldo);
			}
			elseif($r['kode_bank']=='Bank 2'){
		  $saldo=$row_saldo_awal['col_1120b'];
		  echo formatRupiah($saldo);
			}
			elseif($r['kode_bank']=='Bank 3'){
		  $saldo=$row_saldo_awal['col_1120c'];
		  echo formatRupiah($saldo);
			}
			elseif($r['kode_bank']=='Bank 4'){
		  $saldo=$row_saldo_awal['col_1120d'];
		  echo formatRupiah($saldo);
			}
			elseif($r['kode_bank']=='Bank 5'){
		  $saldo=$row_saldo_awal['col_1120e'];
		  echo formatRupiah($saldo);
			}
			else{
			}?>
			<?php echo"</td>
			<td align='right'>";?><?php 
			include 'module/_proses/hitung_bank.php';
			if($r['kode_bank']=='Bank 1'){
		  $saldo=$row_saldo_awal['col_1120a'];
		  echo formatRupiah(($saldo+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd']);
			}
			elseif($r['kode_bank']=='Bank 2'){
		  $saldo=$row_saldo_awal['col_1120b'];
		  echo formatRupiah(($saldo+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd']);
			}
			elseif($r['kode_bank']=='Bank 3'){
		  $saldo=$row_saldo_awal['col_1120c'];
		  echo formatRupiah(($saldo+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd']);
			}
			elseif($r['kode_bank']=='Bank 4'){
		  $saldo=$row_saldo_awal['col_1120d'];
		  echo formatRupiah(($saldo+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd']);
			}
			elseif($r['kode_bank']=='Bank 5'){
		  $saldo=$row_saldo_awal['col_1120e'];
		  echo formatRupiah(($saldo+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd']);
			}
			else{
			}
			?><?php echo"</td>
          </tr>";
                      $no++;
                    }
                    ?>
      </tbody>
      <tfoot>
        </tfoot>
    </table></td>
  </tr>
</table>
        