260 lines
13 KiB
PHP
260 lines
13 KiB
PHP
<?php
|
|
class Mr07 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_mr07 where date(SsrMr07T_OrderHeaderDate) = ?";
|
|
$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_1 = "
|
|
insert into ssr_mr07( SsrMr07M_BranchCode, SsrMr07M_PatientName,
|
|
SsrMr07T_OrderHeaderID, SsrMr07T_OrderHeaderDate, SsrMr07T_OrderHeaderLabNumberExt,
|
|
SsrMr07M_CompanyID,SsrMr07M_MouID,SsrMr07M_OmzetTypeID,
|
|
SsrMr07Bruto, SsrMr07Netto,SsrMr07M_MouJpaIsNetto,
|
|
SsrMr07Price,SsrMr07M_StaffNIK, SsrMr07JpaName, SsrMr07JpaPercent,
|
|
SsrMr07Jpa, SsrMr07M_No_FormRev)
|
|
select
|
|
?, CONCAT(M_TitleName,' ',M_PatientName) AS M_PatientName,
|
|
T_OrderHeaderID, date(T_OrderHeaderDate) as tglorder, T_OrderHeaderLabNumberExt,
|
|
M_CompanyID, M_MouID, M_OmzetTypeID,
|
|
sum(T_OrderDetailPrice) as bruto, sum(T_OrderDetailTotal) as netto, M_MouJpaIsNetto,
|
|
if(M_MouJpaIsNetto = 'Y' ,sum(T_OrderDetailTotal) , sum(T_OrderDetailPrice) ) as harga,
|
|
Nat_StaffNIK,
|
|
M_MouJpa1Name as jpaname,
|
|
M_MouJpa1Percent as jpapersen,
|
|
if(M_MouJpaIsNetto = 'Y' ,
|
|
sum(T_OrderDetailTotal)*(M_MouJpa1Percent/100) ,
|
|
sum(T_OrderDetailPrice) *(M_MouJpa1Percent/100) ) as jpa,
|
|
M_No_FormRev
|
|
from t_orderheader
|
|
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID and M_CompanyIsActive = 'Y'
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID and M_MouIsActive = 'Y'
|
|
join m_omzettype on M_MouM_OmzetTypeID = M_OmzetTypeID and M_OmzetTypeIsActive = 'Y'
|
|
join nat_staff on M_CompanyM_StaffID = Nat_StaffID and Nat_StaffIsActive = 'Y'
|
|
-- left join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
left join m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
left join m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
left join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsPrice = 'Y'
|
|
LEFT JOIN m_no_form on M_No_FormID > 0 and M_No_FormName = 'INV' and M_No_FormIsActive = 'Y'
|
|
left join conf_systems on S_SystemsID > 0
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and
|
|
DATE(T_OrderHeaderDate) = ?
|
|
and M_MouJpa1Name <> ''
|
|
group by T_OrderHeaderID
|
|
having jpa <> '0'";
|
|
$qry = $this->db->query($sql_1,array($branchCode,$prm_date));
|
|
if (!$qry) {
|
|
echo "ERR: ";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$tot_1 = $this->db->affected_rows();
|
|
|
|
|
|
$sql_2 = "
|
|
insert into ssr_mr07( SsrMr07M_BranchCode, SsrMr07M_PatientName,
|
|
SsrMr07T_OrderHeaderID, SsrMr07T_OrderHeaderDate, SsrMr07T_OrderHeaderLabNumberExt,
|
|
SsrMr07M_CompanyID,SsrMr07M_MouID,SsrMr07M_OmzetTypeID,
|
|
SsrMr07Bruto, SsrMr07Netto,SsrMr07M_MouJpaIsNetto,
|
|
SsrMr07Price,SsrMr07M_StaffNIK, SsrMr07JpaName, SsrMr07JpaPercent,
|
|
SsrMr07Jpa, SsrMr07M_No_FormRev)
|
|
select
|
|
?, CONCAT(M_TitleName,' ',M_PatientName) AS M_PatientName,
|
|
T_OrderHeaderID, date(T_OrderHeaderDate) as tglorder, T_OrderHeaderLabNumberExt,
|
|
M_CompanyID, M_MouID, M_OmzetTypeID,
|
|
sum(T_OrderDetailPrice) as bruto, sum(T_OrderDetailTotal) as netto, M_MouJpaIsNetto,
|
|
if(M_MouJpaIsNetto = 'Y' ,sum(T_OrderDetailTotal) , sum(T_OrderDetailPrice) ) as harga,
|
|
Nat_StaffNIK,
|
|
M_MouJpa2Name as jpaname,
|
|
M_MouJpa2Percent as jpapersen,
|
|
if(M_MouJpaIsNetto = 'Y' ,
|
|
sum(T_OrderDetailTotal)*(M_MouJpa2Percent/100) ,
|
|
sum(T_OrderDetailPrice) *(M_MouJpa2Percent/100) ) as jpa,
|
|
M_No_FormRev
|
|
from t_orderheader
|
|
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID and M_CompanyIsActive = 'Y'
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID and M_MouIsActive = 'Y'
|
|
join m_omzettype on M_MouM_OmzetTypeID = M_OmzetTypeID and M_OmzetTypeIsActive = 'Y'
|
|
join nat_staff on M_CompanyM_StaffID = Nat_StaffID and Nat_StaffIsActive = 'Y'
|
|
-- left join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
left join m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
left join m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
left join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsPrice = 'Y'
|
|
LEFT JOIN m_no_form on M_No_FormID > 0 and M_No_FormName = 'INV' and M_No_FormIsActive = 'Y'
|
|
left join conf_systems on S_SystemsID > 0
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and
|
|
DATE(T_OrderHeaderDate) = ?
|
|
and M_MouJpa2Name <> ''
|
|
group by T_OrderHeaderID
|
|
having jpa <> '0'";
|
|
$qry = $this->db->query($sql_2,array($branchCode,$prm_date));
|
|
$tot_2 = $this->db->affected_rows();
|
|
|
|
$sql_3 = "
|
|
insert into ssr_mr07( SsrMr07M_BranchCode, SsrMr07M_PatientName,
|
|
SsrMr07T_OrderHeaderID, SsrMr07T_OrderHeaderDate, SsrMr07T_OrderHeaderLabNumberExt,
|
|
SsrMr07M_CompanyID,SsrMr07M_MouID,SsrMr07M_OmzetTypeID,
|
|
SsrMr07Bruto, SsrMr07Netto,SsrMr07M_MouJpaIsNetto,
|
|
SsrMr07Price,SsrMr07M_StaffNIK, SsrMr07JpaName, SsrMr07JpaPercent,
|
|
SsrMr07Jpa, SsrMr07M_No_FormRev)
|
|
select
|
|
?, CONCAT(M_TitleName,' ',M_PatientName) AS M_PatientName,
|
|
T_OrderHeaderID, date(T_OrderHeaderDate) as tglorder, T_OrderHeaderLabNumberExt,
|
|
M_CompanyID, M_MouID, M_OmzetTypeID,
|
|
sum(T_OrderDetailPrice) as bruto, sum(T_OrderDetailTotal) as netto, M_MouJpaIsNetto,
|
|
if(M_MouJpaIsNetto = 'Y' ,sum(T_OrderDetailTotal) , sum(T_OrderDetailPrice) ) as harga,
|
|
Nat_StaffNIK,
|
|
M_MouJpa3Name as jpaname,
|
|
M_MouJpa3Percent as jpapersen,
|
|
if(M_MouJpaIsNetto = 'Y' ,
|
|
sum(T_OrderDetailTotal)*(M_MouJpa3Percent/100) ,
|
|
sum(T_OrderDetailPrice) *(M_MouJpa3Percent/100) ) as jpa,
|
|
M_No_FormRev
|
|
from t_orderheader
|
|
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID and M_CompanyIsActive = 'Y'
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID and M_MouIsActive = 'Y'
|
|
join m_omzettype on M_MouM_OmzetTypeID = M_OmzetTypeID and M_OmzetTypeIsActive = 'Y'
|
|
join nat_staff on M_CompanyM_StaffID = Nat_StaffID and Nat_StaffIsActive = 'Y'
|
|
-- left join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
left join m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
left join m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
left join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsPrice = 'Y'
|
|
LEFT JOIN m_no_form on M_No_FormID > 0 and M_No_FormName = 'INV' and M_No_FormIsActive = 'Y'
|
|
left join conf_systems on S_SystemsID > 0
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and
|
|
DATE(T_OrderHeaderDate) = ?
|
|
and M_MouJpa3Name <> ''
|
|
group by T_OrderHeaderID
|
|
having jpa <> '0'";
|
|
$qry = $this->db->query($sql_3,array($branchCode,$prm_date));
|
|
$tot_3 = $this->db->affected_rows();
|
|
|
|
$sql_4 = "
|
|
insert into ssr_mr07( SsrMr07M_BranchCode, SsrMr07M_PatientName,
|
|
SsrMr07T_OrderHeaderID, SsrMr07T_OrderHeaderDate, SsrMr07T_OrderHeaderLabNumberExt,
|
|
SsrMr07M_CompanyID,SsrMr07M_MouID,SsrMr07M_OmzetTypeID,
|
|
SsrMr07Bruto, SsrMr07Netto,SsrMr07M_MouJpaIsNetto,
|
|
SsrMr07Price,SsrMr07M_StaffNIK, SsrMr07JpaName, SsrMr07JpaPercent,
|
|
SsrMr07Jpa, SsrMr07M_No_FormRev)
|
|
select
|
|
?, CONCAT(M_TitleName,' ',M_PatientName) AS M_PatientName,
|
|
T_OrderHeaderID, date(T_OrderHeaderDate) as tglorder, T_OrderHeaderLabNumberExt,
|
|
M_CompanyID, M_MouID, M_OmzetTypeID,
|
|
sum(T_OrderDetailPrice) as bruto, sum(T_OrderDetailTotal) as netto, M_MouJpaIsNetto,
|
|
if(M_MouJpaIsNetto = 'Y' ,sum(T_OrderDetailTotal) , sum(T_OrderDetailPrice) ) as harga,
|
|
Nat_StaffNIK,
|
|
M_MouJpa4Name as jpaname,
|
|
M_MouJpa4Percent as jpapersen,
|
|
if(M_MouJpaIsNetto = 'Y' ,
|
|
sum(T_OrderDetailTotal)*(M_MouJpa4Percent/100) ,
|
|
sum(T_OrderDetailPrice) *(M_MouJpa4Percent/100) ) as jpa,
|
|
M_No_FormRev
|
|
from t_orderheader
|
|
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID and M_CompanyIsActive = 'Y'
|
|
join m_mou on T_OrderHeaderM_MouID = M_MouID and M_MouIsActive = 'Y'
|
|
join m_omzettype on M_MouM_OmzetTypeID = M_OmzetTypeID and M_OmzetTypeIsActive = 'Y'
|
|
join nat_staff on M_CompanyM_StaffID = Nat_StaffID and Nat_StaffIsActive = 'Y'
|
|
-- left join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID and T_OrderHeaderIsActive = 'Y'
|
|
left join m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND M_PatientIsActive = 'Y'
|
|
left join m_title ON M_PatientM_TitleID = M_TitleID AND M_TitleIsActive = 'Y'
|
|
left join t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID and T_OrderDetailIsActive = 'Y'
|
|
join t_test on T_OrderDetailT_TestID = T_TestID and T_TestIsPrice = 'Y'
|
|
LEFT JOIN m_no_form on M_No_FormID > 0 and M_No_FormName = 'INV' and M_No_FormIsActive = 'Y'
|
|
left join conf_systems on S_SystemsID > 0
|
|
where T_OrderHeaderIsActive = 'Y'
|
|
and
|
|
DATE(T_OrderHeaderDate) = ?
|
|
and M_MouJpa4Name <> ''
|
|
group by T_OrderHeaderID
|
|
having jpa <> '0'";
|
|
$qry = $this->db->query($sql_4,array($branchCode,$prm_date));
|
|
$tot_4 = $this->db->affected_rows();
|
|
$tot = $tot_1 + $tot_2 + $tot_3 + $tot_4;
|
|
echo "$prm_date : $tot records\n";
|
|
}
|
|
|
|
function upload($prm_date) {
|
|
$sql = "select * from ssr_mr07
|
|
where date(SsrMr07T_OrderHeaderDate) = ?
|
|
and SsrMr07IsSent = 'N'
|
|
and SsrMr07Retry < 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_mr07";
|
|
|
|
echo "Uploading : $prm_date, total " . count($rows) . " records\n";
|
|
$j_result = $this->post($url,$jparam);
|
|
$result = json_decode($j_result,true);
|
|
$sql = "update ssr_mr07 set SsrMr07Retry = SsrMr07Retry + 1 where date(SsrMr07T_OrderHeaderDate) = ?";
|
|
$this->db->query($sql,array($prm_date));
|
|
if ($result["status"] == "OK") {
|
|
$sql = "update ssr_mr07 set SsrMr07IsSent = 'Y' where SsrMr07ID = ?";
|
|
foreach($result["SsrMr07ID"] as $id ) {
|
|
$this->db->query($sql, array($id));
|
|
}
|
|
echo $result["status"] . ", total " . count($result["SsrMr07ID"]) . "\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;
|
|
}
|
|
}
|