<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class Perkiraan extends MX_Controller {
	
	
	public function __construct(){
		parent::__construct();
		
		$this->page->use_directory();
		$this->load->model('model_perkiraan');	
	}

	function index() {
		$this->page->view('perkiraan_index', array (
			'add'		=> $this->page->base_url('/add'),
			'grid'		=> $this->model_perkiraan->get_perkiraan(),
		));
	}
	
	private function form($action = 'insert', $id = ''){
		$this->page->view('perkiraan_form', array (
			'back'			=> $this->agent->referrer(),
			'action'		=> $this->page->base_url("/{$action}/{$id}"),
			'perkiraan'		=> $this->model_perkiraan->by_id_perkiraan($id),
		));
	}
	
	public function add(){
		$this->form();
	}
	
	public function edit($id){
		$this->form('update', $id);
	}
	
	public function insert(){
		$data = array(
			'kode' => $this->input->post('kode'),
			'nama' => $this->input->post('nama'),
			'status' => $this->input->post('status'),
			'aktif' => $this->input->post('aktif'),
		);
		$this->db->insert('perkiraan', $data);
		
		redirect($this->page->base_url());
	}
	
	public function update($id){
		$data = array(
			'kode' => $this->input->post('kode'),
			'nama' => $this->input->post('nama'),
			'status' => $this->input->post('status'),
			'aktif' => $this->input->post('aktif'),			
		);
		$this->db->where('id', $id);
		$this->db->update('perkiraan', $data);
		
		redirect($this->page->base_url());
	}
	
}

/* End of file Perkiraan.php */
/* Location: ./application/modules/master_data/controllers/Perkiraan.php */