<?php
header('Access-Control-Allow-Origin: *');
include "../../inc/config.php";

$json_response = array();

$filter_sms = "";
$filter_angkatan = "";
$filter_status = "";
$tahun_lulus = "";
$jumlah = 0;
$periode_count = "";
$array_status = array();
      if ($_POST['jurusan']!="all") {
            $filter_sms = "id_registrasi_mahasiswa is not null and id_prodi='".$_POST['jurusan']."'";
        } else {
            $filter_sms = "id_registrasi_mahasiswa is not null";
        }
        
        $filter_angkatan = "and (angkatan BETWEEN '".$_POST['angkatan_awal']."' and '".$_POST['angkatan_akhir']."')";

        if ($_POST['jns_keluar']!='') {
               foreach ($_POST['jns_keluar'] as $val) {
                       $array_status[] = "'$val'";
               }
            if (!empty($array_status)) {
                $implode_status = implode(",", $array_status);
                    $filter_status = " and id_jenis_keluar IN(".$implode_status.")";
            }
        }

  if ($_POST['id_periode_keluar']!='all') {   
     $periode_count = "and id_registrasi_mahasiswa in(select id_reg_pd  from reg_pd where smt_yudisium='".$_POST['id_periode_keluar']."' and id_jns_keluar is not null)"; 
  }
        $data_rec = array();
        $filter_mahasiswa = "$filter_sms $filter_angkatan $filter_status $periode_count";

        //echo $filter_mahasiswa;


        $temp_count_mk = [
              'act' => 'GetCountMahasiswaLulusDO',
                'token' => get_token(),
                'filter' => $filter_mahasiswa
            ];
        $temp_count = service_request($temp_count_mk);
        if(!empty($temp_count->data)) {
          $jumlah = $temp_count->data;
        }

        //dump($temp_count_mk);

       
        //dump($temp_count);
        
        if ($jumlah>0) {
           $json_response['jumlah'] = $jumlah;
        } else {
          $json_response['jumlah'] = 0;
        }

        echo json_encode($json_response);
?>