| 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 : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*********************************************************************************************
SUPER CLASS dari semua Modul Inventaris
*********************************************************************************************/
class Inventaris_Controller extends Userpage_Controller{
var $modul_name;
var $modul_display;
var $view_form;
var $view_daftar;
var $report_form;
var $report_daftar;
var $real_path;
var $message_aktivitas_dihapus = 'Inventaris telah dihapus.';
var $message_aktivitas_gagal_dihapus = 'Inventaris tidak bisa dihapus.';
public function __construct()
{
parent::__construct();
$this->real_path = dirname( realpath(SELF) )."/assets/img/temp/";
}
public function index()
{
$this->daftar();
}
protected function get_grid_model()
{
// di override di modul Inventaris
}
public function daftar()
{
$this->load->model('auth/login_model', 'auth');
$data['breadcrumbs'] = 'Daftar '.$this->modul_display;
$data['title'] = get_title($this->modul_display);
$data['modul'] = $this->modul_name;
$data['report_daftar'] = $this->report_daftar;
$data['report_form'] = $this->report_form;
$data['grid']['akses'] = $this->auth->get_level_akses($this->uri->slash_segment(1));
$data['grid']['url'] = base_url($this->modul_name.'/get_daftar');
$data['grid']['url_add'] = base_url($this->modul_name.'/form');
$data['grid']['url_del'] = base_url($this->modul_name.'/hapus');
$data['grid']['data'] = $this->data_model->get_grid_model();
$data['grid']['fields'] = $this->data_model->get_data_fields();
$data['main_content'] = $this->view_daftar;
$this->load->view('layout/template', $data);
}
public function get_daftar()
{
parent::get_daftar();
$aggregate = $this->data_model->get_data($this->search_param, TRUE);
$count = $aggregate['CNT'];
$response = (object) NULL;
$response->sql = $this->db->queries;
if($count == 0) // tidak ada data
{
// menambahkan userdata jika ada
$agg_fields = $this->data_model->fieldmap_daftar_aggregate;
foreach($agg_fields as $kolom => $value)
{
$response->userdata[$kolom] = $aggregate[ strtoupper($kolom) ];
}
echo json_encode($response);
return;
}
$page = $this->page;
$limit = $this->limit;
$total_pages = ceil($count/$limit);
if ($page > $total_pages) $page = $total_pages;
$start = $limit * $page - $limit;
if($start < 0) $start = 0;
$this->search_param['limit'] = array(
'start' => $start,
'end' => $limit
);
$result = $this->data_model->get_data($this->search_param);
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$response->sql = $this->db->queries;
$fields = $this->data_model->fieldmap_daftar;
for($i=0; $i<count($result); $i++)
{
$response->rows[$i]['id'] = $result[$i][$fields[0]];
$data = array();
for ($n=1; $n < count($fields); $n++)
{
$data[] = $result[$i][$fields[$n]];
}
$response->rows[$i]['cell'] = $data;
}
// menambahkan userdata jika ada
$agg_fields = $this->data_model->fieldmap_daftar_aggregate;
foreach($agg_fields as $kolom => $value)
{
$response->userdata[$kolom] = $aggregate[ strtoupper($kolom) ];
}
echo json_encode($response);
}
protected function get_extra_data($id)
{
return;
}
public function form($id=0)
{
$data = array();
$data['tahun_anggaran'] = $this->session->userdata('tahun');
$data['title'] = get_title($this->modul_display);
$data['modul'] = $this->modul_name;
$data['modul_display'] = $this->modul_display;
$data['report_form'] = $this->report_form;
$this->load->model('auth/login_model', 'auth');
$data['akses'] = $this->auth->get_level_akses($this->uri->slash_segment(1));
if ($id !== 0)
{
$data['data'] = $this->data_model->get_data_by_id($id);
}
$data['main_content'] = $this->view_form;
$data['extra'] = $this->get_extra_data($id);
$this->load->view('layout/template',$data);
}
protected function validasi_form()
{
/*if ($this->input->post('auto') !== 'true') {
$this->form_validation->set_rules('no', 'Nomor', 'required|trim|max_length[50]|callback__cek_nomor');
}
$this->form_validation->set_rules('tgl', 'Tanggal', 'required|trim');
$this->form_validation->set_rules('deskripsi', 'Keterangan', 'trim');
$this->form_validation->set_message('required', '%s tidak boleh kosong.');
$this->form_validation->set_message('max_length', '%s tidak boleh melebihi %s karakter.');
$this->form_validation->set_message('_cek_nomor', '%s sudah ada.');*/
$this->validasi();
}
protected function extra_message()
{
return array();
}
public function proses_inv()
{
$response = (object) NULL;
$this->load->model('auth/login_model', 'auth');
$akses = $this->auth->get_level_akses($this->uri->slash_segment(1));
if($akses == '3')
{
$this->load->library('form_validation');
$this->validasi_form();
/* if($this->form_validation->run() == TRUE)
{ */
$this->data_model->fill_data();
$success = $this->data_model->save_data();
if($success){
$response->isSuccess = TRUE;
$response->message = 'Data berhasil disimpan';
$response->id = $this->data_model->id;
$response->sql = $this->db->queries;
}
else
{
$response->isSuccess = FALSE;
$response->message = 'Data gagal disimpan';
$response->error = $this->data_model->last_error_message;
$response->sql = $this->db->queries;
}
/* }
else
{
$response->isSuccess = FALSE;
$response->sql = $this->db->queries;
$response->message = validation_errors();
} */
}
else
{
$response->isSuccess = FALSE;
$response->message = 'Proses Gagal, Anda tidak memiliki hak akses';
}
echo json_encode($response);
}
public function _cek_nomor($nomor)
{
return $this->data_model->cek_duplikasi_nomor($nomor);
}
public function _cek_bku()
{
return FALSE;
}
public function prev($id=0)
{
$response = (object) NULL;
$response->isSuccessful = FALSE;
if ($id !== 0)
{
$result = $this->data_model->get_prev_id($id);
if ($result)
{
$response->isSuccessful = TRUE;
$response->id = $result;
}
}
echo json_encode($response);
}
public function next($id=0)
{
$response = (object) NULL;
$response->isSuccessful = FALSE;
if ($id !== 0)
{
$result = $this->data_model->get_next_id($id);
if ($result)
{
$response->isSuccessful = TRUE;
$response->id = $result;
}
}
echo json_encode($response);
}
protected function check_dependency($id)
{
return TRUE; // di override di modul Aktivitas
}
public function GetNoRegister()
{
$param = array(
'id_skpd' => $this->input->post('id_skpd') ? $this->input->post('id_skpd') : 0,
'jenis' => $this->input->post('jenis') ? $this->input->post('jenis') : '',
);
$result = $this->data_model->GetNoRegister($param);
if (!empty($result[0]['NO_REGISTER']))
{
$plus = $result[0]['NO_REGISTER'] + 1;
$digit = 4;
$no_register = sprintf("%0".$digit."s",$plus);
}
else
{
$no_register = '0001';
}
$response = (object) NULL;
$response = array(
'no_register' => $no_register,
'sql' => $this->db->queries,
);
echo json_encode($response);
}
/* public function GetLokasi()
{
$param = array(
'id_skpd' => $this->input->post('id_skpd') ? $this->input->post('id_skpd') : 0
);
$result = $this->data_model->GetLokasi($param);
$response = (object) NULL;
$response = array(
'x_kode' => isset($result[0]['X_KODE']) ? $result[0]['X_KODE'] : '',
'x_unit' => isset($result[0]['X_UNIT']) ? $result[0]['X_UNIT'] : '',
'sql' => $this->db->queries,
);
echo json_encode($response);
}
*/
public function GetLokasi()
{
$param = array(
'id_skpd' => $this->input->post('id_skpd') ? $this->input->post('id_skpd') : 0
);
$result = $this->data_model->GetLokasi($param);
$response = (object) NULL;
$response = array(
'kd_daerah' => '12.11.22',
'kd_bid' => isset($result[0]['KODE_BIDANG']) ? $result[0]['KODE_BIDANG'] : '',
'kd_unit_bid' => isset($result[0]['KODE_UNIT_BIDANG']) ? $result[0]['KODE_UNIT_BIDANG'] : '',
/* 'thn_perolehan' => '', */
'sat_kerja' => isset($result[0]['SATUAN_KERJA']) ? $result[0]['SATUAN_KERJA'] : '',
'sql' => $this->db->queries,
);
echo json_encode($response);
}
public function GetCaraPerolehan()
{
$keyword = $this->input->post('term', TRUE);
$this->data_model->GetCaraPerolehan($keyword);
}
public function GetSumberDana()
{
$keyword = $this->input->post('term', TRUE);
$this->data_model->GetSumberDana($keyword);
}
public function GetNilaiPenyusutan()
{
$param = array(
'kel_penyusutan' => $this->input->post('kel_penyusutan') ? $this->input->post('kel_penyusutan') : NULL,
'id_maba' => $this->input->post('id_maba') ? $this->input->post('id_maba') : 0
);
$result = $this->data_model->GetNilaiPenyusutan($param);
$response = (object) NULL;
$response = array(
'nilai_penyusutan' => isset($result) ? $result : 0,
'sql' => $this->db->queries,
);
echo json_encode($response);
}
function icon()
{
$response = (object) NULL;
$id_inv = $this->input->post('id_inv');
$desc = $this->input->post('desc');
$foto_file = LOCAL_APP_DIR.'/'.APP_FOTO_PATH.$id_inv.'-'.$desc.'.jpg';
if (file_exists($foto_file)) {
unlink($foto_file);
$success = $this->data_model->update_icon($id_inv, $desc);
if($success){
$response->isSuccess = TRUE;
}
else
{
$response->isSuccess = FALSE;
$response->error = $this->data_model->last_error_message;
$response->sql = $this->db->queries;
}
}
else{
$response->isSuccess = TRUE;
}
echo json_encode($response);
}
function img_save_to_file()
{
$allowedExts = array("gif", "jpeg", "jpg", "png", "GIF", "JPEG", "JPG", "PNG");
$temp = explode(".", $_FILES["img"]["name"]);
$extension = end($temp);
if (in_array($extension, $allowedExts))
{
if ($_FILES["img"]["error"] > 0)
{
$response = array(
"status" => 'error',
"message" => 'ERROR Return Code: '. $_FILES["img"]["error"],
);
echo "Return Code: " . $_FILES["img"]["error"] . "<br>";
}
else
{
$filename = $_FILES["img"]["tmp_name"];
list($width, $height) = getimagesize( $filename );
move_uploaded_file($filename, $this->real_path . $_FILES["img"]["name"]);
$response = array(
"status" => 'success',
"url" => base_url().'assets/img/temp/'.$_FILES["img"]["name"],
"filename" => $_FILES["img"]["name"],
"width" => $width,
"height" => $height
);
}
}
else
{
$response = array(
"status" => 'error',
"message" => 'Format file tidak di dukung.',
);
}
print json_encode($response);
}
function img_crop_to_file()
{
$imgUrl = $_POST['imgUrl'];
$imgInitW = $_POST['imgInitW'];
$imgInitH = $_POST['imgInitH'];
$imgW = $_POST['imgW'];
$imgH = $_POST['imgH'];
$imgY1 = $_POST['imgY1'];
$imgX1 = $_POST['imgX1'];
$cropW = $_POST['cropW'];
$cropH = $_POST['cropH'];
$angle = $_POST['rotation'];
$jpeg_quality = 100;
$temp_name = "croppedImg_".rand();
$output_filename = $this->real_path.$temp_name;
$what = getimagesize($imgUrl);
switch(strtolower($what['mime']))
{
case 'image/png':
$img_r = imagecreatefrompng($imgUrl);
$source_image = imagecreatefrompng($imgUrl);
$type = '.png';
break;
case 'image/jpeg':
$img_r = imagecreatefromjpeg($imgUrl);
$source_image = imagecreatefromjpeg($imgUrl);
$type = '.jpeg';
break;
case 'image/gif':
$img_r = imagecreatefromgif($imgUrl);
$source_image = imagecreatefromgif($imgUrl);
$type = '.gif';
break;
default: die('image type not supported');
}
// resize the original image to size of editor
$resizedImage = imagecreatetruecolor($imgW, $imgH);
imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH);
// rotate the rezized image
$rotated_image = imagerotate($resizedImage, -$angle, 0);
// find new width & height of rotated image
$rotated_width = imagesx($rotated_image);
$rotated_height = imagesy($rotated_image);
// diff between rotated & original sizes
$dx = $rotated_width - $imgW;
$dy = $rotated_height - $imgH;
// crop rotated image to fit into original rezized rectangle
$cropped_rotated_image = imagecreatetruecolor($imgW, $imgH);
imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0));
imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH);
// crop image into selected area
$final_image = imagecreatetruecolor($cropW, $cropH);
imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0));
imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH);
// finally output png image
imagejpeg($final_image, $output_filename.$type, $jpeg_quality);
$response = Array(
"status" => 'success',
"url" => base_url().'assets/img/temp/'.$temp_name.$type
);
print json_encode($response);
}
}