Flatten mockup repo
This commit is contained in:
241
application/controllers/mockup/masterdata/Instrumentlocal.php
Normal file
241
application/controllers/mockup/masterdata/Instrumentlocal.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
class Instrumentlocal extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "Instrument REPORT API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
function lookup(){
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
$instrumentlocalcode = $prm['instrumentlocalcode'];
|
||||
$instrumentlocalname = $prm['instrumentlocalname'];
|
||||
$status = $prm['status'];
|
||||
$all = $prm['all'];
|
||||
$filter = '';
|
||||
if($status != 'A'){
|
||||
$filter .= "AND status = '{$status}' ";
|
||||
}else{
|
||||
$filter .= "";
|
||||
}
|
||||
$limit = '';
|
||||
if($all == 'N'){
|
||||
$limit = ' LIMIT 10';
|
||||
}
|
||||
$number_limit = 10;
|
||||
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
||||
$sql = "select COUNT(*) as total
|
||||
FROM(SELECT *, IF(IFNULL(T_InstrumentLocalID,0) > 0 , 'Y', 'N') as status
|
||||
from nat_instrument
|
||||
LEFT JOIN t_instrument_local ON Nat_InstrumentID = T_InstrumentLocalNat_InstrumentID AND T_InstrumentLocalIsActive = 'Y'
|
||||
WHERE
|
||||
Nat_InstrumentIsActive = 'Y') a
|
||||
WHERE
|
||||
Nat_InstrumentCode like '%{$instrumentlocalcode}%' AND
|
||||
Nat_InstrumentName like '%{$instrumentlocalname}%' $filter";
|
||||
// $total = $this->db_onedev->query($sql,$sql_param)->row()->total;
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
$tot_count = 0;
|
||||
$tot_page = 0;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
$tot_page = ceil($tot_count/$number_limit);
|
||||
} else {
|
||||
$this->sys_error_db("nat_instrument count", $this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM(select Nat_InstrumentID as id,
|
||||
Nat_InstrumentID,
|
||||
Nat_InstrumentCode,
|
||||
Nat_InstrumentName,
|
||||
T_InstrumentLocalID,
|
||||
T_InstrumentLocalNat_InstrumentID,
|
||||
IF(IFNULL(T_InstrumentLocalID,0) > 0 , 'Y', 'N') as status
|
||||
from nat_instrument
|
||||
LEFT JOIN t_instrument_local ON Nat_InstrumentID = T_InstrumentLocalNat_InstrumentID AND T_InstrumentLocalIsActive = 'Y'
|
||||
WHERE
|
||||
Nat_InstrumentIsActive = 'Y') a
|
||||
WHERE
|
||||
Nat_InstrumentCode like '%{$instrumentlocalcode}%' AND
|
||||
Nat_InstrumentName like '%{$instrumentlocalname}%' $filter
|
||||
GROUP BY Nat_InstrumentID
|
||||
ORDER BY Nat_InstrumentCode ASC";
|
||||
$sql_param = array($search);
|
||||
$query = $this->db_onedev->query($sql);
|
||||
//echo $this->db_onedev->last_query();
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
|
||||
|
||||
} else {
|
||||
$this->sys_error_db("nat_instrument select");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function getsexreg(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$rows = [];
|
||||
$query ="
|
||||
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
|
||||
UNION
|
||||
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
|
||||
UNION
|
||||
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
|
||||
";
|
||||
//echo $query;
|
||||
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function getstatus(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$rows = [];
|
||||
|
||||
$query ="
|
||||
SELECT 'A' as M_StatusID, 'Semua' as M_StatusName
|
||||
UNION
|
||||
SELECT 'Y' as M_StatusID, 'Terpilih' as M_StatusName
|
||||
UNION
|
||||
SELECT 'N' as M_StatusID, 'Belum Terpilih' as M_StatusName
|
||||
";
|
||||
//echo $query;
|
||||
$rows['f_statuss'] = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function selected() {
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$sql = "select CONCAT(Nat_InstrumentCode , ' | ',Nat_InstrumentName) as Nat_InstrumentName
|
||||
from t_instrument_local
|
||||
JOIN nat_instrument ON T_InstrumentLocalNat_InstrumentID = Nat_InstrumentID
|
||||
where
|
||||
T_InstrumentLocalIsActive = 'Y' ORDER BY Nat_InstrumentCode ASC";
|
||||
$query = $this->db_onedev->query($sql,$sql_param);
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
} else {
|
||||
$this->sys_error_db( $this->db_onedev->last_query() );
|
||||
exit;
|
||||
}
|
||||
$result = array ("total" => count($rows), "records" => $rows);
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
public function saveaddeditinstrumentlocal()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
//# ambil parameter input
|
||||
$prm = $this->sys_input;
|
||||
$instrumentid = $prm['Nat_InstrumentID'];
|
||||
$instrumentlocalid = $prm['T_InstrumentLocalID'];
|
||||
$status = $prm['status'];
|
||||
$userid = $this->sys_user["M_UserID"];
|
||||
if($status == 'Y'){
|
||||
$sql = "insert into t_instrument_local(
|
||||
T_InstrumentLocalNat_InstrumentID,
|
||||
T_InstrumentLocalUserID,
|
||||
T_InstrumentLocalCreated,
|
||||
T_InstrumentLocalLastUpdated
|
||||
)
|
||||
values(?,?,now(),now())";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array($instrumentid,
|
||||
$userid
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_instrument_local 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{
|
||||
$sql = "UPDATE t_instrument_local SET
|
||||
T_InstrumentLocalIsActive = 'N',
|
||||
T_InstrumentLocalUserID = ?,
|
||||
T_InstrumentLocalCreated = now(),
|
||||
T_InstrumentLocalLastUpdated = now()
|
||||
WHERE T_InstrumentLocalID = ?";
|
||||
$query = $this->db_onedev->query($sql,
|
||||
array(
|
||||
$userid,
|
||||
$instrumentlocalid
|
||||
)
|
||||
);
|
||||
if (!$query) {
|
||||
$this->sys_error_db("t_instrument_local insert",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
$last_id = $this->db_onedev->insert_id();
|
||||
$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