
<table id="akm_data_mahasiswa" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>                          
<th>Program Studi</th>
<th>Mahasiswa Aktif</th>
<th>Cuti</th>
<th>Non-Aktif</th>
<th>Kampus Merdeka</th>
<th>Double Degree</th>
<th>Menunggu Ujian</th>
<th>Total</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_aktif = 0;
$total_cuti = 0;
$total_non_aktif = 0;
$total_kampus_merdeka = 0;
$total_double_degree = 0;
$total_ujian = 0;
$total = 0;
foreach ($jurusan as $jur) {
  //jumlah mahasiswa aktif
  $data_req = [
    'act' => 'GetAktivitasKuliahMahasiswa',
      'token' => $token,
      'filter' => "id_prodi='$jur->id_sms' and id_semester='$periode'",
  ];
  $get_jumlah = service_request($data_req);
  $jml_aktif = 0;
  $jml_cuti = 0;
  $jml_non_aktif = 0;
  $jml_km = 0;
  $jml_degree = 0;
  $jml_menunggu_ujian = 0;

  foreach ($get_jumlah->data as $data) {
    if ($data->id_status_mahasiswa=='A') {
      $aktif[$data->id_prodi] = ++$jml_aktif;
    }
    if ($data->id_status_mahasiswa=='C') {
      $cuti[$data->id_prodi] = ++$jml_cuti;
    }
    if ($data->id_status_mahasiswa=='N') {
      $non_aktif[$data->id_prodi] = ++$jml_non_aktif;
    }
    if ($data->id_status_mahasiswa=='M') {
      $kampus_merdeka[$data->id_prodi] = ++$jml_km;
    }
    if ($data->id_status_mahasiswa=='G') {
      $double_degree[$data->id_prodi] = ++$jml_degree;
    }
    if ($data->id_status_mahasiswa=='U') {
      $ujian[$data->id_prodi] = ++$jml_menunggu_ujian;
    }
/*    $cuti = $data->cuti;
    $non_aktif = $data->non_aktif;
    $double_degree = $data->non_aktif;*/
  }

  $jumlah_aktif = (isset($aktif[$jur->id_sms]))?$aktif[$jur->id_sms]:0;
  $jumlah_cuti = (isset($cuti[$jur->id_sms]))?$cuti[$jur->id_sms]:0;
  $jumlah_non_aktif = (isset($non_aktif[$jur->id_sms]))?$non_aktif[$jur->id_sms]:0;
  $jumlah_kampus_merdeka = (isset($kampus_merdeka[$jur->id_sms]))?$kampus_merdeka[$jur->id_sms]:0;
  $jumlah_double_degree = (isset($double_degree[$jur->id_sms]))?$double_degree[$jur->id_sms]:0;
  $jumlah_ujian = (isset($ujian[$jur->id_sms]))?$ujian[$jur->id_sms]:0;

  $jumlah = $jumlah_aktif + $jumlah_cuti + $jumlah_non_aktif + $jumlah_kampus_merdeka + $jumlah_double_degree + $jumlah_ujian;
?>

  <tr> 
  <td><?=$no;?></td>
  <td><?=$jur->jenjang.' '.$jur->nama_jurusan;?></td>
  <td><?=$jumlah_aktif;?></td>
  <td><?=$jumlah_cuti;?></td>
  <td><?=$jumlah_non_aktif;?></td>
  <td><?=$jumlah_kampus_merdeka;?></td>
  <td><?=$jumlah_double_degree;?></td>
  <td><?=$jumlah_ujian;?></td>
  <td><?=$jumlah?></td>
  </tr>
  <?php
  $no++;
  if (isset($aktif[$jur->id_sms])) {
    $total_aktif += $aktif[$jur->id_sms];
  }
  if (isset($cuti[$jur->id_sms])) {
    $total_cuti += $cuti[$jur->id_sms];
  }
  if (isset($non_aktif[$jur->id_sms])) {
    $total_non_aktif += $non_aktif[$jur->id_sms];
  }
  if (isset($kampus_merdeka[$jur->id_sms])) {
    $total_kampus_merdeka += $kampus_merdeka[$jur->id_sms];
  }
  if (isset($double_degree[$jur->id_sms])) {
    $total_double_degree += $double_degree[$jur->id_sms];
  }
  if (isset($ujian[$jur->id_sms])) {
    $total_ujian += $ujian[$jur->id_sms];
  }

  $total = $total_aktif + $total_cuti + $total_non_aktif + $total_kampus_merdeka + $total_double_degree + $total_ujian;

}
?>
</tbody>
<tfoot>
  <tr>
  <th colspan="2" style="text-align: right;">Total</th>
  <th> <?=$total_aktif;?></th>
  <th> <?=$total_cuti;?></th>
  <th> <?=$total_non_aktif;?></th>
  <th> <?=$total_kampus_merdeka;?></th>
  <th> <?=$total_double_degree;?></th>
  <th> <?=$total_ujian;?></th>
  <th> <?=$total;?></th>
  </tr>
</tfoot>
</table>
<script type="text/javascript">
$(document).ready(function() {
  $('#akm_data_mahasiswa').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 di set Status AKM'
          },
          {
            extend: 'pdfHtml5',
            title: 'Rekap Mahasiswa di set Status AKM'
          },
          {
            extend: 'csvHtml5',
            title: 'Rekap Mahasiswa di set Status AKM'
          },
          {
            extend: 'copyHtml5',
            title: 'Rekap Mahasiswa di set Status AKM'
          },
          {
            extend: 'excelHtml5',
            title: 'Rekap Mahasiswa di set Status AKM'
          }
        ]
      }
    ]
  });
});

</script>