Files
BE_IBL/application/controllers/tools/Mcu_chart.php
2026-04-15 15:23:57 +07:00

130 lines
3.2 KiB
PHP

<?php
class Mcu_chart extends MY_Controller
{
var $url_renderer;
function __construct()
{
parent::__construct();
$this->url_renderer = "http://devkedungdoro.aplikasi.web.id:3000";
}
function render($type, $id)
{
switch ($type) {
case "mcu001":
$this->mcu001($id);
break;
}
}
function mcu001($id)
{
$sql = "SELECT count(Mcu_OrderT_OrderHeaderID) as peserta,Mgm_McuTotalParticipant as total
FROM one_etl.mgm_mcux
join one_etl.mcu_order on Mcu_OrderMgm_McuID = Mgm_McuID
where Mgm_McuID = ?";
$qry = $this->db->query($sql, [$id]);
$this->check_error($qry, "get total mcu");
$rows = $qry->result_arry();
if (count($rows) == 0) {
$this->chart_error("No data found");
}
$total = $rows[0]["total"];
$peserta = $rows[0]["peserta"];
$belum_mcu = $total - $peserta;
$param = array(
'title' => array(
'text' => 'Peserta MCU',
'subtext' => "Total Peserta $total",
'left' => 'center'
),
'tooltip' => array(
'trigger' => 'item'
),
'legend' => array(
'bottom' => 50,
'left' => 'center'
),
'series' => array(
array(
'name' => 'Access From',
'type' => 'pie',
'radius' => '60%',
'data' => array(
array('value' => $belum_mcu, 'name' => "Belum MCU : {$belum_mcu} Peserta"),
array('value' => $peserta, 'name' => "Sudah MCU : {$peserta} Peserta")
),
'emphasis' => array(
'itemStyle' => array(
'shadowBlur' => 10,
'shadowOffsetX' => 0,
'shadowColor' => 'rgba(0, 0, 0, 0.5)'
)
)
)
)
);
}
function check_error($qry, $stage)
{
if (!$qry) {
$errMsg = $stage . "<br/>" . $this->db->error()["messge"];
$this->chart_error($errMsg);
}
}
function chart_error($msg)
{
$param = array(
'title' => array(
'show' => true,
'textStyle' => array(
'color' => 'grey',
'fontSize' => 20
),
'text' => $msg,
'left' => 'center',
'top' => 'center'
),
'xAxis' => array(
'show' => false
),
'yAxis' => array(
'show' => false
),
'series' => array()
);
header("Content-Type: image/jpg");
$j_param = json_encode($param);
echo $this->post($this->url_renderer, $j_param);
exit;
}
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, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/octet-stream",
"Content-Length: " . strlen($data),
]);
$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",
];
}
return $result;
}
}