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

?>
  <!-- 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="x_title" style="text-transform: capitalize;">

              <?php if ($_GET['periode'] == 'y') {
                $tanggal1 = $_POST['tanggal1'];
                
                $tglpilih = date('Y-m-d', strtotime($tanggal1));
                
                $day = date('d', strtotime($tanggal1));
                $bln = date('m', strtotime($tanggal1));
                $thn = date('Y', strtotime($tanggal1));
                $namabulan=namabulan($bln);
              
                echo "<h2>Penyesuaian Harian Tanggal $day $namabulan tahun $thn</h2>";
              } else {
                $day = date('d');
                $bln = date('m');
                $thn = date('Y');
                $tglnow = date('Y-m-d');
                $namabulan=namabulan(date('m'));
                echo "<h2>Penyesuaian Harian Tanggal $day $namabulan tahun $thn</h2>";
              } ?>



              <div class="clearfix"></div>


              <form action="?module=<?php echo $_GET['module'];?>&periode=y" enctype="multipart/form-data" method="POST">


                <div class="well" style="overflow: auto">

                  <div class="col-md-12 col-sm-12 col-xs-12" style="padding: 4px;">
                    <label for="nama">Pilih Tanggal :</label>
                  </div>

                  <div class="col-md-3 col-sm-12 col-xs-12" style="padding: 4px;">

                    <div class="input-group">
                      <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                      <input type="text" autocomplete="off" class="form-control " id="tanggal" required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                  echo $tanggal1;
                                                                                                                } else {
                                                                                                                  echo "";
                                                                                                                } ?>" name="tanggal1">
                    </div>
                  </div>

                  <div class="col-md-6 col-sm-12 col-xs-12" style="padding: 4px;">
                    <button type="submit" class="btn btn-primary btn-sm">Pilih</button>
              </form>


            </div>

            <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)) {
                //untuk mengenolkan setiap divisi
                    $total=0;
                ?>

            <h2 for="namadivisi" style="color:black; text-align: center"><?php echo $row_divisi['nama_divisi']; ?></h2>
              <table id="" class="table table-bordered" style="border-color:black; color:black">
                <thead>
                  <tr>
                    <!--<th>Tanggal</th>-->
                    <!--<th>id transaksi</th> -->
                    <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='$tglpilih'");
                    } 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 tanggal='$tglnow'");
                    }

                    $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 
                      
                      if($row['jenis']=='0'){
                           echo "Rp." . rupiah($rekap['jumlah_kredit']);
                          $rekapdebit=$rekap['jumlah_kredit'];
                      }else{
                      
                      echo "Rp." . rupiah($rekap['jumlah_debit']); 
                      $rekapdebit=$rekap['jumlah_debit'];
                      $rekaptotaldebit=$rekap['jumlah_debit'];
                      }
                      
                      ?></h2></td>
                      <td><h2><?php echo "Rp." . rupiah($rekap['jumlah_kredit']); 
                       if($row['jenis']=='0'){
                           $rekaptotalkredit=0;
                         }else{
                      
                      $rekaptotalkredit=$rekap['jumlah_kredit'];
                      }
                      
                      
                      
                      ?></h2></td>
                      <td><h2>
                        <?php
                        
                        $total = $total + $rekapdebit - $rekap['jumlah_kredit'];
                        echo "Rp." . rupiah($total);
                        $total_debit = $total_debit + $rekaptotaldebit;
                        $total_kredit = $total_kredit + $rekaptotalkredit;
                        $total_rekap = $total_debit - $total_kredit;
                        ?></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 (DILUAR KAS PEMASUKAN *kuning)</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>







<?php } ?>