| 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/sipapbd_2021_sekolah/application/modules/asb/models/ |
Upload File : |
<?php
class Asb_model extends Base_Model {
var $fieldmapASB;
var $dataASB;
var $fieldmap_rincian_asb;
var $fieldmap_rincian_tipe_asb;
var $fieldmap_rincian_skpd_asb;
var $fieldmap_rincian_rekening_asb;
var $data_rincian_tipe_asb;
var $data_rincian_skpd_asb;
var $data_rincian_rekening_asb;
var $last_changed;
var $fieldmap_daftar;
var $fieldmap_daftar_aggregate;
var $fieldmap_filter;
var $purge_rincian_tipe;
var $purge_rincian_skpd;
var $purge_rincian_rekening;
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->fieldmap_daftar = array(
'ID_ASB',
'KODE_ASB',
'NAMA_ASB',
'VARIABLE_COST',
);
$this->fieldmapASB = array(
'id' => 'ID_ASB',
'tahun' => 'TAHUN',
'kode_asb' => 'KODE_ASB',
'nama_asb' => 'NAMA_ASB',
'variable_cost' => 'VARIABLE_COST',
'deskripsi' => 'DESKRIPSI',
);
$this->fieldmap_filter = array(
'kode_asb' => "a.kode_asb",
'nama_asb' => "a.nama_asb",
'variable_cost' => 'a.VARIABLE_COST',
);
$this->fieldmap_rincian_tipe_asb = array(
'idrasb' => 'ID_RINCIAN_TIPE_ASB',
'id_asb' => 'ID_ASB',
'tipe_rincian' => 'TIPE_RINCIAN',
'average_cost' => 'AVERAGE_COST',
'minimum_cost' => 'MINIMUM_COST',
'maximum_cost' => 'MAXIMUM_COST',
);
$this->fieldmap_rincian_skpd_asb = array(
'idrasb' => 'ID_RINCIAN_SKPD_ASB',
'id_asb' => 'ID_ASB',
'idskpd' => 'ID_SKPD',
);
$this->fieldmap_rincian_rekening_asb = array(
'idrasb' => 'ID_RINCIAN_REKENING_ASB',
'id_asb' => 'ID_ASB',
'idrek' => 'ID_REKENING',
'persentase' => 'PERSENTASE',
);
$this->fieldmap_daftar_aggregate = array(
);
}
function get_grid_model()
{
$grid = array(
'colNames' => array('Kode ASB', 'Nama ASB', 'Variable Cost'),
'colModel' => array(
array('name' => 'kode_asb', 'width' => 180, 'sortable' => true),
array('name' => 'nama_asb', 'width' => 350, 'sortable' => true),
array('name' => 'variable_cost', 'width' => 180, 'sortable' => true, 'formatter' => 'currency', 'align' => 'right'),
),
'sortname' => 'kode_asb',
);
return $grid;
}
function fill_data()
{
foreach($this->fieldmapASB as $key => $value){
switch ($key)
{
case 'tahun' : $$key = $this->tahun; break;
default : $$key = $this->input->post($key) ? $this->input->post($key) : NULL;
}
if(isset($$key))
$this->dataASB[$value] = $$key;
}
$this->purge_rincian_tipe = $this->input->post('purge_rincian_tipe'); $this->purge_rincian_tipe = $this->purge_rincian_tipe ? $this->purge_rincian_tipe : NULL;
$this->purge_rincian_skpd = $this->input->post('purge_rincian_skpd'); $this->purge_rincian_skpd = $this->purge_rincian_skpd ? $this->purge_rincian_skpd : NULL;
$this->purge_rincian_rekening = $this->input->post('purge_rincian_rekening'); $this->purge_rincian_rekening = $this->purge_rincian_rekening ? $this->purge_rincian_rekening : NULL;
/* ambil grid rincian tipe*/
$rinci_tipe = $this->input->post('rincian_tipe') ? $this->input->post('rincian_tipe') : NULL;
if ($rinci_tipe)
{
$rinci_tipe = json_decode($rinci_tipe);
for ($i=0; $i < count($rinci_tipe); $i++) {
foreach($this->fieldmap_rincian_tipe_asb as $key => $value){
switch ($key)
{
case 'average_cost' : $$key = isset($rinci_tipe[$i]->$key) && $rinci_tipe[$i]->$key ? $rinci_tipe[$i]->$key : 0; break;
case 'minimun_cost' : $$key = isset($rinci_tipe[$i]->$key) && $rinci_tipe[$i]->$key ? $rinci_tipe[$i]->$key : 0; break;
case 'maximum_cost' : $$key = isset($rinci_tipe[$i]->$key) && $rinci_tipe[$i]->$key ? $rinci_tipe[$i]->$key : 0; break;
default : $$key = isset($rinci_tipe[$i]->$key) && $rinci_tipe[$i]->$key ? $rinci_tipe[$i]->$key : NULL;
}
if(isset($$key))
$this->data_rincian_tipe_asb[$i][$value] = $$key;
}
}
}
/* ambil grid rincian skpd*/
$rinci_skpd = $this->input->post('rincian_skpd') ? $this->input->post('rincian_skpd') : NULL;
if ($rinci_skpd)
{
$rinci_skpd = json_decode($rinci_skpd);
for ($i=0; $i < count($rinci_skpd); $i++) {
foreach($this->fieldmap_rincian_skpd_asb as $key => $value){
switch ($key)
{
default : $$key = isset($rinci_skpd[$i]->$key) && $rinci_skpd[$i]->$key ? $rinci_skpd[$i]->$key : NULL;
}
if(isset($$key))
$this->data_rincian_skpd_asb [$i][$value] = $$key;
}
}
}
/* ambil grid rincian rekening*/
$rinci_rekening = $this->input->post('rincian_rekening') ? $this->input->post('rincian_rekening') : NULL;
if ($rinci_rekening)
{
$rinci_rekening = json_decode($rinci_rekening);
for ($i=0; $i < count($rinci_rekening); $i++) {
foreach($this->fieldmap_rincian_rekening_asb as $key => $value){
switch ($key)
{
default : $$key = isset($rinci_rekening[$i]->$key) && $rinci_rekening[$i]->$key ? $rinci_rekening[$i]->$key : NULL;
}
if(isset($$key))
$this->data_rincian_rekening_asb [$i][$value] = $$key;
}
}
}
}
// ----- search advance ---- >>
function get_data_fields()
{
$fields['kode_asb'] = array('name' => 'Kode ASB', 'kategori' => 'string');
$fields['nama_asb'] = array('name' => 'Nama ASB', 'kategori' => 'string');
$fields['variable_cost'] = array('name' => 'Variable Cost', 'kategori' => 'numeric');
return $fields;
}
function get_data($param, $isCount=FALSE, $CompileOnly=False)
{
isset($param['limit']) && $param['limit'] ? $this->db->limit($param['limit']['end'], $param['limit']['start']) : '';
$this->build_query_daftar();
// proses parameter pencarian, jika ada
if (isset($param['search_mode']) && $param['search_mode'] !=='' )
{
// proses pencarian singkat (simple search)
if ($param['search_mode'] == 'ss')
{
foreach($this->fieldmap_filter as $key => $value){
$flt[$key] = array('search_str' => $param['q'], 'search_op' => 'cn');
}
if (count($flt) > 0)
{
$swhere = get_where_str($flt, $this->fieldmap_filter);
if ($swhere) {
$swhere = build_or_where($swhere);
$this->db->where($swhere);
}
}
}
// proses pencarian lanjut (advanced search)
else if ($param['search_mode'] == 'as') {
$fields = $this->get_data_fields();
if (is_array($param['q']) && count($param['q']) > 0)
{
foreach ($param['q'] as $key=>$val) {
$kolom = $val['c'];
$search_str = isset($val['s']) ? $val['s'] : '';
$search_str2 = isset($val['s2']) ? $val['s2'] : '';
$flt[$kolom] = array(
'search_str' => $search_str,
'search_str2' => $search_str2,
'search_op' => $val['o'],
'search_datatype' => $fields[$kolom]['kategori'],
);
}
if (count($flt) > 0)
{
$wh = get_where_str($flt, $this->fieldmap_filter);
$this->db->where($wh);
}
}
}
}
// proses jika ada pengurutan
if (isset($param['sort_by']) && $param['sort_by'] != null && !$isCount && $ob = get_order_by_str($param['sort_by'], $this->fieldmap_filter))
{
$this->db->order_by($ob, $param['sort_direction']);
}
if ($isCount) {
$this->db->ar_select = array();
$this->db->ar_select[] = 'count(*) cnt';
$daftar_agg = $this->fieldmap_daftar_aggregate;
foreach( $daftar_agg as $agg_key => $agg_value)
{
$this->db->ar_select[] = "coalesce(".$agg_value.", 0) ".$agg_key;
}
$result = $this->db->get();
return $result->row_array();
}
else
{
if ($CompileOnly)
{
return $this->db->get_compiled_select();
}
else
{
$result = $this->db->get()->result_array();
return $result;
}
}
}
/* Query daftar */
function build_query_daftar()
{
$this->db->select("
a.id_asb,
a.kode_asb,
a.nama_asb,
a.fixed_cost,
a.variable_cost
");
$this->db->from('asb a');
$this->db->where('a.tahun', $this->tahun);
}
/* Query form */
function build_query_form($id=0)
{
$this->db->select("
a.id_asb,
a.kode_asb,
a.nama_asb,
a.fixed_cost,
a.variable_cost,
cast(substring(a.deskripsi from 1 for 5000) as varchar(5000)) deskripsi
");
$this->db->from('asb a');
$this->db->where('a.id_asb', $id);
}
function save_data()
{
$this->db->trans_begin();
try {
$this->id = $this->insert_data();
$this->save_detail();
}
catch(Exception $e){
//TODO : log error to file
}
if ($this->db->trans_status() === FALSE)
{
$this->last_error_id = $this->db->_error_number();
$this->last_error_message = $this->db->_error_message();
$this->db->trans_rollback();
return FALSE;
}
$this->db->trans_commit();
return TRUE;
}
function insert_data()
{
if (isset($this->dataASB['ID_ASB']))
{
$this->db->where('ID_ASB', $this->dataASB['ID_ASB']);
$this->db->update('ASB', $this->dataASB);
$this->check_trans_status('update asb failed');
return $this->dataASB['ID_ASB'];
}
else
{
$idfa = $this->get_id('g_id_asb');
$this->dataASB['ID_ASB'] = $idfa;
$this->db->insert('ASB', $this->dataASB);
$this->check_trans_status('insert asb failed');
return $idfa;
}
}
function save_detail()
{
//rincian_tipe
if ($this->purge_rincian_tipe)
{
$this->db->where_in('ID_RINCIAN_TIPE_ASB', $this->purge_rincian_tipe);
$this->db->delete('RINCIAN_TIPE_ASB');
$this->check_trans_status('delete rincian_tipe_asb failed');
}
for ($i=0; $i< count($this->data_rincian_tipe_asb); $i++)
{
$idra = isset($this->data_rincian_tipe_asb[$i]['ID_RINCIAN_TIPE_ASB']) ? $this->data_rincian_tipe_asb[$i]['ID_RINCIAN_TIPE_ASB'] : NULL;
$this->db->select('1')->from('RINCIAN_TIPE_ASB')->where('ID_ASB', $this->id)->where('ID_RINCIAN_TIPE_ASB', $idra);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('ID_RINCIAN_TIPE_ASB', $idra);
$this->db->where('ID_ASB', $this->id);
$this->db->update('RINCIAN_TIPE_ASB', $this->data_rincian_tipe_asb[$i]);
$this->check_trans_status('update rincian_tipe_asb failed');
}
else
{
unset( $this->data_rincian_tipe_asb[$i]['ID_RINCIAN_TIPE_ASB'] );
$this->data_rincian_tipe_asb[$i]['ID_ASB'] = $this->id;
$this->db->insert('RINCIAN_TIPE_ASB', $this->data_rincian_tipe_asb[$i]);
$this->check_trans_status('insert rincian_tipe_asb failed');
}
}
//rincian_skpd
if ($this->purge_rincian_skpd)
{
$this->db->where_in('ID_RINCIAN_SKPD_ASB', $this->purge_rincian_skpd);
$this->db->delete('RINCIAN_SKPD_ASB');
$this->check_trans_status('delete rincian_skpd_asb failed');
}
for ($i=0; $i< count($this->data_rincian_skpd_asb); $i++)
{
$idra = isset($this->data_rincian_skpd_asb[$i]['ID_RINCIAN_SKPD_ASB']) ? $this->data_rincian_skpd_asb[$i]['ID_RINCIAN_SKPD_ASB'] : NULL;
$this->db->select('1')->from('RINCIAN_SKPD_ASB')->where('ID_ASB', $this->id)->where('ID_RINCIAN_SKPD_ASB', $idra);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('ID_RINCIAN_SKPD_ASB', $idra);
$this->db->where('ID_ASB', $this->id);
$this->db->update('RINCIAN_SKPD_ASB', $this->data_rincian_skpd_asb[$i]);
$this->check_trans_status('update rincian_skpd_asb failed');
}
else
{
unset( $this->data_rincian_skpd_asb[$i]['ID_RINCIAN_SKPD_ASB'] );
$this->data_rincian_skpd_asb[$i]['ID_ASB'] = $this->id;
$this->db->insert('RINCIAN_SKPD_ASB', $this->data_rincian_skpd_asb[$i]);
$this->check_trans_status('insert rincian_skpd_asb failed');
$this->db->select_max('ID_RINCIAN_SKPD_ASB')->from('RINCIAN_SKPD_ASB');
$rsx = $this->db->get()->row_array();
$idra = $rsx['ID_RINCIAN_SKPD_ASB'];
}
}
//rincian_rekening
if ($this->purge_rincian_rekening)
{
$this->db->where_in('ID_RINCIAN_REKENING_ASB', $this->purge_rincian_rekening);
$this->db->delete('RINCIAN_REKENING_ASB');
$this->check_trans_status('delete rincian_rekening_asb failed');
}
for ($i=0; $i< count($this->data_rincian_rekening_asb); $i++)
{
$idra = isset($this->data_rincian_rekening_asb[$i]['ID_RINCIAN_REKENING_ASB']) ? $this->data_rincian_rekening_asb[$i]['ID_RINCIAN_REKENING_ASB'] : NULL;
$this->db->select('1')->from('RINCIAN_REKENING_ASB')->where('ID_ASB', $this->id)->where('ID_RINCIAN_REKENING_ASB', $idra);
$rs = $this->db->get()->row_array();
if ($rs)
{
$this->db->where('ID_RINCIAN_REKENING_ASB', $idra);
$this->db->where('ID_ASB', $this->id);
$this->db->update('RINCIAN_REKENING_ASB', $this->data_rincian_rekening_asb[$i]);
$this->check_trans_status('update rincian_rekening_asb failed');
}
else
{
unset( $this->data_rincian_rekening_asb[$i]['ID_RINCIAN_REKENING_ASB'] );
$this->data_rincian_rekening_asb[$i]['ID_ASB'] = $this->id;
$this->db->insert('RINCIAN_REKENING_ASB', $this->data_rincian_rekening_asb[$i]);
$this->check_trans_status('insert rincian_rekening_asb failed');
}
}
}
function check_dependency($id)
{
$this->db->select('count(rd.id_asb) data_exists');
$this->db->from('rincian_rka221_asb rd');
$this->db->join('form_anggaran fa','fa.id_form_anggaran=rd.id_form_anggaran');
$this->db->where('fa.tahun',$this->tahun);
$this->db->where('fa.status',$this->status);
$this->db->where('rd.id_asb',$id);
$result = $this->db->get()->row_array();
if($result && $result['DATA_EXISTS'] > 0)
return FALSE;
else
return TRUE;
}
function build_query_hapus($id=0)
{
$this->db->where('id_asb', $id)->delete('rincian_skpd_asb');
$this->check_trans_status('delete rincian_skpd_asb failed');
$this->db->where('id_asb', $id)->delete('rincian_tipe_asb');
$this->check_trans_status('delete rincian_tipe_asb failed');
$this->db->where('id_asb', $id)->delete('rincian_rekening_asb');
$this->check_trans_status('delete rincian_rekening_asb failed');
$this->db->where('id_asb', $id)->delete('asb');
$this->check_trans_status('delete asb failed');
}
function get_data_rinci_tipe($id)
{
$this->db->select('a.id_rincian_tipe_asb, a.id_asb, a.tipe_rincian, coalesce(a.average_cost,0) average_cost, coalesce(a.minimum_cost,0) minimum_cost, coalesce(a.maximum_cost,0) maximum_cost');
$this->db->from('rincian_tipe_asb a');
$this->db->where('a.id_asb', $id);
$this->db->order_by('a.id_rincian_tipe_asb');
$result = $this->db->get()->result_array();
return $result;
}
function get_data_rinci_skpd($id)
{
$this->db->select('a.id_rincian_skpd_asb, a.id_asb, a.id_skpd, c.kode_skpd_lkp, c.nama_skpd');
$this->db->from('rincian_skpd_asb a');
$this->db->join('v_skpd c','c.id_skpd=a.id_skpd');
$this->db->where('a.id_asb', $id);
$this->db->order_by('c.kode_skpd_lkp');
$result = $this->db->get()->result_array();
return $result;
}
function get_data_rinci_rek($id)
{
$this->db->select('a.id_rincian_rekening_asb, a.id_asb, a.persentase, a.id_rekening, c.kode_rekening, c.nama_rekening');
$this->db->from('rincian_rekening_asb a');
$this->db->join('rekening c','c.id_rekening=a.id_rekening');
$this->db->where('a.id_asb', $id);
$this->db->order_by('c.kode_rekening');
$result = $this->db->get()->result_array();
return $result;
}
function get_prev_id($id)
{
$this->db->select('coalesce(max(a.id_asb), 0) id_asb')
->from('asb a')
->where('a.tahun', $this->tahun)
->where('a.id_asb < ', $id);
$result = $this->db->get()->row_array();
return $result['ID_ASB'];
}
function get_next_id($id)
{
$this->db->select('coalesce(min(a.id_asb), 0) id_asb')
->from('asb a')
->where('a.tahun', $this->tahun)
->where('a.id_asb > ', $id);
$result = $this->db->get()->row_array();
return $result['ID_ASB'];
}
function get_rka221_pakai($id)
{
$this->db->select('count(rd.id_asb) rka221_pakai');
$this->db->from('rincian_kegiatan rd');
$this->db->where('rd.id_asb',$id);
$result = $this->db->get()->row_array();
return $result['RKA221_PAKAI'];
}
}
?>