<?php
//$q = intval($_GET['q']);
$q = $_GET['q'];
$r = $_GET['r'];
$s = $_GET['s'];

require_once('../../Connections/odonto_connection1.php');

$con = mysqli_connect($hostname_odonto_connection,$username_odonto_connection,$password_odonto_connection,$database_odonto_connection);
if (!$con) {die('Could not connect: ' . mysqli_error($con));}

mysqli_select_db($con,"ajax_demo");
//$sql="SELECT * FROM ingreso WHERE id_user = '".$q."'";
$sql="SELECT * FROM pedidos WHERE negocio = '".$q."' AND mesa = '".$r."' AND sucursal = '".$s."' ORDER BY id_ped ASC";
$result0 = mysqli_query($con,$sql);
$row_rs_ingreso0 = mysqli_fetch_assoc($result0);
$row_cnt = mysqli_num_rows($result0);
//$row_cnt = $row_cnt + 10;

if($row_cnt >= 1){
//	$dif=$row_cnt-$r;
//	$sql1="SELECT * FROM avisos WHERE negocio = '".$q."' AND avisado != '1' ORDER BY id_avi DESC LIMIT $dif";
//	$rs_tabla1 = mysqli_query($con,$sql1);
//	$row_rs_ingreso1 = mysqli_fetch_assoc($rs_tabla1);
	//echo "<audio src='tpir-dings.wav' preload='auto' autoplay></audio>";
$suma=0;

echo "<table class='table' ><b><font style='color:white' >";
do{
	$id_pre=$row_rs_ingreso0['cod_pre'];
	$cant=$row_rs_ingreso0['cant'];

	$sql="SELECT * FROM precios WHERE id_pre = '".$id_pre."'";
	$result = mysqli_query($con,$sql);
	$row_rs_ingreso = mysqli_fetch_assoc($result);

	$subtotal = $cant * $row_rs_ingreso['precio'];
	$suma = $subtotal + $suma;
	echo "<tr><td style='widht:200px'>".$row_rs_ingreso['menu']." ($".$row_rs_ingreso['precio'].") cant ".$cant;

	echo "<td>$ ".$subtotal;
		echo "<a href='index_precios.php?borraritem=$id_pre' style='color:white'>&nbsp;&nbsp;&nbsp;<span class='oi oi-trash' aria-hidden='true' style='color:white;width:2px'></span></a>";
		echo "</td></tr>";
	//if ($row_rs_ingreso1['audio'] == '0'){
		//echo "<audio src='http://www.qwizx.com/gssfx/usa/tpir-dings.wav' preload='auto' autoplay></audio>";
		
	//$id_avi=$row_rs_ingreso1['id_avi'];
	//$consulta2 = "UPDATE `avisos` SET `audio` = '1' WHERE `avisos`.`id_avi` = $id_avi;";
	//$resultado2 = mysqli_query( $con, $consulta2 ) or die ( "Algo ha ido mal en la consulta a la base de datos");
	//}
	
//header("Location:" . "pacientes.php");                                                                                            
}
while($row_rs_ingreso0= mysqli_fetch_assoc($result0));
	echo "</font></b></div>";
echo  "<tr><td style='text-align:right'>Total:</td><td>$ ".$suma."</td></tr>";
	echo "</table>";
}
	
mysqli_close($con);
?>
