79 lines
1.9 KiB
PHP
79 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
class ApiServiceController extends BaseController {
|
|
|
|
// // getProductList from CLQMS prodinstid
|
|
// public function getProductList() {
|
|
// $db = \Config\Database::connect();
|
|
// $sql = "SELECT pit.`prodinstid`, pit.productid, MIN(pr.resultdate) as firstdate, MAX(pr.resultdate) as lastdate FROM prodinst pit
|
|
// LEFT JOIN patres pr ON pr.prodinstid=pit.`prodinstid`";
|
|
// $query = $db->query($sql);
|
|
// $data = $query->getResultArray();
|
|
// if(count($data)==0) { $data = array('status' => 'error', 'message' => 'No data found'); }
|
|
// else {
|
|
// header('Content-Type: application/json');
|
|
// echo json_encode($data);
|
|
// }
|
|
// }
|
|
|
|
// Get Data untuk data Test
|
|
public function getPatresCount(...$segments) {
|
|
|
|
$resultsData = array();
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
// Mulai Transaksi
|
|
$db->transStart();
|
|
|
|
foreach ($segments as $value) {
|
|
|
|
if ($value == '6011310722' OR $value == '6015090124'
|
|
OR $value == '6011320722' OR $value == '6005840519'
|
|
OR $value == '6006100619' OR $value == '6015560324') {
|
|
|
|
$sql = "
|
|
SELECT
|
|
COUNT(DISTINCT p.ResultID) AS total_tests
|
|
FROM
|
|
patres p
|
|
JOIN
|
|
patrestech pt ON p.ResultID = pt.ResultID
|
|
WHERE
|
|
pt.DBField = 'REACTION_NO'
|
|
AND EquipmentID = ?
|
|
AND pt.DBValue != '0'
|
|
AND p.ResultDateTime >= DATE_SUB(NOW(), INTERVAL 6 MONTH);
|
|
";
|
|
|
|
$query = $db->query($sql, [$value]);
|
|
$data = $query->getResultArray();
|
|
$result = $data[0]['total_tests'] ?? null;
|
|
|
|
if ($result !== null) {
|
|
$resultsData[$value] = $result;
|
|
}
|
|
|
|
} else {
|
|
continue;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// Commit Transaksi
|
|
$db->transComplete();
|
|
|
|
// Set the header to JSON and return the data
|
|
header('Content-Type: application/json');
|
|
|
|
if (count($resultsData) == 0) {
|
|
echo json_encode(['status' => 'error', 'message' => 'No data found']);
|
|
} else {
|
|
return $this->response->setJSON($resultsData);
|
|
}
|
|
}
|
|
|
|
} |