Batch 6a: application controllers base
This commit is contained in:
219
application/controllers/v1/masterdata/Methode.php
Normal file
219
application/controllers/v1/masterdata/Methode.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
class Methode extends MY_Controller
|
||||
{
|
||||
var $db_regional;
|
||||
public function index()
|
||||
{
|
||||
echo "Methode API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_regional = $this->load->database("regional", true);
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
$prm = $this->sys_input;
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$code = $prm["scode"];
|
||||
$nama = $prm["nama"];
|
||||
|
||||
// echo $nik;
|
||||
|
||||
$sql_where = "WHERE Nat_MethodeIsActive = 'Y' ";
|
||||
$sql_param = array();
|
||||
if ($nama != "") {
|
||||
if ($sql_where != "") {
|
||||
$sql_where .=" and ";
|
||||
}
|
||||
$sql_where .= " Nat_MethodeName like ? ";
|
||||
$sql_param[] = "%$nama%";
|
||||
}
|
||||
if ($code != "") {
|
||||
if ($sql_where != "") {
|
||||
$sql_where .=" and ";
|
||||
}
|
||||
if ($code == "xxx") {
|
||||
$sql_where .= " Nat_MethodeCode = Nat_MethodeOldCode ";
|
||||
$sql_param[] = "%$code%";
|
||||
} else {
|
||||
$sql_where .= " Nat_MethodeCode like ? ";
|
||||
$sql_param[] = "%$code%";
|
||||
}
|
||||
}
|
||||
|
||||
//if ($sql_where != "") $sql_where .= " and ";
|
||||
|
||||
// Order masih dalam status registrasi
|
||||
//$sql_where .= " M_StaffIsActive = 'Y' ";
|
||||
|
||||
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM nat_methode
|
||||
$sql_where
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->db_regional->query($sql, $sql_param);
|
||||
|
||||
$tot_count = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
} else {
|
||||
$this->sys_error_db("nat_methode count", $this->db_regional);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT *
|
||||
FROM nat_methode
|
||||
$sql_where
|
||||
ORDER BY Nat_MethodeCode ASC
|
||||
limit 0,$tot_count";
|
||||
|
||||
$query = $this->db_regional->query($sql, $sql_param);
|
||||
$rows = $query->result_array();
|
||||
if($rows){
|
||||
foreach($rows as $k => $v){
|
||||
//$rows[$k]['verification_px'] = $this->add_verification_methode($v['M_StaffID']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//$this->_add_address($rows);
|
||||
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_regional->last_query());
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function save(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
|
||||
if($prm['Nat_MethodePriority'] == '')
|
||||
$prm['Nat_MethodePriority'] = 0;
|
||||
|
||||
$query ="UPDATE nat_methode SET
|
||||
Nat_MethodeName = '{$prm['Nat_MethodeName']}',
|
||||
Nat_MethodeNameInResult = '{$prm['Nat_MethodeNameInResult']}',
|
||||
Nat_MethodeCode = '{$prm['Nat_MethodeCode']}',
|
||||
Nat_MethodePriority = '{$prm['Nat_MethodePriority']}',
|
||||
Nat_MethodeM_UserID = '{$userid}',
|
||||
Nat_MethodeLastUpdated = now()
|
||||
WHERE Nat_MethodeID = '{$prm['Nat_MethodeID']}'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_regional->query($query);
|
||||
if($rows){
|
||||
}
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK')
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function newmethode(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
if($prm['Nat_MethodePriority'] == '')
|
||||
$prm['Nat_MethodePriority'] = 0;
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
$query ="INSERT INTO nat_methode (
|
||||
Nat_MethodeName,
|
||||
Nat_MethodeNameInResult,
|
||||
Nat_MethodeCode,
|
||||
Nat_MethodePriority,
|
||||
Nat_MethodeM_UserID,
|
||||
Nat_MethodeCreated
|
||||
)
|
||||
VALUES(
|
||||
'{$prm['Nat_MethodeName']}',
|
||||
'{$prm['Nat_MethodeNameInResult']}',
|
||||
'{$prm['Nat_MethodeCode']}',
|
||||
'{$prm['Nat_MethodePriority']}',
|
||||
'{$userid}',
|
||||
now()
|
||||
)
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_regional->query($query);
|
||||
$last_id = $this->db_regional->insert_id();
|
||||
if($rows){
|
||||
}
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK'),
|
||||
"id" => $last_id
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function deletemethode(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$query ="UPDATE nat_methode SET
|
||||
Nat_MethodeIsActive = 'N'
|
||||
WHERE
|
||||
Nat_MethodeID = '{$prm['Nat_MethodeID']}'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_regional->query($query);
|
||||
|
||||
$query ="UPDATE nat_normalvalue SET
|
||||
Nat_NormalValueIsActive = 'N'
|
||||
WHERE
|
||||
Nat_NormalValueNat_MethodeID = '{$prm['Nat_MethodeID']}'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_regional->query($query);
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => array('status'=>'OK')
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function checkcodeexist(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
$rtn = 'N';
|
||||
$query =" SELECT COUNT(*) as countx
|
||||
FROM nat_methode
|
||||
WHERE Nat_MethodeCode = '{$prm['code']}' AND Nat_MethodeIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rst = $this->db_regional->query($query)->row()->countx;
|
||||
if($rst > 0)
|
||||
$rtn = 'Y';
|
||||
|
||||
|
||||
$result = array(
|
||||
"total" => 1 ,
|
||||
"records" => $rtn,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user