81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageAdminGudang extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelAdminGudang', 'MAG');
|
|
$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()
|
|
{
|
|
|
|
$datGudang = $this->MAG->getDataAdminGudang();
|
|
|
|
$data = [
|
|
'sidebar' => "data master service",
|
|
'navChild' => "data master admin gudang",
|
|
'gudang' => $datGudang
|
|
];
|
|
|
|
$this->load->view('master/AdminGudang', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_admingudang = $this->input->post('id');
|
|
$nama = $this->input->post('nama');
|
|
|
|
$this->form_validation->set_rules('nama', 'Nama', 'required');
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'nama' => form_error('nama')
|
|
|
|
]
|
|
];
|
|
$this->output_json($data);
|
|
} else {
|
|
|
|
$input = [
|
|
'NAMA_ADMINGUDANG' => $nama
|
|
|
|
];
|
|
|
|
if ($method === 'add') {
|
|
$action = $this->MAG->create('admingudang', $input);
|
|
} else if ($method === 'edit') {
|
|
$action = $this->MAG->update('admingudang', $input, 'ID_ADMINGUDANG', $id_admingudang);
|
|
}
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
redirect('ManageAdminGudang');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageAdminGudang');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MAG->delete('admingudang', $id, 'ID_ADMINGUDANG')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageAdminGudang');
|
|
}
|
|
}
|
|
|
|
}
|