load->library('session');
$this->load->library('rhlib');
require_once(APPPATH.'libraries/nusoap/nusoap.php'); //includes nusoap
require_once(APPPATH.'libraries/nusoap/class.wsdlcache.php'); //includes nusoap
$this->client = new nusoap_client($this->url, true);
$this->proxy = $this->client->getProxy();
set_time_limit(0);
}
function _get_token(){
$token = $this->proxy->GetToken($this->username, $this->password);
return $token;
}
//get mahasiswa pindahan yang tidak memiliki nilai_transfer
function get_mahasiswa_pindahan(){
$kdstsemester = $this->input->post('kdstsemester');
if(empty($kdstsemester)){
$return = array('success' => true, 'data' => array());
echo json_encode($return);
die;
}
$token = $this->_get_token();
$GetRecordset = $this->proxy->GetRecordset($token, 'mahasiswa_pt', "p.id_jns_daftar = 2 AND mulai_smt = '".$kdstsemester."'", '',1500, 0);
$data_mahasiswa = array();
foreach($GetRecordset['result'] as $idx => $result){
//check data nilai
$GetNilaiTransfer = $this->proxy->GetRecord($token, 'nilai_transfer', "p.id_reg_pd = '".$result['id_reg_pd']."'");
//print_r($GetNilaiTransfer);die;
if(empty($GetNilaiTransfer['result'])){
$data_mahasiswa[] = $result;
}
//$data_mahasiswa[] = $result;
}
$return = array('success' => true, 'data' => $data_mahasiswa);
echo json_encode($return);
die;
}
function export_to_feeder()
{
$data = $this->input->post('json_mahasiswa');
if(empty($data)){
$return = array(
'success' => false,
'message' => 'data yang dimasukkan kosong',
);
echo json_encode($return);
die;
}
$data = json_decode($data);
//get id satuan pendidikan
$token = $this->_get_token();
$nama_pt = 'Universitas Langlang Buana';
$sp = $this->proxy->GetRecord($token, 'satuan_pendidikan', "nm_lemb ilike '%{$nama_pt}%'");
$success_all = true;
$errors = array();
foreach($data as $idx => $dt){
$dt_mhs = (array) $dt;
$nim = $dt_mhs['nim'];
$kdprodi = $dt_mhs['kdprodi'];
$id_jns_daftar = $dt_mhs['id_jns_daftar'];
$tgl_masuk_sp = $dt_mhs['tgl_masuk_sp'];
$mulai_smt = $dt_mhs['mulai_smt'];
$a_pernah_tk = $dt_mhs['a_pernah_tk'];
$a_pernah_paud = $dt_mhs['a_pernah_paud'];
unset($dt_mhs['nim']);
unset($dt_mhs['kdprodi']);
unset($dt_mhs['id_jns_daftar']);
unset($dt_mhs['tgl_masuk_sp']);
unset($dt_mhs['mulai_smt']);
unset($dt_mhs['a_pernah_tk']);
unset($dt_mhs['a_pernah_paud']);
//if already in feeder, update
if($dt_mhs['already_in_feeder']){
$id_pd = $dt_mhs['id_pd'];
unset($dt_mhs['already_in_feeder']);
unset($dt_mhs['id_reg_pd']);
unset($dt_mhs['id_pd']);
$dt_mhs['id_kk']= 0;
$dt_mhs['id_wil']= 999999;
$dt_mhs['id_kebutuhan_khusus_ayah']= 0;
$dt_mhs['id_kebutuhan_khusus_ibu']= 0;
$dt_mhs['kewarganegaraan']= 'ID';
$dt_mhs['id_sp']= $sp['result']['id_sp']; //badan hukum
$update = array(
'key' => array('id_pd' => $id_pd),
'data' => $dt_mhs,
);
$updated_mahasiswa = $this->proxy->UpdateRecord($token, 'mahasiswa', json_encode($update));
if(isset($updated_mahasiswa['result']['error_desc']) && !empty($updated_mahasiswa['result']['error_desc'])){
$success_all = false;
$errors[] = $updated_mahasiswa['result']['error_desc'];
}
}else{ //insert
unset($dt_mhs['already_in_feeder']);
unset($dt_mhs['id_reg_pd']);
unset($dt_mhs['id_pd']);
$dt_mhs['id_kk']= 0;
$dt_mhs['id_wil']= 999999;
$dt_mhs['id_kebutuhan_khusus_ayah']= 0;
$dt_mhs['id_kebutuhan_khusus_ibu']= 0;
$dt_mhs['kewarganegaraan']= 'ID';
$dt_mhs['id_sp']= $sp['result']['id_sp']; //badan hukum
$inserted_mahasiswa = $this->proxy->InsertRecord($token, 'mahasiswa', json_encode($dt_mhs));
if(!isset($inserted_mahasiswa['result']['id_pd'])){
$success_all = false;
$errors[] = $inserted_mahasiswa['result']['error_desc'];
}else{
$id_pd = $inserted_mahasiswa['result']['id_pd'];
//get sms (prodi)
$sms = $this->proxy->GetRecord($token, 'sms', "kode_prodi = '".$kdprodi."' AND p.id_sp = '".$this->id_sp."'");
if(isset($sms['result']['id_sms']) && !empty($sms['result']['id_sms'])){
//add mahasiswa pt
$dtmahasiswa_pt = array();
$dtmahasiswa_pt['nipd'] = $nim;
$dtmahasiswa_pt['id_pd'] = $id_pd;
$dtmahasiswa_pt['id_sp'] = $sp['result']['id_sp'];
$dtmahasiswa_pt['id_sms'] = $sms['result']['id_sms'];
$dtmahasiswa_pt['id_jns_daftar'] = $id_jns_daftar;
$dtmahasiswa_pt['tgl_masuk_sp'] = $tgl_masuk_sp;
$dtmahasiswa_pt['mulai_smt'] = $mulai_smt;
$dtmahasiswa_pt['a_pernah_tk'] = $a_pernah_tk;
$dtmahasiswa_pt['a_pernah_paud'] = $a_pernah_paud;
$inserted_mahasiswa_pt = $this->proxy->InsertRecord($token, 'mahasiswa_pt', json_encode($dtmahasiswa_pt));
}
}
}
}
$message = "";
if(!empty($errors)){
$message .= "Terjadi kesalahan :
";
foreach($errors as $idx => $error)
{
$message .= ($idx+1).'. '.$error.'
';
}
}
$return = array(
'success' => $success_all,
'message' => $message,
);
echo json_encode($return);
die;
}
}
?>