<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">&times;</button>
Untuk melihat daftar mahasiswa yang belum set AKM, klik di angka kolom Belum set AKM
</div>
<table id="akm_data" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>                          
<th>Program Studi</th>
<th>Mahasiswa Terdaftar</th>
<th>Sudah set AKM</th>
<th>Belum set AKM</th>
<th>Prosentasi Laporan</th>
</tr>
</thead>
<tbody id="content_akm">
<?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_terdaftar = 0;
$total_set = 0;
$total_belum_set = 0;
$total_prosen = 0;

foreach ($jurusan as $jur) {
  $prosen = 0;
  //jumlah mahasiswa aktif
  $data_req = [
    'act' => 'GetCountRiwayatPendidikanMahasiswa',
      'token' => $token,
      'filter' => "id_registrasi_mahasiswa in (select id_reg_pd from reg_pd where tgl_keluar is null and mulai_smt<='".$periode."') and id_prodi='$jur->id_sms'",
  ];
  $get_jumlah = service_request($data_req);

  //sudah set akm
  $data_req_set = [
    'act' => 'GetCountRiwayatPendidikanMahasiswa',
      'token' => $token,
      //'filter' => "id_prodi = '$jur->id_sms' and id_semester='$periode' and id_registrasi_mahasiswa not in(select id_reg_pd from reg_pd where tgl_keluar is not null)",
      'filter' => "id_prodi='".$jur->id_sms."' and id_registrasi_mahasiswa in(select id_reg_pd from kuliah_mhs where id_smt='".$periode."')
and id_registrasi_mahasiswa in(select id_reg_pd from reg_pd where tgl_keluar is null and mulai_smt<='".$periode."')"
  ];
  $get_jumlah_akm = service_request($data_req_set);
  //dump($get_jumlah_akm);
  $belum_set_akm = $get_jumlah->data - $get_jumlah_akm->data;

  $total_belum_set+=$belum_set_akm;
  // Add conditional statements to check for division by zero and NaN
  if ($get_jumlah->data != 0) {
    $total_terdaftar+=$get_jumlah->data;
    if ($get_jumlah_akm->data != 0) {
      $prosen = ($get_jumlah_akm->data/$get_jumlah->data)*100;
      $prosen = round($prosen, 2);
      $total_set+=$get_jumlah_akm->data;
    } 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';
}
?>

  <tr> 
  <td><?=$no;?></td>
  <td><?=$jur->jenjang.' '.$jur->nama_jurusan;?></td>
  <td><?=$get_jumlah->data;?></td>
  <td><?=$get_jumlah_akm->data;?></td>
  <td><a class='belum-set' style="cursor: pointer;" data-toggle="tooltip" data-title="Lihat Data Mahasiswa" data-sem="<?=$periode;?>" data-id="<?=$jur->id_sms;?>"><?=$belum_set_akm;?></a></td>
  <td><span class="<?=$btn;?>"><?=round($prosen,2);?> %</span></td>
  </tr>
  <?php
  $no++;
  $total_prosen = 0;
  $total_prosen+=round($prosen,2);
}
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_terdaftar;?></th>
  <th> <?=$total_set;?></th>
  <th> <?=$total_belum_set;?></th>
  <th> <span class="<?=$btn;?>"><?=round($total_prosen/($no-1),2);?> %</span> </th>
  </tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
  $('#akm_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: [
          {
            extend: 'print',
            title: 'Rekap Mahasiswa Input AKM'
          },
          {
            extend: 'pdfHtml5',
            title: 'Rekap Mahasiswa Input AKM'
          },
          {
            extend: 'csvHtml5',
            title: 'Rekap Mahasiswa Input AKM'
          },
          {
            extend: 'copyHtml5',
            title: 'Rekap Mahasiswa Input AKM'
          },
          {
            extend: 'excelHtml5',
            title: 'Rekap Mahasiswa Input AKM'
          }
        ]
      }
    ]
  });
});
    $(".table").on('click','.belum-set',function(event) {
        $("#loadnya").show();
        event.preventDefault();
        var currentBtn = $(this);
        $(".modal-title").html("Data Mahasiswa Belum Set AKM");
        id = currentBtn.attr('data-id');
        sem_id = currentBtn.attr('data-sem');

        $.ajax({
            url : "<?=base_admin();?>modul/rekapitulasi/show_akm_not_set.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>