130 lines
5.8 KiB
PHP
130 lines
5.8 KiB
PHP
<?php
|
|
class Mr04 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_mr04 where SsrMr04Date = ?";
|
|
$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_mr04 (
|
|
SsrMr04M_BranchCode, SsrMr04Date, SsrMr04PasienAps, SsrMr04Aps ,
|
|
SsrMr04PasienDokter , SsrMr04Dokter , SsrMr04PasienPerusahaan , SsrMr04Perusahaan ,
|
|
SsrMr04PasienRujukan , SsrMr04Rujukan , SsrMr04PasienAnakPerusahaan , SsrMr04AnakPerusahaan ,
|
|
SsrMr04PasienPenelitian , SsrMr04Penelitian , SsrMr04PasienRAP , SsrMr04RAP ,
|
|
SsrMr04TotalPasien , SsrMr04TotalOmzet
|
|
)
|
|
select ?, date(T_OrderHeaderDate),
|
|
count(distinct case when M_OmzetTypeID = '1' then T_OrderHeaderID end ) as pasienAPS,
|
|
sum( case when M_OmzetTypeID = '1' then T_OrderHeaderTotal end ) as APS,
|
|
|
|
count(distinct case when M_OmzetTypeID = '2' then T_OrderHeaderID end ) as pasienDokter,
|
|
sum( case when M_OmzetTypeID = '2' then T_OrderHeaderTotal end )as Dokter,
|
|
|
|
count(distinct case when M_OmzetTypeID = '3' then T_OrderHeaderID end ) as pasienPerusahaan,
|
|
sum( case when M_OmzetTypeID = '3' then T_OrderHeaderTotal end ) as Perusahaan,
|
|
|
|
count(distinct case when M_OmzetTypeID = '4' then T_OrderHeaderID end ) as pasienRujukan,
|
|
sum( case when M_OmzetTypeID = '4' then T_OrderHeaderTotal end ) as Rujukan,
|
|
|
|
count(distinct case when M_OmzetTypeID = '5' then T_OrderHeaderID end ) as pasienAnak,
|
|
sum( case when M_OmzetTypeID = '5' then T_OrderHeaderTotal end )as AnakPerusahaan,
|
|
|
|
count(distinct case when M_OmzetTypeID = '6' then T_OrderHeaderID end ) as pasienPenelitian,
|
|
sum( case when M_OmzetTypeID = '6' then T_OrderHeaderTotal end ) as Penelitian,
|
|
|
|
count(distinct case when M_OmzetTypeID = '7' then T_OrderHeaderID end ) as pasienRAP,
|
|
sum( case when M_OmzetTypeID = '7' then T_OrderHeaderTotal end )as RujukanAntarPramita ,
|
|
|
|
count(T_OrderHeaderID) as totpasien,
|
|
sum(T_OrderHeaderTotal) as totalomset
|
|
from t_orderheader
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID
|
|
join m_omzettype on M_MouM_OmzetTypeID = M_OmzetTypeID and T_OrderHeaderIsActive = 'Y'
|
|
|
|
where date(T_OrderHeaderDate) = ?
|
|
and T_OrderHeaderIsActive = 'Y'
|
|
group by date(T_OrderHeaderDate)
|
|
";
|
|
$qry = $this->db->query($sql,array($branchCode,$prm_date));
|
|
$tot = $this->db->affected_rows();
|
|
echo "$prm_date : $tot records\n";
|
|
}
|
|
function upload($prm_date) {
|
|
$sql = "select * from ssr_mr04
|
|
where SsrMr04Date = ?
|
|
and SsrMr04IsSent = 'N'
|
|
and SsrMr04Retry < 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_mr04";
|
|
|
|
echo "Uploading : $prm_date, total " . count($rows) . " records\n";
|
|
$j_result = $this->post($url,$jparam);
|
|
$result = json_decode($j_result,true);
|
|
$sql = "update ssr_mr04 set SsrMr04Retry = SsrMr04Retry + 1 where date(SsrMr04T_OrderHeaderDate) = ?";
|
|
$this->db->query($sql,array($prm_date));
|
|
if ($result["status"] == "OK") {
|
|
$sql = "update ssr_mr04 set SsrMr04IsSent = 'Y' where SsrMr04ID = ?";
|
|
foreach($result["SsrMr04ID"] as $id ) {
|
|
$this->db->query($sql, array($id));
|
|
}
|
|
echo $result["status"] . ", total " . count($result["SsrMr04ID"]) . "\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;
|
|
}
|
|
}
|