url_renderer = "http://devkedungdoro.aplikasi.web.id:3000/chart"; } function task_group_bymonth($sdate, $edate) { $sqlall = "SELECT sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70"; $qryall = $this->db->query($sqlall); $rowsall = $qryall->result_array(); $sql = "SELECT 'Accounting' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND task_name like '%acc%' UNION SELECT 'Point Reward' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%point%' OR task_name like '%reward%' OR task_name like '%member%') UNION SELECT 'Satu Sehat' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%sehat%' OR task_name like '%encounter%') UNION SELECT 'Klinik' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%klinik%') UNION SELECT 'Rujukan Eksternal' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%eksternal%') UNION SELECT 'Pengelolaan MCU' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%mcu%') UNION SELECT 'ETL TAT' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%etl%') UNION SELECT 'E-RESULT' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%eresult%' OR task_name like '%e-result%' OR task_name like '%e result%') UNION SELECT 'E-FORM' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx BETWEEN '{$sdate}' AND '{$edate}' AND project_id = 70 AND (task_name like '%eform%' OR task_name like '%e-form%' OR task_name like '%e form%') GROUP BY group_name ORDER BY group_name ASC"; $qry = $this->db->query($sql); $this->check_error($qry, "get group_name"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } // print_r($rows); // exit; $param = array( 'tooltip' => array( 'trigger' => 'item', 'formatter' => '{b}: {c} ({d}%)' ), 'legend' => array( 'orient' => 'vertical', 'right' => '5%', 'top' => 'center', ), 'series' => array( array( 'name' => 'Access From', 'type' => 'pie', 'radius' => '70%', 'center' => ['40%', '50%'], 'labelLine' => array( 'show' => false ), 'label' => array( 'show' => true, 'position' => 'inside', 'formatter' => '{d}%', 'backgroundColor' => 'rgba(0, 0, 0, 0.5)', 'borderRadius' => 5, 'padding' => 4, 'color' => '#fff' ), 'itemStyle' => array( 'normal' => array( 'shadowBlur' => 20, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ), 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 30, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.7)' ) ), 'data' => array() ) ) ); $total_val = 0.0; foreach ($rows as $itm) { $total_val = $total_val + $itm['s_hour']; } $other_val = 0.0; $all_val = 0.0; foreach ($rowsall as $itm) { $all_val = $all_val + $itm['s_hour']; $other_val = $all_val - $total_val; } for ($i = 0; $i < count($rows); $i++) { $formatted = number_format(($rows[$i]['s_hour'] / $all_val) * 100, 2, '.', ''); // if ($i <= 3) { $param['series'][0]['data'][] = array( 'value' => $rows[$i]['s_hour'], 'name' => $rows[$i]['group_name'] . " [" . $formatted . "%]", ); // } /*else { $other_val = $other_val + floatval($rows[$i]['s_hour']); } */ } $param['series'][0]['data'][] = array( 'value' => floatval($other_val), 'name' => 'Support' . " [" . number_format(($other_val / $all_val) * 100, 2, '.', '') . "%]", ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } function task_group($sdate) { $sqlall = "SELECT sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70"; $qryall = $this->db->query($sqlall); $rowsall = $qryall->result_array(); $sql = "SELECT 'Accounting' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND task_name like '%acc%' UNION SELECT 'Point Reward' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%point%' OR task_name like '%reward%' OR task_name like '%member%') UNION SELECT 'Satu Sehat' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%sehat%' OR task_name like '%encounter%') UNION SELECT 'Klinik' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%klinik%') UNION SELECT 'Rujukan Eksternal' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%eksternal%') UNION SELECT 'Pengelolaan MCU' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%mcu%') UNION SELECT 'ETL TAT' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%etl%') UNION SELECT 'E-RESULT' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%eresult%' OR task_name like '%e-result%' OR task_name like '%e result%') UNION SELECT 'E-FORM' group_name, sum(ifnull(unit_amount,0)) as s_hour FROM one_support.odoo_timesheet WHERE date_trx >= '{$sdate}' AND project_id = 70 AND (task_name like '%eform%' OR task_name like '%e-form%' OR task_name like '%e form%') GROUP BY group_name ORDER BY group_name ASC"; $qry = $this->db->query($sql); $this->check_error($qry, "get group_name"); $rows = $qry->result_array(); if (count($rows) == 0) { $this->chart_error("No data found"); } $param = array( 'tooltip' => array( 'trigger' => 'item', 'formatter' => '{b}: {c} ({d}%)' ), 'legend' => array( 'orient' => 'vertical', 'right' => '5%', 'top' => 'center', ), 'series' => array( array( 'name' => 'Access From', 'type' => 'pie', 'radius' => '70%', 'center' => ['40%', '50%'], 'labelLine' => array( 'show' => false ), 'label' => array( 'show' => true, 'position' => 'inside', 'formatter' => '{d}%', 'backgroundColor' => 'rgba(0, 0, 0, 0.5)', 'borderRadius' => 5, 'padding' => 4, 'color' => '#fff' ), 'itemStyle' => array( 'normal' => array( 'shadowBlur' => 20, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.5)' ) ), 'emphasis' => array( 'itemStyle' => array( 'shadowBlur' => 30, 'shadowOffsetX' => 0, 'shadowColor' => 'rgba(0, 0, 0, 0.7)' ) ), 'data' => array() ) ) ); $total_val = 0.0; foreach ($rows as $itm) { $total_val = $total_val + $itm['s_hour']; } $other_val = 0.0; $all_val = 0.0; foreach ($rowsall as $itm) { $all_val = $all_val + $itm['s_hour']; $other_val = $all_val - $total_val; } for ($i = 0; $i < count($rows); $i++) { $formatted = number_format(($rows[$i]['s_hour'] / $all_val) * 100, 2, '.', ''); // if ($i <= 3) { $param['series'][0]['data'][] = array( 'value' => $rows[$i]['s_hour'], 'name' => $rows[$i]['group_name'] . " [" . $formatted . "%]", ); // } /*else { $other_val = $other_val + floatval($rows[$i]['s_hour']); } */ } $param['series'][0]['data'][] = array( 'value' => floatval($other_val), 'name' => 'Support' . " [" . number_format(($other_val / $all_val) * 100, 2, '.', '') . "%]", ); // 3. encapsulate in config attribute and json encode $config = ["config" => $param]; $j_param = json_encode($config); header("Content-Type: image/png"); // 4. post to chart renderer echo $this->post($this->url_renderer, $j_param); } function check_error($qry, $stage) { if (!$qry) { $errMsg = $stage . "
" . $this->db->error()["messge"]; print_r($errMsg); $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/png"); $config = ["config" => $param]; $j_param = json_encode($config); 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, j120); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "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; } }