<?php

require_once('config.php');

$_hall = $_POST['hall'];
$_table = $_POST['table'];
$_id = $_POST['id'];
$_waiter = $_POST['waiter'];

$response = array("successful" => false);

$total = odbc_fetch_array(odbc_exec($db, "SELECT total FROM Q_master_detay WHERE hall_name='$_hall' AND masa='$_table' AND sil='$_id'"));
$total = $total['total'];

$product = odbc_fetch_array(odbc_exec($db, "SELECT * FROM Q_master_detay WHERE hall_name='$_hall' AND masa='$_table' AND sil='$_id'"));

$remove_from_delete = odbc_exec($db, "DELETE FROM Q_master_delete WHERE hall_name='$_hall' AND masa='$_table' AND sil='$_id'");
$remove_from_detay = odbc_exec($db, "DELETE FROM Q_master_detay WHERE hall_name='$_hall' AND masa='$_table' AND sil='$_id'");

$waiter = odbc_fetch_array(odbc_exec($db,"SELECT * FROM Q_Userkontrol WHERE pwd='$_waiter'"));
$time = date("H:i:s");
$day = date("Y-d-m 00:00:00:000");
$log = odbc_exec($db, "INSERT INTO Q_bugs (GUN,ZAMAN,garson,username,hall_name,masa,total,sebep,URUN_ADI,ADET,deta,PCNAME) VALUES
		  ('$day','$time', '$waiter[username]', '$waiter[username]','$_hall','$_table', '$product[total]','Sil','$product[ReceteAdi]', '$product[adet]','Sil','MOBIL')");

if($remove_from_delete && $remove_from_detay){
  odbc_exec($db, "UPDATE Q_master_table SET total = total-$total, subtotal = subtotal-$total WHERE hall_name='$_hall' AND Masa='$_table'");
  $response = array("successful" => true);
}

utf8_print($response);

?>
