<?PHP
if(!isset($_COOKIE['ADMIN_KEY']) && !isset($_COOKIE['KEY'])){
  header('location:./login/');
  exit;
}
else{
$query_role ="SELECT lihat,modifikasi,hapus FROM role WHERE modul_id='28' AND level_id='$current_user[level]'";
$result_role = $connection->query($query_role);
if($result_role->num_rows > 0){
  $data_role = $result_role->fetch_assoc();

echo'
<span class="modifikasi d-none">'.convert('encrypt', $data_role['modifikasi']).'</span>
<span class="hapus d-none">'.convert('encrypt',$data_role['hapus']).'</span>

<!-- Header -->
<div class="header bg-primary pb-6">
  <div class="container-fluid">
    <div class="header-body">
      <div class="row align-items-center py-4">
        <div class="col-lg-6 col-7">
          <nav aria-label="breadcrumb" class="d-none d-md-inline-block">
            <ol class="breadcrumb breadcrumb-links breadcrumb-dark">
              <li class="breadcrumb-item"><a href="./"><i class="fas fa-home"></i> Dashboard</a></li>
              <li class="breadcrumb-item active" aria-current="page">Pembayaran SPP</li>
            </ol>
          </nav>
        </div>
        
      </div>
    </div>
  </div>
</div>

<!-- Page content -->
<div class="container-fluid mt--6">
  <div class="row">
    <div class="col-md-8">
      <div class="card pb-3">
        <!-- Card header -->
        <div class="card-header mb-2">
          <h3 class="mb-0 text-left float-left">Data Pembayaranan SPP</h3>
          <div class="float-right">
            <div class="dropdown">
                <button class="btn btn-outline-primary dropdown-toggle" type="button" id="download" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  Download
                </button>
                <div class="dropdown-menu" aria-labelledby="download">
                  <button class="dropdown-item btn-download" type="button" data="print"><i class="fas fa-print"></i>PRINT</button>
                  <button class="dropdown-item btn-download" type="button" data="pdf"><i class="fas fa-file-pdf"></i> PDF</button>
                  <button class="dropdown-item btn-download" type="button" data="excel"><i class="far fa-file-excel"></i> EXCEL</button>
                </div>
              </div>
          </div>
        </div>';
        if($data_role['lihat']=='Y'){
          echo'
          <div class="table-responsive">
          <table class="table align-items-center table-flush table-striped datatable" style="width:100%">
            <thead class="bg-primary text-white">
              <tr>
                <th class="text-center" width="5">No</th>
                <th>Nama Siswa</th>
                <th>Kelas</th>
                <th>Tahun Ajaran</th>
                <th>Bulan</th>
                <th>Jumlah</th>
                <th>Tanggal</th>
                <th>Petugas</th>
                <th>Status</th>
                <th class="text-center" width="10">Aksi</th>
              </tr>
            </thead>
            <tbody>
            </tbody>
            <tfoot>

              <tr class="bg-secondary font-weight-bold">
                <td colspan="8" class="text-right">Status</td>
                <td colspan="2">
                  <span class="status_pembayaran">-</span>
                </td>
              </tr>

              <tr class="bg-secondary font-weight-bold">
                <td colspan="8" class="text-right">Jumlah Pembayaran</td>
                <td colspan="2">
                  <span class="total_pembayaran">Rp 0</span>
                </td>
              </tr>

              <tr class="bg-secondary font-weight-bold text-info">
                <td colspan="8" class="text-right">Total Tagihan</td>
                <td colspan="2">
                  <span class="total_tagihan">Rp 0</span>
                </td>
              </tr>
              
              <tr class="bg-secondary font-weight-bold text-danger">
                <td colspan="8" class="text-right">Sisa Tagihan</td>
                <td colspan="2">
                  <span class="sisa_tagihan">Rp 0</span>
                </td>
              </tr>
            </tfoot>
          </table>
          </div>';
        }else{
          hak_akses();
        }
        echo'
      </div>
      </div>

      <div class="col-md-4">
        <div class="card ">
          <div class="card-header mb-2">
            <h3 class="mb-0 text-left float-left">Input Pembayaran</h3>
          </div>

          <div class="card-body">
            <form class="form-add" role="form" action="javascript:;">
            <input type="hidden" class="form-control id d-none" name="id" readonly>
            <input type="hidden" class="form-control d-none user_id" name="user_id" value="" readonly>

            <div class="form-group">
                <label>Tahun Pelajaran</label>
                <select class="form-control master_spp" name="master_spp" required>';
                  $query_spp ="SELECT * FROM master_spp WHERE status='Y'";
                  $result_spp = $connection->query($query_spp);
                  while ($data = $result_spp->fetch_assoc()) {
                    echo'<option value="'.$data['master_spp_id'].'">'.$data['tahun_ajaran'].'</option>';
                  }
                echo'
                </select>
            </div>

            <div class="form-group">
              <label>NISN</label>
              <input type="text" class="form-control nisn" name="nisn" value="" required>
              <small class="result-output"></small>
            </div>

            <div class="form-group">
              <label>Nama Siswa</label>
              <input type="text" class="form-control nama_siswa" name="nama_siswa" value="" readonly required>
            </div>

            <div class="form-group">
              <label>Nama Siswa</label>
              <input type="text" class="form-control kelas" name="kelas" value="" readonly required>
            </div>

            <div class="form-group">
              <label>Angsuran Bulan</label>
              <select class="form-control bulan" name="bulan" required>';
              $bulan_nama =array(1=>"Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
              for($bulan=1; $bulan<=12; $bulan++){
                if($bulan<=$month ) {
                  echo'<option value="'.$bulan.'" selected>'.$bulan_nama[$bulan].'</option>';
                }else { 
                  echo'<option value="'.$bulan.'">'.$bulan_nama[$bulan].'</option>'; 
                }
              }
              echo'
              </select>
            </div>


            <div class="form-group">
              <label>Jumlah Pembayaran</label>
              <input type="text" class="form-control rupiah jumlah_pembayaran" name="jumlah_pembayaran" required>
            </div>

            <hr>';
            if($data_role['modifikasi']=='Y'){
                echo'
                <button type="submit" class="btn  btn-primary btn-save"><i class="far fa-save"></i> Simpan</button>
                <button class="btn btn-secondary btn-reset" type="reset"><i class="fas fa-undo"></i> Reset</button>';
              }else{
                echo'
                <button class="btn btn-primary" disabled><i class="far fa-save"></i> Simpan</button>';
              }
            echo'
            </form>
          </div>
        </div>
  </div>';



  }else{
    echo'Modul tidak ditemukan';
    /** Modul tidak ditemukan */
  }

}?>