[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
simaku-aset
/
application
/
controllers
/
[
Home
]
File: Inventaris.php
<?php defined('BASEPATH') or exit('No direct script access allowed'); class Inventaris extends CI_Controller { function __construct() { parent::__construct(); if ($this->session->userdata('login') == false) { redirect('login'); } $this->load->model('M_master'); $this->load->model('Mpenyusutan'); $this->load->model('Minventaris'); $this->load->model('M_crud', 'model', TRUE); $this->model->set('tbl_inventaris', 'id'); } public function index() { $q = $this->Minfo->info()->row(); $data['namapt'] = !empty($q->namapt) ? $q->namapt : $this->config->item('nameAPP'); $data['title'] = 'Inventaris'; $data['logo'] = !empty($q->logo) ? $q->logo : 'logo'; $data['menu_inventaris'] = 'active'; $data['view'] = 'admin/inventaris/index'; $data['js'] = 'admin/inventaris/index_js'; $data['nama_feild'] = 'item_name'; $this->load->view('admin/beranda', $data); } public function show() { header('Content-Type: application/json; charset=utf-8'); $input = $this->input->get(); $get = $this->Minventaris->all_inventaris($input); $data = $get->result_array(); echo json_encode([ 'status' => 200, 'data' => $data, 'input' => $input, 'total' => $get->num_rows() ]); } public function update() { try { $id = $this->input->post("id"); $room_id = $this->input->post("room_id"); $data = [ "aset_code" => $this->gen_aset_code($id, $room_id), "room_id" => $room_id, "updated_by" => $this->session->userdata('username'), ]; $get = $this->model->update($data, $id); echo json_encode([ 'status' => 200, 'message' => 'Items update.', 'data' => $get, ]); } catch (ValidatorException $e) { echo json_encode([ 'status' => 304, 'message' => $e->getMessage(), ]); } } public function store_penyusutan() { header('Content-Type: application/json; charset=utf-8'); try { $id = $this->input->post("id"); $nominal = $this->input->post("nominal"); $get = $this->Minventaris->inventaris_id($id); if ($get->num_rows() > 0) { $nilai_aset = $get->row()->price - $get->row()->nominal; if ($nilai_aset > $nominal) { // tbl penyusutan $data = [ "first_nominal" => $nilai_aset, "nominal" => $nominal, "inventaris_id" => $id, ]; $this->Mpenyusutan->create($data); $message = 'Penyusutan Berhasil.'; $jenis = 1; } elseif ($nilai_aset == $nominal) { $message = 'Penghapusan Berhasil.'; $jenis = 2; } else { $message = 'Nominal melebihi harga perolehan.'; $jenis = 0; } # cek jenis penyusutan atau penghapusan if ($jenis > 0) { // send simak aset $this->store_simak_penyusutan($nominal, $get->row()->coa, $get->row()->nama_coa, $jenis, $get->row()->idrinci); } } echo json_encode([ 'status' => 200, 'message' => $message, 'data' => $get, ]); } catch (ValidatorException $e) { echo json_encode([ 'status' => 304, 'message' => $e->getMessage(), ]); } } // hapus inventaris public function destroy() { try { $id = $this->input->post("id"); $get = $this->Minventaris->inventaris_id($id); if ($get->num_rows() > 0) { // tbl penyusutan $nilai_aset = $get->row()->price - $get->row()->nominal; $data = [ "first_nominal" => $nilai_aset, "nominal" => $nilai_aset, "inventaris_id" => $id, ]; $this->Mpenyusutan->create($data); // tbl inventaris $data = [ "inventaris_status" => "3", //hilang/dihapus "updated_by" => $this->session->userdata('username'), ]; $this->model->update($data, $id); // send simak aset $this->store_simak_penyusutan($nilai_aset, $get->row()->coa, $get->row()->nama_coa, 2, $get->row()->idrinci); //hapus } echo json_encode([ 'status' => 200, 'message' => 'Items update.', 'data' => $get, ]); } catch (ValidatorException $e) { echo json_encode([ 'status' => 304, 'message' => $e->getMessage(), ]); } } function store_simak_penyusutan($nominal = 0, $coa = null, $nama = null, $jenis = 1, $id = 0) { // tbl simak aset $data = [ "nominal" => $nominal, "coa" => $coa, "nama" => $nama, "jenis" => $jenis, "idrinci" => $id, "createdBy" => $this->session->userdata('username'), ]; $this->Mpenyusutan->store_penyusutan_simak($data); } // genered Aset kode function gen_aset_code($id = 0, $room_id = 0) { $get = $this->Minventaris->inventaris_id($id); $get_room = $this->M_master->read_room_id($room_id); if ($get->num_rows() > 0 and $get_room->num_rows() > 0) { // $item_id = $get->row()->item_id; $get_item_max = $this->Minventaris->inventaris_item_id($item_id); $item_no = "01"; if ($get_item_max->num_rows() > 0) { $item_no = '0' . explode("-", $get_item_max->row()->aset_code)[1] + 1; } // $item_code = $get->row()->item_code; $room_code = $get_room->row()->room_code; $thn_spmu = date('Y', strtotime($get->row()->tgl_spmu)); if ($get->row()->aset_code == null) { return $item_code . '-' . $item_no . '-' . $room_code . '-' . $thn_spmu; //"a12312-02-23423d-2014"; //kode_item#urutan_jumlah_item#koderuang#thn_spmu } return $get->row()->aset_code; } return 0; } public function drowdownCoa() { header('Content-Type: application/json; charset=utf-8'); $get = $this->Minventaris->drowdownInventaris('coa'); $data = $get->result_array(); echo json_encode($data); } public function drowdownAsetItem() { header('Content-Type: application/json; charset=utf-8'); $get = $this->Minventaris->drowdownInventaris('item_id'); $data = $get->result_array(); echo json_encode($data); } public function drowdownRoom() { header('Content-Type: application/json; charset=utf-8'); $get = $this->Minventaris->drowdownInventaris('room'); $data = $get->result_array(); echo json_encode($data); } }