249 lines
8.7 KiB
PHP
249 lines
8.7 KiB
PHP
<?php
|
|
|
|
class Pramitalabku_lunas extends MY_Controller
|
|
{
|
|
function index()
|
|
{
|
|
echo "/check/[date]";
|
|
echo "\n";
|
|
}
|
|
function check($date = "")
|
|
{
|
|
if ($date == "") {
|
|
$date = date("Y-m-d");
|
|
}
|
|
|
|
$this->print_table_style();
|
|
$sql = "select distinct T_OnlineTxOrgID, T_OnlineTxBookingDate,
|
|
T_OnlineTxNumbering, T_OnlineTxBookingName,
|
|
T_OnlineTxPgReference, T_OnlineTxBookingQrCode, T_OnlineTxIsLunas,
|
|
F_Payment_OrderHeaderIsLunas
|
|
from t_onlinetx
|
|
join t_onlineorder on T_OnlineTxID = T_OnlineOrderT_OnlineTxID
|
|
-- and T_OnlineTxIsLunas = 'Y'
|
|
and date(T_OnlineTxLastUpdated) = ?
|
|
join t_orderheader on T_OrderHeaderID = T_OnlineOrderT_OrderHeaderID
|
|
join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID
|
|
join f_payment_orderheader on F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
|
and F_Payment_OrderHeaderIsLunas = 'Y'
|
|
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
|
|
and F_PaymentDetailM_PaymentTypeID <> 1000
|
|
";
|
|
$qry = $this->db->query($sql, [$date]);
|
|
if (!$qry) {
|
|
echo "{$this->now()} ERR Get TxOnineID: {$this->db->error()["message"]}\n";
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "\t No Upload data\n";
|
|
exit();
|
|
}
|
|
|
|
$new_rows = [];
|
|
foreach ($rows as $idx => $r) {
|
|
if ($r["T_OnlineTxPgReference"] != "") continue;
|
|
$txID = $r["T_OnlineTxOrgID"];
|
|
$r[
|
|
"Action"
|
|
] = "<a href='/one-api/fix/pramitalabku_lunas/fix/$txID'>Re-Upload Status Lunas</a>";
|
|
unset($r["T_OnlineTxPgReference"]);
|
|
$new_rows[] = $r;
|
|
}
|
|
$this->print_table($new_rows, array_keys($new_rows[0]), "Bayar di Tempat");
|
|
// belum lunas
|
|
$sql = "select distinct T_OnlineTxOrgID, T_OnlineTxBookingDate, T_OnlineTxID,
|
|
T_OnlineTxNumbering, T_OnlineTxBookingName,
|
|
T_OnlineTxPgReference, T_OnlineTxBookingQrCode, T_OnlineTxIsLunas, T_OrderHeaderID
|
|
from t_onlinetx
|
|
join t_onlineorder on T_OnlineTxID = T_OnlineOrderT_OnlineTxID
|
|
and (
|
|
date(T_OnlineTxLastUpdated) = ?
|
|
or
|
|
date(T_OnlineTxCreated) = ?
|
|
)
|
|
join t_orderheader on T_OrderHeaderID = T_OnlineOrderT_OrderHeaderID";
|
|
$qry = $this->db->query($sql, [$date,$date]);
|
|
if (!$qry) {
|
|
echo "{$this->now()} ERR Get TxOnineID: {$this->db->error()["message"]}\n";
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "\t No Upload data\n";
|
|
exit();
|
|
}
|
|
|
|
$new_rows = [];
|
|
foreach ($rows as $idx => $r) {
|
|
if ($r["T_OnlineTxPgReference"] != "") continue;
|
|
list($is_lunas,$payment_data) = $this->get_payment($r["T_OrderHeaderID"],$r["T_OnlineTxIsLunas"], $r["T_OnlineTxID"]);
|
|
if ($is_lunas) continue;
|
|
unset($r["T_OrderHeaderID"]);
|
|
unset($r["T_OnlineTxID"]);
|
|
unset($r["T_OnlineTxPgReference"]);
|
|
$r["Payment"] = $payment_data;
|
|
$new_rows[] = $r;
|
|
}
|
|
echo "<br/>";
|
|
|
|
$this->print_table($new_rows, array_keys($new_rows[0]), "Bayar di Tempat <b>Belum Lunas</b>");
|
|
}
|
|
|
|
function get_payment($orderID,$txLunas,$tOnlineTxID) {
|
|
$sql = "select ifnull(F_Payment_OrderHeaderIsLunas,'N') IsLunas,
|
|
f_paymentdetail.*
|
|
from
|
|
f_payment
|
|
join f_payment_orderheader on F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
|
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
|
|
and F_PaymentT_OrderHeaderID = ?";
|
|
$qry = $this->db->query($sql,[$orderID]);
|
|
if (!$qry) {
|
|
return [false, "Err : " . $this->db->error()["message"]];
|
|
}
|
|
$rows = $qry->result_array();
|
|
$is_lunas = false;
|
|
foreach($rows as $r) {
|
|
if ($r["IsLunas"] == "Y") {
|
|
$is_lunas = true;
|
|
}
|
|
}
|
|
if ($txLunas == "Y" && !$is_lunas) {
|
|
$sql = "update t_onlinetx set T_OnlineTxIsLunas = 'N' where T_OnlineTxID = ?";
|
|
$qry = $this->db->query($sql,[$tOnlineTxID]);
|
|
if (!$qry) {
|
|
return [true,"Err Fix TxLunas: " . $this->db->error()["message"] ];
|
|
}
|
|
}
|
|
return [$is_lunas, json_encode($rows,JSON_PRETTY_PRINT)];
|
|
}
|
|
function now()
|
|
{
|
|
return Date("Y-m-d H:i:s");
|
|
}
|
|
function fix($txID)
|
|
{
|
|
$sql = "select distinct T_OnlineTxOrgID, T_OnlineTxNumbering, T_OnlineTxBookingName
|
|
from t_onlinetx
|
|
join t_onlineorder on T_OnlineTxID = T_OnlineOrderT_OnlineTxID
|
|
-- and T_OnlineTxIsLunas = 'Y'
|
|
and T_OnlineTxOrgID = ?
|
|
join t_orderheader on T_OrderHeaderID = T_OnlineOrderT_OrderHeaderID
|
|
join f_payment on F_PaymentT_OrderHeaderID = T_OrderHeaderID
|
|
join f_payment_orderheader on F_PaymentID = F_Payment_OrderHeaderF_PaymentID
|
|
and F_Payment_OrderHeaderIsLunas = 'Y'
|
|
join f_paymentdetail on F_PaymentID = F_PaymentDetailF_PaymentID
|
|
and F_PaymentDetailM_PaymentTypeID <> 1000
|
|
";
|
|
$qry = $this->db->query($sql, [$txID]);
|
|
if (!$qry) {
|
|
echo "{$this->now()} ERR Get TxOnineID: {$this->db->error()["message"]}\n";
|
|
exit();
|
|
}
|
|
$rows = $qry->result_array();
|
|
if (count($rows) == 0) {
|
|
echo "\t No Upload data\n";
|
|
exit();
|
|
}
|
|
$param = ["data" => $rows];
|
|
$url =
|
|
"https://mobile.pramita.co.id/one-api/tools/regonline/r_download/status_lunas";
|
|
$z_param = gzdeflate(json_encode($param), 9);
|
|
$resp = $this->post($url, $z_param);
|
|
if ($resp["status"] == "OK") {
|
|
$counter = count($rows);
|
|
$arr = [];
|
|
$arr[] = [
|
|
"Status" => "{$this->now()} Upload Pelunasan bayar di tempat : $counter<br/>",
|
|
];
|
|
$this->print_table($arr, array_keys($arr[0]), "Re Upload");
|
|
} else {
|
|
$arr = [];
|
|
$arr[] = [
|
|
"Status" => "{$this->now()} ERR Upload Pelunasan bayar di tempat : {$resp["message"]}",
|
|
];
|
|
$this->print_table($arr, array_keys($arr[0]), "Re Upload");
|
|
}
|
|
}
|
|
public function post($url, $data)
|
|
{
|
|
echo "{$this->now()} DEBUG : $url\n";
|
|
$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, 5);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"Content-Type: application/json",
|
|
"Content-Length: " . strlen($data),
|
|
]);
|
|
$z_result = curl_exec($ch);
|
|
if (curl_errno($ch) > 0) {
|
|
return [
|
|
"status" => "ERR",
|
|
"message" => curl_error($ch),
|
|
];
|
|
}
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
if ($httpCode != 200) {
|
|
return [
|
|
"status" => "ERR",
|
|
"message" => "Http Response : $httpCode | $z_result",
|
|
];
|
|
}
|
|
|
|
$result = gzinflate($z_result);
|
|
$j_result = json_decode($result, true);
|
|
if (!$j_result) {
|
|
return [
|
|
"status" => "ERR",
|
|
"message" => "JSON invalid: $z_result",
|
|
];
|
|
}
|
|
return $j_result;
|
|
}
|
|
|
|
public function print_table_style()
|
|
{
|
|
echo "
|
|
<style>
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
}
|
|
tr:nth-child(even) {background-color: #f2f2f2;}
|
|
table {
|
|
border: solid 1px ;
|
|
min-width:600px;
|
|
}
|
|
</style>
|
|
";
|
|
}
|
|
public function print_table($rows, $keys, $title = false)
|
|
{
|
|
echo "<table>";
|
|
if ($title) {
|
|
$col_span = count($keys);
|
|
echo "<tr>";
|
|
echo "<th colspan=$col_span>$title</th>";
|
|
echo "</tr>";
|
|
}
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>$k</td>";
|
|
}
|
|
echo "</tr>\n";
|
|
foreach ($rows as $r) {
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>" . $r[$k] . "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
}
|
|
?>
|