<?php

class AppPeriode extends Database {

	protected $mSqlFile= 'module/periode/business/appperiode.sql.php';
	
	function __construct($connectionNumber=0) {
		parent::__construct($connectionNumber);
	}
		
	function GetDataPeriode($offset, $limit) {
		$result=$this->Open($this->mSqlQueries['get_data_periode'], array($offset, $limit));
      return $result;
	}

	function GetCountDataPeriode($prdId) {
		$result = $this->Open($this->mSqlQueries['get_count_data_periode'], array('%'.$prdId.'%'));
		if (!$result) {
			return 0;
		} else {
			return $result[0]['total'];
		}
	}

	function GetDataPeriodeById($prdId) {
		$result = $this->Open($this->mSqlQueries['get_data_periode_by_id'], array($prdId));
		return $result;
	}

	function GetDataPeriodeByArrayId($arrPrdId) {
		$prdId = implode("', '", $arrPrdId);
		$result = $this->Open($this->mSqlQueries['get_data_periode_by_array_id'], array($prdId));
		return $result;
	}
	
	function GetPeriodeAktif(){
      $result=$this->Open($this->mSqlQueries['get_periode_aktif'],array());
      return $result;
   }
   
	function GetComboNamaPeriode() {
      return $this->Open($this->mSqlQueries['get_combo_nama_periode'],array());
   }
   
   function GetComboNamaPeriodeById($id) {
      return $this->Open($this->mSqlQueries['get_combo_nama_periode_by_id'],array($id));
   }
   
   function GetTahun() {
      $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 GetPeriodeAkhir(){
      return $this->Open($this->mSqlQueries['get_periode_akhir'],array());
   }
   
//===DO==
	
	function DoAddPeriode($prdTahun,$prdNmprdId,$prdIsAktif) {
		$result = $this->Execute($this->mSqlQueries['do_add_periode'], array($prdTahun,$prdNmprdId,$prdIsAktif));
		return $result;
	}
	
	function DoUpdatePeriode($prdTahun,$prdNmprdId, $Id) {
		$result = $this->Execute($this->mSqlQueries['do_update_periode'], array($prdTahun,$prdNmprdId, $Id));
		return $result;
	}
	
	function DoNonAktifPeriode($prdIsAktif){
		$result = $this->Execute($this->mSqlQueries['do_non_aktif_periode'], array($prdIsAktif));
      return $result;
   }
	
	function DoAktifPeriode($id){
      $result = $this->Execute($this->mSqlQueries['do_aktif_periode'], array($id));
      return $result;
   }
   
	function DoDeletePeriodeById($prdId) {
		$result=$this->Execute($this->mSqlQueries['do_delete_periode_by_id'], array($prdId));
		return $result;
	}

	function DoDeletePeriodeByArrayId($arrPrdId) {
		$prdId = implode("', '", $arrPrdId);
		$result=$this->Execute($this->mSqlQueries['do_delete_periode_by_array_id'], array($prdId));
		return $result;
	}
}
?>
