<?php
/** Generated Model Class **/ 

Class JenisAkun {    
	private static $columns = "nama,kode,normal,posisi,aktif";
	private static $errors;
	
	private static function generate_date($field_name,$array) {
		if (isset($array[$field_name.'_date']) && isset($array[$field_name.'_month']) && isset($array[$field_name.'_date']))
		$array[$field_name.''] = mktime(0, 0, 0, $array[$field_name.'_month'], $array[$field_name.'_date'], $array[$field_name.'_year']);
		
		return $array;
	}
	
	public static function create($array) {
		$jenis_akun = R::dispense("jenis_akun");
		
		$jenis_akun->import($array,self::$columns);
		$id = R::store($jenis_akun);
		
		return $id;
	}
	
	public static function update($id,$array) {
		$jenis_akun = R::load("jenis_akun",$id);
		
		$jenis_akun->import($array,self::$columns);		
		
		R::store($jenis_akun);
		return true;
	}
	
	public static function countAll($active = "") {
	
		if ($active == "all") {
			$q = "select count(1) from jenis_akun";
		} else {
			$q = "select count(1) from jenis_akun where aktif = 'y'";
		}
		
		$data = R::getCell($q);
		return $data;
	}
	
	public static function getAll($active = "") {

		if ($active == "all") {
			$q = "select * from jenis_akun";
		} else {
			$q = "select * from jenis_akun where aktif = 'y'";
		}
		
		$data = R::getAll($q);
		return $data;
	}
	
	public static function getByName($nama = "") {
		$q = "select * from jenis_akun where nama like '%".$nama."%'";
		
		$data = R::getRow($q);
		return $data;
	}
	
	public static function getByPosisi($posisi) {
		$q = "select * from jenis_akun where posisi = '$posisi'";
		
		$data = R::getAll($q);
		return $data;
	}
	
	public static function get($id) {
		$q = "select * from jenis_akun where id = $id";
		$data = R::getRow($q);
		return $data;
	}
	
	public static function getNama($id) {
		$data = R::getCell("select nama from jenis_akun where id = $id");
		return $data;
	}
	
	public static function getColumns() {
		return explode(",",self::$columns);
	}

	public static function remove($id) {
		$data = R::load("jenis_akun",$id);
		$data["aktif"] = "t";
		R::store($data);
		// R::trash($data);
	}
}
?>
