hr dan payroll
This commit is contained in:
@@ -15,6 +15,7 @@ class JournalService
|
||||
$this->CI->load->library('TransactionService');
|
||||
$this->CI->load->library('FiscalPeriodService');
|
||||
$this->CI->load->library('JournalDescriptionService');
|
||||
$this->CI->load->library('AuditService');
|
||||
if ($this->CI->db->table_exists('companies')) $this->CI->load->library('CompanyContext');
|
||||
}
|
||||
|
||||
@@ -57,7 +58,50 @@ class JournalService
|
||||
return array('debit' => round($debit, 2), 'kredit' => round($credit, 2));
|
||||
}
|
||||
|
||||
private function validateAndNormalize(array $header, array $lines)
|
||||
public function reviseRejected($journalId, array $header, array $lines, $userId)
|
||||
{
|
||||
return $this->CI->transactionservice->run(function () use ($journalId, $header, $lines, $userId) {
|
||||
$journal = $this->CI->db->query(
|
||||
'SELECT * FROM journals WHERE id=? AND company_id=? FOR UPDATE',
|
||||
array((int)$journalId, (int)$this->CI->companycontext->id())
|
||||
)->row();
|
||||
if (!$journal) throw new BusinessException('Jurnal tidak ditemukan.');
|
||||
if ($journal->status !== 'rejected') throw new BusinessException('Hanya jurnal yang ditolak yang dapat dikoreksi.');
|
||||
if (!in_array((string)$journal->ref_type, array('', 'manual_journal'), true)) throw new BusinessException('Jurnal otomatis tidak dapat diedit melalui Jurnal Umum.');
|
||||
if ((int)$journal->created_by !== (int)$userId && !(function_exists('is_master_admin_user') && is_master_admin_user()) && $this->CI->session->userdata('role') !== 'Admin') throw new BusinessException('Hanya pembuat jurnal atau Admin yang dapat melakukan koreksi.');
|
||||
|
||||
$header['no_ref'] = $journal->no_ref;
|
||||
$header['ref_type'] = $journal->ref_type ?: 'manual_journal';
|
||||
$header['ref_id'] = $journal->ref_id;
|
||||
$header['created_by'] = $journal->created_by;
|
||||
$normalized = $this->validateAndNormalize($header, $lines, (int)$journal->id);
|
||||
$before = array('journal'=>$journal, 'lines'=>$this->CI->journalModel->lines($journal->id));
|
||||
$update = array(
|
||||
'tanggal'=>$normalized['header']['tanggal'],
|
||||
'keterangan'=>$normalized['header']['keterangan'],
|
||||
'accounting_period_id'=>$normalized['header']['accounting_period_id'],
|
||||
'status'=>'draft',
|
||||
'submitted_at'=>null,
|
||||
'submitted_by'=>null,
|
||||
'approved_at'=>null,
|
||||
'approved_by'=>null,
|
||||
'updated_by'=>(int)$userId,
|
||||
'updated_at'=>date('Y-m-d H:i:s'),
|
||||
);
|
||||
$this->CI->db->where('id', $journal->id)->update('journals', $update);
|
||||
$this->CI->db->where('journal_id', $journal->id)->delete('journal_details');
|
||||
$details=array();foreach($normalized['lines']as$line){$line['journal_id']=$journal->id;$details[]=$line;}
|
||||
$this->CI->journalModel->addLines($details);
|
||||
$notes='Jurnal dikoreksi dan dikembalikan menjadi Draft.';
|
||||
if(trim((string)$journal->rejection_reason)!=='')$notes.=' Alasan penolakan sebelumnya: '.$journal->rejection_reason;
|
||||
$this->CI->journalModel->addStatusHistory($journal->id,'rejected','draft',$userId,$notes);
|
||||
$after=array('journal'=>$this->CI->journalModel->find($journal->id),'lines'=>$this->CI->journalModel->lines($journal->id));
|
||||
$this->CI->auditservice->record('journal','journal',$journal->id,'revise_rejected',$before,$after,$userId);
|
||||
return $after['journal'];
|
||||
});
|
||||
}
|
||||
|
||||
private function validateAndNormalize(array $header, array $lines, $excludeJournalId = 0)
|
||||
{
|
||||
foreach (array('tanggal', 'no_ref', 'keterangan', 'created_by') as $required) {
|
||||
if (!isset($header[$required]) || trim((string) $header[$required]) === '') {
|
||||
@@ -69,7 +113,7 @@ class JournalService
|
||||
if (!$date || $date->format('Y-m-d') !== $header['tanggal']) {
|
||||
throw new BusinessException('Tanggal jurnal tidak valid.');
|
||||
}
|
||||
if ($this->CI->journalModel->referenceExists($header['no_ref'])) {
|
||||
if ($this->CI->journalModel->referenceExists($header['no_ref'], $excludeJournalId)) {
|
||||
throw new BusinessException('Nomor referensi jurnal sudah digunakan.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user