Update besar apk finance
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class JournalModel extends CI_Model
|
||||
{
|
||||
public function createHeader(array $data)
|
||||
{
|
||||
if (!$this->db->insert('journals', $data)) {
|
||||
throw new RuntimeException('Gagal membuat header jurnal.');
|
||||
}
|
||||
|
||||
return (int) $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function addLines(array $lines)
|
||||
{
|
||||
if (empty($lines) || !$this->db->insert_batch('journal_details', $lines)) {
|
||||
throw new RuntimeException('Gagal membuat detail jurnal.');
|
||||
}
|
||||
}
|
||||
|
||||
public function referenceExists($reference)
|
||||
{
|
||||
return $this->db->where('no_ref', $reference)->count_all_results('journals') > 0;
|
||||
}
|
||||
|
||||
public function sourceExists($type, $id)
|
||||
{
|
||||
return $this->db
|
||||
->where('ref_type', $type)
|
||||
->where('ref_id', $id)
|
||||
->count_all_results('journals') > 0;
|
||||
}
|
||||
|
||||
public function find($id)
|
||||
{
|
||||
return $this->db->get_where('journals', array('id' => (int) $id))->row();
|
||||
}
|
||||
|
||||
public function findForUpdate($id)
|
||||
{
|
||||
return $this->db->query('SELECT * FROM journals WHERE id = ? FOR UPDATE', array((int) $id))->row();
|
||||
}
|
||||
|
||||
public function lines($journalId)
|
||||
{
|
||||
return $this->db->where('journal_id', (int) $journalId)->order_by('id', 'ASC')->get('journal_details')->result_array();
|
||||
}
|
||||
|
||||
public function updateStatus($journalId, $status, array $extra = array())
|
||||
{
|
||||
return $this->db->where('id', (int) $journalId)->update('journals', array_merge(array(
|
||||
'status' => $status,
|
||||
'updated_at' => date('Y-m-d H:i:s')
|
||||
), $extra));
|
||||
}
|
||||
|
||||
public function addStatusHistory($journalId, $from, $to, $userId, $notes = null)
|
||||
{
|
||||
return $this->db->insert('journal_status_histories', array(
|
||||
'journal_id' => (int) $journalId,
|
||||
'from_status' => $from,
|
||||
'to_status' => $to,
|
||||
'notes' => $notes,
|
||||
'changed_by' => (int) $userId,
|
||||
'changed_at' => date('Y-m-d H:i:s')
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user