Files
REG_IBL/one-api/application/controllers/one_mitra/Fpp.php
2026-05-25 20:01:37 +07:00

195 lines
7.3 KiB
PHP

<?php
class Fpp extends MY_Controller
{
var $db_regional;
var $load;
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userID = $this->sys_user['M_UserID'];
$sql_cek_token = "SELECT M_UserActiveToken
from one_mitra.m_user
WHERE M_UserID = ?
AND M_UserActiveToken IS NOT NULL";
$qry_token = $this->db->query($sql_cek_token, [$userID]);
if (!$qry_token) {
$this->sys_error('Invalid token');
exit;
}
$rows_token = $qry_token->result_array();
if (count($rows_token) == 0) {
$this->sys_error('Invalid token');
exit;
}
}
function load()
{
try {
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$mou_id = 0;
if (isset($prm['mou_id'])) {
$mou_id = trim($prm["mou_id"]);
$mou_id = $prm['mou_id'];
} else {
$this->sys_error("mou_id is mandatory");
exit;
}
$sql = "SELECT
group_concat(distinct concat(t_test.T_TestID,'^',t_test.T_TestName,'^',T_PriceTotal,'^', t_test.T_TestSasCode) separator '|') TestList,
Nat_SubGroupName,
child_test
from ss_price_mou
join t_test on T_PriceIsCito= 'N' and is_packet = 'N'
AND Ss_PriceMouM_MouID = ?
and ss_price_mou.T_TestID = t_test.T_TestID
join nat_subgroup on t_test.T_TestNat_SubGroupID = Nat_SubGroupID
group by Nat_SubGroupName
order by Nat_SubGroupNat_GroupID";
$qry = $this->db_regional->query($sql, [
$mou_id,
]);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" =>
$this->db_regional->error()["message"] .
"|" .
$this->db_regional->last_query(),
]);
exit();
}
$rows = $qry->result_array();
$result = [];
$filters = ["Home Service", "Cetak", "Layanan"];
foreach ($rows as $key => $r) {
$tab = $r["Nat_SubGroupName"];
$result[] = ["tab" => $tab, "tab_id" => $key + 1, "is_paket" => "N", "items" => []];
$idx = count($result) - 1;
$a_px = explode("|", $r["TestList"]);
foreach ($a_px as $px) {
list($testID, $testName, $testPrice, $sasCode) = explode("^", $px);
if ($testPrice == 0 && $r["child_test"] != "[]") {
$child_test = json_decode($r["child_test"], true);
foreach ($child_test as $t) {
$testPrice += $t["T_PriceTotal"];
}
}
$is_skip = false;
foreach ($filters as $ft) {
if (stripos($testName, $ft) !== false) {
$is_skip = true;
break;
}
}
if ($is_skip) {
continue;
}
$items = [
"testID" => $testID,
"testName" => $testName,
"testPrice" => $testPrice,
"is_paket" => "N",
"sasCode" => $sasCode
];
$result[$idx]["items"][] = $items;
}
}
$sql = "SELECT
T_PacketID,
T_PacketName,
T_PacketPrice,
T_PacketType,
GROUP_CONCAT(T_TestName SEPARATOR ', ') AS detail,
GROUP_CONCAT(T_TestID SEPARATOR ', ') AS tests
FROM t_packet
JOIN t_packetdetail
ON T_PacketID = T_PacketDetailT_PacketID
AND T_PacketDetailIsActive = 'Y'
JOIN t_test
ON T_PacketDetailT_TestID = T_TestID
AND T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
WHERE T_PacketIsActive = 'Y'
AND T_PacketM_MouID = ?
GROUP BY T_PacketID";
$qry = $this->db_regional->query($sql, [
$mou_id,
]);
if (!$qry) {
echo json_encode([
"status" => "ERR",
"message" =>
$this->db_regional->error()["message"] .
"|" .
$this->db_regional->last_query(),
]);
exit();
}
$paket = $qry->result_array();
$paket_data = [];
for ($i = 0; $i < count($paket); $i++) {
$items = [
"testID" => $paket[$i]['T_PacketID'],
"testName" => $paket[$i]['T_PacketName'],
"testPrice" => $paket[$i]['T_PacketPrice'],
"arrTest" => $paket[$i]['tests'],
"type" => $paket[$i]['T_PacketType'],
"is_paket" => "Y",
"sasCode" => $paket[$i]['detail']
];
$paket_data[] = $items;
}
// $result[] = ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data];
array_unshift($result, ["tab" => "Paket", "tab_id" => count($result) + 1, "is_paket" => "Y", "items" => $paket_data]);
for ($i = 0; $i < count($result); $i++) {
$result[$i]["tab_id"] = $i + 1;
}
echo json_encode(["status" => "OK", "data" => $result]);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getMou()
{
$prm = $this->sys_input;
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$userID = $prm['userID'];
$sql = "SELECT
M_UserMouID as userMouID,
M_UserMouM_MouID as userMouMouID,
M_UserMouAliasName as userMouName,
M_UserMouIsDefault as userMouIsDefault
FROM one_mitra.m_user_mou
WHERE M_UserMouM_UserID = ? AND M_UserMouIsActive = 'Y'";
$qry = $this->db_regional->query($sql, [$userID]);
if (!$qry) {
$this->sys_error('Error get mou');
exit;
}
$rows = $qry->result_array();
$this->sys_ok($rows);
}
}