copy dari repo om Irfan
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class ManageBarang extends CI_Controller
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('ModelBarang', 'MBarang');
|
||||
$this->load->library(['datatables', 'form_validation']);
|
||||
$this->form_validation->set_error_delimiters('', '');
|
||||
}
|
||||
public function output_json($data, $encode = true)
|
||||
{
|
||||
if ($encode) $data = json_encode($data);
|
||||
$this->output->set_content_type('application/json')->set_output($data);
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$username = $this->session->userdata('username');
|
||||
$jabatan = $this->session->userdata('jabatan');
|
||||
if ($username == null) {
|
||||
redirect("Action");
|
||||
} elseif ($jabatan != "ADMIN") {
|
||||
redirect("Action");
|
||||
}
|
||||
|
||||
$datBarang = $this->MBarang->getDataBarang();
|
||||
|
||||
$data = [
|
||||
'sidebar' => "data master service",
|
||||
'navChild' => "data proses barang",
|
||||
'barang' => $datBarang
|
||||
];
|
||||
|
||||
$this->load->view('master/Barang', $data);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$username = $this->session->userdata('username');
|
||||
if ($username == null) {
|
||||
redirect("Login");
|
||||
}
|
||||
$datBarang = $this->MBarang->getDataBarang();
|
||||
$data = [
|
||||
'sidebar' => "data master service",
|
||||
'navChild' => "data proses barang",
|
||||
'barang' => $datBarang
|
||||
];
|
||||
$this->load->view('proses/TambahBarang', $data);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$method = $this->input->post('method');
|
||||
$id_barang = $this->input->post('id');
|
||||
$jenis = $this->input->post('JENIS');
|
||||
$kode_barang = $this->input->post('kode_barang');
|
||||
$nama_barang = $this->input->post('nama_barang');
|
||||
$keterangan_barang = $this->input->post('keterangan_barang');
|
||||
|
||||
$this->form_validation->set_rules('JENIS', 'Pilih Jenis', 'required');
|
||||
$this->form_validation->set_rules('kode_barang', 'Kode Barang', 'required');
|
||||
$this->form_validation->set_rules('nama_barang', 'Nama Barang', 'required');
|
||||
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$data = [
|
||||
'status' => false,
|
||||
'errors' => [
|
||||
'JENIS' => form_error('JENIS'),
|
||||
'kode_barang' => form_error('kode_barang'),
|
||||
'nama_barang' => form_error('nama_barang')
|
||||
]
|
||||
];
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect('ManageBarang');
|
||||
|
||||
} else {
|
||||
|
||||
$input = [
|
||||
'JENIS_ID' => $jenis,
|
||||
'KODE_BARANG' => $kode_barang,
|
||||
'NAMA_BARANG' => $nama_barang,
|
||||
'KETERANGAN_BARANG' => $keterangan_barang
|
||||
];
|
||||
|
||||
$action = $this->MBarang->create('barang', $input);
|
||||
|
||||
if ($action) {
|
||||
$this->session->set_flashdata('flash', 'ditambah');
|
||||
redirect('ManageBarang');
|
||||
} else {
|
||||
$this->session->set_flashdata('flashgagal', 'ditambah');
|
||||
redirect('ManageBarang');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function hapus()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
if ($this->MBarang->delete('barang', $id, 'ID_BARANG')) {
|
||||
$this->session->set_flashdata('flash', 'dihapus');
|
||||
redirect('ManageBarang');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user