| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/wamp/www/SIPBOS_2020/application/modules/pemindahbukuan/models/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Pemindahbukuan_model extends Aktivitas_Model {
var $fieldmap_daftar;
var $fieldmap_filter;
var $fieldmap_pb;
var $fieldmap_jurnal;
var $fieldmap_rincian;
var $data_pb;
var $data_jurnal;
var $data_rincian;
var $purge_rincian;
var $id_jurnal;
function __construct()
{
parent::__construct();
$this->tipe = 'PB';
$this->fieldmap_daftar = array(
'ID_AKTIVITAS',
'NOMOR',
'TANGGAL',
'DESKRIPSI',
'KEPERLUAN',
'DEBET',
'KREDIT',
);
$this->fieldmap_daftar_aggregate = array(
'debet' => "sum(nj.debet)",
'kredit' => "sum(nj.kredit)",
);
$this->fieldmap_filter = array(
'no' => 'a.NOMOR',
'tgl' => 'a.TANGGAL',
'ket' => 'cast(substring(a.deskripsi from 1 for 5000) as varchar(5000))',
'kdskpd' => 's.KODE_SKPD_LKP',
'nmskpd' => 's.NAMA_SKPD',
'keperluan' => 'j.KEPERLUAN',
'debet' => 'nj.DEBET',
'kredit' => 'nj.KREDIT'
);
$this->fieldmap_pb = array(
'id' => 'ID_AKTIVITAS',
'nominal' => 'NOMINAL',
'beban' => 'BEBAN',
'keperluan' => 'KEPERLUAN',
'id_keg' => 'ID_KEGIATAN',
'total_kredit' => 'NOMINAL'
);
$this->fieldmap_jurnal = array(
'id' => 'ID_AKTIVITAS',
'id_jurnal' => 'ID_JURNAL',
'tipe'=> 'TIPE',
'tahun' => 'TAHUN',
'tgl' => 'TANGGAL_JURNAL',
'id_skpd' => 'ID_SKPD',
'beban' => 'BEBAN',
'keperluan' => 'KEPERLUAN',
);
$this->fieldmap_rincian = array(
'idr' => 'ID_RINCIAN_JURNAL',
'idrek' => 'ID_REKENING',
'idkeg' => 'ID_KEGIATAN',
'debet' => 'DEBET',
'kredit' => 'KREDIT'
);
}
function get_grid_model()
{
$grid = array(
'colNames' => array('Nomor', 'Tanggal', 'Keterangan', 'Keperluan', 'Debet', 'Kredit'),
'colModel' => array(
array('name' => 'no', 'width' => 150, 'sortable' => true, 'formatter' => 'daftarOpFmatter'),
array('name' => 'tgl', 'width' => 80, 'sortable' => true, 'formatter' => 'date', 'align' => 'center'),
array('name' => 'ket','width' => 250, 'sortable' => true),
array('name' => 'keperluan','width' => 60, 'sortable' => true, 'align' => 'center'),
array('name' => 'debet','width' => 150, 'sortable' => true, 'formatter' => 'currency', 'align' => 'right'),
array('name' => 'kredit','width' => 150, 'sortable' => true, 'formatter' => 'currency', 'align' => 'right'),
),
);
return $grid;
}
// ----- search advance ---- >>
function get_data_fields()
{
$fields = array(
'no' => array('name' => 'Nomor', 'kategori'=>'string'),
'tgl' => array('name' => 'Tanggal', 'kategori'=>'date'),
'ket' => array('name' => 'Keterangan', 'kategori'=>'string'),
'keperluan' => array('name' => 'Keperluan', 'kategori'=>'string'),
'beban' => array('name' => 'Beban', 'kategori'=>'string'),
'debet' => array('name' => 'Debet', 'kategori'=>'numeric'),
'kredit' => array('name' => 'Kredit', 'kategori'=>'numeric'),
);
return $fields;
}
function fill_data()
{
parent::fill_data();
/* ambil data Pemindahbukuan */
foreach($this->fieldmap_pb as $key => $value){
switch ($key)
{
default : $$key = $this->input->post($key) ? $this->input->post($key) : NULL;
}
if(isset($$key))
$this->data_pb[$value] = $$key;
}
/* ambil data Jurnal */
foreach($this->fieldmap_jurnal as $key => $value){
switch ($key)
{
case 'tipe' : $$key = $this->tipe; break;
case 'tahun' : $$key = $this->tahun; break;
case 'tgl' : $$key = $this->input->post($key) ? prepare_date($this->input->post($key)) : NULL; break;
default : $$key = $this->input->post($key) ? $this->input->post($key) : NULL;
}
if(isset($$key))
$this->data_jurnal[$value] = $$key;
}
/* ambil data rincian Permindahbukuan */
$this->purge_rincian = $this->input->post('purge'); $this->purge_rincian = $this->purge_rincian ? $this->purge_rincian : NULL;
$rinci = $this->input->post('rincian') ? $this->input->post('rincian') : NULL;
if ($rinci)
{
$rinci = json_decode($rinci);
for ($i=0; $i <= count($rinci) - 1; $i++) {
foreach($this->fieldmap_rincian as $key => $value){
switch ($key)
{
case 'tipe' : $$key = $this->tipe; break;
default : $$key = isset($rinci[$i]->$key) && $rinci[$i]->$key ? $rinci[$i]->$key : NULL;
}
if(isset($$key))
$this->data_rincian[$i][$value] = $$key;
}
}
}
}
function get_auto_number()
{
$id_skpd = $this->input->post('id_skpd');
$param = array(
'tipe' => $this->tipe,
'id_skpd' => $id_skpd,
);
return $this->autho->check_nomor_aktivitas($param);
}
function insert_aktivitas()
{
// cek apakah entri baru dan penomoran otomatis
if ($this->input->post('id') == 0 && $this->input->post('auto') == 'true')
{
$this->data_aktivitas['NOMOR'] = $this->get_auto_number();
}
return parent::insert_aktivitas();
}
function insert_pb()
{
$this->db->select('1')->from('PEMINDAHBUKUAN')->where('ID_AKTIVITAS', $this->id);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('ID_AKTIVITAS', $this->id);
$this->db->update('PEMINDAHBUKUAN', $this->data_pb);
$this->check_trans_status('update pemindahbukuan failed');
}
else
{
$this->data_pb['ID_AKTIVITAS'] = $this->id;
$this->db->insert('PEMINDAHBUKUAN', $this->data_pb);
$this->check_trans_status('insert pemindahbukuan failed');
}
}
/*
Simpan data Permindahbukuan
Jurnal pemindahbukuan masuk ke dalam jurnal finansial
- Entitas Akuntansi bila ppkd = 0 (draft 2)
- Entitas Pelaporan bila ppkd = 1 (draft 4)
*/
function insert_jurnal()
{
$this->id_jurnal = isset($this->data_jurnal['ID_JURNAL']) ? $this->data_jurnal['ID_JURNAL'] : 0;
$this->db->select('1')->from('JURNAL')->where('ID_AKTIVITAS', $this->id)->where('ID_JURNAL', $this->id_jurnal);
$rs = $this->db->get()->row_array();
$this->data_jurnal['ID_SKPD'] = $this->data_aktivitas['ID_SKPD'];
$this->data_jurnal['ID_SKPD_AKTIVITAS'] = $this->data_aktivitas['ID_SKPD'];
$this->data_jurnal['NOMOR_AKTIVITAS'] = $this->data_aktivitas['NOMOR'];
$this->data_jurnal['DRAFT'] = $this->ppkd > 0 ? 4 : 2;
if ($rs)
{
$this->db->where('ID_AKTIVITAS', $this->id);
$this->db->where('ID_JURNAL', $this->id_jurnal);
$this->db->update('JURNAL', $this->data_jurnal);
$this->check_trans_status('update jurnal failed');
return $this->data_jurnal['ID_JURNAL'];
}
else
{
$this->data_jurnal['ID_AKTIVITAS'] = $this->id;
$this->db->insert('JURNAL', $this->data_jurnal);
$this->check_trans_status('insert jurnal failed');
$this->db->select_max('ID_JURNAL')->from('JURNAL');
$rs = $this->db->get()->row_array();
return $rs['ID_JURNAL'];
}
}
/* Simpan rincian Pemindahbukuan */
function insert_rincian()
{
if($this->purge_rincian)
{
$this->db->where_in('ID_RINCIAN_JURNAL', $this->purge_rincian);
$this->db->delete('RINCIAN_JURNAL');
$this->check_trans_status('delete rincian_jurnal failed');
}
$jml = count($this->data_rincian);
for ($i=0; $i <= $jml - 1; $i++)
{
$idr = $this->data_rincian[$i]['ID_RINCIAN_JURNAL'];
$this->db->select('1')->from('RINCIAN_JURNAL')->where('ID_RINCIAN_JURNAL', $idr);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('ID_RINCIAN_JURNAL', $idr);
$this->db->update('RINCIAN_JURNAL', $this->data_rincian[$i]);
$this->check_trans_status('update rincian_jurnal failed');
}
else
{
unset($this->data_rincian[$i]['ID_RINCIAN_JURNAL']);
$this->data_rincian[$i]['ID_JURNAL'] = $this->id_jurnal;
$this->db->insert('RINCIAN_JURNAL', $this->data_rincian[$i]);
$this->check_trans_status('insert rincian_jurnal failed');
}
}
}
function save_detail()
{
$this->insert_pb();
$this->id_jurnal = $this->insert_jurnal();
$this->insert_rincian();
}
/* Query daftar */
function build_query_daftar()
{
$this->db->select('
a.id_aktivitas,
a.nomor,
a.tanggal,
cast(substring(a.deskripsi from 1 for 5000) as varchar(5000)) deskripsi,
j.id_jurnal,
a.tipe,
a.tahun,
j.keperluan,
nj.debet,
nj.kredit,
s.kode_skpd,
s.kode_skpd_lkp,
s.nama_skpd,
a.id_skpd
');
$this->db->from('aktivitas a');
$this->db->join('jurnal j ', 'a.id_aktivitas = j.id_aktivitas ');
$this->db->join('v_skpd s', 'a.id_skpd = s.id_skpd');
$this->db->join('v_nominal_jurnal nj ', 'nj.id_jurnal = j.id_jurnal','left outer');
$this->db->where('a.tahun', $this->tahun);
$this->db->where('('.$this ->id_skpd.' = 0 or a.id_skpd = '.$this->id_skpd.')');
$this->db->where("a.tipe = 'PB' and j.tipe = a.tipe");
}
/* Query form */
function build_query_form($id=0)
{
$this->db->select('
a.id_aktivitas,
j.id_jurnal,
a.nomor,
a.nomor_int,
a.tanggal,
a.id_skpd,
s.kode_skpd_lkp,
s.nama_skpd,
cast(substring(a.deskripsi from 1 for 2000) as varchar(2000)) deskripsi,
j.keperluan,
nj.debet as nominal
');
$this->db->from('aktivitas a');
$this->db->join('v_skpd s', 's.id_skpd = a.id_skpd');
$this->db->join('jurnal j', 'j.id_aktivitas = a.id_aktivitas');
$this->db->join('v_nominal_jurnal nj', 'j.id_jurnal = nj.id_jurnal');
$this->db->where('a.id_aktivitas', $id);
}
function build_query_hapus($id=0)
{
$this->db->where("id_jurnal = (select first 1 j.id_jurnal from jurnal j where j.id_aktivitas = '".$id."')")->delete('rincian_jurnal');
$this->check_trans_status('delete rincian_jurnal failed');
$this->db->where('id_aktivitas', $id)->delete('jurnal');
$this->check_trans_status('delete jurnal failed');
$this->db->where('id_aktivitas', $id)->delete('pemindahbukuan');
$this->check_trans_status('delete pemindahbukuan failed');
$this->db->where('id_aktivitas', $id)->delete('aktivitas');
$this->check_trans_status('delete aktivitas failed');
}
/* Query rincian Permindahbukuan */
function get_rinci_by_id($id)
{
$this->db->select('
rj.id_jurnal,
rj.id_rincian_jurnal,
rj.id_rekening,
rj.kode_rekening,
rj.nama_rekening,
rj.debet,
rj.kredit,
sd.nama_bank
');
$this->db->from('aktivitas a');
$this->db->join('jurnal j', 'j.id_aktivitas = a.id_aktivitas');
$this->db->join('rincian_jurnal rj', 'rj.id_jurnal = j.id_jurnal ');
$this->db->join('sumber_dana_skpd sd', 'sd.id_rekening = rj.id_rekening', 'left');
$this->db->where('a.id_aktivitas', $id);
$this->db->order_by('rj.kode_rekening');
$result = $this->db->get()->result_array();
return $result;
}
function get_sisa_kas_bank($param)
{
$this->db->select("a.nominal, a.nominal_tanggal");
$this->db->from("sisa_kas_bank("
.$param['id_skpd'].", "
.$this->tahun.", "
."'".$param['tanggal']."', "
."'".$param['id_kegiatan']."', "
."'".$param['keperluan']."', "
."'".$param['beban']."', "
."0, "
.$param['id'].", 0 ) a
");
$result = $this->db->get()->row_array();
return $result;
}
function get_sisa_kas_tunai($param)
{
$id_pekas = $this->get_akun_kas_tunai($param['id_skpd']);
$id_pekas = $id_pekas ? $id_pekas : 0;
$this->db->select("a.nominal, a.nominal_tanggal");
$this->db->from("sisa_kas_tunai("
.$param['id_skpd'].", "
.$this->tahun.", "
."'".$param['tanggal']."', "
."'".$param['id_kegiatan']."', "
."'".$param['keperluan']."', "
."'".$param['beban']."', "
.$id_pekas.", "
.$param['id'].", 0, 0, 0 ) a
");
$result = $this->db->get()->row_array();
return $result;
}
function get_akun_kas_tunai($id_skpd)
{
$this->db->select('first 1 sd.id_rekening');
$this->db->from('sumber_dana_skpd sd');
$this->db->where('sd.id_skpd', $id_skpd);
$this->db->where('sd.nama_bank', 'TUNAI');
$this->db->where('sd.penerimaan', 0);
$result = $this->db->get()->row_array();
if (count($result) > 0)
{
return $result['ID_REKENING'];
}
return FALSE;
}
}