<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Pad extends MY_Controller {

    protected $template = "app";
    protected $module = "pad";
	
	protected $per_page = 20;

    public function __construct() {
        parent::__construct();
		$this->load->model('m_pad');

    }

    public function index() {
        $this->data['halaman'] = "Data PAD";
        $this->data['sub_halaman'] = "";
		
		
		$total_data = $this->m_pad->getPad(true);
        $this->data['total_data'] = $total_data;

        //CONFIG PAGINATION
        $this->load->library('pagination');

        $url = site_url('inventaris/peralatan/index');
        $per_page = $this->per_page;
        $uri_segment = 3;

        $this->data['link_paging'] = $this->paging->set_paging2($url, $total_data, $per_page,$uri_segment);
        if ($this->uri->segment($uri_segment)) {
            $this->cur_page = $page = $this->uri->segment($uri_segment);
        } else {
            $this->cur_page = $page = 0;
        }

        $this->data['per_page']     = $per_page;
        $this->data['data']         = $this->m_pad->getPad(false, $per_page, $page);
        //END CONFIG PAGINATION
		
		if(!empty($this->input->get('id_padEdit'))){
			$this->data['edit'] = $this->m_pad->getPad(false, false, false, $this->input->get('id_padEdit'));
		}
		
        $this->render('index');
    }
	
	function create_edit(){
		$data = $this->input->post();
		
		//print("<pre>".print_r($data, true)."</pre>"); die();
		
		$param = array(
			"tahun" => $data['tahun'],
			"bulan" => $data['bulan'],
			"nominal" => $data['nominal'],
			"keterangan" => $data['keterangan'],
			"last_modified_user" => $this->idUser
		);
		$status = $this->m_pad->createEdit($param, $data['id_pad']);
		
		if($status){
			$msg = 'PAD berhasil disimpan';
			$this->session->set_flashdata('msg', $msg);
		}else{
			$msg = 'PAD gagal disimpan';
			$this->session->set_flashdata('msgw', $msg);
		}
		redirect('inventaris/pad/index');
	}
	
	function hapus_pad(){
		$id_pad = $this->input->get('id_pad');
		
		$status = $this->m_pad->hapusPad($id_pad);
		
		if($status){
			$msg = 'PAD berhasil dihapus';
			$this->session->set_flashdata('msg', $msg);
		}else{
			$msg = 'PAD gagal dihapus';
			$this->session->set_flashdata('msgw', $msg);
		}
		redirect('inventaris/pad/index');
	}
}