load->library('session'); $this->load->library('rhlib'); } function retValOrNull($val){ //especially for combo & looukup with no item selected $val = ($val=='')? null : $val; return $val; } function autoNumber($column, $tbl) { $q = "SELECT max(" . $column . ")+1 as max FROM " . $tbl . ""; $query = $this->db->query($q); $max = ''; if ($query->num_rows() != 0) { $row = $query->row(); $max = $row->max; } if ($max == null) { $max = 0; } return $max; } function get_sttahapan(){ //Program Studi lokal $q="SELECT * FROM sttahapan"; $this->rhlib->jsonFromQuery($q); } function get_setbiayatahapan(){ $q = "SELECT * from v_setbiayatahapan"; $this->rhlib->jsonFromQueryWLimit($q); } function get_count_setbiayatahapan(){ $idjnsbiaya = $_POST['idjnsbiaya']; $thnmasuk = $_POST['thnmasuk']; $kdstsemester = $_POST['kdstsemester']; $idsttahapan = $_POST['idsttahapan']; if ($idjnsbiaya=='2' || $idjnsbiaya=='5') { $q = "SELECT count(idsetbiayatahapan) AS jml FROM setbiayatahapan WHERE idjnsbiaya = '".$idjnsbiaya."' AND thnmasuk = '".$thnmasuk."' AND idsttahapan = '".$idsttahapan."'"; } else { $q = "SELECT count(idsetbiayatahapan) AS jml FROM setbiayatahapan WHERE idjnsbiaya = '".$idjnsbiaya."' AND kdstsemester = '".$kdstsemester."' AND idsttahapan = '".$idsttahapan."'"; } $query = $this->db->query($q); $data= ''; if ($query->num_rows() > 0) { $row = $query->row(); $data['result']=$row->jml; } else { $data['result']=0; } echo json_encode($data); } function insert_setbiayatahapan(){ $dataArray = $this->getFieldsAndValues(); $ret = $this->rhlib->insertRecord('setbiayatahapan',$dataArray); return $ret; } function update_setbiayatahapan(){ $fieldsAndValues = $this->getFieldsAndValues(); unset($fieldsAndValues['idsetbiayatahapan']); //delete element array->idsetbiayatahapan untuk update $this->db->where('idsetbiayatahapan', $_POST['idsetbiayatahapan']); $this->db->update('setbiayatahapan', $fieldsAndValues); if($this->db->affected_rows()){ $ret["success"]=true; $ret["msg"]='Update Data Berhasil'; }else{ $ret["success"]=false; $ret["msg"]= 'Update Data Gagal'; } return $ret; } function delete_setbiayatahapan(){ $where['idsetbiayatahapan'] = $_POST['idsetbiayatahapan']; $ret = $this->rhlib->deleteRecord('setbiayatahapan',$where); return $ret; } function getFieldsAndValues(){ $dataArray = array( 'idsetbiayatahapan'=> $this->autoNumber('idsetbiayatahapan', 'setbiayatahapan'), 'idsttahapan'=> $this->retValOrNull($_POST['idsttahapan']), 'idjnsbiaya'=> $this->retValOrNull($_POST['idjnsbiaya']), 'thnmasuk'=> $this->retValOrNull($_POST['thnmasuk']), 'kdstsemester'=> $this->retValOrNull($_POST['kdstsemester']), 'nominal'=> $this->retValOrNull($_POST['nominal']), 'persentase'=> $this->retValOrNull($_POST['persentase']), 'tglawal'=> $this->retValOrNull($_POST['tglawal']), 'tglakhir'=> $this->retValOrNull($_POST['tglakhir']), ); return $dataArray; } } ?>