272 lines
10 KiB
PHP
272 lines
10 KiB
PHP
<?php
|
|
class Cashbackpoint extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
var $sspricemou;
|
|
var $hostname;
|
|
var $db_onedev;
|
|
|
|
public function index()
|
|
{
|
|
echo "CPONE MD PRICE API";
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->db_onedev = $this->load->database("onedev", true);
|
|
$this->hostname = 'bankpoint.jala.my.id';
|
|
// $this->load->library("SsPriceMou");
|
|
}
|
|
function reply($resp)
|
|
{
|
|
echo json_encode($resp);
|
|
}
|
|
|
|
function reply_gz($resp, $debug = "")
|
|
{
|
|
if ($debug != "") {
|
|
echo json_encode($resp);
|
|
} else {
|
|
echo gzcompress(json_encode($resp));
|
|
}
|
|
}
|
|
|
|
function get_param()
|
|
{
|
|
$body = file_get_contents("php://input");
|
|
return json_decode($body, true);
|
|
}
|
|
|
|
function get_param_z()
|
|
{
|
|
$body_z = file_get_contents("php://input");
|
|
$body = gzuncompress($body_z);
|
|
return json_decode($body, true);
|
|
}
|
|
public 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_CONNECTTIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/text",
|
|
"Content-Length: " . strlen($data),
|
|
]);
|
|
$result = curl_exec($ch);
|
|
if (curl_error($ch) != "") {
|
|
echo json_encode([
|
|
"status" => "ERR",
|
|
"message" => "Http Error : " . curl_error($ch),
|
|
]);
|
|
curl_close($ch);
|
|
exit();
|
|
}
|
|
curl_close($ch);
|
|
return $result;
|
|
}
|
|
public function list($date = "")
|
|
{
|
|
if ($date == "") {
|
|
$date = date("Y-m-d");
|
|
}
|
|
$sql = "select T_OrderHeaderID,T_OrderHeaderLabNumber,T_OrderHeaderTotal
|
|
from
|
|
t_orderheader
|
|
JOIN m_patient ON M_PatientID = T_OrderHeaderM_PatientID
|
|
JOIN one_pointreward.member_national ON MemberNIK = M_PatientIDNumber AND MemberIsActive = 'Y'
|
|
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsLunas = 'Y'
|
|
WHERE T_OrderHeaderIsActive = 'Y'
|
|
AND date(T_OrderHeaderDate) = ?";
|
|
$qry = $this->db_onedev->query($sql, array($date));
|
|
if (!$qry) {
|
|
$this->sys_error_db("Error get data");
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
$this->sys_ok($rows);
|
|
return $rows;
|
|
}
|
|
function getcashback($headerID){
|
|
|
|
$prm = $this->sys_input;
|
|
$discount = 5;
|
|
$generate_point = 10000;
|
|
// $headerID = $prm['id'];
|
|
|
|
$sql = "SELECT M_PatientIDNumber,T_OrderHeaderM_PatientID,T_OrderHeaderLabNumber,T_OrderHeaderDate,M_BranchCode,M_BranchName
|
|
FROM t_orderheader
|
|
JOIN m_patient ON M_PatientID = T_OrderHeaderM_PatientID
|
|
JOIN m_branch ON M_BranchIsActive = 'Y' AND M_BranchIsDefault = 'Y'
|
|
WHERE T_OrderHeaderID = {$headerID}";
|
|
//echo $sql;
|
|
$data_pasien = $this->db_onedev->query($sql)->row();
|
|
// echo $this->db_onedev->last_query();
|
|
|
|
$sql = "SELECT IFNULL(fn_get_info_member_is_cashback_point(T_OrderHeaderM_PatientID),'N') as is_cashback_point
|
|
FROM t_orderheader
|
|
WHERE T_OrderHeaderID = {$headerID}";
|
|
// echo $sql;
|
|
$is_cashback_point = $this->db_onedev->query($sql)->row()->is_cashback_point;
|
|
|
|
/* $sql = "SELECT Last_StatusPaymentIsLunas as is_lunas
|
|
FROM last_statuspayment
|
|
WHERE Last_StatusPaymentT_OrderHeaderID = {$headerID}";
|
|
// echo $sql;
|
|
$is_lunas = $this->db_onedev->query($sql)->row()->is_lunas;
|
|
*/
|
|
|
|
$sql = "SELECT IF(T_OrderHeaderAddOnLabNumberOrigin IS NULL,'N','Y') as is_pasien_rujukan
|
|
FROM t_orderheader
|
|
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
|
|
WHERE T_OrderHeaderID = {$headerID}";
|
|
//echo $sql;
|
|
$is_pasien_rujukan = $this->db_onedev->query($sql)->row()->is_pasien_rujukan;
|
|
|
|
$point = 0;
|
|
$point_amount = 0;
|
|
$total_before_discount = 0;
|
|
$total_discount = 0;
|
|
|
|
$sql = "SELECT sum(alltotal) as alltotal, ((sum(allprice) - sum(alltotal)) / sum(allprice)) * 100 as diskon
|
|
FROM (
|
|
SELECT sum(T_OrderDetailPrice) as allprice, sum(T_OrderDetailTotal) as alltotal
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailT_TestID <> '0'
|
|
AND T_OrderDetailT_TestCode <> ''
|
|
AND T_OrderDetailIsActive = 'Y'
|
|
JOIN t_test ON T_TestID = T_OrderDetailT_TestID
|
|
LEFT JOIN member_test_eksoteris ON Member_TestEksoterisNat_TestID = T_TestNat_TestID AND Member_TestEksoterisIsActive = 'Y'
|
|
LEFT JOIN t_ref_deliveryorder_detail ON T_RefDeliveryOrderDetailT_OrderHeaderID = T_OrderHeaderID AND
|
|
T_RefDeliveryOrderDetailT_TestID = T_TestID AND
|
|
T_RefDeliveryOrderDetailIsActive = 'Y'
|
|
LEFT JOIN t_ref_deliveryorder ON T_RefDeliveryOrderID = T_RefDeliveryOrderDetailT_RefDeliveryOrderID AND
|
|
T_RefDeliveryOrderIsActive = 'Y'
|
|
WHERE
|
|
T_OrderHeaderID = {$headerID} AND
|
|
Member_TestEksoterisID IS NULL AND
|
|
T_RefDeliveryOrderDetailID IS NULL
|
|
GROUP BY T_OrderHeaderID
|
|
|
|
UNION
|
|
SELECT sum(T_OrderDetailPrice) as allprice, sum(T_OrderDetailTotal) as alltotal
|
|
FROM t_orderheader
|
|
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailT_TestID = '0'
|
|
AND T_OrderDetailT_TestCode = ''
|
|
WHERE
|
|
T_OrderHeaderID = {$headerID}
|
|
GROUP BY T_OrderHeaderID ) a";
|
|
//echo $sql;
|
|
$q_total = $this->db_onedev->query($sql)->row();
|
|
|
|
$total_before_discount = $q_total->alltotal;
|
|
$total_discount = $q_total->diskon;
|
|
|
|
|
|
if($is_cashback_point == 'Y' && $is_pasien_rujukan == 'N' && $total_before_discount > 200000 && round($total_discount,1) < 20){
|
|
$point_amount = ($discount / 100) * $total_before_discount;
|
|
$point_angka = floor($point_amount / $generate_point);
|
|
$point = $point_angka * $generate_point;
|
|
|
|
$data = array(
|
|
"NIK" => $data_pasien->M_PatientIDNumber,
|
|
"pasienID" => $data_pasien->T_OrderHeaderM_PatientID,
|
|
"nolab" => $data_pasien->T_OrderHeaderLabNumber,
|
|
"tgl" => $data_pasien->T_OrderHeaderDate,
|
|
"total_order" => $total_before_discount,
|
|
"point" => $point,
|
|
"point_amount" => $point_amount,
|
|
"brachcode"=> $data_pasien->M_BranchCode,
|
|
"brachname"=> $data_pasien->M_BranchName
|
|
);
|
|
$data = json_encode($data);
|
|
|
|
|
|
$sql = " INSERT INTO member_point_confirm (Member_PointConfirmT_OrderHeaderID,
|
|
Member_PointConfirmData,
|
|
Member_PointConfirmUserID,
|
|
Member_PointConfirmCreated)
|
|
VALUES ({$headerID},
|
|
'{$data}',
|
|
0,
|
|
now()
|
|
)
|
|
ON DUPLICATE KEY UPDATE
|
|
Member_PointConfirmData = '{$data}'";
|
|
$query = $this->db_onedev->query($sql);
|
|
// echo $this->db_onedev->last_query();
|
|
if(!$query){
|
|
$this->sys_error("error insert member_point_confirm");
|
|
exit;
|
|
}
|
|
$result = array(
|
|
"NIK" => $data_pasien->M_PatientIDNumber,
|
|
"pasienID" => $data_pasien->T_OrderHeaderM_PatientID,
|
|
"nolab" => $data_pasien->T_OrderHeaderLabNumber,
|
|
"tgl" => $data_pasien->T_OrderHeaderDate,
|
|
"total_order" => $total_before_discount,
|
|
"point" => $point,
|
|
"point_amount" => $point_amount,
|
|
"brachcode"=> $data_pasien->M_BranchCode,
|
|
"brachname"=> $data_pasien->M_BranchName
|
|
);
|
|
$this->sys_ok($result);
|
|
return $result;
|
|
// exit;
|
|
|
|
|
|
}else{
|
|
$point_amount = 0;
|
|
$point = 0;
|
|
$data = array(
|
|
"NIK" => $data_pasien->M_PatientIDNumber,
|
|
"pasienID" => $data_pasien->T_OrderHeaderM_PatientID,
|
|
"nolab" => $data_pasien->T_OrderHeaderLabNumber,
|
|
"tgl" => $data_pasien->T_OrderHeaderDate,
|
|
"total_order" => $total_before_discount,
|
|
"point" => $point,
|
|
"point_amount" => $point_amount,
|
|
"brachcode"=> $data_pasien->M_BranchCode,
|
|
"brachname"=> $data_pasien->M_BranchName
|
|
);
|
|
$data = json_encode($data);
|
|
$sql = " INSERT INTO member_point_confirm (Member_PointConfirmT_OrderHeaderID,
|
|
Member_PointConfirmData,
|
|
Member_PointConfirmUserID,
|
|
Member_PointConfirmCreated)
|
|
VALUES ({$headerID},
|
|
'{$data}',
|
|
0,
|
|
now()
|
|
)
|
|
ON DUPLICATE KEY UPDATE
|
|
Member_PointConfirmData = '{$data}'";
|
|
$query = $this->db_onedev->query($sql);
|
|
// echo $this->db_onedev->last_query();
|
|
if(!$query){
|
|
$this->sys_error("error insert member_point_confirm");
|
|
exit;
|
|
}
|
|
$result = array(
|
|
"id"=>$headerID,
|
|
"is_cashback_point" => $is_cashback_point,
|
|
"is_pasien_rujukan" => $is_pasien_rujukan,
|
|
"total_before_discount" => $total_before_discount,
|
|
"total_discount" => round($total_discount,1),
|
|
"cashback" => $point_amount,
|
|
);
|
|
$this->sys_ok($result);
|
|
return $result;
|
|
// exit;
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|