<?php

if($bulan=='Januari'){
	$bulannya='Desember';
	$tahunnya=$tahun-1;
}
elseif($bulan=='Februari'){
	$bulannya='Januari';
	$tahunnya=$tahun;
}
elseif($bulan=='Maret'){
	$bulannya='Februari';
	$tahunnya=$tahun;
}
elseif($bulan=='April'){
	$bulannya='Maret';
	$tahunnya=$tahun;
}
elseif($bulan=='Mei'){
	$bulannya='April';
	$tahunnya=$tahun;
}
elseif($bulan=='Juni'){
	$bulannya='Mei';
	$tahunnya=$tahun;
}
elseif($bulan=='Juli'){
	$bulannya='Juni';
	$tahunnya=$tahun;
}
elseif($bulan=='Agustus'){
	$bulannya='Juli';
	$tahunnya=$tahun;
}
elseif($bulan=='September'){
	$bulannya='Agustus';
	$tahunnya=$tahun;
}
elseif($bulan=='Oktober'){
	$bulannya='September';
	$tahunnya=$tahun;
}
elseif($bulan=='November'){
	$bulannya='Oktober';
	$tahunnya=$tahun;
}
elseif($bulan=='Desember'){
	$bulannya='November';
	$tahunnya=$tahun;
}

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&amp;module=kas_unit&amp;kodenya=<?php echo $row_unit['kode_unit'];?>&amp;nama=<?php echo $row_unit['nama_unit'];?>">Laporan Kas</a></td>
    <td align="center"><a href="?section=Report&amp;module=akb_unit&amp;kodenya=<?php echo $row_unit['kode_unit'];?>&amp;nama=<?php echo $row_unit['nama_unit'];?>">Laporan Arus Kas &amp; Bank</a></td>
    <td align="center"><a href="?section=Report&amp;module=labarug_unit&amp;kodenya=<?php echo $row_unit['kode_unit'];?>&amp;nama=<?php echo $row_unit['nama_unit'];?>">Laba Rugi</a></td>
    <td align="center"><a href="?section=Report&amp;module=bank_unit&amp;kodenya=<?php echo $row_unit['kode_unit'];?>&amp;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>&nbsp;</p>
