Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,194 @@
<?php
class Mou extends MY_Controller
{
var $db_regional;
public function index()
{
echo "MOU MONITORING API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = $prm["name"];
$nolab = $prm["nolab"];
$branchid = $prm["branchid"];
$typeid = $prm["typeid"];
$statusid = $prm["statusid"];
$filter_branch = '';
if(intval($branchid) > 0)
$filter_branch = " AND M_BranchID = {$branchid}";
$filter_status = "WHERE TxMouStatus = '{$statusid}'";
$filter_type = '';
if(intval($typeid) == 1){
$filter_type = "AND TxMouT_TestID = 0";
}elseif(intval($typeid) == 2){
$filter_type = "AND TxMouT_TestID > 0";
}
$sql = "SELECT tx_mou.*,
TxMouID as id,
IF(TxMouT_TestID = 0,'Mou Verifikasi','Edit Price') as tipe,
M_BranchName as branchname,
DATE_FORMAT(TxMouCreated,'%d-%m-%Y') as moudate,
TxMouM_MouID as mouid,
M_MouName as mouname,
M_CompanyName as companyname,
IFNULL(T_TestName,'-') as testname,
IF(TxMouStatus = 'N','Pending','Terkirim') as status,
TxMouRetry as pengulangan,
'' as staffname,
IF(TxMouStatus = 'N','Y','N') as chex
FROM tx_mou
JOIN m_branch ON TxMouM_BranchCode = M_BranchCode $filter_branch
JOIN m_mou ON TxMouM_MouID = M_MouID
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
LEFT JOIN t_test ON T_TestID = TxMouT_TestID
$filter_status $filter_type
GROUP BY TxMouID
ORDER BY TxMouID ASC
";
//echo $sql;
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N'){
$rows[$k]['chex'] = false;
}else{
$rows[$k]['chex'] = true;
}
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$rows['types'] = array(array('id'=>0,'name'=>'Semua'),array('id'=>1,'name'=>'Mou Verifikasi'),array('id'=>2,'name'=>'Edit Price'));
$rows['statuss'] = array(array('id'=>'N','name'=>'Pending'),array('id'=>'Y','name'=>'Terkirim'));
$sql = "SELECT 0 as id, 'Semua' as name
UNION
SELECT M_BranchID as id, M_BranchName as name
FROM m_branch
WHERE
M_BranchIsActive = 'Y'
GROUP BY M_BranchID";
$rows['branchs'] = $this->db_regional->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$mous = $prm["mous"];
foreach($mous as $idx => $mou) {
if ( $mou["chex"] == 1 ) {
$txMouID = $mou["TxMouID"];
$ipAddress= $mou["TxMouM_BranchIPAddress"];
$j_param = $mou["TxMouJson"];
try {
if ($mou["TxMouT_TestID"] == 0 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/r_mou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = 1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = 1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
} else {
//edit admin price
$url = "http://$ipAddress/one-api/tools/price/r_mou/edit";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'N' , TxMouRetry = 1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = 1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
} catch(Exception $e) {
$err_msg[] = $e->getMessage();
$flag_error = true;
}
}
}
if (! $flag_error ) {
$result = array ("message" => "Resend OK");
$this->sys_ok($result);
} else {
$this->sys_error( array( "message" => join(",",$err_msg)) );
}
exit;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
return $result;
}
}

View File

