143 lines
4.9 KiB
PHP
143 lines
4.9 KiB
PHP
<?php
|
|
|
|
class Unit extends MY_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo '<pre>';
|
|
echo "cek [NomorLab]<br/> Untuk menampilkan list unit name";
|
|
}
|
|
public function cek($nomorlab)
|
|
{
|
|
//query TestName UnitName NatUnitName MethodeUnitName
|
|
// UnitName : UnitName yang ada di t_orderdetail
|
|
// NatUnitName : UnitName yg diambil dari T_Test
|
|
// MethodeUnitName : UnitName yg diambil dari nat_methode_unit, sesuai dengan t_orderdetail methodeID
|
|
// Action : tampilkan tombol "Fix Unit" jika UnitName <> NatUnitName atau UnitName <> MethodeUnitName
|
|
// parameter dari tombol ini adalah orderDetailID dan nomorlab
|
|
// url_fix = "/one-api/fix/unit/fix/$orderDetailID/$nomorlab"
|
|
// "<button onClick=\"document.location.href='$url_fix'\">Fix Verif Valid Race</button>";
|
|
// utk menampilkan listing bisa menggunakan fungsi print_table dengan parameter rows dari qry->result_array
|
|
|
|
$sql = "select T_OrderDetailT_TestName as test,
|
|
T_OrderDetailNat_UnitName as satuan_byorder,a.Nat_UnitName satuan_bytest, b.Nat_UnitName as satuan_bymethode,
|
|
T_OrderDetailNat_UnitID as idbyorder,a.Nat_UnitID idbytest, IFNULL(b.Nat_UnitID,0) as idbymethode,
|
|
Nat_TestID, T_OrderDetailID, T_OrderDetailNat_MethodeID
|
|
|
|
from t_orderheader
|
|
join t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
|
|
join t_test ON T_TestID = T_OrderDetailT_TestID
|
|
join nat_test ON Nat_TestID = T_TestNat_TestID
|
|
join nat_unit a ON a.Nat_UnitID = Nat_TestNat_UnitID
|
|
left join nat_methodeunit ON Nat_MethodeUnitNat_MethodeID = T_OrderDetailNat_MethodeID AND Nat_MethodeUnitNat_TestID = Nat_TestID AND Nat_MethodeUnitIsActive = 'Y'
|
|
left join nat_unit b ON b.Nat_UnitID = Nat_MethodeUnitNat_UnitID
|
|
where T_OrderHeaderIsActive = 'Y' and T_OrderHeaderLabNumber = ? order by T_OrderDetailID";
|
|
$qry = $this->db->query($sql, [$nomorlab]);
|
|
if (!$qry) {
|
|
echo "ERR : \n";
|
|
print_r($this->db->error());
|
|
exit;
|
|
}
|
|
$rows = $qry->result_array();
|
|
echo '<style>
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
}
|
|
tr:nth-child(even) {background-color: #f2f2f2;}
|
|
table {
|
|
border: solid 1px ;
|
|
min-width:600px;
|
|
}
|
|
</style>
|
|
';
|
|
echo '<table>';
|
|
echo '<tr>';
|
|
echo "<td>Test</td> <td>UnitName</td> <td>NatUnitName</td> <td>MethodeUnitName</td> <td>Aksi</td>
|
|
</tr>\n";
|
|
foreach ($rows as $r) {
|
|
echo '<tr>';
|
|
|
|
echo "<td>{$r['test']} </td> <td>{$r['satuan_byorder']}</td> <td>{$r['satuan_bytest']}</td> <td>{$r['satuan_bymethode']}</td>
|
|
";
|
|
$url_target = '/one-api/fix/unit/fix/'. $r['T_OrderDetailID'] . '/' . $nomorlab . '/' . $r['idbytest'] . '/' .$r['idbymethode'];
|
|
|
|
if($r['idbymethode'] != 0){
|
|
echo '<td>';
|
|
echo "<a type='button' target=\"_blank\" href=\"$url_target\"> Ganti satuan </a>";
|
|
echo "</td>";
|
|
// $x_note = "<pre>" . print_r($r, true) . "</pre>";
|
|
// echo "<td>$x_note</td>";
|
|
}
|
|
echo '</tr>';
|
|
}
|
|
}
|
|
function fix($orderDetailID, $nomorlab, $idbytest, $idbymethode)
|
|
{
|
|
//fix unit name dari t_orderdetail
|
|
//1. jika methodeid ada di nat_methode_unit di update berdasarkan nat_methode_unit
|
|
//2. jika 1 tidak terpenuhi, update berdasarkan t_test
|
|
//3. redirect ke cek lagi
|
|
// header("/one-api/fix/unit/")
|
|
if($idbymethode == 0){
|
|
$unitid = $idbytest;
|
|
}else{
|
|
$unitid = $idbymethode;
|
|
}
|
|
$sql = $this->db->query("SELECT Nat_UnitName as unitname FROM nat_unit WHERE Nat_UnitID = $unitid")->row();
|
|
$unitname = $sql->unitname;
|
|
$sql = "UPDATE t_orderdetail SET T_OrderDetailNat_UnitID = $unitid, T_OrderDetailNat_UnitName = '{$unitname}'
|
|
WHERE T_OrderDetailID = $orderDetailID";
|
|
$qry = $this->db->query($sql);
|
|
if (!$qry) {
|
|
echo json_encode(['status' => 'ERR', 'message' => print_r($this->db->error(), true)]);
|
|
exit;
|
|
}
|
|
|
|
echo 'update OK';
|
|
header("Location: /one-api/fix/unit/cek/".$nomorlab);
|
|
exit();
|
|
|
|
}
|
|
public function print_table_style()
|
|
{
|
|
echo "
|
|
<style>
|
|
th, td {
|
|
padding: 15px;
|
|
text-align: left;
|
|
}
|
|
tr:nth-child(even) {background-color: #f2f2f2;}
|
|
table {
|
|
border: solid 1px ;
|
|
min-width:600px;
|
|
}
|
|
</style>
|
|
";
|
|
}
|
|
public function print_table($keys)
|
|
{
|
|
$this->print_table_style();
|
|
echo "<table>";
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>$k</td>";
|
|
}
|
|
echo "</tr>\n";
|
|
foreach ($rows as $r) {
|
|
echo "<tr>";
|
|
foreach ($keys as $k) {
|
|
echo "<td>" . $r[$k] . "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
echo "</table>";
|
|
}
|
|
|
|
}
|