<table width="90%" border="0" align="center" cellpadding="1" class="isi_tabel">
  <tr>
    <td colspan="2" valign="top"><h1 style="color:#033">Neraca</h1></td>
  </tr>
  <tr>
    <td colspan="2" valign="top"><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>
    <td width="50%" valign="top"><table width="90%" border="0" align="center" cellpadding="1" class="isi_tabel">
      <tr align="center">
        <td colspan="4"><hr /></td>
      </tr>
      <tr align="center">
        <td width="10%">Akun</td>
        <td width="20%">Keterangan</td>
        <td colspan="2">Saldo Akhir</td>
      </tr>
      <tr>
        <td colspan="4"><hr /></td>
      </tr>
      <tr>
        <td>Aktiva Lancar</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td align="center">1110</td>
        <td width="20%">Kas</td>
        <td width="5%" align="right">Rp.</td>
        <td width="15%" align="right"><a href="?section=Report&module=kas"><?php echo formatRupiah($row_saldo_akhir['col_1110']);?></a></td>
      </tr>
      <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where kode_unit='$_GET[kodenya]' and jenis='Bank' order by kode_bank asc");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "
      <tr>
        <td align='center'>1120</td>
        <td>$r[nama_bank] | $r[no_rek]</td>
        <td align='right' width='3%'>Rp.</td>
        <td align='right'>";?>
		<?php 
			if($r['kode_bank']=='Bank 1'){
		  $saldo_akhir=$row_saldo_akhir['col_1120a'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 2'){
		  $saldo_akhir=$row_saldo_akhir['col_1120b'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 3'){
		  $saldo_akhir=$row_saldo_akhir['col_1120c'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 4'){
		  $saldo_akhir=$row_saldo_akhir['col_1120d'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 5'){
		  $saldo_akhir=$row_saldo_akhir['col_1120e'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 6'){
		  $saldo_akhir=$row_saldo_akhir['col_1120f'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 7'){
		  $saldo_akhir=$row_saldo_akhir['col_1120g'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 8'){
		  $saldo_akhir=$row_saldo_akhir['col_1120h'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 9'){
		  $saldo_akhir=$row_saldo_akhir['col_1120i'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 10'){
		  $saldo_akhir=$row_saldo_akhir['col_1120j'];
		  echo formatRupiah($saldo_akhir);
			}
		  elseif($r['kode_bank']=='Bank 11'){
		  $saldo_akhir=$row_saldo_akhir['col_1120k'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 12'){
		  $saldo_akhir=$row_saldo_akhir['col_1120l'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 13'){
		  $saldo_akhir=$row_saldo_akhir['col_1120m'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 14'){
		  $saldo_akhir=$row_saldo_akhir['col_1120n'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 15'){
		  $saldo_akhir=$row_saldo_akhir['col_1120o'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 16'){
		  $saldo_akhir=$row_saldo_akhir['col_1120p'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 17'){
		  $saldo_akhir=$row_saldo_akhir['col_1120q'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 18'){
		  $saldo_akhir=$row_saldo_akhir['col_1120r'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 19'){
		  $saldo_akhir=$row_saldo_akhir['col_1120s'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Bank 20'){
		  $saldo_akhir=$row_saldo_akhir['col_1120t'];
		  echo formatRupiah($saldo_akhir);
			}
			else{
			}
			?>
		<?php echo"</td>
      </tr>";
	   $no++;
                    }
                    ?>
      <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where kode_unit='$_GET[kodenya]' and jenis='Deposito' order by kode_bank asc");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "
      <tr>
        <td align='center'>1130</td>
        <td>$r[nama_bank] | $r[no_rek]</td>
         <td align='right'>Rp.</td>
        <td align='right'>";?>
		<?php 
			if($r['kode_bank']=='Deposito 1'){
		  $saldo_akhir=$row_saldo_akhir['col_1130a'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 2'){
		  $saldo_akhir=$row_saldo_akhir['col_1130b'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 3'){
		  $saldo_akhir=$row_saldo_akhir['col_1130c'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 4'){
		  $saldo_akhir=$row_saldo_akhir['col_1130d'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 5'){
		  $saldo_akhir=$row_saldo_akhir['col_1130e'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 6'){
		  $saldo_akhir=$row_saldo_akhir['col_1130f'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 7'){
		  $saldo_akhir=$row_saldo_akhir['col_1130g'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 8'){
		  $saldo_akhir=$row_saldo_akhir['col_1130h'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 9'){
		  $saldo_akhir=$row_saldo_akhir['col_1130i'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 10'){
		  $saldo_akhir=$row_saldo_akhir['col_1130j'];
		  echo formatRupiah($saldo_akhir);
			}
		  elseif($r['kode_bank']=='Deposito 11'){
		  $saldo_akhir=$row_saldo_akhir['col_1130k'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 12'){
		  $saldo_akhir=$row_saldo_akhir['col_1130l'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 13'){
		  $saldo_akhir=$row_saldo_akhir['col_1130m'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 14'){
		  $saldo_akhir=$row_saldo_akhir['col_1130n'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 15'){
		  $saldo_akhir=$row_saldo_akhir['col_1130o'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 16'){
		  $saldo_akhir=$row_saldo_akhir['col_1130p'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 17'){
		  $saldo_akhir=$row_saldo_akhir['col_1130q'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 18'){
		  $saldo_akhir=$row_saldo_akhir['col_1130r'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 19'){
		  $saldo_akhir=$row_saldo_akhir['col_1130s'];
		  echo formatRupiah($saldo_akhir);
			}
			elseif($r['kode_bank']=='Deposito 20'){
		  $saldo_akhir=$row_saldo_akhir['col_1130t'];
		  echo formatRupiah($saldo_akhir);
			}
			else{
			}
			?>
		<?php echo"</td>
      </tr>";
	   $no++;
                    }
                    ?>
      <tr>
        <td align="center">1140</td>
        <td>Piutang</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1140']);?></td>
      </tr>
      <tr>
        <td align="center">1150</td>
        <td>Persediaan</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1150']);?></td>
      </tr>
      <tr>
        <td align="center">1160</td>
        <td>Piutang Lain</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1160']);?></td>
      </tr>
      <tr>
        <td align="center">1170</td>
        <td>Investasi Lainnya</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1170']);?></td>
      </tr>
      <tr>
        <td colspan="4" align="center"><hr /></td>
      </tr>
      <tr>
        <td align="left">&nbsp;</td>
        <td align="left">&nbsp;</td>
        <td align="right">Rp.</td>
        <td align="right"><?php
        $tal=$row_saldo_akhir['col_1110']+$row_saldo_akhir['col_1120a']+$row_saldo_akhir['col_1120b']+$row_saldo_akhir['col_1120c']+$row_saldo_akhir['col_1120d']+$row_saldo_akhir['col_1120e']+$row_saldo_akhir['col_1120f']+$row_saldo_akhir['col_1120g']+$row_saldo_akhir['col_1120h']+$row_saldo_akhir['col_1120i']+$row_saldo_akhir['col_1120j']+$row_saldo_akhir['col_1120k']+$row_saldo_akhir['col_1120l']+$row_saldo_akhir['col_1120m']+$row_saldo_akhir['col_1120n']+$row_saldo_akhir['col_1120o']+$row_saldo_akhir['col_1120p']+$row_saldo_akhir['col_1120q']+$row_saldo_akhir['col_1120r']+$row_saldo_akhir['col_1120s']+$row_saldo_akhir['col_1120t']+$row_saldo_akhir['col_1130a']+$row_saldo_akhir['col_1130b']+$row_saldo_akhir['col_1130c']+$row_saldo_akhir['col_1130d']+$row_saldo_akhir['col_1130e']+$row_saldo_akhir['col_1130f']+$row_saldo_akhir['col_1130g']+$row_saldo_akhir['col_1130h']+$row_saldo_akhir['col_1130i']+$row_saldo_akhir['col_1130j']+$row_saldo_akhir['col_1130k']+$row_saldo_akhir['col_1130l']+$row_saldo_akhir['col_1130m']+$row_saldo_akhir['col_1130n']+$row_saldo_akhir['col_1130o']+$row_saldo_akhir['col_1130p']+$row_saldo_akhir['col_1130q']+$row_saldo_akhir['col_1130r']+$row_saldo_akhir['col_1130s']+$row_saldo_akhir['col_1130t']+$row_saldo_akhir['col_1140']+$row_saldo_akhir['col_1150']+$row_saldo_akhir['col_1160']+$row_saldo_akhir['col_1170'];
echo formatRupiah($tal);
		
		?></td>
      </tr>
      <tr>
        <td colspan="4" align="left">Aktiva Tetap</td>
      </tr>
      <tr>
        <td align="center">1210</td>
        <td>Tanah</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1210']);?></td>
      </tr>
      <tr>
        <td align="center">1220</td>
        <td>Gedung</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1220']);?></td>
      </tr>
      <tr>
        <td align="center">1230</td>
        <td>Kendaraan</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1230']);?></td>
      </tr>
      <tr>
        <td align="center">1240</td>
        <td>Inventaris</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1240']);?></td>
      </tr>
      <tr>
        <td align="center">1250</td>
        <td>Aktiva Tetap Lainnya</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1250']);?></td>
      </tr>
      <tr>
        <td align="center">1300</td>
        <td>Akumulasi Penyusutan</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_1300']);?></td>
      </tr>
      <tr>
        <td colspan="4" align="center"><hr /></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td align="right">Rp.</td>
        <td align="right"><?php
        $tat=($row_saldo_akhir['col_1210']+$row_saldo_akhir['col_1220']+$row_saldo_akhir['col_1230']+$row_saldo_akhir['col_1240']+$row_saldo_akhir['col_1250'])-$row_saldo_akhir['col_1300'];
echo formatRupiah($tat);
		
		?></td>
        </tr>
      <tr>
        <td colspan="4"><hr /></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>TOTAL AKTIVA</td>
        <td align="right"><strong>Rp.</strong></td>
        <td align="right"><strong><?php
        $ja=$tal+$tat;
echo formatRupiah($ja);
		
		?></strong></td>
        </tr>
    </table></td>
    <td width="50%" valign="top"><table width="90%" border="0" align="center" cellpadding="1" class="isi_tabel">
      <tr align="center">
        <td colspan="4"><hr /></td>
      </tr>
      <tr align="center">
        <td width="10%">Akun</td>
        <td width="20%">Keterangan</td>
        <td colspan="2">Saldo Akhir</td>
      </tr>
          <tr>
            <td colspan="4"><hr /></td>
          </tr>
          <tr>
        <td>Kewajiban</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="center">2110</td>
        <td>Hutang Usaha</td>
        <td width="5%" align="right">Rp.</td>
        <td width="15%" align="right"><?php echo formatRupiah($row_saldo_akhir['col_2110']);?></td>
      </tr>
      <tr>
        <td align="center">2120</td>
        <td>Titipan</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_2120']);?></td>
      </tr>
      <tr>
        <td align="center">2130</td>
        <td>Sumbangan dengan Intensi</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_2130']);?></td>
      </tr>
      <tr>
        <td align="center">2140</td>
        <td>Pendapatan Diterima Dimuka</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_2140']);?></td>
      </tr>
      <tr>
        <td align="center">2150</td>
        <td>Biaya Yang Masih Harus Dibayar</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_2150']);?></td>
      </tr>
      <tr>
        <td colspan="4" align="center"><hr /></td>
        </tr>
      <tr>
        <td align="center">&nbsp;</td>
        <td>Total Kewajiban</td>
        <td align="right">Rp.</td>
        <td align="right"><strong>
          <?php
        $ttl_kwj=$row_saldo_akhir['col_2110']+$row_saldo_akhir['col_2120']+$row_saldo_akhir['col_2130']+$row_saldo_akhir['col_2140']+$row_saldo_akhir['col_2150'];
echo formatRupiah($ttl_kwj);
		
		?>
        </strong></td>
      </tr>
      <tr>
        <td height="200" align="center">&nbsp;</td>
        <td>&nbsp;</td>
        <td align="right">&nbsp;</td>
        <td align="right">&nbsp;</td>
      </tr>
      <tr>
        <td align="center">3000</td>
        <td>Modal</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_akhir['col_3000']);?></td>
      </tr>
      <tr>
        <td align="center">&nbsp;</td>
        <td>SHU</td>
        <td align="right">Rp.</td>
        <td align="right"><?php echo formatRupiah($row_saldo_awal['col_shu']+$row_saldo_akhir['col_shu']);?></td>
      </tr>
      <tr>
        <td colspan="4" align="center"><hr /></td>
        </tr>
      <tr>
        <td align="center">&nbsp;</td>
        <td>TOTAL PASIVA</td>
        <td align="right">Rp.</td>
        <td align="right"><strong>
          <?php
        $jhk=$row_saldo_akhir['col_2110']+$row_saldo_akhir['col_2120']+$row_saldo_akhir['col_2130']+$row_saldo_akhir['col_2140']+$row_saldo_akhir['col_2150']+$row_saldo_akhir['col_3000']+$row_saldo_akhir['col_shu'];
echo formatRupiah($jhk);
		
		?>
        </strong></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td valign="top">&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
