update from prod
This commit is contained in:
@@ -1,168 +1,171 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Accounts extends CI_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('DynamicModel', 'dm');
|
||||
|
||||
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','nama_akun','tipe','posisi','kategori',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->nama_akun,
|
||||
ucfirst($row->tipe),
|
||||
ucfirst($row->posisi),
|
||||
ucfirst($row->kategori),
|
||||
'
|
||||
<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()
|
||||
{
|
||||
$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
|
||||
];
|
||||
|
||||
$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'
|
||||
]);
|
||||
}
|
||||
|
||||
// ================= 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
|
||||
];
|
||||
|
||||
$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'
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$data = $this->dm->setTable('accounts')->find($id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$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'
|
||||
]);
|
||||
}
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Accounts extends CI_Controller {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('DynamicModel', 'dm');
|
||||
|
||||
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','nama_akun','tipe','posisi','kategori',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),
|
||||
'
|
||||
<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()
|
||||
{
|
||||
$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'
|
||||
]);
|
||||
}
|
||||
|
||||
// ================= 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'
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail($id)
|
||||
{
|
||||
$data = $this->dm->setTable('accounts')->find($id);
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$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'
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -646,7 +646,7 @@ class Items extends CI_Controller {
|
||||
public function get_accounts()
|
||||
{
|
||||
$data = $this->db
|
||||
->where_in('kode_akun', [101,102,201])
|
||||
->where_in('kode_akun', [101,102,201,122,125,105])
|
||||
->order_by('kode_akun','ASC')
|
||||
->get('accounts')
|
||||
->result();
|
||||
|
||||
@@ -101,7 +101,7 @@ class Neraca extends CI_Controller {
|
||||
}
|
||||
|
||||
$this->db->group_by('a.id');
|
||||
$this->db->order_by('a.kode_akun','ASC');
|
||||
$this->db->order_by('a.priority','ASC');
|
||||
|
||||
$rows = $this->db->get()->result();
|
||||
|
||||
|
||||
@@ -1,215 +1,223 @@
|
||||
<div class="container mt-4">
|
||||
<div class="card modern-card shadow-sm border-0 rounded-4">
|
||||
<div class="card-body p-4">
|
||||
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<h5 class="mb-0">Chart of Account (COA)</h5>
|
||||
<button class="btn btn-warning btn-add">Tambah Akun</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="tableAccounts" class="table modern-table align-middle w-100">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th width="5%">No</th>
|
||||
<th>Kode</th>
|
||||
<th>Nama</th>
|
||||
<th>Tipe</th>
|
||||
<th>Posisi</th>
|
||||
<th>Kategori</th>
|
||||
<th width="15%">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL -->
|
||||
<div class="modal fade" id="modalAccount">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content rounded-4">
|
||||
<div class="modal-header bg-warning text-white">
|
||||
<h5 class="modal-title">Tambah Akun</h5>
|
||||
<button class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<input type="hidden" id="inputId">
|
||||
|
||||
<label class="fw-semibold">Kode Akun</label>
|
||||
<input type="text" class="form-control" id="kode_akun">
|
||||
|
||||
<label class="fw-semibold mt-2">Nama Akun</label>
|
||||
<input type="text" class="form-control" id="nama_akun">
|
||||
|
||||
<label class="fw-semibold mt-2">Tipe</label>
|
||||
<select class="form-control" id="tipe">
|
||||
<option value="asset">Asset</option>
|
||||
<option value="liability">Liability</option>
|
||||
<option value="equity">Equity</option>
|
||||
<option value="revenue">Revenue</option>
|
||||
<option value="expense">Expense</option>
|
||||
</select>
|
||||
|
||||
<label class="fw-semibold mt-2">Parent</label>
|
||||
<select class="form-control" id="parent_id">
|
||||
<option value="">-- Tanpa Parent --</option>
|
||||
<?php foreach($parent_accounts as $p): ?>
|
||||
<option value="<?= $p->id ?>">
|
||||
<?= $p->kode_akun ?> - <?= $p->nama_akun ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
||||
<button class="btn btn-warning" id="btnSimpan">Simpan</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
|
||||
let table = $('#tableAccounts').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
responsive: true,
|
||||
autoWidth: false,
|
||||
order: [],
|
||||
ajax: {
|
||||
url: "<?= base_url('accounts/get_data'); ?>",
|
||||
type: "POST"
|
||||
},
|
||||
columns: [
|
||||
{ data: 0, orderable:false },
|
||||
{ data: 1 },
|
||||
{ data: 2 },
|
||||
{ data: 3 },
|
||||
{ data: 4 },
|
||||
{ data: 5 },
|
||||
{ data: 6, orderable:false }
|
||||
],
|
||||
language: {
|
||||
processing: `<div class="text-center"><div class="spinner-border text-warning"></div></div>`
|
||||
}
|
||||
});
|
||||
|
||||
// ================= RESET FORM
|
||||
function resetForm(){
|
||||
$('#inputId').val('');
|
||||
$('#kode_akun').val('');
|
||||
$('#nama_akun').val('');
|
||||
$('#tipe').val('asset');
|
||||
$('#parent_id').val('');
|
||||
$('#modalAccount .modal-title').text('Tambah Akun');
|
||||
}
|
||||
|
||||
// ================= OPEN MODAL
|
||||
$('.btn-add').click(function(){
|
||||
resetForm();
|
||||
$('#btnSimpan').data('action','add');
|
||||
$('#modalAccount').modal('show');
|
||||
});
|
||||
|
||||
// ================= SAVE / UPDATE
|
||||
$('#btnSimpan').click(function(){
|
||||
|
||||
let action = $(this).data('action');
|
||||
|
||||
let data = {
|
||||
id: $('#inputId').val(),
|
||||
kode_akun: $('#kode_akun').val().trim(),
|
||||
nama_akun: $('#nama_akun').val().trim(),
|
||||
tipe: $('#tipe').val(),
|
||||
parent_id: $('#parent_id').val()
|
||||
};
|
||||
|
||||
if(!data.kode_akun || !data.nama_akun){
|
||||
Swal.fire('Warning','Kode & Nama wajib diisi','warning');
|
||||
return;
|
||||
}
|
||||
|
||||
let url = action === 'add'
|
||||
? "<?= base_url('accounts/save'); ?>"
|
||||
: "<?= base_url('accounts/update'); ?>";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function(res){
|
||||
if(res.status){
|
||||
$('#modalAccount').modal('hide');
|
||||
table.ajax.reload(null,false);
|
||||
Swal.fire('Sukses', res.message, 'success');
|
||||
} else {
|
||||
Swal.fire('Error', res.message, 'error');
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
Swal.fire('Error','Terjadi kesalahan server','error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ================= EDIT
|
||||
$(document).on('click','.btn-edit',function(){
|
||||
|
||||
let id = $(this).data('id');
|
||||
|
||||
$.get("<?= base_url('accounts/detail/'); ?>" + id, function(res){
|
||||
|
||||
$('#inputId').val(res.id);
|
||||
$('#kode_akun').val(res.kode_akun);
|
||||
$('#nama_akun').val(res.nama_akun);
|
||||
$('#tipe').val(res.tipe);
|
||||
$('#parent_id').val(res.parent_id);
|
||||
|
||||
$('#modalAccount .modal-title').text('Edit Akun');
|
||||
$('#btnSimpan').data('action','edit');
|
||||
|
||||
$('#modalAccount').modal('show');
|
||||
|
||||
},'json');
|
||||
});
|
||||
|
||||
// ================= DELETE
|
||||
$(document).on('click','.btn-delete',function(){
|
||||
|
||||
let id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Yakin hapus?',
|
||||
text: 'Data tidak bisa dikembalikan!',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, hapus'
|
||||
}).then((result)=>{
|
||||
if(result.isConfirmed){
|
||||
|
||||
$.get("<?= base_url('accounts/delete/'); ?>" + id, function(res){
|
||||
|
||||
if(res.status){
|
||||
table.ajax.reload(null,false);
|
||||
Swal.fire('Sukses', res.message, 'success');
|
||||
} else {
|
||||
Swal.fire('Error', res.message, 'error');
|
||||
}
|
||||
|
||||
},'json');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
<div class="container mt-4">
|
||||
<div class="card modern-card shadow-sm border-0 rounded-4">
|
||||
<div class="card-body p-4">
|
||||
|
||||
<div class="d-flex justify-content-between mb-3">
|
||||
<h5 class="mb-0">Chart of Account (COA)</h5>
|
||||
<button class="btn btn-warning btn-add">Tambah Akun</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="tableAccounts" class="table modern-table align-middle w-100">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th width="5%">No</th>
|
||||
<th>Kode</th>
|
||||
<th>Urutan Laporan</th>
|
||||
<th>Nama</th>
|
||||
<th>Tipe</th>
|
||||
<th>Posisi</th>
|
||||
<th>Kategori</th>
|
||||
<th width="15%">Aksi</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL -->
|
||||
<div class="modal fade" id="modalAccount">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content rounded-4">
|
||||
<div class="modal-header bg-warning text-white">
|
||||
<h5 class="modal-title">Tambah Akun</h5>
|
||||
<button class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<input type="hidden" id="inputId">
|
||||
|
||||
<label class="fw-semibold">Kode Akun</label>
|
||||
<input type="text" class="form-control" id="kode_akun">
|
||||
|
||||
<label class="fw-semibold mt-2">Nama Akun</label>
|
||||
<input type="text" class="form-control" id="nama_akun">
|
||||
|
||||
<label class="fw-semibold mt-2">Urutan Laporan</label>
|
||||
<input type="number" class="form-control" id="priority">
|
||||
|
||||
<label class="fw-semibold mt-2">Tipe</label>
|
||||
<select class="form-control" id="tipe">
|
||||
<option value="asset">Asset</option>
|
||||
<option value="liability">Liability</option>
|
||||
<option value="equity">Equity</option>
|
||||
<option value="revenue">Revenue</option>
|
||||
<option value="expense">Expense</option>
|
||||
</select>
|
||||
|
||||
<label class="fw-semibold mt-2">Parent</label>
|
||||
<select class="form-control" id="parent_id">
|
||||
<option value="">-- Tanpa Parent --</option>
|
||||
<?php foreach($parent_accounts as $p): ?>
|
||||
<option value="<?= $p->id ?>">
|
||||
<?= $p->kode_akun ?> - <?= $p->nama_akun ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
||||
<button class="btn btn-warning" id="btnSimpan">Simpan</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
|
||||
let table = $('#tableAccounts').DataTable({
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
responsive: true,
|
||||
autoWidth: false,
|
||||
order: [],
|
||||
ajax: {
|
||||
url: "<?= base_url('accounts/get_data'); ?>",
|
||||
type: "POST"
|
||||
},
|
||||
columns: [
|
||||
{ data: 0, orderable:false },
|
||||
{ data: 1 },
|
||||
{ data: 2 },
|
||||
{ data: 3 },
|
||||
{ data: 4 },
|
||||
{ data: 5 },
|
||||
{ data: 6 },
|
||||
{ data: 7, orderable:false }
|
||||
],
|
||||
language: {
|
||||
processing: `<div class="text-center"><div class="spinner-border text-warning"></div></div>`
|
||||
}
|
||||
});
|
||||
|
||||
// ================= RESET FORM
|
||||
function resetForm(){
|
||||
$('#inputId').val('');
|
||||
$('#kode_akun').val('');
|
||||
$('#nama_akun').val('');
|
||||
$('#priority').val('');
|
||||
$('#tipe').val('asset');
|
||||
$('#parent_id').val('');
|
||||
$('#modalAccount .modal-title').text('Tambah Akun');
|
||||
}
|
||||
|
||||
// ================= OPEN MODAL
|
||||
$('.btn-add').click(function(){
|
||||
resetForm();
|
||||
$('#btnSimpan').data('action','add');
|
||||
$('#modalAccount').modal('show');
|
||||
});
|
||||
|
||||
// ================= SAVE / UPDATE
|
||||
$('#btnSimpan').click(function(){
|
||||
|
||||
let action = $(this).data('action');
|
||||
|
||||
let data = {
|
||||
id: $('#inputId').val(),
|
||||
kode_akun: $('#kode_akun').val().trim(),
|
||||
nama_akun: $('#nama_akun').val().trim(),
|
||||
priority: $('#priority').val().trim(),
|
||||
tipe: $('#tipe').val(),
|
||||
parent_id: $('#parent_id').val()
|
||||
};
|
||||
|
||||
if(!data.kode_akun || !data.nama_akun){
|
||||
Swal.fire('Warning','Kode & Nama wajib diisi','warning');
|
||||
return;
|
||||
}
|
||||
|
||||
let url = action === 'add'
|
||||
? "<?= base_url('accounts/save'); ?>"
|
||||
: "<?= base_url('accounts/update'); ?>";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function(res){
|
||||
if(res.status){
|
||||
$('#modalAccount').modal('hide');
|
||||
table.ajax.reload(null,false);
|
||||
Swal.fire('Sukses', res.message, 'success');
|
||||
} else {
|
||||
Swal.fire('Error', res.message, 'error');
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
Swal.fire('Error','Terjadi kesalahan server','error');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ================= EDIT
|
||||
$(document).on('click','.btn-edit',function(){
|
||||
|
||||
let id = $(this).data('id');
|
||||
|
||||
$.get("<?= base_url('accounts/detail/'); ?>" + id, function(res){
|
||||
|
||||
$('#inputId').val(res.id);
|
||||
$('#kode_akun').val(res.kode_akun);
|
||||
$('#nama_akun').val(res.nama_akun);
|
||||
$('#priority').val(res.priority);
|
||||
$('#tipe').val(res.tipe);
|
||||
$('#parent_id').val(res.parent_id);
|
||||
|
||||
$('#modalAccount .modal-title').text('Edit Akun');
|
||||
$('#btnSimpan').data('action','edit');
|
||||
|
||||
$('#modalAccount').modal('show');
|
||||
|
||||
},'json');
|
||||
});
|
||||
|
||||
// ================= DELETE
|
||||
$(document).on('click','.btn-delete',function(){
|
||||
|
||||
let id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Yakin hapus?',
|
||||
text: 'Data tidak bisa dikembalikan!',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, hapus'
|
||||
}).then((result)=>{
|
||||
if(result.isConfirmed){
|
||||
|
||||
$.get("<?= base_url('accounts/delete/'); ?>" + id, function(res){
|
||||
|
||||
if(res.status){
|
||||
table.ajax.reload(null,false);
|
||||
Swal.fire('Sukses', res.message, 'success');
|
||||
} else {
|
||||
Swal.fire('Error', res.message, 'error');
|
||||
}
|
||||
|
||||
},'json');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -995,7 +995,7 @@ $(function(){
|
||||
|
||||
refreshTable(dtKembalikan, kembalikanData);
|
||||
$('#scanKembalikan').val('').focus();
|
||||
Swal.fire({icon:'success', text:'Barang ditambahkan ke daftar pengembalian', timer:1200, showConfirmButton:false});
|
||||
// Swal.fire({icon:'success', text:'Barang ditambahkan ke daftar pengembalian', timer:1200, showConfirmButton:false});
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
@@ -1059,7 +1059,7 @@ $(function(){
|
||||
|
||||
refreshTable(dtDibawa, dibawaData);
|
||||
$('#scanDibawa').val('').focus();
|
||||
Swal.fire({icon:'success', text:'Barang ditambahkan ke daftar bawaan', timer:1200, showConfirmButton:false});
|
||||
// Swal.fire({icon:'success', text:'Barang ditambahkan ke daftar bawaan', timer:1200, showConfirmButton:false});
|
||||
}, 'json');
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 150 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 133 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 150 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 138 KiB |
Reference in New Issue
Block a user