<script type="text/javascript">
function Ajax(){
var $http,$self = arguments.callee;
if (window.XMLHttpRequest) {$http = new XMLHttpRequest();}
else if (window.ActiveXObject) {
try {$http = new ActiveXObject('Msxml2.XMLHTTP');}
catch(e) {$http = new ActiveXObject('Microsoft.XMLHTTP');}
}
if ($http) {
$http.onreadystatechange = function(){
if (/4|^complete$/.test($http.readyState)) {
document.getElementById('ReloadThis').innerHTML = $http.responseText;
setTimeout(function(){$self();}, 1000);
}
};
$http.open('GET', 'expire.php' + '?' + new Date().getTime(), true);
$http.send(null);
}
}
</script>
<script type="text/javascript">setTimeout(function() {Ajax();}, 1000);</script>
<label id="ReloadThis">...</label><br>
Secara Automatis dan periodeik sistem akan membaca data order.....
jika waktu order > 10 menit system akan menginfokan ada keterlambatan pembuatan menu dan denda deh................
<?php
require_once"konmysqli.php";
$w=date("Y-m-d H:i:s");
$sql="select kode_order,tanggal_order,jam_order from `tb_order` where status_order='Konfirmasi'";
$jum=getJum($conn,$sql);
if($jum>0){
$arr=getData($conn,$sql);
foreach($arr as $d) {
$kode_order=$d["kode_order"];
$tanggal_order=$d["tanggal_order"];
$jam_order=$d["jam_order"];
if(getEXP($tanggal_order,$jam_order)==1){
echo $sql="update `tb_order` set status_order='Denda' where `kode_order`='$kode_order'";
$up=process($conn,$sql);
}
}
}//jum
echo $w;
function process($conn,$sql){
$s=false;
$conn->autocommit(FALSE);
try {
$rs = $conn->query($sql);
if($rs){
$conn->commit();
$last_inserted_id = $conn->insert_id;
$affected_rows = $conn->affected_rows;
$s=true;
}
}
catch (Exception $e) {
echo 'fail: ' . $e->getMessage();
$conn->rollback();
}
$conn->autocommit(TRUE);
return $s;
}
function getEXP($tanggal,$jam){
$awal = date_create($tanggal ." ".$jam);
$akhir = date_create(); // waktu sekarang
$diff = date_diff( $awal, $akhir );
$jummenit=$diff->i;
$kon=0;
if($jummenit>10){
$kon=1;
}
return $kon;
}
function getJum($conn,$sql){
$rs=$conn->query($sql);
$jum= $rs->num_rows;
$rs->free();
return $jum;
}
function getField($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$d= $rs->fetch_assoc();
$rs->free();
return $d;
}
function getData($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
//foreach($arr as $row) {
// echo $row['nama_kelas'] . '*<br>';
//}
$rs->free();
return $arr;
}
?>