Files
BE_IBL/application/controllers/mockup/faktur008/Report.php
2026-04-15 15:24:12 +07:00

93 lines
3.3 KiB
PHP

<?php
class Report extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "REF RECEIVE SAMPLE API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function lookup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$search = $prm['search'];
$sql = $this->db_onedev->query("SELECT COUNT(*) as semua FROM incoming_ref_detail
WHERE incomingRefDetailIncomingRefID = '{$id}'")->row();
$semua = $sql->semua;
$sql = $this->db_onedev->query("SELECT count(*) as terima FROM incoming_ref_detail
WHERE incomingRefDetailIncomingRefID = '{$id}' AND incomingRefDetailStatus <> 'N'")->row();
// echo $sql;
$terima = $sql->terima;
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$sql = "SELECT COUNT(*) as total
FROM incoming_ref_detail
LEFT JOIN t_test ON incomingRefDetailT_TestID = T_TestID
where
incomingRefDetailIncomingRefID = '{$id}' AND
(incomingRefDetailT_OrderHeaderLabNumber LIKE CONCAT('%','{$search}','%') OR incomingRefDetailM_PatientName LIKE CONCAT('%','{$search}','%') OR T_TestName LIKE CONCAT('%','{$search}','%')) ";
//echo $sql;
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("incoming_ref_detail count", $this->db_onedev);
exit;
}
$sql = "SELECT incoming_ref_detail.*,
T_TestName,
incomingRefDetailID as id
FROM incoming_ref_detail
LEFT JOIN t_test ON incomingRefDetailT_TestID = T_TestID
where
incomingRefDetailIncomingRefID = '{$id}' AND
(incomingRefDetailT_OrderHeaderLabNumber LIKE CONCAT('%','{$search}','%') OR incomingRefDetailM_PatientName LIKE CONCAT('%','{$search}','%') OR T_TestName LIKE CONCAT('%','{$search}','%'))
GROUP BY incomingRefDetailID
ORDER BY incomingRefDetailT_OrderHeaderLabNumber ASC
limit $number_limit offset $number_offset";
// echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("incoming_ref_detail select");
exit;
}
$result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows, "semua" => $semua, "terima" => $terima);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}