<?
require_once('../conf/connection.php');

 $numero = $_GET["numero"];
 $ventana = $_GET["ventana"];
 $mesa = $_GET["mesa"];
 
 $grupos = $_GET["grupos"];
 
 $fecha = date("Y-m-d");
 
 $hora =  date("H:i:s");

$up_mesa="UPDATE mesa SET est_mesa='2' WHERE num_mesa='$mesa' ";    
mysql_query($up_mesa, $conn) or die("Error en el query: ".mysql_error());

// NOMBRE MESA
$query_mesa="SELECT * FROM mesa WHERE num_mesa='$mesa'";
$rs_query_mesa=mysql_query($query_mesa);
$nom_mesa=mysql_result($rs_query_mesa,0,"nombre_mesa");

$query_addmesa="SELECT * FROM add_mesa WHERE pedido='$numero'";
$rs_query_addmesa=mysql_query($query_addmesa);

$nr_add=mysql_num_rows($rs_query_addmesa);
if($nr_add==0){}else{$add=mysql_result($rs_query_addmesa,0,"mesa");}

$query_mesa_add="SELECT * FROM mesa WHERE num_mesa='$add'";
$rs_query_mesa_add=mysql_query($query_mesa_add);

$nr_add_ms=mysql_num_rows($rs_query_mesa_add);
if($nr_add_ms==0){}else{$nom_mesa_add=mysql_result($rs_query_mesa_add,0,"nombre_mesa");}
//fin mesas

$query_suma="SELECT  SUM(valor_total) AS total_venta  FROM detalles_pedido WHERE numero='$numero'";
$rs_query_suma=mysql_query($query_suma);
$total_venta=mysql_result($rs_query_suma,0,"total_venta");
$propina=$total_venta*(10/100); 
$comprobar="select * from pedido where idpedido='$numero'";
 $r_ide=mysql_query($comprobar,$conn) or die("Error en el query: ".mysql_error());
 $nr_ide=mysql_num_rows($r_ide);
 

if($nr_ide==0)
{
	    $up_pedido="insert into pedido (idpedido, total_venta, fecha, hora, idmesa) 
		values ('$numero', '0','$fecha','$hora','$mesa')";    
		mysql_query($up_pedido, $conn) or die("Error en el query: ".mysql_error());	
}else{  
	}
?>
<!DOCTYPE html>

<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60745 -->
    
    <meta charset="utf-8">
    <title>SELECCION DE MESAS</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">

    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="../style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="../style.responsive.css" media="all">


    <script src="../jquery.js"></script>
    <script src="../script.js"></script>
    <script src="../script.responsive.js"></script>



