134 lines
3.6 KiB
PHP
134 lines
3.6 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Warehouses extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
if (!$this->session->userdata('logged_in')) {
|
|
redirect('auth');
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
redirect('inventoryprofessional/locations');
|
|
}
|
|
|
|
// =========================
|
|
// GET DATA (DATATABLE)
|
|
// =========================
|
|
public function get_data()
|
|
{
|
|
$data = $this->db->where('company_id',(int)$this->session->userdata('company_id'))->get('warehouses')->result();
|
|
|
|
$result = [];
|
|
$no = 1;
|
|
|
|
foreach ($data as $row) {
|
|
$result[] = [
|
|
$no++,
|
|
$row->nama,
|
|
($this->session->userdata('role')==='Admin'||check_permission('items','can_update'))?'<button class="btn btn-sm btn-secondary btn-editgudang" data-id="'.$row->id.'">Edit</button>':'-'
|
|
];
|
|
}
|
|
|
|
echo json_encode(["data"=>$result]);
|
|
}
|
|
|
|
// =========================
|
|
// DETAIL
|
|
// =========================
|
|
public function detail($id)
|
|
{
|
|
echo json_encode(
|
|
$this->db->get_where('warehouses',['id'=>$id,'company_id'=>(int)$this->session->userdata('company_id')])->row()
|
|
);
|
|
}
|
|
|
|
// =========================
|
|
// SAVE
|
|
// =========================
|
|
public function save()
|
|
{
|
|
$nama = $this->input->post('nama');
|
|
|
|
if(!$nama){
|
|
echo json_encode(['status'=>false,'message'=>'Nama wajib diisi']);
|
|
return;
|
|
}
|
|
|
|
$this->db->insert('warehouses', [
|
|
'nama' => $nama,
|
|
'company_id'=>(int)$this->session->userdata('company_id'),
|
|
'code'=>'GD-'.strtoupper(substr(sha1(uniqid('',true)),0,6)),
|
|
'is_active'=>1
|
|
]);
|
|
|
|
log_activity(
|
|
'kode_barang',
|
|
'create',
|
|
'Tambah gudang '.$nama,
|
|
'success'
|
|
);
|
|
|
|
echo json_encode(['status'=>true,'message'=>'Gudang berhasil ditambahkan']);
|
|
}
|
|
|
|
// =========================
|
|
// UPDATE
|
|
// =========================
|
|
public function update()
|
|
{
|
|
$id = $this->input->post('id');
|
|
$nama = $this->input->post('nama');
|
|
|
|
if(!$nama){
|
|
echo json_encode(['status'=>false,'message'=>'Nama wajib diisi']);
|
|
return;
|
|
}
|
|
|
|
$this->db->where(array('id'=>$id,'company_id'=>(int)$this->session->userdata('company_id')))->update('warehouses', [
|
|
'nama' => $nama
|
|
]);
|
|
|
|
log_activity(
|
|
'kode_barang',
|
|
'update',
|
|
'Update gudang '.$nama,
|
|
'success'
|
|
);
|
|
|
|
echo json_encode(['status'=>true,'message'=>'Gudang berhasil diupdate']);
|
|
}
|
|
|
|
// =========================
|
|
// DELETE
|
|
// =========================
|
|
public function delete($id)
|
|
{
|
|
if (strtoupper($this->input->method()) !== 'POST') {
|
|
$this->output->set_status_header(405);
|
|
} else {
|
|
$this->output->set_status_header(409);
|
|
}
|
|
|
|
return $this->output
|
|
->set_content_type('application/json')
|
|
->set_output(json_encode(array(
|
|
'status' => false,
|
|
'message' => 'Gudang tidak dapat dihapus. Nonaktifkan melalui menu Gudang & Lokasi Rak.'
|
|
)));
|
|
}
|
|
|
|
|
|
public function list()
|
|
{
|
|
echo json_encode(
|
|
$this->db->where(array('company_id'=>(int)$this->session->userdata('company_id'),'is_active'=>1))->order_by('nama')->get('warehouses')->result()
|
|
);
|
|
}
|
|
}
|