db_inventory = $this->load->database("inventory", true); } function index() { echo "Api: Training Playground"; echo "
"; $cek = $this->db_inventory->query("select database() as cunrrent_db")->result(); } // function coba() // { // $prm = $this->sys_input; // $prmuser = $this->sys_user; // echo 'Nama :'.($prm["nama"])."\n"; // echo 'Alamat :'.($prm["alamat"])."\n"; // echo 'Umur :'.($prm["umur"])."\n"; // echo 'DOB :'.($prm["dob"])."\n"; // echo 'User ID :'.($prmuser["M_UserID"]); // } function insert() { try{ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db_inventory->trans_begin(); $param = $this->sys_input; $paramuser = $this->sys_user; $sql_data = "insert into adjustmentreason( AdjustmentReasonDescription, AdjustmentReasonCreated, AdjustmentReasonLastUpdated, AdjustmentReasonUserID) values (?, now(), now(), ?)"; $qry = $this->db_inventory->query($sql_data, [ $param["AdjustmentReasonDescription"], $paramuser["M_UserID"] ]); if(!$qry){ $this->db_inventory->trans_rollback(); $this->sys_error_db("Adjustmentreason add", $this->db_inventory); exit; } $this->db_inventory->trans_commit(); $result = array( "total" => 1, "records" => array("id" => 0) ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function search() { try{ if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $param = $this->sys_input; $sql_data = ""; $sql_filter = ""; $search = ""; if(isset($param["search"])) { $search = trim($param["search"]); if ($search != "") { $search = "%" . $param["search"] . "%"; }else{ $search = "%%"; } } $sortBy = $param["sortBy"]; $sortStatus = $param["sortStatus"]; if($sortBy){ $q_sort = "ORDER BY ".$sortBy." ".$sortStatus; } $number_offset = 0; $number_limit = 10; if($param["current_page"] > 0) { $number_offset = ($param["current_page"] - 1) * $number_limit; } $sql_filter = "select count(distinct AdjustmentReasonID, AdjustmentReasonIsActive) as total from adjustmentreason where AdjustmentReasonDescription like ? and AdjustmentReasonIsActive = 'Y'"; $qry_filter = $this->db_inventory->query($sql_filter, [$search]); $tot_count = 0; $tot_page = 0; if($qry_filter) { $tot_count = $qry_filter->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); }else{ $this->sys_error_db("Adjustmentreason select count", $this->db_inventory); exit; } $sql_data = "select distinct AdjustmentReasonDescription, AdjustmentReasonIsActive from adjustmentreason where AdjustmentReasonDescription like ? and AdjustmentReasonIsActive = 'Y' $q_sort limit ? offset ?"; $qry_data = $this->db_inventory->query($sql_data, [$search, $number_limit, $number_offset]); if($qry_data) { $rows = $qry_data->result_array(); }else{ $this->sys_error_db("Adjustmentreason select", $this->db_inventory); exit; } $result = array( "total" => $tot_page, "total_filter" => $tot_count, "records" => $rows ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function update() { try { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db_inventory->trans_begin(); $param = $this->sys_input; $userid = $this->sys_user['M_UserID']; $sql_data = "update adjustmentreason set AdjustmentReasonDescription = ?, AdjustmentReasonLastUpdated = now(), AdjustmentReasonUserID = ? where AdjustmentReasonID = ?"; $qry_data = $this->db_inventory->query($sql_data, [ $param["AdjustmentReasonDescription"], $userid, $param["AdjustmentReasonID"] ]); if(!$qry_data){ $this->db_inventory->trans_rollback(); $this->sys_error_db("Adjustmentreason update", $this->db_inventory); exit; } $this->db_inventory->trans_commit(); $result = array( "total" => 1, "records" => array("id" => 0) ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } function delete() { try { if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $this->db_inventory->trans_begin(); $param = $this->sys_input; $sql_data = "update adjustmentreason set AdjustmentReasonIsActive = ? where AdjustmentReasonID = ?"; $qry_data = $this->db_inventory->query($sql_data, [ "N", $param["AdjustmentReasonID"] ]); if(!$qry_data){ $this->db_inventory->trans_commit(); $this->sys_error_db("Adjustmentreason delete"); exit; } $this->db_inventory->trans_commit(); $result = array( "total" => 1, "records" => array("id" => 0) ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }