<? 

$nivel = $_GET["nivel"];

$nombrevar =$_GET["nombreuser"];

$estado =$_POST["estado"];

$rut =$_POST["identidad"];

$ano=date("Y");



$desde_ft =$_POST["desde"];

$desde=date('Y-m-d',strtotime($desde_ft));



$hasta_ft =$_POST["hasta"];

$hasta=date('Y-m-d',strtotime($hasta_ft));



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



$query2="SELECT * FROM ventas WHERE rut_clientes='$rut' and fecha BETWEEN '$desde' AND '$hasta'";

$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.close(); </script>  <? 



}else{	



$saldo="SELECT SUM(total) AS saldo FROM  ventas WHERE rut_clientes='$rut' and   fecha BETWEEN '$desde' AND '$hasta'";

$rs_query=mysql_query($saldo);

$suma=mysql_result($rs_query,0,"saldo");



?>

<!DOCTYPE html>

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

    <meta charset="utf-8">

    <title>Home</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 href="../../../style.css" rel="stylesheet" type="text/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; }



</style>



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

<script type="text/javascript" src="../js/jquery-1.6.2.js"></script>

<script type="text/javascript" src="../js/funciones/scripts.js"></script>

<link rel="stylesheet" href="../menu/styles.css" />  

 <script>

function imprimir() {

	window.open("rejilla_imprime.php?desde=<? echo $desde ?>&hasta=<? echo $hasta ?>&estado=<? echo $estado ?>&rut=<? echo $rut ?>");

	window.history.back()

}
</script>

	<script>
	 function pagar(idpedido) {
		 
	window.open("../../../caja/pago_post.php?numero=" + idpedido + "");

}
	</script>
	 <script>
	 
	 
function cerrar() {

	window.close();	

}

</script>

</head>

<body>

<div id="art-main">

    <div class="art-sheet clearfix">



<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%" >

 

       <h3>LISTADO DE VENTAS</h3>

        Rut Cliente: <? echo $rut ?> <br>

        Desde: <? echo $desde_ft ?> Hasta: <? echo $hasta_ft ?><br><br>

        

         <input type="button" id="imprime" name="Imprimir" value="Imprimir" class="art-button" 

                        onClick="imprimir()">

				        <input type="button" id="cerrar" name="cerrar" value="Cerrar ventana" class="art-button" onClick="cerrar()"><br><br>

        

  <? 



        $buscar='select * from ventas where rut_clientes like \'%'.$rut.'%\' and  fecha like \'%'.$fecha_ft.'%\'ORDER BY idpedido desc';

		   $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="586" border="0">

				<tr bgcolor="#69BFE0" >

				<td width="71">Pedido</td>

				<td width="148">Fecha</td>

				<td width="67">subtotal </td>

				<td width="56">Propina</td>

				<td width="68">Total </td>
				<td>estado</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><? echo  $row["fecha"] ?></td>

					 <td align="right"><? echo $row["subtotal"] ?></td>

					 <td align="right"><? echo $row["propina"] ?></td>

					 <td align="right"><? echo $row["total"] ?></td>
					 <td align="right"><? $est=$row["estado"];
						 				 switch ($est) {
										case 0:
											echo "PENDIENTE";
												 
										  ?> <a href="" ><img src="../../images/modificar.png" alt="Pagar" width="16" height="16" onclick="pagar('<? echo  $row["idpedido"] ?>')"  /> </a><?
												 
												 
											break;
										case 1:
											echo "PAGADO";
											break;
   									 }
						 ?></td>
					 </tr>

					

				<? }?>

                <tr>

					  <td colspan="6" align="right">Total: <? echo $suma ?></td>

				  </tr>

				</table><br>

			

<? } 

			else

			{

				echo "No hubieron coincidencias!";

     

			}} ?>

            

                                  

    </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"><a href="http://www.virtualsurchile.cl" target="_blank">Informatica Francisco Arias E.I.R.L.</a></p>

</div>





</body></html>