Files
2026-04-27 10:26:26 +07:00

108 lines
3.4 KiB
PHP

<?php
class Qr_code extends MY_Controller
{
var $url_renderer;
var $db_onedev;
public function index()
{
echo "BRANCH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
$this->url_renderer = "http://localhost/xcharts/qr.php";
}
public function doctor($id)
{
try {
//hardcode data
$jabatan = "Penanggung Jawab Laboratorium Patologi Klinik";
$situs = "https://westerindo.com/";
$address = "Jl. Cipaku 1 No. 5 Kebayoran Baru, Jakarta Selatan ";
$perusahaan = "Perusahaan: LABORATORIUM KLINIK UTAMA WESTERINDO";
//query sql mencari nama doctor
$sql = "SELECT T_OrderHeaderPjM_DoctorID as m_doctor_id,
CONCAT(m.M_DoctorPrefix2, m.M_DoctorName, m.M_DoctorSuffix) AS doctor_name,
T_OrderHeaderPj2M_DoctorID as m_doctor_id_pj2,
CONCAT(pj2.M_DoctorPrefix2, pj2.M_DoctorName, pj2.M_DoctorSuffix) AS doctor_name_pj2
FROM
t_orderheader
JOIN
m_doctor AS m ON T_OrderHeaderPjM_DoctorID = m.M_DoctorID
AND T_OrderHeaderIsActive = 'Y'
AND M_DoctorIsActive = 'Y'
AND T_OrderHeaderID = ?
LEFT JOIN
m_doctor AS pj2 ON T_OrderHeaderPj2M_DoctorID = pj2.M_DoctorID
";
$qry = $this->db_onedev->query($sql, [$id]);
if ($qry) {
$rows = $qry->result_array();
// Variabel untuk menyimpan hasil akhir sebagai string
$output = "";
// Loop melalui hasil dan format output menjadi string
foreach ($rows as $row) {
$output .= "Nama: " . $row['doctor_name'] . "\n";
$output .= "Jabatan: " . $jabatan . "\n\n";
if (!empty($row['doctor_name_pj2'])) {
$output .= "Nama: " . $row['doctor_name_pj2'] . "\n";
$output .= "Jabatan: " . $jabatan . "\n\n";
}
}
// Tambahkan informasi tambahan ke string
$output .= "Situs web: " . $situs . "\n";
$output .= "Alamat: " . $address . "\n";
$output .= "Perusahaan: " . $perusahaan . "\n";
// 3. encapsulate in config attribute and json encode
// print_r($param);
$config = ["data" => $output];
$j_param = json_encode($config);
header("Content-Type: image/png");
// 4. post to chart renderer
echo $this->post($this->url_renderer, $j_param);
} else {
$this->sys_error_db("t_orderheader rows", $this->db_onedev);
exit;
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
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, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
'Content-Type: application/text',
'Content-Length: ' . strlen($data)
)
);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
return "ERROR Accessing QrCode : " . curl_error($ch) . "\n";
}
curl_close($ch);
return $result;
}
}