<?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_saldo_awal = "SELECT sum(col_2110)as usaha, sum(col_2120)as bank, sum(col_2130)as pajak, sum(col_2140)as pdp, sum(col_2150)as bym FROM saldo_tb where kode_unit='$_GET[kodenya]' and bulan='$bulannya' and tahun='$tahunnya'";
$saldo_awal = mysql_query($query_saldo_awal, $sistem) or die(mysql_error());
$row_saldo_awal = mysql_fetch_assoc($saldo_awal);
$totalRows_saldo_awal = mysql_num_rows($saldo_awal);

mysql_select_db($database_sistem, $sistem);
$query_saldo_akhir = "SELECT sum(col_2110)as usaha, sum(col_2120)as bank, sum(col_2130)as pajak, sum(col_2140)as pdp, sum(col_2150)as bym FROM saldo_tb where kode_unit='$_GET[kodenya]' and bulan='$bulan' and tahun='$tahun'";
$saldo_akhir = mysql_query($query_saldo_akhir, $sistem) or die(mysql_error());
$row_saldo_akhir = mysql_fetch_assoc($saldo_akhir);
$totalRows_saldo_akhir = mysql_num_rows($saldo_akhir);
?>
<?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><h3>Tabel Data Unit</h3></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" align="center" cellpadding="2" cellspacing="2" class="form_body">
      <tr align="center">
        <td background="images/bg1.png"  height="30">kode unit</td>
        <td background="images/bg1.png">nama unit</td>
        <td background="images/bg1.png">alamat</td>
        <td background="images/bg1.png">telp</td>
        <td background="images/bg1.png">email</td>
        <td background="images/bg1.png">direktur</td>
        <td background="images/bg1.png">bendahara</td>
        <td background="images/bg1.png">nama admin</td>
      </tr>
      <tr align="center">
        <td colspan="8"><hr /></td>
      </tr>
      <?php do { ?>
      <tr align="center">
        <td><a href="?section=Report&module=show_hutang&amp;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>
      <tr align="center">
        <td colspan="8"><hr /></td>
      </tr>
      <?php } while ($row_unit = mysql_fetch_assoc($unit)); ?>
    </table></td>
  </tr>
  <tr>
    <td><table width="400" class="isi_tabel">
        <tr>
          <td colspan="3"><h1 style="color:#033">Index Buku Besar Hutang</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>
        <tr>
          <td>Cetak Laporan</td>
          <td>:</td>
          <td><a href="?section=Report&module=print&amp;bb=bb_kas"><img src="images/cetak1.png" width="41" height="32" /></a></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="90%" align="center"  bgcolor="#FFFFFF" class="display" id="bbkas">
      <thead>
        <tr class="form_body" height="30">
          <th align="center" width="48">No</th>
          <th width="95" align="center">Akun</th>
           <th width="104" align="center">Perkiraan</th>
          <th width="264" align="center">Keterangan</th>
          <th width="118" align="center">Saldo Awal</th>
          <th width="120" align="center">Saldo Akhir</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From akun_tb where kelompok='Hutang' order by akun");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "<tr height='25'>
          <td align='center'>$no</td>";?>
          <?php
		  $saldo_all=$row_saldo_awal['usaha']+$row_saldo_awal['bank']+$row_saldo_awal['pajak']+$row_saldo_awal['pdp']+$row_saldo_awal['bym'];
		  ?>
          <?php echo
			"<td align='center'>";?><a href="?section=Report&module=bb_hutang&akun=<?php echo $r['akun'];?>&saldo=<?php echo $saldo_all;?>&kodenya=<?php echo $_GET['kodenya'];?>"><?php echo $r['akun'];?></a><?php echo"</td>";?>
						<?php
			if($r['perkiraan']=='2110'){
		  $saldo=$row_saldo_awal['usaha'];
	
			}
			elseif($r['perkiraan']=='2120'){
		  $saldo=$row_saldo_awal['bank'];
	
			}
			elseif($r['perkiraan']=='2130'){
		  $saldo=$row_saldo_awal['pajak'];
	
			}
			elseif($r['perkiraan']=='1240'){
		  $saldo=$row_saldo_awal['pdp'];
	
			}
			elseif($r['perkiraan']=='2150'){
		  $saldo=$row_saldo_awal['bym'];
		
			}
			else{
			}?> 	

             <?php echo       
			"<td align='center'>";?><a href="?section=Report&module=bb_hutang_perkir&perkir=<?php echo $r['perkiraan'];?>&saldo=<?php echo $saldo;?>&kodenya=<?php echo $_GET['kodenya'];?>"><?php echo $r['perkiraan'];?></a><?php echo"</td>
			<td align='left'>$r[keterangan]</td>
			<td align='right'>";?>
			<?php
			if($r['perkiraan']=='2110'){
		  $saldo=$row_saldo_awal['usaha'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2120'){
		  $saldo=$row_saldo_awal['bank'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2130'){
		  $saldo=$row_saldo_awal['pajak'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2140'){
		  $saldo=$row_saldo_awal['pdp'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2150'){
		  $saldo=$row_saldo_awal['bym'];
		  echo formatRupiah($saldo);
			}
			else{
			}?>
			<?php echo"</td>
			<td align='right'>";?>
			<?php
			include 'module/_proses/hitung_aktiva_pus.php';
			if($r['perkiraan']=='2110'){
		  $saldo=($row_saldo_awal['usaha']+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2120'){
		  $saldo=($row_saldo_awal['bank']+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2130'){
		  $saldo=($row_saldo_awal['pajak']+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2140'){
		  $saldo=($row_saldo_awal['pdp']+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd'];
		  echo formatRupiah($saldo);
			}
			elseif($r['perkiraan']=='2150'){
		  $saldo=($row_saldo_awal['bym']+$row_saldo['ttl_dbt'])-$row_saldo['ttl_krd'];
		  echo formatRupiah($saldo);
			}
			else{
			}?>
			<?php echo"</td>
          </tr>";
                      $no++;
                    }
                    ?>
      </tbody>
      <tfoot>
        </tfoot>
    </table></td>
  </tr>
</table>
        