231 lines
7.1 KiB
PHP
231 lines
7.1 KiB
PHP
<?php
|
|
|
|
class Qclevel extends MY_Controller
|
|
{
|
|
var $load;
|
|
var $db_mitra;
|
|
var $db_mitra_log;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_regional = $this->load->database("onedev", true);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
// $cek = $this->db_regional->query("select database() as current_db")->result();
|
|
// print_r($cek);
|
|
echo "MASTER QC LEVEL";
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
$search = "";
|
|
if (isset($prm["search"])) {
|
|
$search = trim($prm["search"]);
|
|
if ($search != "") {
|
|
$search = "%" . $prm["search"] . "%";
|
|
} else {
|
|
$search = "%%";
|
|
}
|
|
}
|
|
|
|
$number_offset = 0;
|
|
$number_limit = 10;
|
|
if ($prm["current_page"] > 0) {
|
|
$number_offset = ($prm["current_page"] - 1) * $number_limit;
|
|
}
|
|
|
|
$sql_filter = "SELECT count(*) as total
|
|
FROM nat_qc_level
|
|
WHERE Nat_QcLevelIsActive = 'Y'
|
|
AND Nat_QcLevelName LIKE ?
|
|
ORDER BY Nat_QcLevelName ASC";
|
|
$qry_filter = $this->db_regional->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("count qc level error", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT Nat_QcLevelID,
|
|
Nat_QcLevelName,
|
|
'' as rownumber
|
|
FROM nat_qc_level
|
|
WHERE Nat_QcLevelIsActive = 'Y'
|
|
AND Nat_QcLevelName LIKE ?
|
|
ORDER BY Nat_QcLevelName ASC";
|
|
$qry = $this->db_regional->query($sql, [$search]);
|
|
if ($qry) {
|
|
$rows = $qry->result_array();
|
|
} else {
|
|
$this->sys_error_db("select qc level error", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
foreach ($rows as $k => $v) {
|
|
$xno = ($k + 1) + $number_offset;
|
|
$rows[$k]['rownumber'] = $xno;
|
|
}
|
|
|
|
$result = array(
|
|
"total_page" => $tot_page,
|
|
"total_filter" => $tot_count,
|
|
"records" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_regional->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$nameqclevel = "";
|
|
if (isset($prm["nameqclevel"])) {
|
|
$nameqclevel = trim($prm["nameqclevel"]);
|
|
}
|
|
|
|
$sql = "INSERT INTO nat_qc_level(
|
|
Nat_QcLevelName,
|
|
Nat_QcLevelIsActive,
|
|
Nat_QcLevelCreated,
|
|
Nat_QcLevelLastUpdated,
|
|
Nat_QcLevelUserID) VALUES(?,'Y',NOW(),NOW(),?)";
|
|
$qry = $this->db_regional->query($sql, array(
|
|
$nameqclevel,
|
|
$userid
|
|
));
|
|
|
|
if (!$qry) {
|
|
$this->db_regional->trans_rollback();
|
|
$this->sys_error_db("insert qc level error", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$this->db_regional->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_regional->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$id = "";
|
|
if (isset($prm["id"])) {
|
|
$id = trim($prm["id"]);
|
|
}
|
|
|
|
$nameqclevel = "";
|
|
if (isset($prm["nameqclevel"])) {
|
|
$nameqclevel = trim($prm["nameqclevel"]);
|
|
}
|
|
|
|
$sql = "UPDATE nat_qc_level SET
|
|
Nat_QcLevelName = ?,
|
|
Nat_QcLevelLastUpdated = NOW(),
|
|
Nat_QcLevelUserID = ?
|
|
WHERE Nat_QcLevelID = ?";
|
|
$qry = $this->db_regional->query($sql, array(
|
|
$nameqclevel,
|
|
$userid,
|
|
$id
|
|
));
|
|
if (!$qry) {
|
|
$this->db_regional->trans_rollback();
|
|
$this->sys_error_db("update qc level error", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$this->db_regional->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
public function deleterow()
|
|
{
|
|
try {
|
|
if (!$this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$this->db_regional->trans_begin();
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user['M_UserID'];
|
|
|
|
$id = "";
|
|
if (isset($prm["id"])) {
|
|
$id = trim($prm["id"]);
|
|
}
|
|
|
|
$sql = "UPDATE nat_qc_level SET
|
|
Nat_QcLevelIsActive = 'N',
|
|
Nat_QcLevelLastUpdated = NOW(),
|
|
Nat_QcLevelUserID = ?
|
|
WHERE Nat_QcLevelID = ?";
|
|
$qry = $this->db_regional->query($sql, array(
|
|
$userid,
|
|
$id
|
|
));
|
|
if (!$qry) {
|
|
$this->db_regional->trans_rollback();
|
|
$this->sys_error_db("qc level delete error", $this->db_regional);
|
|
exit;
|
|
}
|
|
|
|
$this->db_regional->trans_commit();
|
|
$result = array(
|
|
"total" => 1,
|
|
"records" => array("xid" => 0)
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
}
|