<style>
.art-content .art-postcontent-0 .layout-item-0 { margin-bottom: 10px;  }
.art-content .art-postcontent-0 .layout-item-1 { border-right-style:solid;border-right-width:1px;border-right-color:#C4C6BD; padding-right: 10px;padding-left: 10px;  }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }

.table { border:2px black solid;
 border-radius:10px;
 min-width:300px;
 min-height:300px;
 font-family: Helvetica,Arial;
}
</style>
 <script type='text/javascript' src='js/jquery-1.7.1.min.js'></script>
 <script type="text/javascript" src="js/jquery-1.6.2.js"></script>
 <script src="js/jquery.Rut.js" type="text/javascript"></script>

<script>

$(document).ready(function(){
// Demo 5
$('#rut').Rut({
  on_error: function(){ alert('Rut incorrecto'); },
  format_on: 'keyup' 
});
$("#content > ul").tabs();
});

 var miPopup
				function menu(mesa){

			window.location.href = "pedido.php?mesa=" + mesa + "&numero=<? echo $num_act ?>&ventana=<? echo $ventana ?>";
		}
		
		function dia(){

			window.location.href = "funciones/dia.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		
		function agregado(){

			window.location.href = "funciones/agregado.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function ensalada(){

			window.location.href = "funciones/ensalada.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function almuerzo(){

			window.location.href = "funciones/almuerzo.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function picar(){

			window.location.href = "funciones/picar.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function postre(){

			window.location.href = "funciones/postre.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function sambuches(){

			window.location.href = "funciones/sambuches.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function cafe(){

			window.location.href = "funciones/cafe.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function bebida(){

			window.location.href = "funciones/bebida.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function jugos(){

			window.location.href = "funciones/jugos.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function cervesas(){

			window.location.href = "funciones/cervesas.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function vinos(){

			window.location.href = "funciones/vinos.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		
		function agregar(idplatos){

			window.location.href = "agregar.php?codigo=" + idplatos + "&numero=<? echo $numero ?>&mesa=<? echo $mesa ?>&ventana=<? echo $ventana ?>";
		}
		function agregar_sn(idplatos){

			window.location.href = "funciones/agre_pro_sn.php?codigo=" + idplatos + "&numero=<? echo $numero ?>&mesa=<? echo $mesa ?>&ventana=<? echo $ventana ?>";
		}
		function agr(idplatos){

			window.location.href = "agregado.php?codigo=" + idplatos + "&numero=<? echo $numero ?>&mesa=<? echo $mesa ?>&ventana=<? echo $ventana ?>";
		}
		
		function eliminar(idplatos){

			window.location.href = "funciones/eliminar.php?codigo=" + idplatos + "&numero=<? echo $numero ?>&mesa=<? echo $mesa ?>&ventana=<? echo $ventana ?>";
		}
		
		function pre(){

			window.location.href = "imprimir/imprimir.php?idpedido=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function cambio(){

			window.location.href = "funciones/cambio_mesa.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function add_mesa(){

			window.location.href = "add_m.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function cuenta(){

			window.location.href = "cto_cliente.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		
		function final(){

			window.location.href = "funciones/agre_reg_fn.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		function anular(){

			window.location.href = "funciones/anular.php?mesa=<? echo $mesa ?>&numero=<? echo $numero ?>&ventana=<? echo $ventana ?>";
		}
		
		
		
</script>
</head>
<body>
<div id="art-main">
    <div class="art-sheet clearfix">
<nav class="art-nav">
    <ul class="art-hmenu">
    <li><a>Mesas adjuntas:<? echo  $nom_mesa_add;?></a></li>
    <li><a><? echo  $nom_mesa;?></a></li>
    <li><a>PEDIDO:<? echo  $numero;?></a></li>
    </ul> 
    </nav>
<div class="art-layout-wrapper">
                <div class="art-content-layout">
                    <div class="art-content-layout-row">
                      <div class="art-layout-cell art-content"><article class="art-post art-article">
                                
                                                
                                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout-wrapper layout-item-0">
<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-1" style="width: 100%" >
        <table border="0">
  <tr>
    <td width="261"><h3><strong><center>RESTAURANT LA GUARIDA</center></strong></h3>
      <p><strong><center>DETALLES PEDIDO ACTUAL</center></strong></p></td>
    <td width="781" >
      <input type="button" class="art-button" id="dia" name="dia" value="Menu del día"
      style="height:50px; width:100px;" onClick="dia()" title="Menu del día">
      
      <input type="button" class="art-button" id="agregado" name="agregado" value="Agregados"
      style="height:50px; width:100px;" onClick="agregado()" title="Agregados">
      
      <input type="button" class="art-button" id="endalada" name="ensalada" value="Ensaladas"
      style="height:50px; width:100px;" onClick="ensalada()" title="Ensaladas">
      
      <input type="button" class="art-button" id="almuerzo" name="almuerzo" value="Almuerzos y cenas"
      style="height:50px; width:100px;" onClick="almuerzo()" title="Almuerzos y cenas">
      
      <input type="button" class="art-button" id="picar" name="picar" value="Para picar"
      style="height:50px; width:100px;" onClick="picar()" title="Para picar">
      
      <input type="button" class="art-button" id="postre" name="postre" value="Postres"
      style="height:50px; width:100px;" onClick="postre()" title="Postres">
      
      <input type="button" class="art-button" id="sambuches" name="sambuches" value="Sambuches"
      style="height:50px; width:100px;" onClick="sambuches()" title="Sambuches">
      
      <input type="button" class="art-button" id="cafe" name="cafe" value="Cafeteria"
      style="height:50px; width:100px;" onClick="cafe()" title="cafeteria">
      
      <input type="button" class="art-button" id="bebida" name="bebida" value="Bebidas CCU"
      style="height:50px; width:100px;" onClick="bebida()" title="Bebidas CCU">
      
      <input type="button" class="art-button" id="jugos" name="jugos" value="Bebidasy jugos"
      style="height:50px; width:100px;" onClick="jugos()" title="menu">
      <input type="button" class="art-button" id="cervesas" name="cervesas" value="Cervesas"
      style="height:50px; width:100px;" onClick="cervesas()" title="Cervesas">
      
      <input type="button" class="art-button" id="vinos" name="vinos" value="Vinos"
      style="height:50px; width:100px;" onClick="vinos()" title="Vinos">
    </td>
    </tr>
  <tr>
    <td>
    <div style="height:300px; width:100%;  overflow: auto;">
    <?
        $buscar='select *, SUM(cantidad) as cant, SUM(valor_total) as valor 
		from detalles_pedido where numero like \'%'.$numero.'%\'  group by idplatos';
		   $r=mysql_query($buscar,$conn) or die("Error en el query: ".mysql_error());
		   $n=mysql_num_rows($r);
		    //si hay registros los procesamos
			if($n>0)
			{
			?>
    <table  width="227" border="0">
      <tr bgcolor="#69BFE0" >
        <td width="80" bgcolor="#FFFFFF">&nbsp;</td>
        <td width="82" bgcolor="#FFFFFF"><strong>Productos</strong></td>
        <td width="66" bgcolor="#FFFFFF"><strong>Cantidad</strong></td>
        <td width="61" bgcolor="#FFFFFF"><strong>Total </strong></td>
      </tr>
      <tr bgcolor="#69BFE0" >
        <td colspan="4" bgcolor="#FFFFFF">-------------------------------------------------</td>
      </tr>
      <?
				while($row=mysql_fetch_assoc($r))
				{ //Procesamos cada registro como una fila de tabla
					?>
      <tr>
        <?
					//$row["nomCampo"] estos nomCampo son los campos devueltos por el
					//query en la variable $r que procesa mysql_fetch_assoc
					?>
        <td><img src="images/delete.png" alt="Eliminar" width="24" onClick="eliminar('<? echo $row["idplatos"] ?>')"
         height="21" ></td>
        <td><? $plato=$row["idplatos"];
					 $query="SELECT *  FROM platos WHERE idplatos='$plato'";
 					 $rs_query=mysql_query($query);$nombre=mysql_result($rs_query,0,"descrip_plato");
                     echo $nombre;
					 
					  ?>
          <? $obs=$row["obs"]; if($obs==""){}else{ ?>
          <br>
          ¬<em> <? echo $obs; } ?></em></td>
        <td align="right"><? echo $row["cant"] ?></td>
        <td align="right"><? echo $row["valor"] ?></td>
      </tr>
      <? }?>
      <tr>
        <td colspan="4">-------------------------------------------------</td>
      </tr>
      <tr>
        <td colspan="4" align="right">TOTAL A VENTA: <? echo $total_venta;  ?></td>
      </tr>
      <tr>
        <td colspan="4" >-------------------------------------------------</td>
      </tr>
    </table>
    <? } 
			else
			{
				echo "No hubieron coincidencias!";
     
			} ?>
    </div>
    
    </td>
    <td rowspan="2" >
     <div style="height:450px; width:100%;  overflow: auto;">
     <h3>Cuenta Cliente</h3>
     <form action="funciones/agre_reg.php" method="post" id="cuenta" name="cuenta">
      <input type="hidden" name="pedido" id="pedido" value="<? echo $numero ?>" >
      <input type="hidden" name="mesa" id="mesa" value="<? echo $mesa ?>" >
       <table width="657" border="0">
         <tr>
           <td width="167">RUT CLIENTE</td>
           <td colspan="3">
             <input type="text" name="rut" id="rut"></td>
         </tr>
         <tr>
           <td colspan="4"><hr></td>
         </tr>
         <tr>
           <td>TOTAL VENTA</td>
           <td colspan="3"><input type="text" name="venta" id="venta" value="<? echo $total_venta ?>"></td>
         </tr>
         <tr>
           <td>PROPINA SUGERIDA (10%)</td>
           <td colspan="3"><input type="text" name="propina" id="propina" value="<? echo $propina;  ?>"></td>
         </tr>
         <tr>
           <td>&nbsp;</td>
           <td width="262" align="right">&nbsp;</td>
           <td width="103" align="right">&nbsp;</td>
           <td width="107" align="right"><input type="submit" class="art-button" 
           id="final2" name="final2" value="Guardar" style="height:50px; width:100px;"></td>
         </tr>
       </table>
       </form>
     </div></td>
  </tr>
  <tr>
    <td >  <input type="button" class="art-button" id="final" name="final" value="Finalizar Pedido"
      style="height:50px; width:100px;" onClick="final()" title="Finalizar pedido">
      
      <input type="button" class="art-button" id="pre" name="pre" value="Precuenta"
      style="height:50px; width:100px;" onClick="pre()" title="Precuenta">
      <br>
      <input type="button" class="art-button" id="cuenta" name="cuenta" value="Cuenta Cliente"
      style="height:50px; width:100px;" onClick="cuenta()" title="cuenta">
      
      <input type="button" class="art-button" id="liberar" name="liberar" value="Anular Pedido"
      style="height:50px; width:100px;" onClick="anular()" title="liberar mesa">
      <br>
      <input type="button" class="art-button" id="juntar" name="juntar" value="Juntar Mesas"
      style="height:50px; width:100px;" onClick="add_mesa()" title="juntar">
      <input type="button" class="art-button" id="cambio" name="cambio" value="Cambiar Mesa"
      style="height:50px; width:100px;" onClick="cambio()" title="Cambiar mesa"></td>
    </tr>

  <tr>
    <td colspan="3" align="right" bgcolor="#46BBD2"> <font color="#FFFFFF" size="+4">TOTAL $<? echo 
	$format_number = number_format($total_venta, 0, ',', '.'); ?></font></td>
    </tr>
</table>
    </div>
    </div>
</div>
</div>
</div>


</article></div>
                    </div>
                </div>
            </div>

    </div>
    <p class="art-page-footer">
        <span id="art-footnote-links"><a href="http://www.virtualsurchile.cl" target="_blank">Informatica Francisco Arias E.I.R.L.</a></span>
    </p>
</div>


</body></html>