<?php
session_start();
$query_saldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi");
$row_saldo = mysqli_fetch_array($query_saldo);
$saldo_keseluruhan = $row_saldo['jumlah_debit'] - $row_saldo['jumlah_kredit'];

$bulan = date('Y-m');
$query_saldo = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE DATE_FORMAT((tanggal),'%Y-%m') like '%$bulan%'");
$saldo = mysqli_fetch_array($query_saldo);
$saldo_bulan = $saldo['jumlah_debit'] - $saldo['jumlah_kredit'];

$hari = date('Y-m-d');
$query_hari = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE DATE_FORMAT((tanggal),'%Y-%m-%d') like '%$hari%'");
$saldo_h = mysqli_fetch_array($query_hari);
$saldo_hari = $saldo_h['jumlah_debit'] - $saldo_h['jumlah_kredit'];


// data
//jumlah seluruh santri
$query_santri = mysqli_query($conn, "SELECT *  FROM santri");
$num_santri = mysqli_num_rows($query_santri);
//jumlah santri putra
$query_santri_putra = mysqli_query($conn, "SELECT jenkel,
COUNT(nama) as Jumlah
FROM santri
GROUP BY jenkel'");
$jml_santri = mysqli_fetch_array($query_santri_putra);



?>

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

    <div class="row">
      <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_content" style="padding: 20px; text-align: center; background-color:#273d61;">
          <h2 style="font-size: x-large; text-align: left; color:snow;">Selamat datang, <?php echo $_SESSION['namalengkap']; ?></h2>
          


<?php if ($_SESSION['leveluser'] == 'admin') { ?>

<!----tombol AKSES AKUN BIASA-->
<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>
            
            <?php } ?>
            
            <?php if ($_SESSION['leveluser'] == 'admin' or $_SESSION['leveluser'] == 'user1') { ?>

            <!-- count  -->
            <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">
                    <br>
                    <div class="analytics-sparkle-line reso-mg-b-30">
                      <form action="?module=perkas" enctype="multipart/form-data" method="POST">
                        <div class="analytics-content ">
                         
                       
                          <h5>Detail Keseluruhan</h5>
                           <?php
                           if ($_SESSION['leveluser'] == 'admin') {?>
                          <h2>Rp.<span class="counter"><?php echo rupiah($saldo_keseluruhan); ?>
                            </span> </h2><?php } ?>
                          <input type="hidden" value="" name="jenis_kas">
                          <h6><span><input type="submit" value="Detail" class="stretched-link"></span></h6>
                          <span class="text-success">100%</span>
                          <div class="progress m-b-0">
                            <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:100%;"> <span class="sr-only">20% Complete</span> </div>
                          </div>
                          
                        </div>

                      </form>
                    </div>
                  </div>
                  <?php
                  $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'];
                  ?>
                    <div class="animated flipInY col-lg-4 col-md-6 col-sm-6 col-xs-12">
                      <br>

                      <div class="analytics-sparkle-line reso-mg-b-100">
                        <form action="?module=perkas" enctype="multipart/form-data" method="POST">
                          <div class="analytics-content">
                              
                       
                            <h5>Detail <?php echo $jenkas['nama']; ?></h5>
                           <?php if ($_SESSION['leveluser'] == 'admin') {?>
                            <h2>Rp.<span class="counter"><?php echo rupiah($kas); ?></span> </h2>
                             <?php } ?>
                            <input type="hidden" value="<?php echo $jenkas['id']; ?>" name="jenis_kas">
                            <h6><span><input type="submit" value="Detail" class="stretched-link"></span></h6>
                            <span class="text-danger"><?php echo persen($jenkas['id']); ?>%</span>
                            <div class="progress m-b-0">
                              <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo persen($jenkas['id']); ?>%;"> <span class="sr-only">230% Complete</span> </div>
                            </div>

                          </div>
                        </form>
                      </div>

                    </div>


                  <?php } ?>
                  <div class="animated flipInY col-lg-4 col-md-6 col-sm-6 col-xs-12">
                    <br>
                    <div class="analytics-sparkle-line reso-mg-b-30">

                      <div class="analytics-content ">
                        <h5>Total Kas Uang Saku </h5>

                        <?php
                        $query_saku = mysqli_query($conn, "SELECT SUM(debit) as jumlah_debit, SUM(kredit) as jumlah_kredit FROM transaksi WHERE id_jenis='21'");

                        $row_saku = mysqli_fetch_array($query_saku);
                        $saldo_keseluruhan_saku = $row_saku['jumlah_debit'] - $row_saku['jumlah_kredit']; ?>

                        <h2>Rp.<span class="counter"><?php echo rupiah($saldo_keseluruhan_saku); ?>
                          </span> </h2>
                        <input type="hidden" value="" name="jenis_kas">



                        <span class="text-warning">100%</span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-warning" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:100%;"> <span class="sr-only">20% Complete</span> </div>
                        </div>
                      </div>


                    </div>
                  </div>



                </div>
              </div>
            </div>

            <!-- count -->
            <br><br>
             <?php if ($_SESSION['leveluser'] == 'admin') {?>
            <!-- count  -->
            <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 table-mg-t-pro dk-res-t-pro-30">
                      <form action="?module=perbln" enctype="multipart/form-data" method="POST">
                        <div class="analytics-content">
                          <h5>Pemasukan Bulan Ini</h5>
                         
                          <h2>Rp.<span class="counter"><?php echo rupiah($saldo['jumlah_debit']); ?></span> </h2>
                          
                          <h6><span><input type="submit" value="Detail" class="stretched-link"></span></h6>
                          <span class="text-info">100%
                          </span>
                          <div class="progress m-b-0">
                            <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:100%;"> <span class="sr-only">20% Complete</span> </div>
                          </div>
                        </div>
                      </form>
                    </div>
                  </div>

                  <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 table-mg-t-pro dk-res-t-pro-30">
                      <div class="analytics-content">
                        <h5>Pengeluaran Bulan Ini</h5>
                        <h2>Rp.<span class="counter"><?php echo rupiah($saldo['jumlah_kredit']); ?></span> </h2>
                        <span class="text-inverse">
                          <?php

                          $persenbln = $saldo['jumlah_kredit'] / $saldo['jumlah_debit'] * 100;

                          echo number_format($persenbln, 2, ".", ""); ?>%

                        </span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-inverse" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo number_format($persenbln, 2, ".", ""); ?>%;"> <span class="sr-only">230% Complete</span> </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <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>Saldo Bulan Ini</h5>
                        <h2>Rp.<span class="counter"><?php echo rupiah($saldo_bulan); ?></span> </h2>
                        <span class="text-success">
                          <?php

                          $persenblnsaldo = $saldo_bulan / $saldo['jumlah_debit'] * 100;

                          echo number_format($persenblnsaldo, 2, ".", ""); ?>%
                        </span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo number_format($persenblnsaldo, 2, ".", ""); ?>%;"> <span class="sr-only">230% Complete</span> </div>
                        </div>
                      </div>
                    </div>
                  </div>



                </div>
              </div>
            </div>

            <!-- count -->
            <?php }?>
            <br>
            <!-- count  -->

            <div class="analytics-sparkle-area">
              <div class="container-fluid">
                <div class="row">
                  <div class="animated flipInY shadow-sm col-lg-4 col-md-6 col-sm-6 col-xs-12">
                    <div class="analytics-sparkle-line reso-mg-b-30">
                      <form action="?module=perhari" enctype="multipart/form-data" method="POST">
                        <div class="analytics-content">
                          <h5>Pemasukan Hari ini</h5>
                          <h2>Rp.<span class="counter"><?php echo rupiah($saldo_h['jumlah_debit']); ?></span> </h2>
                          <h6><span><input type="submit" value="Detail" class="stretched-link"></span></h6>
                          <span class="text-info">100%</span>
                          <div class="progress m-b-0">
                            <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:100%;"> <span class="sr-only">230% Complete</span> </div>
                          </div>
                        </div>
                      </form>
                    </div>
                  </div>
                  <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 table-mg-t-pro dk-res-t-pro-30">
                      <div class="analytics-content">
                        <h5>Pengeluaran Hari Ini</h5>
                        <h2>Rp.<span class="counter"><?php echo rupiah($saldo_h['jumlah_kredit']); ?></span> </h2>
                        <span class="text-inverse">
                          <?php

                          $persenhr = $saldo_h['jumlah_kredit'] / $saldo_h['jumlah_debit'] * 100;

                          echo number_format($persenhr, 2, ".", ""); ?>%
                        </span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-inverse" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo number_format($persenhr, 2, ".", ""); ?>%;"> <span class="sr-only">20% Complete</span> </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="animated flipInY 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>Saldo Hari Ini</h5>
                        <h2>Rp.<span class="counter"><?php echo rupiah($saldo_hari); ?>
                          </span> </h2>
                        <span class="text-success">
                          <?php

                          $persenhr = $saldo_hari / $saldo_h['jumlah_debit'] * 100;

                          echo number_format($persenhr, 2, ".", ""); ?>%
                        </span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo number_format($persenhr, 2, ".", ""); ?>%;"> <span class="sr-only">20% Complete</span> </div>
                        </div>
                      </div>
                    </div>
                  </div>

                </div>
              </div>
            </div>

            <!-- count -->
            <br>

            <!-- jumlah santri -->
            <?php
            // data
            //jumlah seluruh santri
            $query_santri = mysqli_query($conn, "SELECT *  FROM santri WHERE statuus = '1' OR statuus = '2'");
            $num_santri = mysqli_num_rows($query_santri);
            //jumlah seluruh santri rt
            $query_santri_rt = mysqli_query($conn, "SELECT *  FROM santri_rt");
            $num_santri_rt = mysqli_num_rows($query_santri_rt);
            //jumlah santri 
            $jml_santrii = mysqli_query($conn, "SELECT jenkel,
                COUNT(nama) as jumlah
                FROM santri WHERE statuus = '1' OR statuus = '2'
                GROUP BY jenkel");
            $i = 0;
            while ($jml_santri = mysqli_fetch_array($jml_santrii)) {

              if ($i == 0) {
                $l = $jml_santri['jumlah'];
              } else {
                $p = $jml_santri['jumlah'];
              }
              $i++;
            }
            //jumlah santri rt
            $jml_santri_rt = mysqli_query($conn, "SELECT jenkel,
                COUNT(nama) as jumlah
                FROM santri_rt
                GROUP BY jenkel");
            $i = 0;
            while ($jml_santrirt = mysqli_fetch_array($jml_santri_rt)) {

              if ($i == 0) {
                $lrt = $jml_santrirt['jumlah'];
              } else {
                $prt = $jml_santrirt['jumlah'];
              }
              $i++;
            }


            ?>

            <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>Jumlah Santri Pondok</h5>
                        <h2><span class="counter"><?php echo $num_santri; ?></span> <span class="glyphicon glyphicon-user"></span></h2>
                        <span class="text-info">Laki-laki <?php echo $l;
                                                          $persenl = $l / $num_santri * 100;
                                                          ?></span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $persenl; ?>%;"> <span class="sr-only">230% Complete</span> </div>
                        </div>
                        <span class="text-danger">Perempuan <?php echo $p;
                                                            $persenp = $p / $num_santri * 100;
                                                            ?></span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $persenp; ?>%;"> <span class="sr-only">230% Complete</span> </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <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>Jumlah Santri Rumah Tahfidz</h5>
                        <h2><span class="counter"><?php echo $num_santri_rt; ?></span> <span class="glyphicon glyphicon-user"></span></h2>
                        <span class="text-info">Laki-laki <?php echo $lrt;
                                                          $persenlrt = $lrt / $num_santri_rt * 100;
                                                          ?></span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $persenlrt; ?>%;"> <span class="sr-only">230% Complete</span> </div>
                        </div>
                        <span class="text-danger">Perempuan <?php echo $prt;
                                                            $persenprt = $prt / $num_santri_rt * 100;
                                                            ?></span>
                        <div class="progress m-b-0">
                          <div class="progress-bar progress-bar-danger" role="progressbar" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo $persenprt; ?>%;"> <span class="sr-only">230% Complete</span> </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>




        </div>





      <?php } ?>



      </div>
    </div>

  </div>
</div>
</div><br><br>
</div>
</div>
</div>

 
<!-- /page content -->