113 lines
5.1 KiB
PHP
113 lines
5.1 KiB
PHP
<?php
|
|
class Mr11 extends CI_Controller
|
|
{
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->db = $this->load->database('onedev', true);
|
|
}
|
|
function getRegionalIP() {
|
|
$sql = "select S_SystemIPAddressRegional from conf_systems";
|
|
$qry = $this->db->query($sql);
|
|
if (! $qry ) {
|
|
return "devone.aplikasi.web.id";
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) > 0 ) return $rows[0]["S_SystemIPAddressRegional"];
|
|
|
|
return "devone.aplikasi.web.id";
|
|
}
|
|
function do($prm_date) {
|
|
$sql = "delete from ssr_mr11 where date(SsrMr11Date) = ?";
|
|
$qry = $this->db->query($sql, array($prm_date));
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true). '\n';
|
|
exit;
|
|
}
|
|
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchIsDefault = 'Y'";
|
|
$qry = $this->db->query($sql);
|
|
if (! $qry ) {
|
|
echo 'Err : ' . print_r($this->db->error(),true) . '\n';
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$branchCode = '';
|
|
if (count($rows) > 0 ) {
|
|
$branchCode = $rows[0]['M_BranchCode'];
|
|
}
|
|
if ($branchCode == '') {
|
|
echo 'Err : Invalid Branch\n';
|
|
exit;
|
|
}
|
|
$sql = " insert into ssr_mr11(
|
|
ssrMr11M_CompanyID, ssrMr11M_CompanyNumber, SsrMr11M_BranchCode, SsrMr11M_CompanyOldID,
|
|
ssrMr11M_CompanyName, ssrMr11M_MouTypeName, ssrMr11M_MouTypeID,
|
|
ssrMr11KerjasamaLokal, ssrMr11KerjasamaNasional, ssrMr11TagihanLokal,
|
|
ssrMr11TagihanNasional, ssrMr11Date, ssrMr11Year, ssrMr11Month, ssrMr11Total, ssrMr11TotalPasien
|
|
)
|
|
select M_CompanyID, M_CompanyNumber ,?, M_CompanyOldID,
|
|
M_CompanyName, M_MouTypeName, M_MouTypeID,
|
|
if(M_MouTypeName = 'Lokal' , 'Ya', '') as kerjasamalokal,
|
|
if(M_MouTypeName in ('Nasional 1','Nasional 2') , 'Ya', '') as kerjasamanasional,
|
|
if(M_MouTypeName = 'Lokal' , 'Ya', '') as tagihanlokal,
|
|
if(M_MouTypeName in ('Nasional 1','Nasional 2') , 'Ya', '') as tagihannasonal,
|
|
date(T_OrderHeaderDate) date, year(T_OrderHeaderDate) year, month(T_OrderHeaderDate) month,
|
|
sum(T_OrderHeaderTotal) total, count(T_OrderHeaderID ) as totpasien
|
|
from t_orderheader
|
|
left join m_company on T_OrderHeaderM_CompanyID = M_CompanyID and M_CompanyIsActive = 'Y'
|
|
left join m_mou on T_OrderHeaderM_MouID = M_MouID and M_MouIsActive = 'Y'
|
|
left join m_moutype on M_MouM_MouTypeID = M_MouTypeID
|
|
where date(T_OrderHeaderDate) = ? and T_OrderHeaderIsActive = 'Y'
|
|
group by M_CompanyID
|
|
";
|
|
$qry = $this->db->query($sql,array($branchCode,$prm_date));
|
|
if (!$qry) print_r($this->db->error());
|
|
$tot = $this->db->affected_rows();
|
|
echo "$prm_date : $tot records\n";
|
|
}
|
|
function upload($prm_date) {
|
|
$sql = "select * from ssr_mr11
|
|
where SsrMr11Date = ?
|
|
and SsrMr11IsSent = 'N'
|
|
and SsrMr11Retry < 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);
|
|
$regionalIP = $this->getRegionalIP();
|
|
$url = "http://$regionalIP/one-api/tools/marketing/r_mr11";
|
|
|
|
echo "Uploading : $prm_date, total " . count($rows) . " records\n";
|
|
$j_result = $this->post($url,$jparam);
|
|
$result = json_decode($j_result,true);
|
|
$sql = "update ssr_mr11 set SsrMr11Retry = SsrMr11Retry + 1 where date(SsrMr11Date) = ?";
|
|
$this->db->query($sql,array($prm_date));
|
|
if ($result["status"] == "OK") {
|
|
$sql = "update ssr_mr11 set SsrMr11IsSent = 'Y' where SsrMr11ID = ?";
|
|
foreach($result["SsrMr11ID"] as $id ) {
|
|
$this->db->query($sql, array($id));
|
|
}
|
|
echo $result["status"] . ", total " . count($result["SsrMr11ID"]) . "\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;
|
|
}
|
|
}
|