
<table id="kelas_dosen_data" class="table table-bordered table-striped">
<thead>
<tr>
<th>No</th>    
<th>Kode MK</th>                      
<th>Nama Matakuliah</th>
<th>Kelas</th>
<th>SKS Kelas</th>
<th>SKS Dosen</th>
<th>Jumlah Pengajar</th>
<th>Action</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_sks = 0;


foreach ($jurusan as $jur) {
  //jumlah mahasiswa aktif

  $data_req_dosen = [
    'act' => 'GetDosenPengajarKelasKuliah',
      'token' => $token,
      'filter' => "id_prodi='$jur->id_sms' and id_semester='$periode'"
  ];

  $get_jumlah_dosen = service_request($data_req_dosen);
  //dump($get_jumlah_dosen);
$sks_total_dosen = array();
$jumlah_dosen = array();
foreach ($get_jumlah_dosen->data as $dosen) {
  if (!isset($sks_total_dosen[$dosen->id_kelas_kuliah])) {
    $sks_total_dosen[$dosen->id_kelas_kuliah] = 0;
    $jumlah_dosen[$dosen->id_kelas_kuliah] = 0;
  }
  $sks_total_dosen[$dosen->id_kelas_kuliah] += (float)$dosen->sks_substansi_total;
  $jumlah_dosen[$dosen->id_kelas_kuliah]++;
}


  $data_req = [
    'act' => 'GetListKelasKuliah',
      'token' => $token,
      'filter' => "id_prodi='$jur->id_sms' and id_semester='$periode' and id_dosen is not null"
  ];
  $jml_kelas = 0;
  $jml_terisi = 0;
  $jml_tidak_terisi = 0;
  $get_jumlah = service_request($data_req);
  //exit
  $array_kelas = array();
  if ($get_jumlah->data) {
    foreach ($get_jumlah->data as $data) {
          $sks = (float)$data->sks;
          if (in_array($data->id_kelas_kuliah, array_keys($sks_total_dosen))) {
            if ($sks!=$sks_total_dosen[$data->id_kelas_kuliah]) {
                $array_kelas[] = array(
                  'kode_mk' => $data->kode_mata_kuliah,
                  'nama_mk' => $data->nama_mata_kuliah,
                  'kelas' => $data->nama_kelas_kuliah,
                  'sks_kelas' => $data->sks,
                  'sks_dosen' => $sks_total_dosen[$data->id_kelas_kuliah],
                  'jumlah_dosen' => $jumlah_dosen[$data->id_kelas_kuliah],
                  'id_kelas_kuliah' => $data->id_kelas_kuliah
                );
                $kode_mk[$data->id_kelas_kuliah] = $data->kode_mata_kuliah;
                $nama_mk[$data->id_kelas_kuliah] = $data->nama_mata_kuliah;
                $kelas[$data->id_kelas_kuliah] = $data->nama_kelas_kuliah;
                $sks_kelas[$data->id_kelas_kuliah] = $data->sks;
                $sks_dosen[$data->id_kelas_kuliah] = (float)$sks_total_dosen[$data->id_kelas_kuliah];
            }
          }
    }
  }

}


if (!empty($array_kelas)) {
  foreach ($array_kelas as $data_kelas) {
    ?>
      <tr> 
      <td><?=$no;?></td>
      <td><?=$data_kelas['kode_mk'];?></td>
      <td><?=$data_kelas['nama_mk'];?></td>
      <td><?=$data_kelas['kelas'];?></td>
      <td><?=$data_kelas['sks_kelas'];?></td>
      <td><?=$data_kelas['sks_dosen'];?></td>
      <td><?=$data_kelas['jumlah_dosen'];?></td>
      <td><span class="btn btn-sm btn-primary hitung-bobot" data-id="<?=$data_kelas['id_kelas_kuliah'];?>" data-toggle="tooltip" data-title="Hitung Prosentase Bobot SKS"><i class="fa fa-calculator"></i> Hitung</span></td>
      </tr>
      <?php
      $no++;
    }
}
?>
</tbody>
</table>
    <div class="modal" id="modal_perhitungan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog modal-lg"> <div class="modal-content"><div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title">Perhitungan Persentase Bobot / SKS</h4> </div> <div class="modal-body" id="isi_perhitungan"> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div>
<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' ]
      }
    ]
  });

  $(".hitung-bobot").click(function(){
    $("#loadnya").show();
     var id = $(this).data("id");
        $.ajax({
      type: "POST",
      url: "<?=base_admin();?>modul/rekapitulasi/hitung_bobot.php",
      data: {id_kelas: id},
      success: function(result) {
        $("#loadnya").hide();
        $('#isi_perhitungan').html(result);
      }
    });

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

  });
});

</script>