@@ -0,0 +1,196 @@
<?php
class Mou extends MY_Controller
{
var $db_regional;
public function index()
{
echo "MOU MONITORING API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = $prm["name"];
$nolab = $prm["nolab"];
$branchid = $prm["branchid"];
$typeid = $prm["typeid"];
$statusid = $prm["statusid"];
$filter_branch = '';
if(intval($branchid) > 0)
$filter_branch = " AND M_BranchID = {$branchid}";
$filter_status = "WHERE TxMouStatus = '{$statusid}'";
$filter_type = '';
if(intval($typeid) == 1){
$filter_type = "AND TxMouT_TestID = 0";
}elseif(intval($typeid) == 2){
$filter_type = "AND TxMouT_TestID > 0";
}
$sql = "SELECT tx_mou.*,
TxMouID as id,
IF(TxMouT_TestID = 0,'Mou Verifikasi','Edit Price') as tipe,
M_BranchName as branchname,
DATE_FORMAT(TxMouCreated,'%d-%m-%Y %T') as moudate,
TxMouM_MouID as mouid,
M_MouName as mouname,
M_CompanyName as companyname,
IFNULL(T_TestName,'-') as testname,
IF(TxMouStatus = 'N','Pending','Terkirim') as status,
TxMouRetry as pengulangan,
M_StaffName as staffname,
IF(TxMouStatus = 'N','Y','N') as chex
FROM tx_mou
JOIN m_branch ON TxMouM_BranchCode = M_BranchCode $filter_branch
JOIN m_mou ON TxMouM_MouID = M_MouID
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
JOIN m_user ON TxMouM_UserID = M_UserID
JOIN m_staff ON M_UserM_StaffID = M_StaffID
LEFT JOIN t_test ON T_TestID = TxMouT_TestID
$filter_status $filter_type
GROUP BY TxMouID
ORDER BY TxMouID ASC
";
//echo $sql;
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N'){
$rows[$k]['chex'] = false;
}else{
$rows[$k]['chex'] = true;
}
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$rows['types'] = array(array('id'=>0,'name'=>'Semua'),array('id'=>1,'name'=>'Mou Verifikasi'),array('id'=>2,'name'=>'Edit Price'));
$rows['statuss'] = array(array('id'=>'N','name'=>'Pending'),array('id'=>'Y','name'=>'Terkirim'));
$sql = "SELECT 0 as id, 'Semua' as name
UNION
SELECT M_BranchID as id, M_BranchName as name
FROM m_branch
WHERE
M_BranchIsActive = 'Y'
GROUP BY M_BranchID";
$rows['branchs'] = $this->db_regional->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$mous = $prm["mous"];
foreach($mous as $idx => $mou) {
if ( $mou["chex"] == 1 ) {
$txMouID = $mou["TxMouID"];
$ipAddress= $mou["TxMouM_BranchIPAddress"];
$j_param = $mou["TxMouJson"];
try {
if ($mou["TxMouT_TestID"] == 0 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/r_mou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
} else {
//edit admin price
$url = "http://$ipAddress/one-api/tools/price/r_mou/edit";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'N' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
} catch(Exception $e) {
$err_msg[] = $e->getMessage();
$flag_error = true;
}
}
}
if (! $flag_error ) {
$result = array ("message" => "Resend OK");
$this->sys_ok($result);
} else {
$this->sys_error( array( "message" => join(",",$err_msg)) );
}
exit;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
return $result;
}
}

View File

