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 = ' '
. ' '
. '';
$rows[] = array(
$period->fiscal_year_name,
$period->period_number,
$period->name,
$period->start_date,
$period->end_date,
''.strtoupper(str_replace('_', ' ', $period->status)).'',
$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);
}
}
}