<?php
class AppPembuatanNim extends Database {

   protected $mSqlFile= 'module/pembuatan_nim/business/apppembuatannim.sql.php';

   function __construct($connectionNumber=0) {
      parent::__construct($connectionNumber);
      #$this->SetDebugOn();
   }
   
   function GetNimKomponen($nim) {
      $result=$this->Open($this->mSqlQueries['get_nim_komponen'], array($nim));
      return $result;
   }
   
   function GetNimFormula() {
      $result=$this->Open($this->mSqlQueries['get_nim_formula'], array());
      return $result;
   }
   
   function GetNimKomponenByKode($kode) {
      $result=$this->Open($this->mSqlQueries['get_nim_komponen_by_kode'], array($kode));
      return $result[0];
   }
   
   function GetDataFromQuery($query, $arr_params=array()) {
      $result=$this->Open($query, $arr_params);
      #print($this->GetLastError());
      return $result[0]['VALUE'];
   }
   
   function GetProdiByMhsid($mhs_id) {
      $result=$this->Open($this->mSqlQueries['get_prodi_by_mhsid'], array($mhs_id));
      return $result[0]['VALUE'];
   }
   
   function GetFakultasByMhsid($mhs_id) {
      $result=$this->Open($this->mSqlQueries['get_fakultas_by_mhsid'], array($mhs_id));
      return $result[0]['VALUE'];
   }
   
   function GetJenjangByMhsid($mhs_id) {
      $result=$this->Open($this->mSqlQueries['get_jenjang_by_mhsid'], array($mhs_id));
      return $result[0]['VALUE'];
   }

   function GetCekVerifikasi($mhs_id) {
      $result=$this->Open($this->mSqlQueries['get_cek_verifikasi'], array($mhs_id));
      return $result[0]['JML'];
   }
   
   function GetCountDataMahasiswa($prodi,$notes_nim,$notes_nim,$nama,$status_reg,$status_mhs,$status_byr){
      $result =$this->Open($this->mSqlQueries['get_count_data_mahasiswa'],array('%'.$prodi.'%','%'.$nama.'%','%'.$status_reg.'%','%'.$status_mhs.'%','%'.$status_byr.'%','%'.$notes_nim.'%','%'.$notes_nim.'%'));
		#print($this->GetLastError());
	   if (!$result) {
			return 0;
		} else {
			return $result[0]['total'];
		}
   }
   
   function GetDataMahasiswa($prodi,$notes_nim,$notes_nim,$nama,$status_reg,$status_mhs,$status_byr,$offset,$limit){
      $result = $this->Open($this->mSqlQueries['get_data_mahasiswa'],array('%'.$prodi.'%','%'.$nama.'%','%'.$status_reg.'%','%'.$status_mhs.'%','%'.$status_byr.'%','%'.$notes_nim.'%','%'.$notes_nim.'%',$offset,$limit));
      #print($this->GetLastError());
      return $result;
   }
   
   function getDataBuatNimMassal($prodi,$notes_nim,$notes_nim,$nama,$status_reg,$status_mhs,$status_byr){
   		$result = $this->Open($this->mSqlQueries['get_data_buat_nim_massal'],array('%'.$prodi.'%','%'.$nama.'%','%'.$status_reg.'%','%'.$status_mhs.'%','%'.$status_byr.'%','%'.$notes_nim.'%','%'.$notes_nim.'%'));
	    //print($this->GetLastError()); exit;
   		return $result;	
   }
   
   function GetDataTahunMasuk() {
      $tahun = date("Y");
      $awal = $tahun-10;
      $akhir = $tahun+10;
      $cnt = 0;
      while ($akhir >= $awal) {
         $tmp = $akhir + 1;
         $result_array[$cnt][id] = $akhir;
         $result_array[$cnt][name] = $akhir.'/'.$tmp;
         $akhir--;
         $cnt++;
      }
      return $result_array;
   }
   
   function GetDataProdi(){
      $result=$this->Open($this->mSqlQueries['get_data_prodi'], array());
      return $result;
   }
   
   function GetDataProdiById($idProdi){
      $result=$this->Open($this->mSqlQueries['get_data_prodi_by_id'], array($idProdi));
      return $result;
   }
   
   function GetPeriodeAktif(){
      $result=$this->Open($this->mSqlQueries['get_periode_aktif'], array());
      return $result;
   }
   
   function GetStatusRegistrasi(){
      $dataStatusReg[0]['id']="S";
      $dataStatusReg[0]['name']="Sudah";
      $dataStatusReg[1]['id']="B";
      $dataStatusReg[1]['name']="Belum";      
      return $dataStatusReg;
   }
   
   function GetStatusMahasiswa(){
      $dataStatusMhs[0]['id']="0";
      $dataStatusMhs[0]['name']="Mahasiswa";
      $dataStatusMhs[1]['id']="1";
      $dataStatusMhs[1]['name']="Calon Mahasiswa";      
      return $dataStatusMhs;
   }
   
   //combo status bayar
   function GetStatusBayar(){
      $statusBayar[0]['id']="BB";
      $statusBayar[0]['name']="Belum Bayar";
      $statusBayar[1]['id']="BL";
      $statusBayar[1]['name']="Belum Lunas";
      $statusBayar[2]['id']="LN";
      $statusBayar[2]['name']="Lunas";
      return $statusBayar;
   }
   
//===DO===
   function DoUpdateMahasiswaIsCalon($id){
      $result=$this->Execute($this->mSqlQueries['do_update_mahasiswa_is_calon'],array($id));
      return $result;
   }

   function DoUpdateNim($nim, $id) {
      $result=$this->Execute($this->mSqlQueries['do_update_nim'], array($nim, $id));
      #print($this->GetLastError());
      return $result;
   }

   function DoUpdateIsSent($mhs_id) {
      $result=$this->Execute($this->mSqlQueries['do_update_is_sent'], array($mhs_id));
      #print($this->GetLastError());
      return $result;
   }
   
   function DoCreateNim($mhs_id,$nim_formula){
      $result=$this->Open($this->mSqlQueries['do_create_nim'],array($mhs_id,$nim_formula));
      //print($this->GetLastError());exit;
      return $result[0]['NIM'];
   }
   
   
   function getSettPembayaran(){
   		$result = $this->Open($this->mSqlQueries['get_sett_pembayaran'],array());
   		return $result[0]['IS_AKTIF'];
   }
   
   function getSettBuatNIMMassal(){
   		$result = $this->Open($this->mSqlQueries['get_sett_buatnimmassal'],array());
   		return $result[0]['IS_AKTIF'];
   }

}
?>