<?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'];?>">Laporan 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>
<p></p>
<table width="90%" border="0" align="center" class="form_body">
  <tr>
    <td colspan="8"><h1 style="color:#033">Laba Rugi</h1></td>
  </tr>
  <tr height="30">
    <td colspan="8" align="left" ><table width="400" class="isi_tabel">
      <tr>
        <td>Bulan/ Tahun Lapor</td>
        <td>:</td>
        <td><?php echo $bulan.'/ '.$tahun;?></td>
      </tr>
      <tr>
        <td>Unit</td>
        <td>:</td>
        <td><?php echo $_GET['nama'];?></td>
      </tr>
      <tr>
        <td>Tanggal</td>
        <td>:</td>
        <td><?php echo date('d-M-Y');?></td>
      </tr>
    </table></td>
  </tr>
  <tr height="30">
    <td width="100" align="center" background="images/bg1.png">Akun</td>
    <td align="center" background="images/bg1.png">Keterangan</td>
    <td colspan="6" align="center" background="images/bg1.png">Nominal</td>
  </tr>
  <tr height="30">
    <td colspan="8" align="left">Pendapatan</td>
  </tr>
  <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From akun_tb where kode_unit='All' and kelompok='Pendapatan' order by akun asc ");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "<tr>
          <td align='center'>$r[akun]</td>
          <td align='left'>$r[keterangan]</td>
          <td align='right'>Rp.</td>
          <td align='right'>";?>
  <?php 
			if($r['index']==''){
			include 'module/_report/hitung_pdp_lr_pus.php';
			}else{
				echo '';
			}
			?>
  <?php echo"</td>
          <td align='right'>Rp.</td>
          <td align='right'>";?>
  <?php 
			if($r['index']=='Ya'){
			include 'module/_report/hitung_pdp_index_lr_pus.php';
			}else{
				echo '';
			}
			?>
  <?php echo"</td>
          <td></td>
          <td></td>
        </tr>";
		 $no++;
                    }
                    ?>
  <tr height="30">
    <td colspan="2"></td>
    <td></td>
    <td></td>
    <td></td>
    <td align="right"><?php include 'module/_proses/hitung_ttl_pdp_lr_pus.php';?></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td colspan="8"><hr /></td>
  </tr>
  <tr height="30">
    <td colspan="8">Pengeluaran</td>
  </tr>
  <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From akun_tb where kode_unit='All' and kelompok='Pengeluaran' order by akun asc ");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "<tr>
          <td align='center'>$r[akun]</td>
          <td align='left'>$r[keterangan]</td>
          <td align='right'>Rp.</td>
          <td align='right'>";?>
  <?php 
			if($r['index']==''){
			include 'module/_report/hitung_pnl_lr_pus.php';
			}else{
				echo '';
			}
			?>
  <?php echo"</td>
          <td align='right'>Rp.</td>
          <td align='right'>";?>
  <?php 
			if($r['index']=='Ya'){
			include 'module/_report/hitung_pnl_index_lr_pus.php';
			}else{
				echo '';
			}
			?>
  <?php echo"</td>
          <td></td>
          <td></td>
        </tr>";
		 $no++;
                    }
                    ?>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right"><?php include 'module/_proses/hitung_ttl_pnl_lr_pus.php';?></td>
    <td align="right"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="8"><hr /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>Sisa Hasil Usaha</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right">Rp.</td>
    <td align="right"><?php 
  $lr=$ttl_pdp-$ttl_pnl;
  echo formatRupiah($lr);
  ?></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td align="right">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="8"><form id="form1" name="form1" method="post" action="?section=Report&amp;module=rekap&amp;shu=<?php echo $lr;?>">
      <table class="isi_tabel" width="70%" border="0" align="center">
        <tr>
          <td width="200">&nbsp;</td>
          <td width="10">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Tahun</td>
          <td>:</td>
          <td><?php echo $tahun;?></td>
        </tr>
        <tr>
          <td>Bulan</td>
          <td>:</td>
          <td><?php echo $bulan;?></td>
        </tr>
        <tr>
          <td>Laba diterima</td>
          <td>:</td>
          <td><?php 
  $lr=$ttl_pdp-$ttl_pnl;
  echo formatRupiah($lr);
  ?></td>
        </tr>
        </table>
    </form></td>
  </tr>
</table>
