284 lines
8.0 KiB
PHP
284 lines
8.0 KiB
PHP
<?php
|
|
class Mcu_top3 extends MY_Controller
|
|
{
|
|
var $db_onedev;
|
|
public function index()
|
|
{
|
|
echo "Resultentry API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
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
|
|
JOIN m_mou ON M_MouM_CompanyID = M_CompanyID AND M_MouIsActive = 'Y'
|
|
WHERE
|
|
M_CompanyName like ?
|
|
AND M_CompanyIsActive = 'Y'";
|
|
$query = $this->db_onedev->query($sql,$q['search']);
|
|
//echo $query;
|
|
//echo $this->db_onedev->last_query();
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
}
|
|
else {
|
|
$this->sys_error_db("m_city count",$this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
$sql = "
|
|
SELECT M_CompanyID as id, M_CompanyName as name, '' as mous
|
|
FROM m_company
|
|
JOIN m_mou ON M_MouM_CompanyID = M_CompanyID AND M_MouIsActive = 'Y'
|
|
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();
|
|
if($rows){
|
|
foreach($rows as $k => $v){
|
|
$sql = "SELECT '0' as id, 'Semua' as name
|
|
UNION
|
|
SELECT M_MouID as id, M_MouName as name
|
|
FROM m_mou
|
|
WHERE
|
|
M_MouM_CompanyID = {$v['id']} AND M_MouIsActive = 'Y'";
|
|
$details = $this->db_onedev->query($sql)->result_array();
|
|
$rows[$k]['mous'] = $details;
|
|
}
|
|
}
|
|
//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;
|
|
}
|
|
}
|
|
|
|
public function search()
|
|
{
|
|
$prm = $this->sys_input;
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
$company = isset($prm["company"])?$prm["company"]:'0';
|
|
$search = $prm["search"];
|
|
|
|
if(!isset($prm['current_page']))
|
|
$prm['current_page'] = 1;
|
|
if($company == 0 && $search !== ''){
|
|
$sql_where = "WHERE Mgm_McuNumber like '%$search%' AND Mgm_McuIsActive = 'Y'";
|
|
}elseif($company != 0 && $search === ''){
|
|
$sql_where = "WHERE Mgm_McuM_CompanyID = {$company} AND Mgm_McuIsActive = 'Y'";
|
|
}elseif($company != 0 && $search !== ''){
|
|
$sql_where = "WHERE Mgm_McuM_CompanyID = {$company} AND Mgm_McuNumber like '%$search%' AND Mgm_McuIsActive = 'Y'";
|
|
}
|
|
|
|
$number_limit = 10;
|
|
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
|
|
//$sql_param = array();
|
|
|
|
|
|
$sql = " SELECT count(*) as total
|
|
FROM (
|
|
SELECT Mgm_McuID
|
|
FROM
|
|
one_etl.mgm_mcu
|
|
$sql_where
|
|
GROUP BY Mgm_McuID
|
|
) x
|
|
";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
|
|
$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("t_samplestorageout count", $this->db_onedev);
|
|
exit;
|
|
}
|
|
|
|
|
|
$sql = "SELECT Mgm_McuID,
|
|
Mgm_McuM_CompanyID,
|
|
Mgm_McuNumber as ordernumber,
|
|
Mgm_McuNumberNational,
|
|
Mgm_McuStartDate,
|
|
Mgm_McuEndDate,
|
|
CONCAT(DATE_FORMAT(Mgm_McuStartDate,'%d-%m-%Y'), ' s/d ',DATE_FORMAT(Mgm_McuStartDate,'%d-%m-%Y')) as orderdate
|
|
FROM
|
|
one_etl.mgm_mcu
|
|
$sql_where
|
|
GROUP BY Mgm_McuID
|
|
ORDER BY Mgm_McuID ASC
|
|
limit $number_limit offset $number_offset";
|
|
//echo $sql;
|
|
$query = $this->db_onedev->query($sql);
|
|
$rows = $query->result_array();
|
|
//echo $this->db_onedev->last_query();
|
|
/* if($rows){
|
|
foreach($rows as $k => $v){
|
|
$rows[$k]['langs'] = $this->getlangs($v['trx_id']);
|
|
$rows[$k]['doctors'] = $this->getdoctors();
|
|
}
|
|
}
|
|
*/
|
|
|
|
|
|
//$this->_add_address($rows);
|
|
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
function copynote(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "UPDATE one_etl.mcu_top3_kelainan SET
|
|
Mcu_Top3KelainanDescription = '{$prm['note']}',
|
|
Mcu_Top3KelainanUpdatedUserID = {$userid}
|
|
WHERE
|
|
Mcu_Top3KelainanID = '{$prm['Mcu_Top3KelainanID']}'";
|
|
$query = $this->db_onedev->query($sql);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("mcu_top3_kelainan update");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("id" => $prm['Mcu_Top3KelainanID']));
|
|
$this->sys_ok($result);
|
|
}
|
|
function updatenote(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "UPDATE one_etl.mcu_top3_kelainan SET
|
|
Mcu_Top3KelainanDescription = '{$prm['note']}',
|
|
Mcu_Top3KelainanUpdatedUserID = {$userid}
|
|
WHERE
|
|
Mcu_Top3KelainanID = '{$prm['Mcu_Top3KelainanID']}'";
|
|
$query = $this->db_onedev->query($sql);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("mcu_top3_kelainan update");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("id" => $prm['Mcu_Top3KelainanID']));
|
|
$this->sys_ok($result);
|
|
}
|
|
function newnote(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$userid = $this->sys_user["M_UserID"];
|
|
$sql = "UPDATE one_etl.mcu_top3_kelainan SET
|
|
Mcu_Top3KelainanDescription = '{$prm['Mcu_Top3KelainanDescription']}',
|
|
Mcu_Top3KelainanUpdatedUserID = {$userid}
|
|
WHERE
|
|
Mcu_Top3KelainanID = '{$prm['Mcu_Top3KelainanID']}'";
|
|
$query = $this->db_onedev->query($sql);
|
|
// echo $query;
|
|
if (!$query) {
|
|
$this->sys_error_db("mcu_top3_kelainan update");
|
|
exit;
|
|
}
|
|
$result = array ("total" => 1, "records" => array("id" => $prm['Mcu_Top3KelainanID']));
|
|
$this->sys_ok($result);
|
|
}
|
|
function getdatadetails(){
|
|
if (! $this->isLogin) {
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
$prm = $this->sys_input;
|
|
$id = $prm['Mgm_McuID'];
|
|
$rows = array();
|
|
$sql = "SELECT Mcu_Top3KelainanID,
|
|
Mcu_Top3KelainanXTotalPerItem,
|
|
Mcu_Top3KelainanMcu_KelainangroupName,
|
|
Mcu_Top3KelainanMcu_KelainanGroupID,
|
|
Mcu_Top3KelainanMcuKelainanID,
|
|
Mcu_Top3KelainanMgm_McuID,
|
|
Mcu_Top3KelainanPercentage,
|
|
Mcu_Top3KelainanDescription,
|
|
IF(Mcu_Top3KelainanDescription = '' OR Mcu_Top3KelainanDescription IS NULL,'N','Y') as isvalue,
|
|
'' as note,
|
|
'' as note_old
|
|
FROM
|
|
one_etl.mcu_top3_kelainan
|
|
WHERE Mcu_Top3KelainanMgm_McuID = $id AND Mcu_Top3KelainanIsActive = 'Y'";
|
|
//echo $sql;
|
|
$rows = $this->db_onedev->query($sql)->result_array();
|
|
foreach($rows as $k => $v){
|
|
$old_note = '';
|
|
$top_id = $v['Mcu_Top3KelainanID'];
|
|
if($v['isvalue'] == 'N'){
|
|
$old_note = $this->db_onedev->query("SELECT Mcu_Top3KelainanDescription as note
|
|
FROM one_etl.mcu_top3_kelainan
|
|
WHERE Mcu_Top3KelainanMgm_McuID = $id
|
|
AND Mcu_Top3KelainanID < $top_id
|
|
ORDER BY Mcu_Top3KelainanMgm_McuID DESC
|
|
LIMIT 1")->row()->note;
|
|
$rows[$k]['note'] = $old_note;
|
|
$rows[$k]['note_old'] = $old_note;
|
|
|
|
}else{
|
|
$rows[$k]['note'] = $v['Mcu_Top3KelainanDescription'];
|
|
$rows[$k]['note_old'] = $v['Mcu_Top3KelainanDescription'];
|
|
}
|
|
}
|
|
|
|
$result = array(
|
|
"total" => count($rows) ,
|
|
"records" => $rows,
|
|
);
|
|
$this->sys_ok($result);
|
|
exit;
|
|
}
|
|
|
|
}
|
|
|