@@ -0,0 +1,225 @@
<?php
class Mouv2 extends MY_Controller
{
var $db_regional;
public function index()
{
echo "MOU MONITORING API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = $prm["name"];
$nolab = $prm["nolab"];
$branchid = $prm["branchid"];
$typeid = $prm["typeid"];
$statusid = $prm["statusid"];
$filter_branch = '';
if(intval($branchid) > 0)
$filter_branch = " AND M_BranchID = {$branchid}";
$filter_status = "WHERE TxMouStatus = '{$statusid}'";
$filter_type = '';
if(intval($typeid) == 1){
$filter_type = "AND TxMouT_TestID = 0";
}elseif(intval($typeid) == 2){
$filter_type = "AND TxMouT_TestID > 0";
}elseif(intval($typeid) == 3){
$filter_type = "AND TxMouT_TestID < 0";
}
$sql = "SELECT tx_mou.*,
TxMouID as id,
CASE
WHEN TxMouT_TestID = 0 THEN 'Mou Verifikasi'
WHEN TxMouT_TestID > 0 THEN 'Edit Price'
ELSE 'Extend Mou'
END as tipe,
M_BranchName as branchname,
DATE_FORMAT(TxMouCreated,'%d-%m-%Y %T') as moudate,
TxMouM_MouID as mouid,
M_MouName as mouname,
M_CompanyName as companyname,
IFNULL(T_TestName,'-') as testname,
IF(TxMouStatus = 'N','Pending','Terkirim') as status,
TxMouRetry as pengulangan,
M_StaffName as staffname,
IF(TxMouStatus = 'N','Y','N') as chex
FROM tx_mou
JOIN m_branch ON TxMouM_BranchCode = M_BranchCode $filter_branch
JOIN m_mou ON TxMouM_MouID = M_MouID
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
JOIN m_user ON TxMouM_UserID = M_UserID
JOIN m_staff ON M_UserM_StaffID = M_StaffID
LEFT JOIN t_test ON T_TestID = TxMouT_TestID
$filter_status $filter_type
GROUP BY TxMouID
ORDER BY TxMouID ASC
";
//echo $sql;
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N'){
$rows[$k]['chex'] = false;
}else{
$rows[$k]['chex'] = true;
}
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$rows['types'] = array(array('id'=>0,'name'=>'Semua'),array('id'=>1,'name'=>'Mou Verifikasi'),array('id'=>2,'name'=>'Edit Price'),array('id'=>3,'name'=>'Extend MOU'));
$rows['statuss'] = array(array('id'=>'N','name'=>'Pending'),array('id'=>'Y','name'=>'Terkirim'));
$sql = "SELECT 0 as id, 'Semua' as name
UNION
SELECT M_BranchID as id, M_BranchName as name
FROM m_branch
WHERE
M_BranchIsActive = 'Y'
GROUP BY M_BranchID";
$rows['branchs'] = $this->db_regional->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$mous = $prm["mous"];
foreach($mous as $idx => $mou) {
if ( $mou["chex"] == 1 ) {
$txMouID = $mou["TxMouID"];
$ipAddress= $mou["TxMouM_BranchIPAddress"];
$j_param = $mou["TxMouJson"];
try {
if ($mou["TxMouT_TestID"] == 0 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/r_mou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
elseif ($mou["TxMouT_TestID"] == -1 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/extendmou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
} else {
//edit admin price
$url = "http://$ipAddress/one-api/tools/price/r_mou/edit";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'N' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
} catch(Exception $e) {
$err_msg[] = $e->getMessage();
$flag_error = true;
}
}
}
if (! $flag_error ) {
$result = array ("message" => "Resend OK");
$this->sys_ok($result);
} else {
$this->sys_error( array( "message" => join(",",$err_msg)) );
}
exit;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
if (curl_errno($ch)){
return json_encode( array("status" => "ERR",
"message" => curl_error($ch)) );
}
curl_close($ch);
return $result;
}
}

View File

@@ -0,0 +1,257 @@
<?php
if (true) {
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
}
class Mouv3 extends MY_Controller
{
var $db_regional;
public function index()
{
echo "MOU MONITORING API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = $prm["name"];
$nolab = $prm["nolab"];
$branchid = $prm["branchid"];
$typeid = $prm["typeid"];
$statusid = $prm["statusid"];
$filter_branch = '';
if(intval($branchid) > 0)
$filter_branch = " AND M_BranchID = {$branchid}";
$filter_status = "WHERE TxMouStatus = '{$statusid}'";
$filter_type = '';
if(intval($typeid) == 1){
$filter_type = "AND TxMouT_TestID = 0";
}elseif(intval($typeid) == 2){
$filter_type = "AND TxMouT_TestID > 0";
}elseif(intval($typeid) == 3){
$filter_type = "AND TxMouT_TestID = -1";
}elseif(intval($typeid) == 4){
$filter_type = "AND TxMouT_TestID = -2";
}
$join_staff = "
JOIN m_user ON TxMouM_UserID = M_UserID
JOIN m_staff ON M_UserM_StaffID = M_StaffID
LEFT JOIN t_test ON TxMouT_TestID = T_TestID";
if ( intval($typeid) == 4 ) {
$join_staff = "
LEFT JOIN m_user ON TxMouM_UserID = M_UserID
LEFT JOIN m_staff ON M_UserM_StaffID = M_StaffID
LEFT JOIN t_test ON TxMouT_TestID = T_TestID";
}
$sql = "SELECT tx_mou.*,
TxMouID as id,
CASE
WHEN TxMouT_TestID = 0 THEN 'Mou Verifikasi'
WHEN TxMouT_TestID > 0 THEN 'Edit Price'
WHEN TxMouT_TestID = -1 THEN 'Extend Mou'
ELSE 'Un Release'
END as tipe,
M_BranchName as branchname,
DATE_FORMAT(TxMouCreated,'%d-%m-%Y %T') as moudate,
TxMouM_MouID as mouid,
M_MouName as mouname,
M_CompanyName as companyname,
IFNULL(T_TestName,'-') as testname,
IF(TxMouStatus = 'N','Pending','Terkirim') as status,
TxMouRetry as pengulangan,
M_StaffName as staffname,
IF(TxMouStatus = 'N','Y','N') as chex
FROM tx_mou
JOIN m_branch ON TxMouM_BranchCode = M_BranchCode $filter_branch
JOIN m_mou ON TxMouM_MouID = M_MouID
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
$join_staff
$filter_status $filter_type
GROUP BY TxMouID
ORDER BY TxMouLastUpdated desc ";
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N'){
$rows[$k]['chex'] = false;
}else{
$rows[$k]['chex'] = true;
}
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$rows['types'] = array(array('id'=>0,'name'=>'Semua'),array('id'=>1,'name'=>'Mou Verifikasi'),array('id'=>2,'name'=>'Edit Price'),array('id'=>3,'name'=>'Extend MOU'),array('id'=>4,'name'=>'Un Release'));
$rows['statuss'] = array(array('id'=>'N','name'=>'Pending'),array('id'=>'Y','name'=>'Terkirim'));
$sql = "SELECT 0 as id, 'Semua' as name
UNION
SELECT M_BranchID as id, M_BranchName as name
FROM m_branch
WHERE
M_BranchIsActive = 'Y'
GROUP BY M_BranchID";
$rows['branchs'] = $this->db_regional->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$mous = $prm["mous"];
foreach($mous as $idx => $mou) {
if ( $mou["chex"] == 1 ) {
$txMouID = $mou["TxMouID"];
$ipAddress= $mou["TxMouM_BranchIPAddress"];
$j_param = $mou["TxMouJson"];
try {
if ($mou["TxMouT_TestID"] == 0 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/r_mou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
elseif ($mou["TxMouT_TestID"] == -1 ) {
//extendmou
$url = "http://$ipAddress/one-api/tools/price/extendmou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
} elseif ($mou["TxMouT_TestID"] == -2 ) {
// unrelease
$url = "http://$ipAddress/one-api/tools/price/r_mou/unrelease";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
} else {
//edit admin price
$url = "http://$ipAddress/one-api/tools/price/r_mou/edit";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'N' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
} catch(Exception $e) {
$err_msg[] = $e->getMessage();
$flag_error = true;
}
}
}
if (! $flag_error ) {
$result = array ("message" => "Resend OK");
$this->sys_ok($result);
} else {
$this->sys_error( array( "message" => join(",",$err_msg)) );
}
exit;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
if (curl_errno($ch)){
return json_encode( array("status" => "ERR",
"message" => curl_error($ch)) );
}
curl_close($ch);
return $result;
}
}

View File

@@ -0,0 +1,250 @@
<?php
class Mouv4 extends MY_Controller
{
var $db_regional;
public function index()
{
echo "MOU MONITORING API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->load->helper(array('form', 'url'));
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$name = $prm["name"];
$nolab = $prm["nolab"];
$branchid = $prm["branchid"];
$typeid = $prm["typeid"];
$statusid = $prm["statusid"];
$filter_branch = '';
if(intval($branchid) > 0)
$filter_branch = " AND M_BranchID = {$branchid}";
$filter_status = "WHERE TxMouStatus = '{$statusid}'";
$filter_type = '';
if(intval($typeid) == 1){
$filter_type = "AND TxMouT_TestID = 0";
}elseif(intval($typeid) == 2){
$filter_type = "AND TxMouT_TestID > 0";
}elseif(intval($typeid) == 3){
$filter_type = "AND TxMouT_TestID = -1";
}elseif(intval($typeid) == 4){
$filter_type = "AND TxMouT_TestID = -3";
}elseif(intval($typeid) == 0){
$filter_type = "AND TxMouT_TestID <> -4";
}
$sql = "SELECT tx_mou.*,
TxMouID as id,
CASE
WHEN TxMouT_TestID = 0 THEN 'Mou Verifikasi'
WHEN TxMouT_TestID > 0 THEN 'Edit Price'
WHEN TxMouT_TestID = -1 THEN 'Extend Mou'
WHEN TxMouT_TestID = -3 THEN 'Edi Flag Mou'
END as tipe,
M_BranchName as branchname,
DATE_FORMAT(TxMouCreated,'%d-%m-%Y %T') as moudate,
TxMouM_MouID as mouid,
M_MouName as mouname,
M_CompanyName as companyname,
IFNULL(T_TestName,'-') as testname,
IF(TxMouStatus = 'N','Pending','Terkirim') as status,
TxMouRetry as pengulangan,
Nat_StaffName as staffname,
IF(TxMouStatus = 'N','Y','N') as chex
FROM tx_mou
JOIN m_branch ON TxMouM_BranchCode = M_BranchCode $filter_branch
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y'
JOIN m_mou ON TxMouM_MouID = M_MouID
JOIN m_company ON M_MouM_CompanyID = M_CompanyID
JOIN m_user ON TxMouM_UserID = M_UserID
JOIN nat_staff ON M_UserM_StaffID = Nat_StaffID
LEFT JOIN t_test ON T_TestID = TxMouT_TestID
$filter_status $filter_type
GROUP BY TxMouID
ORDER BY TxMouID ASC
";
//echo $sql;
$query = $this->db_regional->query($sql);
//echo $this->db_regional->last_query();
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N'){
$rows[$k]['chex'] = false;
}else{
$rows[$k]['chex'] = true;
}
}
}
//$this->_add_address($rows);
$result = array("total" => count($rows), "records" => $rows, "sql"=> $this->db_regional->last_query());
$this->sys_ok($result);
exit;
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$rows['types'] = array(array('id'=>0,'name'=>'Semua'),array('id'=>1,'name'=>'Mou Verifikasi'),array('id'=>2,'name'=>'Edit Price'),array('id'=>3,'name'=>'Extend MOU'),array('id'=>4,'name'=>'Edit Flag Mou'));
$rows['statuss'] = array(array('id'=>'N','name'=>'Pending'),array('id'=>'Y','name'=>'Terkirim'));
$sql = "SELECT 0 as id, 'Semua' as name
UNION
SELECT M_BranchID as id, M_BranchName as name
FROM m_branch
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y'
WHERE
M_BranchIsActive = 'Y'
GROUP BY M_BranchID";
$rows['branchs'] = $this->db_regional->query($sql)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$mous = $prm["mous"];
foreach($mous as $idx => $mou) {
if ( $mou["chex"] == 1 ) {
$txMouID = $mou["TxMouID"];
$ipAddress= $mou["TxMouM_BranchIPAddress"];
$j_param = $mou["TxMouJson"];
try {
if ($mou["TxMouT_TestID"] == 0 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/r_mou_gz/verify";
$z_param = gzdeflate($j_param,9);
$post_rst = $this->post($url,$z_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
elseif ($mou["TxMouT_TestID"] == -1 ) {
//verify
$url = "http://$ipAddress/one-api/tools/price/extendmou/verify";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}elseif ($mou["TxMouT_TestID"] == -3 ) {
//edit flag
$url = "http://$ipAddress/one-api/tools/price/extendmou/editflag";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
else {
//edit admin price
$url = "http://$ipAddress/one-api/tools/price/r_mou/edit";
$post_rst = $this->post($url,$j_param);
$j_rst = json_decode($post_rst,true);
if ($j_rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_error = true;
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'N' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
} else {
$qry = $this->db_regional->query("update tx_mou set TxMouStatus = 'Y' , TxMouRetry = TxMouRetry+1 where TxMouID = ? ", array($txMouID));
}
if (! $qry) {
$err_msg[] = "Update Tx Mou : " . print_r($this->db_regional->error(),true);
$flag_error = true;
}
}
} catch(Exception $e) {
$err_msg[] = $e->getMessage();
$flag_error = true;
}
}
}
if (! $flag_error ) {
$result = array ("message" => "Resend OK");
$this->sys_ok($result);
} else {
$this->sys_error( array( "message" => join(",",$err_msg)) );
}
exit;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function post($url,$data) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
if (curl_errno($ch)){
return json_encode( array("status" => "ERR",
"message" => curl_error($ch)) );
}
curl_close($ch);
return $result;
}
}