
<table id="mhs_lulus" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>                          
<th>Program Studi</th>
<th>Aktif</th>
<th>Lulus</th>
<th>Mutasi</th>
<th>Dikeluarkan</th>
<th>Mengundurkan Diri</th>
<th>Putus Sekolah</th>
<th>Wafat</th>
<th>Hilang</th>
<th>Jml Mhs Baru</th>
<th>Prosen Lulus</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_lulus = 0;
  $total_mutasi = 0;
  $total_dikeluarkan = 0;
  $total_resign = 0;
  $total_putus = 0;
  $total_wafat = 0;
  $total_hilang = 0;

  $jml_aktif = 0;
   $jumlah_masuk = 0;
$and_periode = "";
$filter_angkatan = "";
  $angkatan_lulus = "";
  $angkatan_mahasiswa = "";
if ($_POST['angkatan_awal']!='all') {
  $filter_angkatan = "BETWEEN '".$_POST['angkatan_awal']."' and '".$_POST['angkatan_akhir']."'";
}
if ($filter_angkatan!="") {
  $angkatan_lulus = " and (angkatan $filter_angkatan)";
  $angkatan_mahasiswa = " and (left(id_periode,4) $filter_angkatan)";
}
foreach ($jurusan as $jur) {

  // jumlah mahasiswa aktif
  if ($periode!='all') {
    $and_periode = " and id_periode_keluar='$periode'";
  }

  $data_req = [
    'act' => 'GetListMahasiswaLulusDO',
    'token' => $token,
    'filter' => "id_prodi='$jur->id_sms' $and_periode $angkatan_lulus",
  ];



  $get_jumlah = service_request($data_req);

  $data_req_mhs = [
    'act' => 'GetCountMahasiswa',
    'token' => $token,
    'filter' => "id_registrasi_mahasiswa in (select id_reg_pd from reg_pd where tgl_keluar is null) AND id_prodi='$jur->id_sms' $angkatan_mahasiswa",
  ];

  //dump($data_req_mhs);

  $get_jumlah_aktif = service_request($data_req_mhs);

  $data_req_mhs_masuk = [
    'act' => 'GetCountMahasiswa',
    'token' => $token,
    'filter' => "id_prodi='$jur->id_sms' $angkatan_mahasiswa",
  ];

  $get_jumlah_masuk = service_request($data_req_mhs_masuk);


  

  $jml_aktif =$get_jumlah_aktif->data;
  $jumlah_masuk =$get_jumlah_masuk->data;


  



  $jml_lulus = 0;
  
  $jml_mutasi = 0;
  $jml_dikeluarkan = 0;
  $jml_resign = 0;
  $jml_putus = 0;
  $jml_wafat = 0;
  $jml_hilang = 0;

  $prosen_lulus = 0;



  foreach ($get_jumlah->data as $data) {
    if ($data->id_jenis_keluar == '1') {
      $lulus[$data->id_prodi] = ++$jml_lulus;
      ++$total_lulus;
    } else if ($data->id_jenis_keluar == '2') {
      $mutasi[$data->id_prodi] = ++$jml_mutasi;
      ++$total_mutasi;
    } else if ($data->id_jenis_keluar == '3') {
      $dikeluarkan[$data->id_prodi] = ++$jml_dikeluarkan;
      ++$total_dikeluarkan;
    } else if ($data->id_jenis_keluar == '4') {
      $resign[$data->id_prodi] = ++$jml_resign;
      ++$total_resign;
    } else if ($data->id_jenis_keluar == '5') {
      $putus[$data->id_prodi] = ++$jml_putus;
      ++$total_putus;
    } else if ($data->id_jenis_keluar == '6') {
      $wafat[$data->id_prodi] = ++$jml_wafat;
      ++$total_wafat;
    } else if ($data->id_jenis_keluar == '7') {
      $hilang[$data->id_prodi] = ++$jml_hilang;
      ++$total_hilang;
    }
  }

  $btn = 'badge bg-red';
  if (isset($lulus[$jur->id_sms])) {
    $prosen_lulus = ($lulus[$jur->id_sms]/$jumlah_masuk)*100;
    $prosen_lulus = round($prosen_lulus,2);
    if ($prosen_lulus>80) {
      $btn = 'badge bg-green';
    } elseif ($prosen_lulus > 50) {
      $btn = 'badge bg-light-blue';
    }
  }

?>

  <tr> 
  <td><?=$no;?></td>
  <td><?=$jur->jenjang.' '.$jur->nama_jurusan;?></td>
  <td><?=$get_jumlah_aktif->data;?></td>
  <td><?=(isset($lulus[$jur->id_sms]))?$lulus[$jur->id_sms]:0;?></td>
  <td><?=(isset($mutasi[$jur->id_sms]))?$mutasi[$jur->id_sms]:0;?></td>
  <td><?=(isset($dikeluarkan[$jur->id_sms]))?$dikeluarkan[$jur->id_sms]:0;?></td>
  <td><?=(isset($resign[$jur->id_sms]))?$resign[$jur->id_sms]:0;?></td>
  <td><?=(isset($putus[$jur->id_sms]))?$putus[$jur->id_sms]:0;?></td>
  <td><?=(isset($wafat[$jur->id_sms]))?$wafat[$jur->id_sms]:0;?></td>
  <td><?=(isset($hilang[$jur->id_sms]))?$hilang[$jur->id_sms]:0;?></td>
  <td><?=$jumlah_masuk;?></td>
  <td><span class="<?=$btn;?>"><?=$prosen_lulus;?> %</span></td>
  
  </tr>
  <?php
  $no++;
}
?>

</tbody>
<tfoot>
  <tr>
  <th colspan="2" style="text-align: right;">Total</th>
  <th><?=$jml_aktif;?></th>
  <th> <?=$total_lulus;?></th>
  <th> <?=$total_mutasi;?></th>
  <th> <?=$total_dikeluarkan;?></th>
  <th> <?=$total_resign;?></th>
  <th> <?=$total_putus;?></th>
  <th> <?=$total_wafat;?></th>
  <th> <?=$total_hilang;?></th>
  <th> <?=$jumlah_masuk;?></th>
  <th> <?=$jumlah_masuk;?></th>
  </tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
  $('#mhs_lulus').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 LULUS/DO'
          },
          {
            extend: 'pdfHtml5',
            title: 'Rekap Mahasiswa LULUS/DO'
          },
          {
            extend: 'csvHtml5',
            title: 'Rekap Mahasiswa LULUS/DO'
          },
          {
            extend: 'copyHtml5',
            title: 'Rekap Mahasiswa LULUS/DO'
          },
          {
            extend: 'excelHtml5',
            title: 'Rekap Mahasiswa LULUS/DO'
          }
        ]
      }
    ]
  });
});

</script>