167 lines
3.9 KiB
PHP
167 lines
3.9 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageInventorySn extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelInventorySn', 'MISn');
|
|
$this->load->model('ModelInventory', 'MI');
|
|
$this->load->model('ModelType', 'MType');
|
|
$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");
|
|
}
|
|
|
|
$datInventorySn = $this->MISn->getDataInventorySn();
|
|
|
|
$data = [
|
|
'sidebar' => "data inventory",
|
|
'navChild' => "data inventory sn",
|
|
'sn' => $datInventorySn
|
|
];
|
|
|
|
$this->load->view('inventory/table-inventorySn', $data);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
}
|
|
$datInventorySn = $this->MISn->getDataInventorySn();
|
|
$datInventory = $this->MI->getDataInventory();
|
|
$data = [
|
|
'sidebar' => "data inventory",
|
|
'navChild' => "data inventory sn",
|
|
'sn' => $datInventorySn,
|
|
'inventory' => $datInventory
|
|
];
|
|
//var_dump($data);
|
|
$this->load->view('inventory/sn', $data);
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$method = $this->input->post('method');
|
|
$id_sn = $this->input->post('id');
|
|
$nama_sn = $this->input->post('nama_sn');
|
|
$inventory = $this->input->post('INVENTORY');
|
|
|
|
$this->form_validation->set_rules('nama_sn', 'Serial Number', 'required');
|
|
$this->form_validation->set_rules('INVENTORY', 'Pilih Type', 'required');
|
|
|
|
if ($this->form_validation->run() == FALSE) {
|
|
$data = [
|
|
'status' => false,
|
|
'errors' => [
|
|
'nama_sn' => form_error('nama_sn'),
|
|
'INVENTORY' => form_error('INVENTORY')
|
|
]
|
|
];
|
|
//$this->output_json($data);//
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
redirect('ManageInventorySn');
|
|
|
|
} else {
|
|
|
|
$input = [
|
|
'NAMA_SN' => $nama_sn,
|
|
'ID_INVENTORY' => $inventory
|
|
];
|
|
|
|
$action = $this->MISn->create('sn', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('flash', 'ditambah');
|
|
//$this->output_json(['status' => true]);
|
|
redirect('ManageInventorySn');
|
|
} else {
|
|
$this->session->set_flashdata('flashgagal', 'ditambah');
|
|
//$this->output_json(['status' => true]);
|
|
redirect('ManageInventorySn');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public function hapus()
|
|
{
|
|
$id = $this->input->post('id');
|
|
if ($this->MISn->delete('sn', $id, 'ID_SN')) {
|
|
$this->session->set_flashdata('flash', 'dihapus');
|
|
redirect('ManageInventorySn');
|
|
}
|
|
}
|
|
|
|
public function sn()
|
|
{
|
|
$username = $this->session->userdata('username');
|
|
$jabatan = $this->session->userdata('jabatan');
|
|
if ($username == null) {
|
|
redirect("Login");
|
|
} elseif ($jabatan != "ADMIN") {
|
|
redirect("Login");
|
|
}
|
|
|
|
$inventory = $this->MISn->getInventory();
|
|
|
|
$data = [
|
|
'sidebar' => "data inventory",
|
|
'navChild' => "data inventory sn",
|
|
'sn' => $inventory
|
|
];
|
|
|
|
$this->load->view('inventory/sn', $data);
|
|
}
|
|
|
|
public function getsn($id)
|
|
{
|
|
$sn = $this->MISn->getSnn($id);
|
|
$this->output_json(['sn' => $sn]);
|
|
}
|
|
|
|
public function ambildata($id = null)
|
|
{
|
|
if ($id != null) {
|
|
$sn = $this->MISn->getSnn($id);
|
|
$data = ['inventory' => $id, 'sn' => $sn];
|
|
$this->load->view('inventory/ambildata', $data);
|
|
} else {
|
|
$data = ['inventory' => null, 'sn' => []];
|
|
$this->load->view('inventory/ambildata', $data);
|
|
}
|
|
}
|
|
|
|
public function tambahsn($inventory, $sn)
|
|
{
|
|
|
|
$input = [
|
|
'NAMA_SN' => $sn,
|
|
'ID_INVENTORY' => $inventory
|
|
];
|
|
|
|
$action = $this->MISn->create('sn', $input);
|
|
|
|
if ($action) {
|
|
$this->output_json(['value' => "berhasil"]);
|
|
}
|
|
}
|
|
|
|
}
|