<?php
include '../../config/conn.php';
if ($_GET['aksi'] == '') {
  $jenis = $_GET['type'];

   if ($_GET['periode'] == 'y') {
    $tanggal1 = $_POST['tanggal1'];
    $tanggal2 = $_POST['tanggal2'];
    $tgl1 = date('Y-m-d', strtotime($tanggal1));
    $tgl2 = date('Y-m-d', strtotime($tanggal2));
   
  } else {
    $bln = date('m');
    $thn = date('Y');
   
  } 

?>
  <!-- page content -->
  <div class="col" role="main">
    <div class="">
      <div class="clearfix"></div>

      <div class="row">
        <div class="col-md-12">
          <div class="x_panel">
              
              <div class="analytics-sparkle-area">
              <div class="container-fluid">
                <div class="row">
                  <div class="animated flipInY col-lg-4 col-md-6 col-sm-6 col-xs-12">
                    <div class="analytics-sparkle-line reso-mg-b-30">
                      <div class="analytics-content">
                        <h5>AKSES PENGGUNA <br>
                         <?php 
                        $accuser = mysqli_query($conn, "SELECT * FROM pengaturan LIMIT 1");
                          $au = mysqli_fetch_array($accuser);
                        if($au['akses_pengguna']=='Y'){
                            echo "<h2 style='color:green';>AKTIF</h2>";
                        }else{ 
                            echo "<h2 style='color:red';>NONAKTIF</h2>";
                         
                        }
                        ?>
                        
                        
                           </h5>
                        <h6><span><div class="form-group">
                  <a href ="?module=aksespengguna&aksi=onoff" class="btn btn-success btn-xl"><span class="glyphicon glyphicon-off"></span></a>
                  
                </div></span></h6>
                       
                      </div>
                    </div>
                  </div>
                  
                </div>
              </div>
            </div>
              
              
              
              <!--//rekap new-->
            <div class="x_content">


              <table style="color:black;font-size:15px;" class="table table-bordered">
                <thead>
                  <tr>
                    <th width="15px">NO.</th>
                    <th>Jenis</th>
                    <th>Saldo</th>
                    <th>Detail</th>
                    
                 </tr>
                </thead>
         
                
                <tbody>
                    
                     <?php
                     $no=0;
                     $kas_total=0;
                  $namakas = mysqli_query($conn, "SELECT * FROM jenis_kas ORDER BY id");
                  while ($jenkas = mysqli_fetch_array($namakas)) {
                    $perkas = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(debit) as debit, SUM(kredit) as kredit 
                      FROM transaksi WHERE jenis_kas='$jenkas[id]' "));
                    $kas = $perkas['debit'] - $perkas['kredit'];
                    $kas_total=$kas_total + $kas;
                    $no++;
                  ?>

                    
                   <tr style="background: <?php if ($no % 2 == 0) { ?>
                          #defff1;
                          <?php } else { ?>
                            #f2f2f2;
                            <?php } ?>;">
                    <td><?php echo $no; ?></td>
                    <td ><b><h2></h2><?php echo $jenkas['nama']; ?></h2></b></td>
                    <td align="right"><b><h2>Rp. <?php echo rupiah($kas); ?></h2></b></td>
                    <td>
                         <form action="?module=perkas" enctype="multipart/form-data" method="POST">
                             <input type="hidden" value="<?php echo $jenkas['id']; ?>" name="jenis_kas">
                            <h6><span><input class='open_modal btn  btn-default btn-xs' type="submit" value="Detail" class="stretched-link"></span></h6>
                        </form>
                    </td>
                  </tr>
                 
                  <?php } ?>
                   <tr bgcolor="#defff1">
                   
                    <td colspan="2" align="center"><b><h2></h2>TOTAL</h2></b></td>
                    <td align="right"><b><h2>Rp. <?php echo rupiah($kas_total); ?></h2></b></td>
                    <td> 
                    
                    <form action="?module=perkas" enctype="multipart/form-data" method="POST">
                         <h6><span><input class='open_modal btn  btn-default btn-xs' type="submit" value="Detail" class="stretched-link"></span></h6>
                     </form>
                    </td>
                  </tr>
                </tbody>
              </table>
              <?php
              if ($_GET['periode'] == 'y') {
                echo "<a href='component/com_transaksi/export.php?tgl1=$tgl1&tgl2=$tgl2' class='btn btn-primary btn-sm'><i class='fa fa-print'></i> Cetak</a>";
              } else {
                echo "<a href='component/com_transaksi/export.php?bln=$bln&thn=$thn' class='btn btn-primary btn-sm'><i class='fa fa-print'></i> Cetak</a>";
              }
              ?>
            </div>
            
            <!--rekap new-->
              
              
            
            
            
            <div class="x_content">
                
                <?php
                
                 $query_divisi = mysqli_query($conn, "SELECT * FROM jenis_divisi order by id_divisi ASC ");
                 
                 
                 while ($row_divisi = mysqli_fetch_array($query_divisi)) {
                
                ?>

            <h2 for="namadivisi" style="color:black; text-align: center"><?php echo $row_divisi['nama_divisi']." ".namabulan($bln)." ".$thn;  ?> </h2>
              <table id="" class="table table-bordered" style="border-color:black; color:black">
                <thead>
                  <tr>
                    <th width="15px">NO.</th>
                    <th width="15px">Kode</th>
                    <th>keterangan</th>
                    <th>Debit</th>
                    <th>Kredit</th>
                    <th width="110">TOTAL<br>(debit-kredit)</th>
                    <th width="100">Cetak laporan<br>per bulan</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
                  $no = 0;
                  $count = 1;
                  $total_rekap = 0;
                  $total_debit = 0;
                  $total_kredit = 0;
                  $query = mysqli_query($conn, "SELECT * FROM jenis_transaksi WHERE id_jenis NOT IN (1) AND id_divisi='$row_divisi[id_divisi]' order by jenis ASC ");


                  $ro = 0;



                  while ($row = mysqli_fetch_array($query)) {

                    
                     if ($_GET['periode'] == 'y') {
                      $query_rekap = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE id_jenis ='$row[id_jenis]'
                      AND tanggal BETWEEN '$tgl1' AND '$tgl2'");
                    } else {
                      $query_rekap = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE id_jenis ='$row[id_jenis]'
                                AND MONTH(tanggal)='$bln' 
                                AND YEAR(tanggal)='$thn'");
                    }

                    $rekap = mysqli_fetch_array($query_rekap);
                    $no++;
                  ?>

                    <tr style="background: <?php 
                    if($row['jenis']=='0' OR $row['id_jenis']=='21'){echo "#eefc6f";}else{
                    
                    if ($no % 2 == 1) { ?>
                          white;
                          <?php } else { ?>
                            white;
                            <?php }} ?>">

                      <!--<td><?php //echo $row['id_transaksi'];
                              ?></td>-->
                      <td><?php echo $no; ?></td>
                      <td><?php echo $row['id_jenis']; ?></td>
                      <td><h2><?php echo $row['nama_jenis']; ?></h2></td>

                      <td><h2><?php echo "Rp." . rupiah($rekap['jumlah_debit']); ?></h2></td>
                      <td><h2><?php echo "Rp." . rupiah($rekap['jumlah_kredit']); ?></h2></td>
                      <td><h2>
                        <?php
                        $total = $rekap['jumlah_debit'] - $rekap['jumlah_kredit'];
                        echo "Rp." . rupiah($total);
                        $total_debit = $total_debit + $rekap['jumlah_debit'];
                        $total_kredit = $total_kredit + $rekap['jumlah_kredit'];
                        $total_rekap = $total_rekap + $total;
                        ?></h2>
                      </td>
                      <td>
                        <?php
                        if ($_GET['periode'] == 'y') {
                          echo "<a href='component/com_transaksi/export_pembukuan.php?periode=y&type=$row[id_jenis]&tanggal1=$tgl1&tanggal2=$tgl2' class='btn btn-primary btn-sm'><i class='fa fa-print'></i></a>";
                        } else {
                          echo "<a href='component/com_transaksi/export_pembukuan.php?periode=bln&type=$row[id_jenis]&bln=$bln&thn=$thn' class='btn btn-primary btn-sm'><i class='fa fa-print'></i></a>";
                        }
                        ?> </td>


                      <?php
                      $count++
                      ?>

                    </tr>

                  <?php } ?>



                  <tr bgcolor="#f6eee0">
                    <td colspan="3" align="center"><b>TOTAL</b></td>
                    <td><h2><?php echo "Rp." . rupiah($total_debit); ?></h2></td>
                    <td><h2><?php echo "Rp." . rupiah($total_kredit); ?></h2></td>
                    <td><h2><?php echo "Rp." . rupiah($total_rekap); ?></h2></td>
                  </tr>



                </tbody>
              </table>
              <br><br>
              <?php
              
                 }
              
              if ($_GET['periode'] == 'y') {
                echo "<a href='component/com_transaksi/export.php?tgl1=$tgl1&tgl2=$tgl2' class='btn btn-primary btn-sm'><i class='fa fa-print'></i> Cetak</a>";
              } else {
                echo "<a href='component/com_transaksi/export.php?bln=$bln&thn=$thn' class='btn btn-primary btn-sm'><i class='fa fa-print'></i> Cetak</a>";
              }
              ?>
            </div>










          </div>

        </div>

      </div>
    </div>
  </div>
  <!-- /page content --><br>










          </div>

        </div>

      </div>
    </div>
  </div>
  <!-- /page content --><br>







<?php } ?>