403Webshell
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/simbada_2019/application/core/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /wamp/www/simbada_2019/application/core/Inventaris_Model.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*********************************************************************************************
  SUPER CLASS dari semua Model Inventaris
 *********************************************************************************************/
class Inventaris_Model extends Base_Model{

  var $tipe;
  var $id;
  var $nomor;
  var $fieldmap_inventaris;
  var $data_inventaris;
  var $fieldmap_daftar_aggregate; // variabel untuk menampung kolom yang di aggregate (sum, count, dll)
  var $sort_default;

  function __construct()
  {
    parent::__construct();
		$this->sort_default = array();

    $this->fieldmap_inventaris = array(
			'id' => 'ID_INVENTARIS',
			'id_skpd' => 'ID_SKPD',
			'id_maba' => 'ID_MASTER_BARANG',
			'cara_perolehan' => 'CARA_PEROLEHAN',
			'tahun_perolehan' => 'TAHUN_PEROLEHAN',
			'tahun_anggaran' => 'TAHUN_ANGGARAN',
			'jenis_inventaris' => 'JENIS_INVENTARIS',
			'nm_inv' => 'NAMA_INVENTARIS',
			'no_reg' => 'NO_REGISTER',
			'no_bast' => 'NO_BAST',
			'status_inv' => 'STATUS',
			'harga_beli' => 'HARGA_BELI',
			'atribusi' => 'ATRIBUSI',
			'harga_perolehan' => 'NILAI_ASET',
			'sd' => 'SUMBER_DANA',
			'ket' => 'DESKRIPSI',			
			'tgl_perolehan' => 'TGL_PEROLEHAN',
			'id_lokasi' => 'ID_KODE_LOKASI'	
    );		
  }		

  function get_grid_model()
  {

  }

  function fill_data()
  {	
		/* ambil data Inventaris */
    foreach($this->fieldmap_inventaris as $key => $value)
		{
			switch ($key)
			{
				case 'tgl_perolehan' : $$key = $this->input->post('tgl_perolehan') ? prepare_date($this->input->post('tgl_perolehan')) : NULL; break;
				default : $$key = $this->input->post($key) ? $this->input->post($key) : NULL;
			}
			
			if(isset($$key))
			$this->data_inventaris[$value] = $$key;
		}

    /* pengambilan data lain di override di modul Inventaris */
  }

  function insert_inventaris()
  {
    if (isset($this->data_inventaris['ID_INVENTARIS']))
    {			
			$this->db->where('ID_INVENTARIS', $this->data_inventaris['ID_INVENTARIS']);
			$this->db->update('INVENTARIS', $this->data_inventaris);
			$this->check_trans_status('UPDATE INVENTARIS FAILED');
			$this->id = $this->data_inventaris['ID_INVENTARIS'];
    }
    else
    {			
			$id = $this->get_id('G_ID_INVENTARIS');
			$this->data_inventaris['ID_INVENTARIS'] = $id;
			$this->id = $id;	
			
			$this->db->insert('INVENTARIS', $this->data_inventaris);
			$this->check_trans_status('INSERT INVENTARIS FAILED');
			
    }
		//$this->nomor = $this->data_aktivitas['NOMOR'];
  }

