<? 
$nivel = $_GET["nivel"];
$nombrevar =$_GET["nombreuser"];

$fecha_ft = $_POST["fecha"];

date_default_timezone_set("America/Buenos aires" ) ; 
$hora = date('h:i a',time() - 3600*date('I')); 



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

//suma total de ventas boletas = "2" y faturas="3" 
$query="SELECT sum(total) AS boletas FROM ventas  WHERE doc='2' AND fecha='$fecha_ft'";
$rs_query=mysql_query($query);
$boletas=mysql_result($rs_query,0,"boletas");
if($boletas==""){$boletas="0";}else{}
$query="SELECT sum(total) AS facturas FROM ventas  WHERE doc='1' AND fecha='$fecha_ft'";
$rs_query=mysql_query($query);
$facturas=mysql_result($rs_query,0,"facturas");
if($facturas==""){$facturas="0";}else{}
$totalventa=$boletas+$facturas;

//fin 

//suma total de ventas efectivo = "1" y debito="2" y cheque=3 

$query="SELECT sum(total) AS efectivo FROM ventas  WHERE f_pagos='1' AND fecha='$fecha_ft'";
$rs_query=mysql_query($query);
$efectivo=mysql_result($rs_query,0,"efectivo");
if($efectivo==""){$efectivo="0";}else{}
$query="SELECT sum(total) AS debito FROM ventas  WHERE f_pagos='2' AND fecha='$fecha_ft'";
$rs_query=mysql_query($query);
$debito=mysql_result($rs_query,0,"debito");
if($debito==""){$debito="0";}else{}

$query="SELECT sum(total) AS cheques FROM ventas  WHERE f_pagos='3' AND fecha='$fecha_ft'";
$rs_query=mysql_query($query);
$cheques=mysql_result($rs_query,0,"cheques");
if($cheques==""){$cheques="0";}else{}

$query="SELECT sum(total) AS cuenta FROM ventas  WHERE f_pagos='4' AND fecha='$fecha_ft'";
$rs_query=mysql_query($query);
$cuenta=mysql_result($rs_query,0,"cuenta");
if($cuenta==""){$cuenta="0";}else{}

$totalventa_pago=$efectivo+$debito+$cheques+$cuenta;

//fin 


$query2="SELECT * FROM ventas WHERE fecha='$fecha_ft'";
$rs_query2=mysql_query($query2);


$nr_ide2=mysql_num_rows($rs_query2);

if($nr_ide2==0){ 

    ?><script>alert("ERROR: No existen registros, verifique los datos ingresados.");window.history.back(); </script>  <? 

}else{	



?>
<!DOCTYPE html>

<html dir="ltr" lang="en-US"><head><!-- Created by Artisteer v4.3.0.60745 -->

    <meta charset="utf-8">
    <title>CIERRE DE CAJA</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 language="javascript">

function imprimir() {
	window.open("imprimir.php?fecha=<? echo $fecha ?>");
	window.history.back()
	
}
function cerrar() {
	window.close();	
}

function imp(){

			window.location.href = "imp_cierre.php?fecha=<? echo $fecha ?>";
		}

function dia(){

			window.location.href = "dia_cierre.php?fecha=<? echo $fecha ?>";
		}
</script>
</head>
<body>
<div id="art-main">
    <div class="art-sheet clearfix">
<nav class="art-nav">
    <ul class="art-hmenu"><li><a href="../index.php" class="active">INICIO</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%" >
        <div class="image-caption-wrapper" style="width: 100%">
        <h3>INFORME DE CIERRE DE CAJA</h3>
      <br><br>
    
        Fecha: <? echo $fecha_ft ?> Hora: <? echo $hora ?><br><br>
        <table width="200" border="0">
  <tr>
    <td bgcolor="#69BFE0">Docuentos</td>
    <td bgcolor="#69BFE0">Total </td>
    </tr>
  <tr>
    <td width="86">Facturas</td>
    <td width="98" align="right"><? echo $facturas ?></td>
  </tr>
  <tr>
    <td>Boletas </td>
    <td align="right"><? echo $boletas ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right"><hr></td>
  </tr>
  <tr>
    <td bgcolor="#69BFE0">Total</td>
    <td align="right" bgcolor="#69BFE0"><? echo $totalventa ?></td>
  </tr><br><br><br>
</table>
        <table width="200" border="0">
          <tr>
            <td bgcolor="#69BFE0">Tipos de pago</td>
            <td bgcolor="#69BFE0">Total </td>
          </tr>
          <tr>
            <td width="111">Efectivo</td>
            <td width="79" align="right"><? echo $efectivo ?></td>
          </tr>
          <tr>
            <td>Cheques</td>
            <td align="right"><? echo $cheques ?></td>
          </tr>
          <tr>
            <td>targeta | debito</td>
            <td align="right"><? echo $debito ?></td>
          </tr>
          <tr>
            <td>Cuenta Cliente </td>
            <td align="right"><? echo $cuenta ?></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td align="right"><hr></td>
          </tr>
          <tr>
            <td bgcolor="#69BFE0">Total</td>
            <td align="right" bgcolor="#69BFE0"><? echo $totalventa_pago ?></td>
          </tr>
        </table>
        <br>
 <?
        $buscar='select * from ventas where fecha like \'%'.$fecha_ft.'%\'';
		   $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="267" border="0">
				<tr bgcolor="#69BFE0" >
				<td width="90">Pedido</td>
				<td width="82">Mesa</td>
				<td width="81">Total </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><? echo  $row["idpedido"] ?></td>
					 <td><? $mesa=$row["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"); echo $nom_mesa;
					   ?></td>
					 <td align="right"><? echo $row["total"] ?></td>
				    </tr>
				<? }?>
				</table><br>
			
			<? } 
			else
			{
				echo "No hubieron coincidencias!";
     
			}} ?>
        
        <br>
        <input name="Imprimir" type="button" class="art-button" id="imprime" style="height:50px; width:120px;" onClick="imp()" value="Imprimir">
         <input name="dia" type="button" class="art-button" id="dia" style="height:50px; width:120px;" onClick="dia()" value="Cerrar ventas del día">
         <input name="cerrar" type="button" class="art-button" id="cerrar" style="height:50px; width:120px;" onClick="cerrar()" value="Cerrar ventana">
        </div>
    </div>
    </div>
</div>
</div>
</div>


</article></div>
                    </div>
                </div>
            </div><footer class="art-footer">
<p><br></p>
<p>Copyright © <? echo $ano; ?>. All Rights Reserved.</p>
</footer>

    </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>