126 lines
3.7 KiB
PHP
126 lines
3.7 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class ManageKendaraan extends CI_Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('ModelDashboard', 'Dashboard');
|
|
$this->load->library(['datatables', 'form_validation']);
|
|
$this->form_validation->set_error_delimiters('', '');
|
|
$this->Dashboard->ceklogin();
|
|
}
|
|
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() {
|
|
$id_karyawan = $this->session->userdata('id_karyawan');
|
|
$datShm = $this->Dashboard->getData_SetHakMaster_byKARYAWAN($id_karyawan);
|
|
$datKendaraan = $this->Dashboard->getData_Kendaraan();
|
|
|
|
$no = 0;
|
|
foreach ($datKendaraan as $key) {
|
|
$datBbe = $this->Dashboard->getData_BiayaBensin_byKENDARAAN($key['ID_KENDARAAN']);
|
|
$datBsk = $this->Dashboard->getData_BiayaServiceKendaraan_byKENDARAAN($key['ID_KENDARAAN']);
|
|
if ($datBbe==TRUE OR $datBsk==TRUE) {
|
|
$lock = 1;
|
|
} else {
|
|
$lock = 0;
|
|
}
|
|
$datKendaraan[$no++] += ['LOCK' => $lock];
|
|
}
|
|
|
|
if ($datShm[0]['KENDARAAN_SHM']==0) {
|
|
$akses = "Tidak Berhak";
|
|
$datKendaraan = NULL;
|
|
} else if ($datShm[0]['KENDARAAN_SHM']==1) {
|
|
$akses = "Hanya Baca";
|
|
} else if ($datShm[0]['KENDARAAN_SHM']==2) {
|
|
$akses = "Akses Penuh";
|
|
}
|
|
|
|
$data = [
|
|
'sidebar' => "dashboard",
|
|
'navChild' => "",
|
|
'kendaraan' => $datKendaraan,
|
|
'hak' => $datShm[0]['KENDARAAN_SHM'],
|
|
'akses' => $akses,
|
|
];
|
|
$this->load->view('master/Kendaraan', $data);
|
|
}
|
|
|
|
public function simpan() {
|
|
$method = $this->input->post('method');
|
|
$id_kendaraan = $this->input->post('id');
|
|
$nama_kendaraan = $this->input->post('nama_kendaraan');
|
|
$type_kendaraan = $this->input->post('type_kendaraan');
|
|
$nopol_kendaraan = $this->input->post('nopol_kendaraan');
|
|
|
|
$input = [
|
|
'NAMA_KENDARAAN' => $nama_kendaraan,
|
|
'TYPE_KENDARAAN' => $type_kendaraan,
|
|
'NOPOL_KENDARAAN' => $nopol_kendaraan
|
|
];
|
|
$action = $this->Dashboard->create('kendaraan', $input);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'ditambah');
|
|
redirect('ManageKendaraan');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'ditambah');
|
|
redirect('ManageKendaraan');
|
|
}
|
|
|
|
}
|
|
|
|
public function ubah() {
|
|
$method = $this->input->post('method');
|
|
$id_kendaraan = $this->input->post('id_kendaraaned');
|
|
$nama_kendaraan = $this->input->post('nama_kendaraaned');
|
|
$type_kendaraan = $this->input->post('type_kendaraaned');
|
|
$nopol_kendaraan = $this->input->post('nopol_kendaraaned');
|
|
|
|
$update = [
|
|
'NAMA_KENDARAAN' => $nama_kendaraan,
|
|
'TYPE_KENDARAAN' => $type_kendaraan,
|
|
'NOPOL_KENDARAAN' => $nopol_kendaraan
|
|
];
|
|
$action = $this->Dashboard->update('kendaraan', $update, 'ID_KENDARAAN', $id_kendaraan);
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'diubah');
|
|
redirect('ManageKendaraan');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'diubah');
|
|
redirect('ManageKendaraan');
|
|
}
|
|
|
|
}
|
|
|
|
public function hapus() {
|
|
$id = $this->input->post('id_kendaraandel');
|
|
|
|
$datBbe = $this->Dashboard->getData_BiayaBensin_byKENDARAAN($id);
|
|
$datBse = $this->Dashboard->getData_BiayaServiceKendaraan_byKENDARAAN($id);
|
|
if ($datBbe==TRUE OR $datBse==TRUE) {
|
|
$this->session->set_flashdata('data_used', 'error');
|
|
redirect('ManageKendaraan');
|
|
}
|
|
|
|
$action = $this ->Dashboard->delete('kendaraan', $id, 'ID_KENDARAAN');
|
|
|
|
if ($action) {
|
|
$this->session->set_flashdata('success', 'dihapus');
|
|
redirect('ManageKendaraan');
|
|
} else {
|
|
$this->session->set_flashdata('failed', 'dihapus');
|
|
redirect('ManageKendaraan');
|
|
}
|
|
}
|
|
|
|
}
|