Files
2026-06-13 16:02:07 +10:00

124 lines
3.2 KiB
PHP

<?php
use Restserver\Libraries\REST_Controller;
defined('BASEPATH') or exit('No direct script access allowed');
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';
class ManageKelompok 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);
$datKelompok = $this->Dashboard->getData_Kelompok();
$no = 0;
foreach ($datKelompok as $key) {
$datPelanggan = $this->Dashboard->getData_Pelanggan_byKELOMPOK($key['ID_KELOMPOK']);
if ($datPelanggan==TRUE) {
$lock = 1;
} else {
$lock = 0;
}
$datKelompok[$no++] += ['LOCK' => $lock];
}
if ($datShm[0]['KELOMPOK_SHM']==0) {
$akses = "Tidak Berhak";
$datKelompok = NULL;
} else if ($datShm[0]['KELOMPOK_SHM']==1) {
$akses = "Hanya Baca";
} else if ($datShm[0]['KELOMPOK_SHM']==2) {
$akses = "Akses Penuh";
}
$data = [
'sidebar' => "dashboard",
'navChild' => "",
'kelompok' => $datKelompok,
'hak' => $datShm[0]['KELOMPOK_SHM'],
'akses' => $akses,
];
$this->load->view('master/Kelompok', $data);
}
public function simpan() {
$method = $this->input->post('method');
$id = $this->input->post('id_kelompok');
$nama_kelompok = $this->input->post('nama_kelompok');
$input = [
'NAMA_KELOMPOK' => $nama_kelompok
];
$action = $this->Dashboard->create('kelompok', $input);
if ($action) {
$this->session->set_flashdata('success', 'ditambah');
redirect('ManageKelompok');
} else {
$this->session->set_flashdata('failed', 'ditambah');
redirect('ManageKelompok');
}
}
public function ubah() {
$method = $this->input->post('method');
$id_kelompok = $this->input->post('id_kelompoked');
$nama_kelompok = $this->input->post('nama_kelompoked');
$update = [
'NAMA_KELOMPOK' => $nama_kelompok
];
$action = $this->Dashboard->update('kelompok', $update, 'ID_KELOMPOK', $id_kelompok);
if ($action) {
$this->session->set_flashdata('success', 'diubah');
redirect('ManageKelompok');
} else {
$this->session->set_flashdata('failed', 'diubah');
redirect('ManageKelompok');
}
}
public function hapus() {
$method = $this->input->post('method');
$id = $this->input->post('id_kelompokdel');
$datPelanggan = $this->Dashboard->getData_Pelanggan_byKELOMPOK($id);
if ($datPelanggan==TRUE) {
$this->session->set_flashdata('data_used', 'error');
redirect('ManageKelompok');
}
$action = $this->Dashboard->delete('kelompok', $id, 'ID_KELOMPOK');
if ($action) {
$this->session->set_flashdata('success', 'dihapus');
redirect('ManageKelompok');
} else {
$this->session->set_flashdata('failed', 'dihapus');
redirect('ManageKelompok');
}
}
}