<? 
require_once('../../conf/connection.php');
$nivel = $_GET["nivel"];
$nombrevar =$_GET["nombreuser"];

$fecha =$_POST["fecha"];
$sucu =$_POST["sucu"];
	   $query_nom="SELECT * FROM sucu WHERE codsucu='$sucu'";
	   $res_nom=mysql_query($query_nom);
	   $nom_sucu=mysql_result($res_nom,0,"nombre");
	   
$hora=date("H:i:s");
$fecha_ft=date('d-m-Y',strtotime($fecha));




//suma total de ventas boletas = "1" y faturas="2" 

$query="SELECT sum(valor_total) AS boletas FROM tp_doc  WHERE sucu='$sucu' AND tipo=1 AND fecha='$fecha'";
$rs_query=mysql_query($query);
$boletas=mysql_result($rs_query,0,"boletas");
if($boletas==""){$boletas="0";}else{}

$query="SELECT sum(valor_total) AS facturas FROM tp_doc  WHERE sucu='$sucu' AND tipo=10 AND fecha='$fecha'";
$rs_query=mysql_query($query);
$facturas=mysql_result($rs_query,0,"facturas");
if($facturas==""){$facturas="0";}else{}

$totalventa=$boletas+$facturas;

$query2="SELECT * FROM tp_doc WHERE sucu='$sucu' AND fecha='$fecha'";
$rs_query2=mysql_query($query2);

//SUMA TOTAL POR FORMA DE PAGO

// efectivo=1 | transbank (credito)=2 | transbank(debito)=3 | cuenta_cliente=4

$query="SELECT sum(valor_total) AS efectivo FROM tp_doc  WHERE sucu='$sucu' AND forma='1' AND fecha='$fecha'";
$rs_query=mysql_query($query);
$efectivo=mysql_result($rs_query,0,"efectivo");
if($efectivo==""){$efectivo="0";}else{}

$query="SELECT sum(valor_total) AS credito FROM tp_doc  WHERE sucu='$sucu' AND forma='2' AND fecha='$fecha'";
$rs_query=mysql_query($query);
$credito=mysql_result($rs_query,0,"credito");
if($credito==""){$credito="0";}else{}

$query="SELECT sum(valor_total) AS debito FROM tp_doc  WHERE sucu='$sucu' AND forma='3' AND fecha='$fecha'";
$rs_query=mysql_query($query);
$debito=mysql_result($rs_query,0,"debito");
if($debito==""){$debito="0";}else{}

$query="SELECT sum(valor_total) AS cuenta FROM tp_doc  WHERE sucu='$sucu' AND forma='4' AND fecha='$fecha'";
$rs_query=mysql_query($query);
$cuenta=mysql_result($rs_query,0,"cuenta");
if($cuenta==""){$cuenta="0";}else{}

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

//fin 

$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>
    <meta charset="utf-8">
    <title>mod_venta</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">
    <script type='text/javascript' src='../jquery-1.7.1.min.js'></script>
    <!--[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 { border-top-width:1px;border-top-style:solid;border-top-color:#B1C9C7;margin-top: 10px;margin-bottom: 10px;  }
.art-content .art-postcontent-0 .layout-item-1 { border-right-style:solid;border-right-width:1px;border-right-color:#B1C9C7; 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>

function cerrar() {
			window.close();
		}
		
</script>  
<script language="javascript">

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

function ver(numero){
			
			window.location.href="ver.php?numero="+ numero +"&sucu=<? echo $sucu ?>";
		}

function volver(){
			
			window.history.back();
		}
</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">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-1" style="width: 100%" >
       
        <p>
      
      <h3>Registro de anulación de documentos | Sucursal: <? echo $nom_sucu  ?></h3>
      <br><br>
    
        Fecha: <? echo $fecha_ft ?> Hora: <? echo $hora ?><br>
        <br>
        
        <?
        $buscar='select * from tp_doc where sucu='.$sucu.' AND tipo<>3 and fecha like \'%'.$fecha.'%\' Order by numero';
		   $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="383" >
				<tr bgcolor="#69BFE0" >
				<td width="109">Documento</td>
				<td width="62">Tipo doc</td>
				<td width="62">Obs</td>
				<td width="90">Total </td>
				<td width="38">&nbsp;</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 height="56"><? echo  $row["numero"] ?></td>
					 
					 <td align="left"><? $tipo=$row["tipo"];if($tipo==1){echo "Boleta";}else{echo "Sin doc";} ?></td>
					 <td align="left"><? echo  $row["est"] ?></td>
					 <td align="right"><? echo $row["valor_total"] ?></td>
					 <td align="right">
                     <img src="../../images/modificar.png" width="16" height="16"
                     onClick="ver('<? echo  $row["numero"] ?>')"
                     >
                     </td>
				    </tr>
				<? }?>
				</table><br>
			
			<? } 
			else
			{
				echo "No hubieron coincidencias!";
     
			}} ?>
            
            <input type="button" value="Volver atrás" class="art-button" onClick="volver()">
        </p>
    </div>
    </div>
</div>
<div class="art-content-layout-br layout-item-0">
</div></div>


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

    </div>
    
</div>


</body></html>
