79 lines
3.3 KiB
PHP
79 lines
3.3 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Accountingperiods extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->requirePermission('jurnal');
|
|
$this->load->model('FiscalPeriodModel', 'fiscalPeriodModel');
|
|
$this->load->library('FiscalPeriodService');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$data = array('active_menu' => 'accounting_periods');
|
|
$this->load->view('partials/header', $data);
|
|
$this->load->view('accounting_periods/layout');
|
|
$this->load->view('partials/footer');
|
|
}
|
|
|
|
public function get_data()
|
|
{
|
|
$rows = array();
|
|
foreach ($this->fiscalPeriodModel->allWithFiscalYear() as $period) {
|
|
$class = array('open' => 'success', 'soft_closed' => 'warning', 'closed' => 'danger');
|
|
$actions = '<button class="btn btn-sm btn-outline-success btn-period-status" data-id="'.$period->id.'" data-status="open">Open</button> '
|
|
. '<button class="btn btn-sm btn-outline-warning btn-period-status" data-id="'.$period->id.'" data-status="soft_closed">Soft Close</button> '
|
|
. '<button class="btn btn-sm btn-outline-danger btn-period-status" data-id="'.$period->id.'" data-status="closed">Close</button>';
|
|
$rows[] = array(
|
|
$period->fiscal_year_name,
|
|
$period->period_number,
|
|
$period->name,
|
|
$period->start_date,
|
|
$period->end_date,
|
|
'<span class="badge bg-'.$class[$period->status].'">'.strtoupper(str_replace('_', ' ', $period->status)).'</span>',
|
|
$actions
|
|
);
|
|
}
|
|
return json_response(true, 'Data periode berhasil dimuat.', array('data' => $rows));
|
|
}
|
|
|
|
public function change_status($id)
|
|
{
|
|
if (strtoupper($this->input->method()) !== 'POST') {
|
|
return json_response(false, 'Metode request tidak diizinkan.', array(), 405);
|
|
}
|
|
try {
|
|
$period = $this->fiscalperiodservice->changeStatus(
|
|
$id,
|
|
$this->input->post('status', true),
|
|
$this->session->userdata('user_id'),
|
|
$this->input->post('reason', true)
|
|
);
|
|
log_activity('Accounting Period', 'change_status', 'Periode '.$period->name.' menjadi '.$period->status, 'success');
|
|
return json_response(true, 'Status periode berhasil diperbarui.', array('period' => $period));
|
|
} catch (Throwable $exception) {
|
|
return business_exception_response($exception);
|
|
}
|
|
}
|
|
|
|
public function create_year()
|
|
{
|
|
if (strtoupper($this->input->method()) !== 'POST') {
|
|
return json_response(false, 'Metode request tidak diizinkan.', array(), 405);
|
|
}
|
|
try {
|
|
$id = $this->fiscalperiodservice->createCalendarYear(
|
|
$this->input->post('year', true),
|
|
$this->session->userdata('user_id')
|
|
);
|
|
log_activity('Fiscal Year', 'create', 'Membuat tahun buku ID '.$id, 'success');
|
|
return json_response(true, 'Tahun buku dan 12 periode berhasil dibuat.', array('fiscal_year_id' => $id));
|
|
} catch (Throwable $exception) {
|
|
return business_exception_response($exception);
|
|
}
|
|
}
|
|
}
|