= '2021-12-13' and T_OrderHeaderLabNumber = ? join t_orderheaderaddon on T_OrderHeaderID = T_OrderHeaderAddOnT_OrderHeaderID join pb_upload on pbUploadCode = 'RESULT' join result_processtooffice on Result_ProcessToOfficeT_OrderHeaderID = T_OrderHeaderID and Result_ProcessToOfficeIsActive = 'Y' group by T_OrderHeaderID "; $qry = $this->db->query($sql,[$nolab]); if (!$qry) { echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]); exit; } $rows = $qry->result_array(); if (count($rows) == 0) { echo $this->db->last_query(); echo "No record"; exit; } $maxDate = $rows[0]["maxDate"]; $this->print_table_style(); $this->print_table($rows,array_keys($rows[0])); if (count($rows)>0) { $res = $this->get_report($rows[0]["T_OrderHeaderID"]); if(count($res) > 0 ) { $encDate= bin2hex($maxDate); $url_fix = "/one-api/fix/mobile_report/force/" . $encDate . "/$nolab"; echo "
"; } } } function force($encDate,$nolab) { $maxDate = hex2bin($encDate); $newMax = date("Y-m-d H:i:s", strtotime($maxDate . " - 1 hour")); $sql = "update pb_upload set pbUploadExecuted = ? where pbUploadCode ='RESULT'"; $qry = $this->db->query($sql,[$newMax]); if(!$qry){ echo "ERR : " . $this->db->error()["message"]; exit; } header("Location: /one-api/fix/mobile_report/info/$nolab"); } function get_report($headerID) { $sql = "select distinct Group_ResultID,Group_ResultName, Group_ResultFlagNonLab,IFNULL(T_EmailNonLabUrl,'-') EmailNonLabUrl, IF(T_EmailNonLabUrl IS NULL AND Group_ResultFlagNonLab = 'Y',' [Belum Pilih Format Hasil]','') temail from t_orderdetail join group_resultdetail on Group_ResultDetailT_TestID = T_OrderDetailT_TestID and T_OrderDetailIsActive = 'Y' and Group_ResultDetailIsActive = 'Y' and T_OrderDetailT_OrderHeaderID = ? join group_result on Group_ResultDetailGroup_ResultID = Group_ResultID and Group_ResultIsActive = 'Y' LEFT JOIN t_email_nonlab ON T_EmailNonLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND T_EmailNonLabType LIKE CONCAT('%',REPLACE(Group_ResultName, 'Elektromedik', 'electromedis'),'%') group by Group_ResultID"; $qry = $this->db->query($sql, [$headerID]); if (!$qry) { echo "{$this->now()} Error Ger Report : " . $this->db->error()["message"] . "|\n" . $this->db->last_query() . " \n"; return []; } $rows = $qry->result_array(); $ts = "&ts=" . date("Ymdhis"); $id = $headerID; $result = []; foreach ($rows as $r) { $xname = $r["Group_ResultName"]; $name = $this->escape_fname($xname); $gid = $r["Group_ResultID"]; $temail = $r["temail"]; $isnonlab = $r["Group_ResultFlagNonLab"]; $emailnonlaburl = str_replace(" ", "", $r["EmailNonLabUrl"]); if (strpos($emailnonlaburl, "fisik") > 0) { continue; } $report = ""; switch ($gid) { case 1: $report = "/birt/frameset?__report=report/one/lab/rpt_test_email.rptdesign&__format=pdf&username=admin&PID=" . $id . $ts; break; case 2: $report = "/birt/frameset?__report=report/one/lab/rpt_hasil_papsmear_email.rptdesign&__format=pdf&username=admin&PID=" . $id . $ts; break; case 3: $report = "/birt/frameset?__report=report/one/lab/rpt_hasil_fna_email.rptdesign&__format=pdf&username=admin&PID=" . $id . $ts; break; case 4: $report = $emailnonlaburl; break; case 5: $report = $emailnonlaburl; break; case 6: $report = $emailnonlaburl; break; case 7: $report = $emailnonlaburl; break; case 8: $report = $emailnonlaburl; break; case 9: $report = $emailnonlaburl; break; case 10: $report = $emailnonlaburl; break; case 11: $report = $emailnonlaburl; break; case 12: $report = "/birt/frameset?__report=report/one/lab/rpt_hasil_lcprep_email.rptdesign&__format=pdf&username=admin&PID=" . $id . $ts; break; case 13: $report = "/birt/frameset?__report=report/one/lab/rpt_test_mikro_email.rptdesign&__format=pdf&username=admin&PID=" . $id . $ts; break; case 14: $report = "/birt/frameset?__report=report/one/lab/rpt_hasil_cytologi_email.rptdesign&__format=pdf&username=admin&PID=" . $id . $ts; break; case 15: $report = $emailnonlaburl; break; case 16: $report = $emailnonlaburl; break; case 17: $report = $emailnonlaburl; break; } $result[] = ["Group_ResultName" => $xname, "url_rpt" => $report]; } $this->print_table($result,array_keys($result[0])); return $result; } function escape_fname($xname) { $find = [" ", "&", '\r\n', '\n', "+", ","]; $xname = str_replace($find, "-", $xname); //delete and replace rest of special chars $find = ["/[^a-zA-Z0-9\-<>]/", "/[\-]+/", "/<[^>]*>/"]; $repl = ["", "-", ""]; $xname = preg_replace($find, $repl, $xname); return $xname; } public function print_table_style() { echo " "; } public function print_table($rows, $keys) { $this->print_table_style(); echo ""; echo ""; foreach ($keys as $k) { echo ""; } echo "\n"; foreach ($rows as $r) { echo ""; foreach ($keys as $k) { echo ""; } echo ""; } echo "
$k
" . $r[$k] . "
"; } }