Flatten mockup repo
This commit is contained in:
205
application/controllers/mockup/masterdata/Kapus.php
Normal file
205
application/controllers/mockup/masterdata/Kapus.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
class Kapus extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
public function index()
|
||||
{
|
||||
echo "KAPUS API";
|
||||
}
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database("onedev", true);
|
||||
}
|
||||
|
||||
public function getdata()
|
||||
{
|
||||
try {
|
||||
//# cek token valid
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "select *
|
||||
from sys_kapus
|
||||
JOIN m_company ON sysKaPusM_CompanyID = M_CompanyID
|
||||
JOIN m_paymenttype ON sysKaPusM_PaymentTypeID = M_PaymentTypeID
|
||||
where
|
||||
sysKaPusIsActive = 'Y' LIMIT 1";
|
||||
$rows = $this->db_onedev->query($sql)->row_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
if (!$rows) {
|
||||
$this->sys_error_db("kapus select");
|
||||
exit;
|
||||
|
||||
}
|
||||
$result = array ("total" => count($rows),"records" => $rows);
|
||||
$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;
|
||||
//print_r($prm);
|
||||
if($prm['sysKaPusID'] == "0" || $prm['sysKaPusID'] == 0){
|
||||
$sql = "INSERT INTO sys_kapus
|
||||
(sysKaPusM_CompanyID,
|
||||
sysKaPusM_PaymentTypeID,
|
||||
sysKaPusPct,
|
||||
sysKaPusControl,
|
||||
sysKaPusUse,
|
||||
sysKaPusCreated,
|
||||
sysKaPusLastUpdated)
|
||||
VALUES
|
||||
('{$prm['sysKaPusM_CompanyID']}',
|
||||
'{$prm['sysKaPusM_PaymentTypeID']}',
|
||||
'{$prm['sysKaPusPct']}',
|
||||
'{$prm['sysKaPusControl']}',
|
||||
'{$prm['sysKaPusUse']}',
|
||||
now(),
|
||||
now())
|
||||
";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error_db("kapus insert");
|
||||
exit;
|
||||
}
|
||||
}else{
|
||||
$sql = "update sys_kapus SET
|
||||
sysKaPusM_CompanyID = '{$prm['sysKaPusM_CompanyID']}',
|
||||
sysKaPusM_PaymentTypeID = '{$prm['sysKaPusM_PaymentTypeID']}',
|
||||
sysKaPusPct = '{$prm['sysKaPusPct']}',
|
||||
sysKaPusControl = '{$prm['sysKaPusControl']}',
|
||||
sysKaPusUse = '{$prm['sysKaPusUse']}',
|
||||
sysKaPusLastUpdated = now()
|
||||
where
|
||||
sysKaPusID = {$prm['sysKaPusID']}
|
||||
";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
|
||||
if (!$query) {
|
||||
//echo $this->db_onedev->last_query();
|
||||
$this->sys_error_db("kapus update");
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$result = array ("total" => 1, "records" => array());
|
||||
$this->sys_ok($result);
|
||||
|
||||
} catch(Exception $exc) {
|
||||
$message = $exc->getMessage();
|
||||
$this->sys_error($message);
|
||||
}
|
||||
}
|
||||
function searchcompany(){
|
||||
if (! $this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$max_rst = 12;
|
||||
$tot_count =0;
|
||||
|
||||
$q = [
|
||||
'search' => '%'
|
||||
];
|
||||
|
||||
if ($prm['search'] != '')
|
||||
{
|
||||
$q['search'] = "%{$prm['search']}%";
|
||||
}
|
||||
|
||||
// QUERY TOTAL
|
||||
$sql = "SELECT count(*) as total
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'";
|
||||
$query = $this->db_onedev->query($sql,$q['search']);
|
||||
//echo $query;
|
||||
if ($query) {
|
||||
$tot_count = $query->result_array()[0]["total"];
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_company count",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT *
|
||||
FROM m_company
|
||||
WHERE
|
||||
M_CompanyName like ?
|
||||
AND M_CompanyIsActive = 'Y'
|
||||
ORDER BY M_CompanyName DESC
|
||||
";
|
||||
$query = $this->db_onedev->query($sql, array($q['search']));
|
||||
|
||||
if ($query) {
|
||||
$rows = $query->result_array();
|
||||
//echo $this->db_onedev->last_query();
|
||||
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
else {
|
||||
$this->sys_error_db("m_company rows",$this->db_onedev);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
function getmou(){
|
||||
$prm = $this->sys_input;
|
||||
$query ="SELECT M_MouID, M_MouName, CONCAT(M_MouName, ' | Exp: ', DATE_FORMAT(M_MouEndDate,'%d-%m-%Y')) as M_MouDesc
|
||||
FROM m_mou
|
||||
WHERE
|
||||
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
function getpaymenttype(){
|
||||
$prm = $this->sys_input;
|
||||
$query ="SELECT M_PaymentTypeID, M_PaymentTypeName
|
||||
FROM m_paymenttype
|
||||
WHERE
|
||||
M_PaymentTypeIsActive = 'Y'
|
||||
";
|
||||
//echo $query;
|
||||
$rows = $this->db_onedev->query($query)->result_array();
|
||||
|
||||
$result = array(
|
||||
"total" => count($rows) ,
|
||||
"records" => $rows,
|
||||
);
|
||||
$this->sys_ok($result);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user