85 lines
3.0 KiB
PHP
85 lines
3.0 KiB
PHP
|
|
<?php
|
||
|
|
include("../config.php");
|
||
|
|
if(!isset($_POST['submit'])) {
|
||
|
|
$controlid = $_POST['control'];
|
||
|
|
$date = $_POST['date'];
|
||
|
|
/*
|
||
|
|
$sql = "select dr.testid, dt.name, drx.resvalue, drx.resdate as latestVal, ct.mean, ct.sd
|
||
|
|
from CONTROL_TEST ct
|
||
|
|
left join DICT_TEST dt on ct.testid=dt.id
|
||
|
|
left join (
|
||
|
|
select controlid, testid, max(resdate) as resdate from DAILY_RESULT
|
||
|
|
group by controlid, testid
|
||
|
|
) as dr on dr.controlid=ct.controlid and dr.testid=ct.testid
|
||
|
|
left join DAILY_RESULT drx on drx.controlid=dr.controlid and drx.testid=dr.testid and drx.resdate=dr.resdate
|
||
|
|
where ct.controlid='$controlid'";
|
||
|
|
*/
|
||
|
|
$sql = "select ct.testid, dt.name, ct.mean, ct.sd, dr.resvalue
|
||
|
|
from CONTROL_TEST ct
|
||
|
|
left join DICT_TEST dt on ct.testid=dt.id
|
||
|
|
full join DAILY_RESULT dr on dr.controlid=ct.controlid and dr.testid=ct.testid
|
||
|
|
and dr.resdate between '$date 00:00' and '$date 23:59'
|
||
|
|
where ct.controlid='$controlid'";
|
||
|
|
$stmt = sqlsrv_query( $conn1, $sql );
|
||
|
|
if( $stmt == false) { die( print_r( sqlsrv_errors(), true) ); }
|
||
|
|
|
||
|
|
?>
|
||
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
|
<html>
|
||
|
|
<head>
|
||
|
|
<title>QC APP</title>
|
||
|
|
<link rel="stylesheet" href="../assets/styles.css?v=<?php echo time(); ?>">
|
||
|
|
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div id='container'>
|
||
|
|
<div id='content'>
|
||
|
|
<h3><b>Tanggal</b> <?=$date;?></h3>
|
||
|
|
<table border='1'>
|
||
|
|
<form method='POST'>
|
||
|
|
<tr> <th>Test</th> <th>Value</th> <th>Mean (SD)</th>
|
||
|
|
<?php
|
||
|
|
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC ) ) {
|
||
|
|
$tid = $row[0];
|
||
|
|
$tname = $row[1];
|
||
|
|
$tmean = $row[2];
|
||
|
|
$tsd = $row[3];
|
||
|
|
$tvalue = $row[4];
|
||
|
|
echo "<tr> <td>$tname</td>
|
||
|
|
<td><input type='text' name='value[$tid]' value='$tvalue' /></td>
|
||
|
|
<td>$tmean ($tsd)</td>
|
||
|
|
</tr>";
|
||
|
|
}
|
||
|
|
?>
|
||
|
|
<tr> <td colspan='3' style='text-align:right;'> <input type='submit' name='submit' value='save' /> </td></tr>
|
||
|
|
</table>
|
||
|
|
<br/>
|
||
|
|
<input type='hidden' name='controlid' value='<?=$controlid;?>' />
|
||
|
|
<input type='hidden' name='date' value='<?=$date;?>' />
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</body>
|
||
|
|
</html>
|
||
|
|
<?php
|
||
|
|
} else {
|
||
|
|
$controlid = $_POST['controlid'];
|
||
|
|
$date = $_POST['date'];
|
||
|
|
$data = $_POST['value'];
|
||
|
|
foreach($data as $testid => $value) {
|
||
|
|
if($value != '') {
|
||
|
|
$sql = "if exists (select * from DAILY_RESULT where controlid='$controlid' and testid='$testid' and resdate='$date 00:00')
|
||
|
|
update DAILY_RESULT set resvalue='$value' where controlid='$controlid' and testid='$testid' and resdate='$date 00:00'
|
||
|
|
else
|
||
|
|
insert into DAILY_RESULT(controlid, testid, resvalue, resdate) values ('$controlid', '$testid', '$value', '$date 00:00')";
|
||
|
|
} else {
|
||
|
|
$sql = "if exists (select * from DAILY_RESULT where controlid='$controlid' and testid='$testid' and resdate='$date 00:00')
|
||
|
|
delete from DAILY_RESULT where controlid='$controlid' and testid='$testid' and resdate='$date 00:00'";
|
||
|
|
}
|
||
|
|
//echo "<pre>$sql</pre><br/>";
|
||
|
|
$stmt = sqlsrv_query( $conn1, $sql );
|
||
|
|
if( $stmt == false) { die( print_r( sqlsrv_errors(), true) ); }
|
||
|
|
}
|
||
|
|
echo "Data updated...";
|
||
|
|
}
|
||
|
|
?>
|