356 lines
8.8 KiB
PHP
356 lines
8.8 KiB
PHP
<?php
|
|
class Akreditasi
|
|
extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Samplingverify API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT IFNULL(M_AkreditasiID,0) as id,
|
|
M_AkreditasiID,
|
|
M_AkreditasiName,
|
|
M_AkreditasiKode,
|
|
M_AkreditasiPrefix
|
|
FROM m_akreditasi
|
|
WHERE
|
|
M_AkreditasiIsActive = 'Y'
|
|
GROUP BY M_AkreditasiID
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
public function search_listing()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT IFNULL(M_AkreditasiID,0) as id,
|
|
M_AkreditasiID,
|
|
M_AkreditasiName,
|
|
M_AkreditasiKode,
|
|
M_AkreditasiPrefix
|
|
FROM m_akreditasi
|
|
WHERE
|
|
M_AkreditasiIsActive = 'Y'
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function selectcategory(){
|
|
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$rows = [];
|
|
$query ="SELECT *
|
|
FROM t_category
|
|
WHERE
|
|
T_CategoryIsActive = 'Y'
|
|
ORDER BY T_CategoryName asc";
|
|
//echo $query;
|
|
$rows['categorys'] = $this->db_onedev->query($query)->result_array();
|
|
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
|
|
}
|
|
function save(){
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$M_AkreditasiName = $prm['name'];
|
|
$M_AkreditasiKode = $prm['kode'];
|
|
$M_AkreditasiPrefix = $prm['prefix'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
|
|
if($prm['xid'] == 0){
|
|
$query = "SELECT COUNT(*) as exist FROM m_akreditasi WHERE M_AkreditasiIsActive = 'Y' AND M_AkreditasiName = '{$M_AkreditasiName}'";
|
|
$exist_code = $this->db_onedev->query($query)->row()->exist;
|
|
if($exist_code == 0){
|
|
$sql = "insert into m_akreditasi(
|
|
M_AkreditasiName,
|
|
M_AkreditasiKode,
|
|
M_AkreditasiPrefix,
|
|
M_AkreditasiUserID,
|
|
M_AkreditasiLastUpdated,
|
|
M_AkreditasiCreated)
|
|
values(?,?,?,?,now(),now())";
|
|
$query = $this->db_onedev->query($sql,
|
|
array(
|
|
$M_AkreditasiName,
|
|
$M_AkreditasiKode,
|
|
$M_AkreditasiPrefix,
|
|
$userid)
|
|
);
|
|
if (!$query) {
|
|
$this->sys_error_db("m_akreditasi insert",$this->db_onedev);
|
|
exit;
|
|
}
|
|
$last_id = $this->db_onedev->insert_id();
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
}else{
|
|
$errors = array();
|
|
if($exist_code != 0){
|
|
array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong'));
|
|
}
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
}else{
|
|
$query = "SELECT COUNT(*) as exist FROM m_akreditasi WHERE M_AkreditasiIsActive = 'Y' AND M_AkreditasiName = '{$M_AkreditasiName}' AND M_AkreditasiID <> {$prm['xid']}";
|
|
//echo $query;
|
|
$exist_code = $this->db_onedev->query($query)->row()->exist;
|
|
// echo $exist_code;
|
|
if($exist_code == 0){
|
|
$sql = "UPDATE m_akreditasi SET
|
|
M_AkreditasiName = '{$M_AkreditasiName}',
|
|
M_AkreditasiKode = '{$M_AkreditasiKode}',
|
|
M_AkreditasiPrefix = '{$M_AkreditasiPrefix}',
|
|
M_AkreditasiUserID = '{$userid}'
|
|
WHERE M_AkreditasiID = '{$prm['xid']}'";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
}else{
|
|
$errors = array();
|
|
if($exist_code != 0){
|
|
array_push($errors,array('field'=>'code','msg'=>'Nama sudah ada yang pakai dong'));
|
|
}
|
|
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
public function delete()
|
|
{
|
|
try {
|
|
//# cek token valid
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
//# ambil parameter input
|
|
$prm = $this->sys_input;
|
|
$id = $prm['xid'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "update m_akreditasi SET
|
|
M_AkreditasiIsActive = 'N',
|
|
M_AkreditasiUserID = $userid,
|
|
M_AkreditasiLastUpdated = now()
|
|
WHERE
|
|
M_AkreditasiID = $id";
|
|
|
|
$query = $this->db_onedev->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("m_akreditasi delete");
|
|
exit;
|
|
}
|
|
$sqltest = "update m_akreditasipx SET
|
|
M_AkreditasiPxIsActive = 'N',
|
|
M_AkreditasiPxUserID = $userid,
|
|
M_AkreditasiPxLastUpdated = now()
|
|
WHERE
|
|
M_AkreditasiPxM_AkreditasiID = $id";
|
|
|
|
$querytest = $this->db_onedev->query($sqltest);
|
|
// echo $query;
|
|
if (!$querytest) {
|
|
$this->sys_error_db("m_akreditasipx delete");
|
|
exit;
|
|
}
|
|
|
|
$result = array ("total" => 1, "records" => array("xid" => 0));
|
|
$this->sys_ok($result);
|
|
|
|
} catch(Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function savejpagroup(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$query = "insert into m_akreditasi(
|
|
M_AkreditasiName,
|
|
M_AkreditasiUserID,
|
|
M_AkreditasiCreated
|
|
)
|
|
VALUES(
|
|
'{$prm['value']}',
|
|
{$userid},
|
|
NOW()
|
|
)";
|
|
|
|
//echo $query;
|
|
$action = $this->db_onedev->query($query);
|
|
|
|
if($action){
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array(),
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
else{
|
|
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function savelistingjpagroup(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$query = " UPDATE m_akreditasi SET
|
|
M_AkreditasiName = '{$prm['name']}',
|
|
M_AkreditasiIsActive = '{$prm['status']}',
|
|
M_AkreditasiUserID = {$userid}
|
|
WHERE
|
|
M_AkreditasiID = {$prm['id']}
|
|
";
|
|
|
|
//echo $query;
|
|
$action = $this->db_onedev->query($query);
|
|
|
|
if($action){
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array(),
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
else{
|
|
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function savealljpadetail(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$details = $prm['details'];
|
|
$userid = $this->sys_user["M_UserID"];
|
|
foreach($details as $k => $v){
|
|
$query = "insert into m_akreditasi(
|
|
Nat_JPADetailNat_JPAID,
|
|
Nat_JPADetailM_AkreditasiID,
|
|
Nat_JPADetailDiscount,
|
|
Nat_JPADetailUserID,
|
|
Nat_JPADetailCreated
|
|
)
|
|
VALUES(
|
|
'{$v['Nat_JpaID']}',
|
|
'{$v['M_AkreditasiID']}',
|
|
'{$v['Nat_JPADetailDiscount']}',
|
|
{$userid},
|
|
NOW()
|
|
) ON DUPLICATE KEY UPDATE
|
|
Nat_JPADetailDiscount = {$v['Nat_JPADetailDiscount']},
|
|
Nat_JPADetailUserID = {$userid}";
|
|
|
|
//echo $query;
|
|
$action = $this->db_onedev->query($query);
|
|
}
|
|
|
|
|
|
if($action){
|
|
$result = array(
|
|
"total" => 1 ,
|
|
"records" => array(),
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
else{
|
|
$this->sys_error_db($this->db_onedev->last_query(), $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |