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,121 @@
<?php
class Ss extends CI_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database('regional', true);
}
function create($mouID) {
$sql = "select * from m_mou where M_MouID = ?";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
echo 'Err : ' . print_r($this->db->error(),true). '\n';
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
echo "Err : No Mou Found!";
exit;
}
$mouName = $rows[0]["M_MouName"];
//Test kecuali Profile
$sql = "select T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode
from t_price
join t_test on T_PriceT_TestID = T_TestID
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
and T_TestIsPrice = 'Y'
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
where T_PriceM_MouID = ?
and length(T_TestSasCode) = 8 ";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
echo 'Err : ' . print_r($this->db->error(),true). '\n';
exit;
}
$rows = $qry->result_array();
$flag_error = false;
foreach($rows as $idx => $r) {
$nat_testType = $r["Nat_TestNat_TestTypeID"];
switch($nat_testType) {
case 1: //Single
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
break;
case 3: //Multi
case 4: //Panel
$sasCode = $r["T_TestSasCode"] . '%';
$sql = "select T_TestNat_TestID
from t_test
where T_TestIsResult = 'Y'
and T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
echo "Err : " . print_r($this->db->error(),true) . "\n";
$flag_error = true;
}
$nt_rows = $qry->result_array();
$t_rows = array();
foreach($nt_rows as $nr) {
$t_rows[] = $nr["T_TestNat_TestID"];
}
$rows[$idx]['nat_test'] = "[" . join($t_rows) . "]";
break;
}
}
print_r($rows);
}
function upload($prm_date) {
$sql = "select * from ssr_mr03
where date(SsrMr03T_OrderHeaderDate) = ?
and SsrMr03IsSent = 'N'
and SsrMr03Retry < 10";
$qry = $this->db->query($sql,array($prm_date));
if (! $qry) {
echo "Err : " . print_r($this->db->error(),true);
exit;
}
$rows = $qry->result_array();
$data = json_encode($rows);
$md5 = md5($data);
$param = array("data" => $data, "md5" => $md5);
$jparam = json_encode($param);
$url = "http://bandungraya.aplikasi.web.id/one-api/tools/marketing/r_mr03";
$url = "http://devbandungraya.aplikasi.web.id/one-api/tools/marketing/r_mr03";
echo "Uploading : $prm_date, total " . count($rows) . " records\n";
$j_result = $this->post($url,$jparam);
$result = json_decode($j_result,true);
$sql = "update ssr_mr03 set SsrMr03Retry = SsrMr03Retry + 1 where date(SsrMr03T_OrderHeaderDate) = ?";
$this->db->query($sql,array($prm_date));
if ($result["status"] == "OK") {
$sql = "update ssr_mr03 set SsrMr03IsSent = 'Y' where SsrMr03ID = ?";
foreach($result["SsrMr03ID"] as $id ) {
$this->db->query($sql, array($id));
}
echo $result["status"] . ", total " . count($result["SsrMr03ID"]) . "\n";
exit;
}
echo "ERR : " . $result["message"] . "\n";
}
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_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
return $result;
}
}

View File

@@ -0,0 +1,161 @@
<?php
class Ss extends CI_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database('regional', true);
}
function create($mouID) {
$sql = "select * from m_mou where M_MouID = ?";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
echo 'Err : ' . print_r($this->db->error(),true). '\n';
exit;
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
echo "Err : No Mou Found!";
exit;
}
$mouName = $rows[0]["M_MouName"];
//Test kecuali Profile
$sql = "select T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode
from t_price
join t_test on T_PriceT_TestID = T_TestID
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
and T_TestIsPrice = 'Y'
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
where T_PriceM_MouID = ?
and length(T_TestSasCode) = 8 ";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
echo 'Err : ' . print_r($this->db->error(),true). '\n';
exit;
}
$rows = $qry->result_array();
$flag_error = false;
foreach($rows as $idx => $r) {
$nat_testType = $r["Nat_TestNat_TestTypeID"];
switch($nat_testType) {
case 1: //Single
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
break;
case 3: //Multi
case 4: //Panel
$sasCode = $r["T_TestSasCode"] . '%';
$sql = "select T_TestNat_TestID
from t_test
where T_TestIsResult = 'Y'
and T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
echo "Err : " . print_r($this->db->error(),true) . "\n";
$flag_error = true;
}
$nt_rows = $qry->result_array();
$t_rows = array();
foreach($nt_rows as $nr) {
$t_rows[] = $nr["T_TestNat_TestID"];
}
$rows[$idx]['nat_test'] = "[" . join($t_rows) . "]";
break;
}
}
//print_r($rows);
//Test Profile
$sql = "select T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode
from t_price
join t_test on T_PriceT_TestID = T_TestID
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
where T_PriceM_MouID = ?
and length(T_TestSasCode) = 8 ";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
echo 'Err : ' . print_r($this->db->error(),true). '\n';
exit;
}
$rows = $qry->result_array();
$flag_error = false;
foreach($rows as $idx => $r) {
$sasCode = $r["T_TestSasCode"] . '%';
$sql = "select T_TestNat_TestID
from t_test
where T_TestIsResult = 'Y'
and T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
echo "Err : " . print_r($this->db->error(),true) . "\n";
$flag_error = true;
}
$nt_rows = $qry->result_array();
$t_rows = array();
foreach($nt_rows as $nr) {
$t_rows[] = $nr["T_TestNat_TestID"];
}
$rows[$idx]['nat_test'] = "[" . join($t_rows) . "]";
}
}
function upload($prm_date) {
$sql = "select * from ssr_mr03
where date(SsrMr03T_OrderHeaderDate) = ?
and SsrMr03IsSent = 'N'
and SsrMr03Retry < 10";
$qry = $this->db->query($sql,array($prm_date));
if (! $qry) {
echo "Err : " . print_r($this->db->error(),true);
exit;
}
$rows = $qry->result_array();
$data = json_encode($rows);
$md5 = md5($data);
$param = array("data" => $data, "md5" => $md5);
$jparam = json_encode($param);
$url = "http://bandungraya.aplikasi.web.id/one-api/tools/marketing/r_mr03";
$url = "http://devbandungraya.aplikasi.web.id/one-api/tools/marketing/r_mr03";
echo "Uploading : $prm_date, total " . count($rows) . " records\n";
$j_result = $this->post($url,$jparam);
$result = json_decode($j_result,true);
$sql = "update ssr_mr03 set SsrMr03Retry = SsrMr03Retry + 1 where date(SsrMr03T_OrderHeaderDate) = ?";
$this->db->query($sql,array($prm_date));
if ($result["status"] == "OK") {
$sql = "update ssr_mr03 set SsrMr03IsSent = 'Y' where SsrMr03ID = ?";
foreach($result["SsrMr03ID"] as $id ) {
$this->db->query($sql, array($id));
}
echo $result["status"] . ", total " . count($result["SsrMr03ID"]) . "\n";
exit;
}
echo "ERR : " . $result["message"] . "\n";
}
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_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data))
);
$result = curl_exec($ch);
return $result;
}
}

View File

@@ -0,0 +1,157 @@
<?php
class Upl_mou extends MY_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database('regional', true);
}
function unrelease() {
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$md5 = $this->sys_input["md5"];
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
$this->sys_error("Md5 $md5 <> $l_md5");
exit;
}
$mouID = $param["mouID"];
$staffNIK = $param["staffNIK"];
$branchCode = $param["branchCode"];
$ipAddress = $param["ipAddress"];
$staffName = $param["staffName"];
$jsonParam = json_encode(array("param" => $param, "md5" => $md5 ));
$data = array("TxMouReleaseM_MouID" => $mouID,
"TxMouReleaseIPAddress" => $ipAddress,
"TxMouReleaseM_BranchCode" => $branchCode,
"TxMouReleaseM_StaffNIK" => $staffNIK,
"TxMouReleaseM_StaffName" => $staffName,
"TxMouReleaseJson" => $jsonParam,
"TxMouReleaseStatus" => $param["status"]
);
$qry = $this->db->insert("tx_mou_release",$data);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$mouID}',
'UR',
'3',
now(),
now())";
$qry = $this->db->query($sql);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "update m_mou SET
M_MouIsReleased = 'N',
M_MouStatus = 'UR',
M_MouAllowVerify = 'Y',
M_MouReleaseDate = now(),
M_MouReleaseUserID = 3,
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$this->sys_ok( array("message" => "Un Release OK"));
}
function release() {
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$md5 = $this->sys_input["md5"];
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
$this->sys_error("Md5 $md5 <> $l_md5");
exit;
}
$mouID = $param["mouID"];
$staffNIK = $param["staffNIK"];
$branchCode = $param["branchCode"];
$ipAddress = $param["ipAddress"];
$staffName = $param["staffName"];
$jsonParam = json_encode(array("param" => $param, "md5" => $md5 ));
$data = array("TxMouReleaseM_MouID" => $mouID,
"TxMouReleaseIPAddress" => $ipAddress,
"TxMouReleaseM_BranchCode" => $branchCode,
"TxMouReleaseM_StaffNIK" => $staffNIK,
"TxMouReleaseM_StaffName" => $staffName,
"TxMouReleaseJson" => $jsonParam,
"TxMouReleaseStatus" => $param["status"]
);
$qry = $this->db->insert("tx_mou_release",$data);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$mouID}',
'R',
'3',
now(),
now())";
$qry = $this->db->query($sql);
if (!$qry ) {
$this->sys_error( " Insert MOU " . print_r($this->db->error(),true));
exit;
}
$sql = "update m_mou SET
M_MouIsReleased = 'Y',
M_MouStatus = 'R',
M_MouAllowVerify = 'N',
M_MouReleaseDate = now(),
M_MouReleaseUserID = 3,
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$this->sys_ok( array("message" => "Release OK"));
}
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_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,205 @@
<?php
class Upl_mou_v2 extends MY_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database('regional', true);
}
function unrelease() {
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$md5 = $this->sys_input["md5"];
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
$this->sys_error("Md5 $md5 <> $l_md5");
exit;
}
$mouID = $param["mouID"];
$staffNIK = $param["staffNIK"];
$branchCode = $param["branchCode"];
$ipAddress = $param["ipAddress"];
$staffName = $param["staffName"];
$jsonParam = json_encode(array("param" => $param, "md5" => $md5 ));
$data = array("TxMouReleaseM_MouID" => $mouID,
"TxMouReleaseIPAddress" => $ipAddress,
"TxMouReleaseM_BranchCode" => $branchCode,
"TxMouReleaseM_StaffNIK" => $staffNIK,
"TxMouReleaseM_StaffName" => $staffName,
"TxMouReleaseJson" => $jsonParam,
"TxMouReleaseStatus" => $param["status"]
);
$qry = $this->db->insert("tx_mou_release",$data);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$mouID}',
'UR',
'3',
now(),
now())";
$qry = $this->db->query($sql);
if (!$qry ) {
$this->sys_error( "Log : " . print_r($this->db->error(),true));
exit;
}
$sql = "update m_mou SET
M_MouIsReleased = 'N',
M_MouStatus = 'UR',
M_MouAllowVerify = 'Y',
M_MouReleaseDate = now(),
M_MouReleaseUserID = 3,
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
$this->sys_error( "M_Mou : " . print_r($this->db->error(),true));
exit;
}
//insert into other branch unrelease
$data = array("M_MouID" => $mouID,
"M_StaffNIK" => $staffNIK,
"M_StaffName" => $staffName);
$md5 = md5( json_encode($data) );
$jsonParam = json_encode(array("md5" => $md5, "param" => $data));
$sql = "insert into tx_mou(TxMouM_MouID, TxMouT_TestID, TxMouM_BranchCode,
TxMouM_BranchIPAddress,TxMouJson)
select ?, -2, M_BranchCode, M_BranchIPAddress , ?
from m_branch
where M_BranchIsActive = 'Y' and M_BranchCode <> ? ";
$qry = $this->db->query($sql, array($mouID,$jsonParam,$branchCode));
if (!$qry ) {
$this->sys_error( "Tx Mou : " . print_r($this->db->error(),true));
exit;
}
$records = $this->db->affected_rows();
$sql = "select * from tx_mou where TxMouM_MouID = ?
and TxMouT_TestID = -2 and TxMouStatus = 'N'
order by TxMouID desc
limit 0,$records";
$qry = $this->db->query($sql, array($mouID));
if (!$qry ) {
$this->sys_error( "Sel tx Mou : " . print_r($this->db->error(),true));
exit;
}
$rows = $qry->result_array();
$flag_err = false;
$err_msg = array();
foreach($rows as $r) {
$data = $r["TxMouJson"];
$md5 = md5($data);
$ipAddress = $r["TxMouM_BranchIPAddress"];
$url = "http://$ipAddress/one-api/tools/price/r_mou/unrelease";
$post_rst = $this->post($url, $jsonParam);
$rst = json_decode($post_rst, true);
if ( $rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_err = true;
}
}
if ($flag_err) {
$this->sys_error( join(",", $err_msg) );
exit;
}
$this->sys_ok( array("message" => "Un Release OK"));
}
function release() {
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$md5 = $this->sys_input["md5"];
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
$this->sys_error("Md5 $md5 <> $l_md5");
exit;
}
$mouID = $param["mouID"];
$staffNIK = $param["staffNIK"];
$branchCode = $param["branchCode"];
$ipAddress = $param["ipAddress"];
$staffName = $param["staffName"];
$jsonParam = json_encode(array("param" => $param, "md5" => $md5 ));
$data = array("TxMouReleaseM_MouID" => $mouID,
"TxMouReleaseIPAddress" => $ipAddress,
"TxMouReleaseM_BranchCode" => $branchCode,
"TxMouReleaseM_StaffNIK" => $staffNIK,
"TxMouReleaseM_StaffName" => $staffName,
"TxMouReleaseJson" => $jsonParam,
"TxMouReleaseStatus" => $param["status"]
);
$qry = $this->db->insert("tx_mou_release",$data);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$mouID}',
'R',
'3',
now(),
now())";
$qry = $this->db->query($sql);
if (!$qry ) {
$this->sys_error( " Insert MOU " . print_r($this->db->error(),true));
exit;
}
$sql = "update m_mou SET
M_MouIsReleased = 'Y',
M_MouStatus = 'R',
M_MouAllowVerify = 'N',
M_MouReleaseDate = now(),
M_MouReleaseUserID = 3,
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$this->sys_ok( array("message" => "Release OK"));
}
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, 60);
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,215 @@
<?php
class Upl_mou_v2 extends MY_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database('regional', true);
}
function unrelease() {
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$md5 = $this->sys_input["md5"];
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
$this->sys_error("Md5 $md5 <> $l_md5");
exit;
}
$mouID = $param["mouID"];
$staffNIK = $param["staffNIK"];
$branchCode = $param["branchCode"];
$ipAddress = $param["ipAddress"];
$staffName = $param["staffName"];
$jsonParam = json_encode(array("param" => $param, "md5" => $md5 ));
$data = array("TxMouReleaseM_MouID" => $mouID,
"TxMouReleaseIPAddress" => $ipAddress,
"TxMouReleaseM_BranchCode" => $branchCode,
"TxMouReleaseM_StaffNIK" => $staffNIK,
"TxMouReleaseM_StaffName" => $staffName,
"TxMouReleaseJson" => $jsonParam,
"TxMouReleaseStatus" => $param["status"]
);
$qry = $this->db->insert("tx_mou_release",$data);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$mouID}',
'UR',
'3',
now(),
now())";
$qry = $this->db->query($sql);
if (!$qry ) {
$this->sys_error( "Log : " . print_r($this->db->error(),true));
exit;
}
$sql = "update m_mou SET
M_MouIsReleased = 'N',
M_MouStatus = 'UR',
M_MouAllowVerify = 'Y',
M_MouReleaseDate = now(),
M_MouReleaseUserID = 3,
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
$this->sys_error( "M_Mou : " . print_r($this->db->error(),true));
exit;
}
//insert into other branch unrelease
$data = array("M_MouID" => $mouID,
"M_StaffNIK" => $staffNIK,
"M_StaffName" => $staffName);
$md5 = md5( json_encode($data) );
$jsonParam = json_encode(array("md5" => $md5, "param" => $data));
$sql = "insert into tx_mou(TxMouM_MouID, TxMouT_TestID, TxMouM_BranchCode,
TxMouM_BranchIPAddress,TxMouJson)
select ?, -2, M_BranchCode, M_BranchIPAddress , ?
from m_branch
JOIN s_regional ON M_BranchS_RegionalID = S_RegionalID AND S_RegionalIsDefault = 'Y'
where M_BranchIsActive = 'Y' and M_BranchCode <> ? ";
$qry = $this->db->query($sql, array($mouID,$jsonParam,$branchCode));
if (!$qry ) {
$this->sys_error( "Tx Mou : " . print_r($this->db->error(),true));
exit;
}
$records = $this->db->affected_rows();
$sql = "select * from tx_mou where TxMouM_MouID = ?
and TxMouT_TestID = -2 and TxMouStatus = 'N'
order by TxMouID desc
limit 0,$records";
$qry = $this->db->query($sql, array($mouID));
if (!$qry ) {
$this->sys_error( "Sel tx Mou : " . print_r($this->db->error(),true));
exit;
}
$rows = $qry->result_array();
$flag_err = false;
$err_msg = array();
foreach($rows as $r) {
$data = $r["TxMouJson"];
$md5 = md5($data);
$ipAddress = $r["TxMouM_BranchIPAddress"];
$url = "http://$ipAddress/one-api/tools/price/r_mou/unrelease";
$post_rst = $this->post($url, $jsonParam);
$rst = json_decode($post_rst, true);
$txMouID = $r["TxMouID"];
if ( $rst["status"] != "OK" ) {
$err_msg[] = $post_rst;
$flag_err = true;
$sql = "update tx_mou set TxMouRetry = TxMouRetry + 1 where TxMouID = ?";
} else {
$sql = "update tx_mou set TxMouRetry = TxMouRetry + 1, TxMouStatus = 'Y' where TxMouID = ?";
}
$qry = $this->db->query($sql,array($txMouID));
if (! $qry ) {
$flag_err = true;
$err_msg[] = print_r($this->db->error(),true);
}
}
if ($flag_err) {
$this->sys_error( join(",", $err_msg) );
exit;
}
$this->sys_ok( array("message" => "Un Release OK"));
}
function release() {
$param = $this->sys_input["param"];
$j_param = json_encode($param);
$md5 = $this->sys_input["md5"];
$l_md5 = md5($j_param);
if ($md5 != $l_md5 ) {
$this->sys_error("Md5 $md5 <> $l_md5");
exit;
}
$mouID = $param["mouID"];
$staffNIK = $param["staffNIK"];
$branchCode = $param["branchCode"];
$ipAddress = $param["ipAddress"];
$staffName = $param["staffName"];
$jsonParam = json_encode(array("param" => $param, "md5" => $md5 ));
$data = array("TxMouReleaseM_MouID" => $mouID,
"TxMouReleaseIPAddress" => $ipAddress,
"TxMouReleaseM_BranchCode" => $branchCode,
"TxMouReleaseM_StaffNIK" => $staffNIK,
"TxMouReleaseM_StaffName" => $staffName,
"TxMouReleaseJson" => $jsonParam,
"TxMouReleaseStatus" => $param["status"]
);
$qry = $this->db->insert("tx_mou_release",$data);
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$sql = "INSERT g_moustatuslog
(G_MouStatusLogDate,
G_MouStatusLogM_MouID,
G_MouStatusLogStatus,
G_MouStatusLogUserID,
G_MouStatusLogCreated,
G_MouStatusLogLastUpdated)
VALUES(
date(now()),
'{$mouID}',
'R',
'3',
now(),
now())";
$qry = $this->db->query($sql);
if (!$qry ) {
$this->sys_error( " Insert MOU " . print_r($this->db->error(),true));
exit;
}
$sql = "update m_mou SET
M_MouIsReleased = 'Y',
M_MouStatus = 'R',
M_MouAllowVerify = 'N',
M_MouReleaseDate = now(),
M_MouReleaseUserID = 3,
M_MouIsApproved = 'Y',
M_MouLastUpdated = now()
WHERE
M_MouID = ?";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
$this->sys_error( print_r($this->db->error(),true));
exit;
}
$this->sys_ok( array("message" => "Release OK"));
}
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, 60);
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,127 @@
<?php
class Xfer extends CI_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database("regional", true);
$this->db_regional = $this->load->database("regional", true);
}
function upload_mou($mouID,$branchCode) {
//upload aggrement , ss_price_mou
$sql = "select * from m_mou where M_MouID = ?";
$qry = $this->db_regional->query($sql, array($mouID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return array(false, "No MOU : " . $this->db_regional->last_query());
}
$mou = $rows[0];
$sql = "select * from m_company where M_CompanyID = ?";
$qry = $this->db_regional->query($sql, array($mou["M_MouM_CompanyID"]));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No Company");
}
$company = $rows[0];
$sql = "select * from g_moustatuslog where G_MouStatusLogM_MouID = ?";
$qry = $this->db_regional->query($sql, array($mouID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0) {
return array(false, "No Log");
}
$logs = $rows;
$mou["M_MouUserID"] = 3; // set to 3
foreach($logs as $idx => $l ) {
$logs[$idx]["G_MouStatusLogUserID"] = 3;
}
$sql = "select * from ss_price_mou where Ss_PriceMouM_MouID= ?";
$qry = $this->db_regional->query($sql, array($mouID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No Ss Price Mou");
}
$sql = "select * from t_price where T_PriceM_MouID= ?";
$qry = $this->db_regional->query($sql, array($mouID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$t_rows = $qry->result_array();
$sql = "select * from t_packet where T_PacketM_MouID = ?";
$qry = $this->db_regional->query($sql, array($mouID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$pkt_rows = $qry->result_array();
$sql = "select t_packetdetail.*
from t_packet
join t_packetdetail on T_PacketDetailT_PacketID = T_PacketID
where T_PacketM_MouID = ?";
$qry = $this->db_regional->query($sql, array($mouID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$pd_rows = $qry->result_array();
$param = array (
"mou" => $mou,
"company" => $company,
"logs" => $logs,
"price_mou" => $rows,
"t_price" => $t_rows,
"packet" => $pkt_rows,
"packet_detail" => $pd_rows
);
$param_md5 = md5(json_encode($param));
$j_param = json_encode(array("param" => $param, "md5" => $param_md5 ));
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchCode=?";
$qry = $this->db_regional->query($sql, array($branchCode));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No Ss Price Mou");
}
$sql = "insert into tx_mou(TxMouM_BranchIPAddress, TxMouM_BranchCode,TxMouM_MouID, TxMouJson,TxMouM_UserID )
values(?,?,?,?,?)";
$sql_del = "delete from tx_mou where TxMouM_MouID=? and TxMouM_BranchCode=?";
$flag_error = false;
$err_msg = array();
$userID = 3;
foreach($rows as $r ) {
$branchCode = $r["M_BranchCode"];
$ipAddress = $r["M_BranchIPAddress"];
$qry = $this->db_regional->query($sql_del, array($mouID,$branchCode));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
$qry = $this->db_regional->query($sql, array($ipAddress, $branchCode,$mouID,$j_param,$userID));
if (! $qry) {
return array(false, print_r($this->db_regional->error(),true));
}
}
if ( $flag_error) {
return array(false, join(",",$err_msg));
}
return array(true,"OK");
}
}