
<table id="kelas_dosen_data" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>                          
<th>Program Studi</th>
<th>Jumlah Kelas</th>
<th>Jumlah Kelas Terisi Dosen</th>
<th>Jumlah Kelas Tidak Terisi Dosen</th>
<th>Prosentasi Laporan</th>
</tr>
</thead>
<tbody>
<?php
session_start();
include "../../inc/config.php";
$and_jurusan = "";
if ($_POST['jurusan']!='all') {
  $and_jurusan = "and kode_jurusan='".$_POST['jurusan']."'";
}
$periode = $_POST['semester'];
$jurusan = $db->fetch_custom("select * from jurusan where status='A' $and_jurusan order by nama_jurusan asc");
$no=1;
$token = get_token();
$total_kelas = 0;
$total_kelas_terisi = 0;
$total_tidak_terisi = 0;
$total_prosen  = 0;
foreach ($jurusan as $jur) {
  //jumlah mahasiswa aktif
  $data_req = [
    'act' => 'GetListKelasKuliah',
      'token' => $token,
      'filter' => "id_prodi='$jur->id_sms' and id_semester='$periode'"
  ];
  $jml_kelas = 0;
  $jml_terisi = 0;
  $jml_tidak_terisi = 0;
  $get_jumlah = service_request($data_req);
  //dump($get_jumlah);
  if ($get_jumlah->data) {
    foreach ($get_jumlah->data as $data) {
      $jumlah_kelas[$data->id_prodi] = $data->id_kelas_kuliah;
      ++$jml_kelas;
      if ($data->id_dosen!='') {
         $jumlah_kelas_terisi[$data->id_prodi] = $data->id_kelas_kuliah;
         ++$jml_terisi;
      }
      if ($data->id_dosen=='') {
         $jumlah_kelas_kosong[$data->id_prodi] = $data->id_kelas_kuliah;
         ++$jml_tidak_terisi;
      }
    }
  }

  $total_kelas +=$jml_kelas;
  $total_kelas_terisi +=$jml_terisi;
  $total_tidak_terisi +=$jml_tidak_terisi;
  //dump($get_jumlah_akm);
  // Add conditional statements to check for division by zero and NaN
  if ($jml_kelas != 0) {
    if ($jml_terisi != 0) {
      $prosen = ($jml_terisi/$jml_kelas)*100;
      $prosen = round($prosen, 2);
    } else {
      $prosen = 0;
    }
  } else {
    $prosen = 0;
  }
if ($prosen==100) {
  $btn = 'badge bg-green';
} elseif ($prosen > 50) {
  $btn = 'badge bg-light-blue';
} else {
  $btn = 'badge bg-red';
}
$total_prosen+=$prosen;
?>

  <tr> 
  <td><?=$no;?></td>
  <td><?=$jur->jenjang.' '.$jur->nama_jurusan;?></td>
  <td><?=$jml_kelas;?></td>
  <td><?=$jml_terisi;?></td>
    <td><a class='belum-set-dosen' style="cursor: pointer;" data-toggle="tooltip" data-title="Lihat Data Kelas" data-sem="<?=$periode;?>" data-id="<?=$jur->id_sms;?>"><?=$jml_tidak_terisi;?></a></td>
  <td><span class="<?=$btn;?>"><?=round($prosen,2);?> %</span></td>
  </tr>
  <?php
  $no++;
}
if ($total_prosen==100) {
  $btn = 'badge bg-green';
} elseif ($total_prosen > 50) {
  $btn = 'badge bg-light-blue';
} else {
  $btn = 'badge bg-red';
}
?>
</tbody>
<tfoot>
  <tr>
  <th colspan="2" style="text-align: right;">Total</th>
  <th> <?=$total_kelas;?></th>
  <th> <?=$total_kelas_terisi;?></th>
  <th> <?=$total_tidak_terisi;?></th>
  <td><span class="<?=$btn;?>"><?=round($total_prosen/($no-1),2);?> %</span></td>
  </tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
  $('#kelas_dosen_data').DataTable({
    "dom": "<'row'<'col-sm-12'B>>" + "<'row'<'col-sm-6'l><'col-sm-6'f>>" +"<'row'<'col-sm-12'tr>>" +"<'row'<'col-sm-5'i><'col-sm-7'p>>",
    buttons: [
      {
        extend: 'collection',
        text: 'Export Data',
        buttons: [ 'print','pdfHtml5', 'csvHtml5', 'copyHtml5', 'excelHtml5' ]
      }
    ]
  });
});
    $("#kelas_dosen_data").on('click','.belum-set-dosen',function(event) {
    
        $("#loadnya").show();
        event.preventDefault();
        var currentBtn = $(this);
        $(".modal-title").html("Data Kelas Belum Set Dosen");
        id = currentBtn.attr('data-id');
        sem_id = currentBtn.attr('data-sem');

        $.ajax({
            url : "<?=base_admin();?>modul/rekapitulasi/show_kelas_not_set_dosen.php",
            type : "post",
            data : {id_data:id,sem_id:sem_id},
            success: function(data) {
                $("#isi_data").html(data);
                $("#loadnya").hide();
          }
        });

    $('#modal_data').modal({ keyboard: false,backdrop:'static' });

    });
</script>