Flatten mockup repo
This commit is contained in:
203
application/controllers/mockup/masterdata/Formnumber.php
Normal file
203
application/controllers/mockup/masterdata/Formnumber.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
class Formnumber extends MY_Controller
|
||||
{
|
||||
var $db_antrione;
|
||||
public function index()
|
||||
{
|
||||
echo "SERVICE API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_smartone = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function loadx()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/*if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}*/
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$sql = "select COUNT(*) as total
|
||||
from m_no_form
|
||||
where
|
||||
M_No_FormIsActive = 'Y'";
|
||||
$sql_param = array($search);
|
||||
$total = $this->db_smartone->query($sql,$sql_param)->row()->total;
|
||||
|
||||
|
||||
$sql = "select *
|
||||
from m_no_form
|
||||
where
|
||||
M_No_FormIsActive = 'Y'";
|
||||
$sql_param = array($search);
|
||||
$query = $this->db_smartone->query($sql,$sql_param);
|
||||
//echo $this->db_antrione->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("m_schedule select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows,
|
||||
"ownIP" => $_SERVER["REMOTE_ADDR"] );
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/*if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}*/
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$code = $prm['code'];
|
||||
$no = $prm['no'];
|
||||
$note = $prm['note'];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist
|
||||
FROM m_no_form
|
||||
WHERE M_No_FormIsActive = 'Y' AND M_No_FormName = '{$code}'";
|
||||
$exist_code = $this->db_smartone->query($query)->row()->exist;
|
||||
|
||||
if($exist_code == 0){
|
||||
$sql = "insert into m_no_form(
|
||||
M_No_FormName,
|
||||
M_No_FormRev,
|
||||
M_No_FormNote
|
||||
)
|
||||
values( ?,?,?)";
|
||||
$query = $this->db_smartone->query($sql,
|
||||
array(
|
||||
$code,
|
||||
$no,
|
||||
$note
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("m_no_form insert");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$result = array ("total" => -1, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/*if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}*/
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
$code = $prm['code'];
|
||||
$no = $prm['no'];
|
||||
$note = $prm['note'];
|
||||
|
||||
$query = "SELECT COUNT(*) as exist FROM m_no_form WHERE M_No_FormIsActive = 'Y' AND M_No_FormName = '{$code}' AND M_No_FormID <> {$id}";
|
||||
//echo $query;
|
||||
$exist_code = $this->db_smartone->query($query)->row()->exist;
|
||||
|
||||
if($exist_code == 0){
|
||||
$sql = "update m_no_form set
|
||||
M_No_FormName = ?,
|
||||
M_No_FormRev = ?,
|
||||
M_No_FormNote = ?
|
||||
where M_No_FormID = ?
|
||||
";
|
||||
$query = $this->db_smartone->query($sql,
|
||||
array(
|
||||
$code,
|
||||
$no,
|
||||
$note,
|
||||
$id
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("m_no_form update");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
}else{
|
||||
$result = array ("total" => -1, "records" => 0);
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function deletex()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
/*if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}*/
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$id = $prm['id'];
|
||||
|
||||
$sql = "update m_no_form set
|
||||
M_No_FormIsActive = 'N'
|
||||
where M_No_FormID = ?
|
||||
";
|
||||
$query = $this->db_smartone->query($sql,
|
||||
array(
|
||||
$id
|
||||
)
|
||||
);
|
||||
//echo $query;
|
||||
if (!$query) {
|
||||
$this->sys_error_db("m_no_form delete");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => 1, "records" => array("xid" => 0));
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user