  function save_detail()
  {
		$foto_file_depan = LOCAL_APP_DIR.'/'.APP_FOTO_PATH.$this->id.'-foto_depan.jpg';
		$foto_file_samping = LOCAL_APP_DIR.'/'.APP_FOTO_PATH.$this->id.'-foto_samping.jpg';
		$foto_file_belakang = LOCAL_APP_DIR.'/'.APP_FOTO_PATH.$this->id.'-foto_belakang.jpg';
		
		try {
			if(!empty($_POST['image_1'])){
				$source_1 = $this->real_path.$_POST['image_1'];
				if (!file_exists( $source_1 )) throw new Exception("File foto depan tidak ditemukan.");
				if(!copy($source_1, $foto_file_depan)){
					echo "Foto Depan Gagal Dibuat";
					throw new Exception("File foto depan tidak bisa diproses.");
				}
			}
			
			if(!empty($_POST['image_2'])){
				$source_2 = $this->real_path.$_POST['image_2'];
				if (!file_exists( $source_2 )) throw new Exception("File foto samping tidak ditemukan.");
				if(!copy($source_2, $foto_file_samping)){
					echo "Foto Samping Gagal Dibuat";
					throw new Exception("File foto samping tidak bisa diproses.");
				}
			}
			
			if(!empty($_POST['image_3'])){
				$source_3 = $this->real_path.$_POST['image_3'];
				if (!file_exists( $source_3 )) throw new Exception("File foto belakang tidak ditemukan.");
				if(!copy($source_3, $foto_file_belakang)){
					echo "Foto Belakang Gagal Dibuat";
					throw new Exception("File foto belakang tidak bisa diproses.");
				}
			}
			
			$handle=opendir($this->real_path);
			while (($file = readdir($handle))!==false) {
				chown($this->real_path.$file, 666);
				@unlink($this->real_path.$file);
			}
			closedir($handle);
		}
		catch(Exception $e) {
			$this->last_error_message = $e->getMessage();
			return FALSE;
		}
		
		$dbh = $this->db->conn_id;
		
		if (file_exists($foto_file_depan)) {
			$fd_1 = fopen($foto_file_depan, 'r');
			$blob = ibase_blob_import($dbh, $fd_1);
			fclose($fd_1);

			if (!is_string($blob)) {
				throw new Exception("File foto depan tidak bisa dibaca.");
			} else {
				$this->db->select('1')->from('INVENTARIS_FOTO')->where('ID_INVENTARIS', $this->id)->where("DESKRIPSI = 'foto_depan'");
				$rs = $this->db->get()->row_array();

				if ($rs)
				{
					$query = "UPDATE INVENTARIS_FOTO SET FOTO = ? WHERE ID_INVENTARIS = ".$this->id." AND DESKRIPSI = 'foto_depan'";
				}
				else
				{
					$query = "INSERT INTO INVENTARIS_FOTO (ID_INVENTARIS, FOTO, DESKRIPSI) VALUES (".$this->id.",?,'foto_depan')";
				}		
				
				$prepared = ibase_prepare($dbh, $query);
				if (!ibase_execute($prepared, $blob)) {
					throw new Exception("Gagal menyimpan Foto Depan");
				}
			}
		}
		
		if (file_exists($foto_file_samping)) {
			$fd_2 = fopen($foto_file_samping, 'r');
			$blob = ibase_blob_import($dbh, $fd_2);
			fclose($fd_2);

			if (!is_string($blob)) {
				throw new Exception("File foto samping tidak bisa dibaca.");
			} else {
				$this->db->select('1')->from('INVENTARIS_FOTO')->where('ID_INVENTARIS', $this->id)->where("DESKRIPSI = 'foto_samping'");
				$rs = $this->db->get()->row_array();

				if ($rs)
				{
					$query = "UPDATE INVENTARIS_FOTO SET FOTO = ? WHERE ID_INVENTARIS = ".$this->id." AND DESKRIPSI = 'foto_samping'";
				}
				else
				{
					$query = "INSERT INTO INVENTARIS_FOTO (ID_INVENTARIS, FOTO, DESKRIPSI) VALUES (".$this->id.",?,'foto_samping')";
				}		
				
				$prepared = ibase_prepare($dbh, $query);
				if (!ibase_execute($prepared, $blob)) {
					throw new Exception("Gagal menyimpan Foto Samping");
				}
			}
		}
		
		if (file_exists($foto_file_belakang)) {
			$fd_3 = fopen($foto_file_belakang, 'r');
			$blob = ibase_blob_import($dbh, $fd_3);
			fclose($fd_3);

			if (!is_string($blob)) {
				throw new Exception("File foto belakang tidak bisa dibaca.");
			} else {
				$this->db->select('1')->from('INVENTARIS_FOTO')->where('ID_INVENTARIS', $this->id)->where("DESKRIPSI = 'foto_belakang'");
				$rs = $this->db->get()->row_array();

				if ($rs)
				{
					$query = "UPDATE INVENTARIS_FOTO SET FOTO = ? WHERE ID_INVENTARIS = ".$this->id." AND DESKRIPSI = 'foto_belakang'";
				}
				else
				{
					$query = "INSERT INTO INVENTARIS_FOTO (ID_INVENTARIS, FOTO, DESKRIPSI) VALUES (".$this->id.",?,'foto_belakang')";
				}		
				
				$prepared = ibase_prepare($dbh, $query);
				if (!ibase_execute($prepared, $blob)) {
					throw new Exception("Gagal menyimpan Foto Belakang");
				}
			}
		}
  }

