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

class Supl extends CI_Controller
{

	function __construct()
	{
		parent::__construct();
		check_not_login(); // kode akses login diambil dari helper
		check_admin();
		$this->load->model(['Lokcab_m', 'Supl_m']);
		$this->load->library('form_validation');
	}

	public function index()
	{
		$data['lokcabID'] = $this->Lokcab_m->get();
		$data['invid'] = $this->Supl_m->get();
		$this->template->load('template', 'supl', $data);
	}

	public function addsupl()
	{
		$this->form_validation->set_rules('nama_sup', 'nama_sup', 'trim|required|is_unique[tb_supplier.nama_sup]');
		$this->form_validation->set_message('required', '" masih kossong "');
		$this->form_validation->set_message('is_unique', '" sudah terdaftar "');
		if ($this->form_validation->run() == false) {
			$this->template->load('template', 'supl/addsupl');
		} else {
			$post = $this->input->post(null, TRUE);
			$this->Supl_m->addsupl($post);
			if ($this->db->affected_rows() > 0) {
				$this->session->set_flashdata('success', 'Data Suplier Baru berhasil Disimpan');
			}
			redirect($_SERVER['HTTP_REFERER']);
		}
	}

	public function delsupl($id)
	{
		$this->Supl_m->delsupl($id);
		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('success', 'Data Supllier berhasil Dihapus');
		}
		redirect($_SERVER['HTTP_REFERER']);
	}
}
