<?php

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

class Glassware extends MY_Controller {

    protected $template = "app";
    protected $module = "glassware";

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

    public function index() {
        $this->data['halaman'] = "Glassware";
        $this->data['sub_halaman'] = '';
        $this->data['data']= $this->model->get_data();

        $this->render('index');
    }

    public function create_edit($id=null) {
      $this->data['halaman'] = is_null($id) ? "Tambah Data Glassware" : "Edit Data Glassware";
      if(!is_null($id)){
        $this->data['edit'] = $this->model->get_detail($id);
      }else {
        $this->data['sub_halaman'] = '';
      }

      $data = $this->input->post();

      if($data){
        $data['last_modified_user'] = $this->idUser;
        $param_keys = array_keys($data);

        if($id) $status = $this->model->set_data($data, $param_keys, $id);
        else $status = $this->model->set_data($data, $param_keys);

        if($status){
            if(is_null($id))$this->session->set_flashdata('msg', 'data bahan habis pakai berhasil ditambahkan');
            else $this->session->set_flashdata('msg', 'data bahan habis pakai berhasil diubah');
        }else{
            $this->session->set_flashdata('msg', 'data bahan habis pakai gagal ditambahkan');
        }
        redirect('/inventaris/glassware/index');
      }
      $this->render('create_edit');
    }

    function hapus($id){
      $data['is_active'] = '0';
      $data['last_modified_user'] = $this->idUser;

      $param_keys = array_keys($data);
      $status = $this->model->set_data($data, $param_keys, $id);

      if($status){
          $this->session->set_flashdata('msg', 'data bahan habis pakai berhasil dihapus');
      }else{
          $this->session->set_flashdata('msg', 'data bahan habis pakai gagal dihapus');
      }
      redirect('/inventaris/glassware/index');
    }
}