  function save_data()
  {
    $this->db->trans_begin();
    try {
      if ($this->modul_name == 'aset_takberwujud' || $this->modul_name == 'inventaris_ruangan') 
			{ 
				$this->save_detail();
			}
			else 
			{
				$this->insert_inventaris();
				$this->save_detail();
			}
    }
    catch(Exception $e){
      //TODO : log error to file
			$this->last_error_message = $e->getMessage();
      return FALSE;
    }

    if ($this->db->trans_status() === FALSE)
    {
      $this->id = NULL;
      $this->nomor = NULL;

      $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 delete_data($id)
  {
    $this->db->trans_begin();
    try {
      $this->build_query_hapus($id);
    }
    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;
  }

  // jika aktivitas sudah masuk bud, maka yang bisa diubah hanya Setup Jurnal
  function fill_data_bku()
  {
    foreach($this->fieldmap_aktivitas as $key => $value){
      switch ($key)
      {
        case 'id'   : $$key = $this->input->post($key) ? prepare_date($this->input->post($key)) : NULL; $this->data_aktivitas[$value] = $$key; break;
        case 'jurnal'   : $$key = $this->input->post($key) ? prepare_date($this->input->post($key)) : NULL; $this->data_aktivitas[$value] = $$key; break;
      }
    }
  }

  function save_data_bku()
  {
    try {
      $this->db->where('ID_AKTIVITAS', $this->data_aktivitas['ID_AKTIVITAS']);
      $this->db->update('AKTIVITAS_BLUD', $this->data_aktivitas);
      $this->check_trans_status('update aktivitas_blud failed');
      $this->id = $this->data_aktivitas['ID_AKTIVITAS'];
    }
    catch(Exception $e){
      //TODO : log error to file
    }

    if ($this->db->trans_status() === FALSE)
    {
      $this->id = NULL;
      $this->nomor = NULL;

      $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 build_query_daftar()
  {
    // di override di modul Aktivitas
  }

  function build_query_form($id=0)
  {
    // di override di modul Aktivitas
  }

  function build_query_hapus()
  {
    // di override di modul Aktivitas
  }
  
	// override get_data dari base_model
  function get_data($param, $isCount=FALSE, $CompileOnly=False)
  {
    $this->build_query_daftar();

    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 ($isCount) {
      $this->db->ar_select = array();
      $this->db->ar_select[] = 'count(*) cnt';
      foreach( $this->fieldmap_daftar_aggregate as $agg_key => $agg_value)
      {
        $this->db->ar_select[] = "coalesce(".$agg_value.", 0) ".$agg_key;
      }

      $result = $this->db->get();
      return $result->row_array();
    }
    else
    {
      // 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']);
      }
      // urutkan sesuai default jika ada
      else {
        if (count($this->sort_default) > 0){
          $this->db->_protect_identifiers = FALSE;
          $urutan = implode( ',', $this->sort_default);
          $this->db->order_by( $urutan );
          $this->db->_protect_identifiers = TRUE;
        }
      }

      if ($CompileOnly)
      {
        return $this->db->get_compiled_select();
      }
      else
      {
        $result = $this->db->get();
        return $result->result_array();
      }
    }
  }

  function get_prev_id($id)
  {
    $this->db->select('coalesce(max(inv.ID_INVENTARIS), 0) ID_INVENTARIS');
		$this->db->from('INVENTARIS inv');
		$this->db->where('inv.ID_INVENTARIS < ', $id);
		
    $result = $this->db->get()->row_array();

    return $result['ID_INVENTARIS'];
  }

  function get_next_id($id)
  {
    $this->db->select('coalesce(min(inv.ID_INVENTARIS), 0) ID_INVENTARIS');
		$this->db->from('INVENTARIS inv');
		$this->db->where('inv.ID_INVENTARIS > ', $id);
   
    $result = $this->db->get()->row_array();

    return $result['ID_INVENTARIS'];
  }

  function check_dependency($id)
  {
    return TRUE; // fungsi ini di override di modul Inventaris
  }
	
	function GetNoRegister($param)
  {
    $query = $this->db->query("SELECT COUNT (r.NO_REGISTER ) AS NO_REGISTER
															FROM INVENTARIS r 
															WHERE r.JENIS_INVENTARIS = '".$param['jenis']."'
																AND r.TAHUN_ANGGARAN = '".$this->tahun."'
																AND r.ID_SKPD = '".$param['id_skpd']."'");
		
		return $query->result_array();
  }
	
	function GetLokasi($param)
  {
    $query = $this->db->query("
			SELECT 
				U.KODE_URUSAN AS KODE_BIDANG
				, B.KODE_BIDANG AS KODE_UNIT_BIDANG				
				, r.KODE_SKPD AS SATUAN_KERJA
				, r.KODE_SKPD_LKP
				, r.NAMA_SKPD
			FROM V_SKPD R
				INNER JOIN BIDANG B 
					ON B.ID_BIDANG = R.ID_BIDANG
				INNER JOIN URUSAN U 
					ON U.ID_URUSAN = R.ID_URUSAN
			WHERE R.ID_SKPD = '".$param['id_skpd']."'
		");
		
		return $query->result_array();
  }
	
	/* function GetLokasi($param)
  {
		$tahun_sekarang = date('y');		
		
    $query = $this->db->query("SELECT																
																'12.11.22.' || IIF(u.KODE_URUSAN = '0', '', u.KODE_URUSAN || '.') ||  b.KODE_BIDANG || '.' || s.KODE_SKPD AS X_KODE
																, s.UNIT_KERJA AS X_UNIT
															FROM SKPD s
																INNER JOIN BIDANG b on b.ID_BIDANG = s.ID_BIDANG
																INNER JOIN URUSAN u on u.ID_URUSAN = b.ID_URUSAN
															WHERE s.ID_SKPD = '".$param['id_skpd']."'");
		
		return $query->result_array();
  } */
	
	function GetCaraPerolehan($keyword)
  {
		$query = $this->db->query("SELECT CARA_PEROLEHAN
																FROM CARA_PEROLEHAN
																WHERE CARA_PEROLEHAN LIKE '%".$keyword."%'");
		echo json_encode($query->result_array());
  }
	
	function GetSumberDana($keyword)
  {
		$query = $this->db->query("SELECT SUMBER_DANA
																FROM SUMBER_DANA
																WHERE SUMBER_DANA LIKE '%".$keyword."%'");
		echo json_encode($query->result_array());
  }
	
	function GetNilaiPenyusutan($param)
  {
		$query = $this->db->query('
			SELECT r.ID_PARENT_MASTER_BARANG, r.MASA_MANFAAT
			FROM MASTER_BARANG r
			WHERE r.ID_MASTER_BARANG = '.$param['id_maba'].'
		');
		$result = $query->row_array();
		
    $id_parent = $result['ID_PARENT_MASTER_BARANG'];
		$masa_manfaat = isset($result['MASA_MANFAAT']) ? $result['MASA_MANFAAT'] : 0;
		
		if ($param['kel_penyusutan'] == 1) // Per Kelompok
		{
			// 1
			$query = $this->db->query('
				SELECT r.ID_PARENT_MASTER_BARANG
				FROM MASTER_BARANG r
				WHERE r.ID_MASTER_BARANG = '.$id_parent.'
			');
			$result = $query->row_array();
			
			$id_parent = $result['ID_PARENT_MASTER_BARANG'];
			
			// 2
			$query = $this->db->query('
				SELECT r.MASA_MANFAAT
				FROM MASTER_BARANG r
				WHERE r.ID_MASTER_BARANG = '.$id_parent.'
			');
			$result = $query->row_array();
			
			$nilai_penyusutan = isset($result['MASA_MANFAAT']) ? $result['MASA_MANFAAT'] : 0;
		} 
		else if ($param['kel_penyusutan'] == 2) // Per Sub Kelompok
		{
			// 1
			$query = $this->db->query('
				SELECT r.MASA_MANFAAT
				FROM MASTER_BARANG r
				WHERE r.ID_MASTER_BARANG = '.$id_parent.'
			');
			$result = $query->row_array();
			
			$nilai_penyusutan = isset($result['MASA_MANFAAT']) ? $result['MASA_MANFAAT'] : 0;
		}
		else if ($param['kel_penyusutan'] == 3) // Tidak Ada
		{
			$nilai_penyusutan = $masa_manfaat;
		}
		
		return $nilai_penyusutan;
  }
	
	function update_icon($id_inv, $desc)
  {
    $this->db->trans_begin();
    try {
			$this->db->where('ID_INVENTARIS', $id_inv);
			$this->db->where('DESKRIPSI', $desc);
      $this->db->update('INVENTARIS_FOTO', array('FOTO' => NULL));
    }
    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;
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit