Update besar apk finance
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Accounts extends CI_Controller {
|
||||
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');
|
||||
@@ -34,7 +36,7 @@ class Accounts extends CI_Controller {
|
||||
{
|
||||
$this->dm->setTable('accounts')
|
||||
->setColumn(
|
||||
[null,'kode_akun','nama_akun','tipe','posisi','kategori',null],
|
||||
[null,'kode_akun','priority','nama_akun','tipe','posisi','kategori','is_header','is_hidden','is_active',null],
|
||||
['kode_akun','nama_akun','tipe'],
|
||||
['kode_akun'=>'ASC']
|
||||
);
|
||||
@@ -55,6 +57,9 @@ class Accounts extends CI_Controller {
|
||||
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>
|
||||
@@ -73,64 +78,21 @@ class Accounts extends CI_Controller {
|
||||
// ================= SAVE
|
||||
public function save()
|
||||
{
|
||||
$tipe = $this->input->post('tipe');
|
||||
|
||||
$data = [
|
||||
'kode_akun' => $this->input->post('kode_akun'),
|
||||
'nama_akun' => $this->input->post('nama_akun'),
|
||||
'tipe' => $tipe,
|
||||
'posisi' => in_array($tipe, ['asset','expense']) ? 'debit' : 'kredit',
|
||||
'kategori' => in_array($tipe, ['asset','liability','equity']) ? 'neraca' : 'laba_rugi',
|
||||
'parent_id' => $this->input->post('parent_id') ?: NULL,
|
||||
'priority' => $this->input->post('priority') ?: NULL
|
||||
];
|
||||
|
||||
$insert = $this->dm->setTable('accounts')->insert($data);
|
||||
|
||||
if($insert){
|
||||
log_activity(
|
||||
'Accounts',
|
||||
'create',
|
||||
'Menambah akun: '.$data['kode_akun'].' - '.$data['nama_akun']
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => $insert ? true : false,
|
||||
'message' => $insert ? 'Data berhasil disimpan' : 'Gagal simpan'
|
||||
]);
|
||||
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()
|
||||
{
|
||||
$id = $this->input->post('id');
|
||||
$tipe = $this->input->post('tipe');
|
||||
|
||||
$data = [
|
||||
'kode_akun' => $this->input->post('kode_akun'),
|
||||
'nama_akun' => $this->input->post('nama_akun'),
|
||||
'tipe' => $tipe,
|
||||
'posisi' => in_array($tipe, ['asset','expense']) ? 'debit' : 'kredit',
|
||||
'kategori' => in_array($tipe, ['asset','liability','equity']) ? 'neraca' : 'laba_rugi',
|
||||
'parent_id' => $this->input->post('parent_id') ?: NULL,
|
||||
'priority' => $this->input->post('priority') ?: NULL
|
||||
];
|
||||
|
||||
$update = $this->dm->setTable('accounts')->update($id, $data);
|
||||
|
||||
if($update){
|
||||
log_activity(
|
||||
'Accounts',
|
||||
'update',
|
||||
'Update akun ID '.$id.' menjadi: '.$data['kode_akun'].' - '.$data['nama_akun']
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => $update ? true : false,
|
||||
'message' => $update ? 'Data berhasil diupdate' : 'Gagal 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)
|
||||
@@ -141,31 +103,13 @@ class Accounts extends CI_Controller {
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
// cek apakah jadi parent
|
||||
$child = $this->db->where('parent_id',$id)->count_all_results('accounts');
|
||||
|
||||
if($child > 0){
|
||||
echo json_encode([
|
||||
'status'=>false,
|
||||
'message'=>'Tidak bisa hapus, akun punya child'
|
||||
]);
|
||||
return;
|
||||
if (strtoupper($this->input->method()) !== 'POST') {
|
||||
return json_response(false, 'Metode request tidak diizinkan.', array(), 405);
|
||||
}
|
||||
|
||||
$delete = $this->dm->setTable('accounts')->delete($id);
|
||||
|
||||
if($delete){
|
||||
log_activity(
|
||||
'Accounts',
|
||||
'delete',
|
||||
'Menghapus akun ID '.$id,
|
||||
'success'
|
||||
);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'status' => $delete ? true : false,
|
||||
'message' => $delete ? 'Data berhasil dihapus' : 'Gagal hapus'
|
||||
]);
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user