116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Accounts extends MY_Controller {
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->requirePermission('jurnal');
|
|
$this->load->model('DynamicModel', 'dm');
|
|
$this->load->library('ChartOfAccountsService');
|
|
|
|
if (!$this->session->userdata('logged_in')) {
|
|
redirect('auth');
|
|
}
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
if($this->session->userdata('role') != 'Admin'){
|
|
show_error('Akses ditolak', 403);
|
|
}
|
|
|
|
$data = [
|
|
"active_menu" => "accounts",
|
|
"parent_accounts" => $this->db->get('accounts')->result()
|
|
];
|
|
|
|
$this->load->view('partials/header', $data);
|
|
$this->load->view('accounts/layout', $data);
|
|
$this->load->view('partials/footer');
|
|
}
|
|
|
|
public function get_data()
|
|
{
|
|
$this->dm->setTable('accounts')
|
|
->setColumn(
|
|
[null,'kode_akun','priority','nama_akun','tipe','posisi','kategori','is_header','is_hidden','is_active',null],
|
|
['kode_akun','nama_akun','tipe'],
|
|
['kode_akun'=>'ASC']
|
|
);
|
|
|
|
$list = $this->dm->get_datatables();
|
|
|
|
$data = [];
|
|
$no = $_POST['start'];
|
|
|
|
foreach ($list as $row) {
|
|
$no++;
|
|
|
|
$data[] = [
|
|
$no,
|
|
$row->kode_akun,
|
|
$row->priority,
|
|
$row->nama_akun,
|
|
ucfirst($row->tipe),
|
|
ucfirst($row->posisi),
|
|
ucfirst($row->kategori),
|
|
$row->is_header ? 'Header' : 'Transaksi',
|
|
$row->is_hidden ? '<span class="badge bg-warning text-dark">Disembunyikan</span>' : '<span class="badge bg-info text-dark">Ditampilkan</span>',
|
|
$row->is_active ? '<span class="badge bg-success">Aktif</span>' : '<span class="badge bg-secondary">Nonaktif</span>',
|
|
'
|
|
<button class="btn btn-sm btn-warning btn-edit" data-id="'.$row->id.'">Edit</button>
|
|
<button class="btn btn-sm btn-danger btn-delete" data-id="'.$row->id.'">Delete</button>
|
|
'
|
|
];
|
|
}
|
|
|
|
echo json_encode([
|
|
"draw" => $_POST['draw'],
|
|
"recordsTotal" => $this->dm->count_all(),
|
|
"recordsFiltered" => $this->dm->count_filtered(),
|
|
"data" => $data
|
|
]);
|
|
}
|
|
|
|
// ================= SAVE
|
|
public function save()
|
|
{
|
|
try {
|
|
$id = $this->chartofaccountsservice->save($this->input->post(), null, $this->session->userdata('user_id'));
|
|
log_activity('Accounts', 'create', 'Menambah akun ID '.$id);
|
|
return json_response(true, 'Akun berhasil disimpan.', array('id' => $id));
|
|
} catch (Throwable $exception) { return business_exception_response($exception); }
|
|
}
|
|
|
|
// ================= UPDATE
|
|
public function update()
|
|
{
|
|
try {
|
|
$id = $this->chartofaccountsservice->save($this->input->post(), $this->input->post('id'), $this->session->userdata('user_id'));
|
|
log_activity('Accounts', 'update', 'Memperbarui akun ID '.$id);
|
|
return json_response(true, 'Akun berhasil diperbarui.', array('id' => $id));
|
|
} catch (Throwable $exception) { return business_exception_response($exception); }
|
|
}
|
|
|
|
public function detail($id)
|
|
{
|
|
$data = $this->dm->setTable('accounts')->find($id);
|
|
echo json_encode($data);
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
if (strtoupper($this->input->method()) !== 'POST') {
|
|
return json_response(false, 'Metode request tidak diizinkan.', array(), 405);
|
|
}
|
|
try {
|
|
$this->chartofaccountsservice->delete($id, $this->session->userdata('user_id'));
|
|
log_activity('Accounts', 'delete', 'Menghapus akun ID '.$id, 'success');
|
|
return json_response(true, 'Akun berhasil dihapus.');
|
|
} catch (Throwable $exception) { return business_exception_response($exception); }
|
|
}
|
|
}
|