| 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 : /wamp/www/sipapbd_2018_xxxx/application/modules/ssh/models/ |
Upload File : |
<?php
class Ssh_model extends CI_Model {
var $fieldmapSsh = array();
var $dataSsh;
var $last_changed;
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->fieldmapSsh = array(
'id_ssh' => 'ID_SSH',
'id_rek' => 'ID_REKENING',
'kat' => 'KATEGORI',
'URAIAN' => 'URAIAN',
'KODE_STANDAR' => 'KODE_STANDAR',
'SATUAN' => 'SATUAN',
'HARGA_SATUAN' => 'HARGA',
'last_changed' => 'LAST_CHANGED',
);
$this->fieldmap_filter = array(
'URAIAN' => 'A.URAIAN',
'KODE_STANDAR' => 'A.KODE_STANDAR',
'KODE_REKENING' => 'R.KODE_REKENING',
'NAMA_REKENING' => 'R.NAMA_REKENING',
'KATEGORI' => 'A.KATEGORI',
'SATUAN' => 'A.SATUAN',
'HARGA' => 'A.HARGA'
);
}
// ----- search advance ---- >>
function get_data_fields()
{
$fields = array(
'URAIAN' => array('name' => 'Uraian', 'kategori'=>'string'),
'KODE_STANDAR' => array('name' => 'Kode Standar', 'kategori'=>'string'),
'KODE_REKENING' => array('name' => 'Kode Rekening', 'kategori'=>'string'),
'NAMA_REKENING' => array('name' => 'Nama Rekening', 'kategori'=>'string'),
'KATEGORI' => array('name' => 'Kategori', 'kategori'=>'string'),
);
return $fields;
}
function update_data($id)
{
$this->db->trans_start();
if($id <= 0){
$update = $this->db->insert('SSH', array('KATEGORI' => $this->input->post('KATEGORI'),
'URAIAN' => $this->input->post('URAIAN'),
'KODE_STANDAR' => $this->input->post('KODE_STANDAR'),
'SATUAN' => $this->input->post('SATUAN'),
'HARGA' => $this->input->post('HARGA'),
'ID_REKENING' => $this->input->post('ID_REKENING'),
'LAST_CHANGED' => date('d.m.Y.H.i.s')
));
$idx = $this->db->query("select max(ID_SSH) as ID from SSH")->row_array();
$this->last_changed = $this->get_last_changed('SSH','ID_SSH',$idx['ID']);
}
else{
$this->db->where('ID_SSH', $id);
$update = $this->db->update('SSH', array('KATEGORI' => $this->input->post('KATEGORI'),
'URAIAN' => $this->input->post('URAIAN'),
'KODE_STANDAR' => $this->input->post('KODE_STANDAR'),
'SATUAN' => $this->input->post('SATUAN'),
'HARGA' => $this->input->post('HARGA'),
'LAST_CHANGED' => date('d.m.Y.H.i.s')
));
$this->last_changed = $this->get_last_changed('SSH','ID_SSH',$id);
}
$this->db->trans_complete();
return $update;
}
function check_dependency($id)
{
return TRUE;
}
function get_last_changed($modul,$id_modul,$id)
{
$last_changed = $this->db->query("select last_changed from ".$modul." where ".$id_modul."=".$id."")->row_array();
return $last_changed['LAST_CHANGED'];
}
function delete_data($id){
$this->db->trans_start();
$this->db->where('ID_SSH', $id);
$delete = $this->db->delete('SSH');
$this->db->trans_complete();
return $delete;
}
/*==============================GET DATA========================================*/
function get_data($param, $isCount=FALSE, $CompileOnly=False)
{
isset($param['limit']) && $param['limit'] ? $this->db->limit($param['limit']['end'], $param['limit']['start']) : '';
// 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);
}
}
}
}
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']);
}
$this->db->select("a.ID_SSH, a.ID_REKENING, a.KATEGORI, a.URAIAN, a.KODE_STANDAR, a.SATUAN, a.HARGA, r.KODE_REKENING, r.NAMA_REKENING, a.last_changed, 0 param");
$this->db->from('SSH a');
$this->db->join('REKENING R', 'R.ID_REKENING = A.ID_REKENING','LEFT OUTER');
/*$this->db->where('A.STATUS',$this->session->userdata('STATUS_LOGIN'));
$this->db->where('A.TAHUN',$this->session->userdata('TAHUN_LOGIN'));
$this->db->group_by('1,2');*/
if ($isCount) {
$result = $this->db->count_all_results();
return $result;
}
else
{
if ($CompileOnly)
{
return $this->db->get_compiled_select();
}
else
{
$result = $this->db->get()->result_array();
return $result;
}
}
}
function insert_data()
{
$this->db->trans_start();
$this->fill_data();
for ($i=0; $i<=count($this->dataSsh)-1; $i++)
{
$this->db->insert('SSH', $this->dataSsh[$i]);
}
$this->db->trans_complete();
if ($this->db->trans_status() === FALSE)
{
return FALSE;
}
}
function fill_data()
{
$ssh = $this->input->post('ssh') ? $this->input->post('ssh') : NULL;
if ($ssh)
{
$ssh = json_decode($ssh);
for ($i=0; $i <= count($ssh) - 1; $i++) {
$id = $this->max_id_ssh();
$last_id = $id['GEN_ID'];
foreach($this->fieldmapSsh as $key => $value){
switch ($key)
{
case 'id_ssh' : $$key = $last_id; break;
case 'id_rek' : $$key = $this->input->post($key) ? $this->input->post($key) : ''; break;
case 'kat' : $$key = $this->input->post($key) ? $this->input->post($key) : ''; break;
case 'last_changed' : $$key = date('d.m.Y.H.i.s'); break;
default : $$key = isset($ssh[$i]->$key) && $ssh[$i]->$key ? $ssh[$i]->$key : NULL;
}
if(isset($$key))
$this->dataSsh[$i][$value] = $$key;
}
}
}
}
function max_id_ssh()
{
$sql = "SELECT NEXT VALUE FOR G_ID_SSH FROM RDB\$DATABASE";
$result = $this->db->query($sql)->row_array();
return $result;
}
function get_opt_satuan($q)
{
$isi = strtolower($q);
$this->db->select('NAMA_SATUAN');
$this->db->like('LOWER(NAMA_SATUAN)', $isi, 'after');
$this->db->order_by('NAMA_SATUAN');
$result = $this->db->get('SATUAN')->result_array();
return $result;
}
function cek_exist()
{
if($this->input->post('id') > 0){
$this->db->select('count(fa.id_ssh) ssh_exists');
$this->db->from('SSH fa');
$this->db->where('fa.id_ssh',$this->input->post('id'));
$result = $this->db->get()->row_array();
if($result && $result['SSH_EXISTS'] > 0)
{
return 1;
}
else{
return 0;
}
}
else{
return 1;
}
}
function cek_changed()
{
if($this->input->post('id') > 0 || $this->input->post('last_changed') !=''){
$this->db->select('fa.last_changed');
$this->db->from('ssh fa');
$this->db->where('fa.id_ssh',$this->input->post('id'));
$result = $this->db->get()->row_array();
if($result)
{
if($result['LAST_CHANGED'] <= $this->input->post('last_changed')){
return 1;
}
else{
return $result['LAST_CHANGED'];
}
}
else{
return 1;
}
}
else{
return 1;
}
}
}
?>