<?
include ("../conectar.php"); 
include ("../funciones/fechas.php"); 


session_start();
	$usuario=limpiar($_SESSION['username']);
		$sqll=mysql_query("SELECT * FROM usuarios WHERE usu='$usuario'");
		if($dato=mysql_fetch_array($sqll)){
			$nombre=$dato['usu'];
			$palabra=explode(" ", $nombre);
			$nomb=$palabra[0];
			$codigo=$dato['codusu'];
			$codusu=explode(" ", $codigo);
			$cod=$codusu[0];
		}
		


 $codfactura=$_GET["codfactura"];


$query="SELECT * FROM facturas WHERE codfactura='$codfactura' ";
$rs_query=mysql_query($query);
$cdgcli=mysql_result($rs_query,0,"cdgcli");
$dsccli=mysql_result($rs_query,0,"dsccli"); 
$numfac=mysql_result($rs_query,0,"numfactura");
$cdgtipven=mysql_result($rs_query,0,"cdgtipven");



	//************************************************ Anulo en la  tabla Facturas y 2201 *********************************
 if ($cdgtipven==2) { 
 
		 $query = "delete from WEB_2101 where cdgcli = '$cdgcli' AND  numfac = '$numfac'"; 
		$result = mysql_query($query);
 
 	
		$result = mysql_query("SELECT SUM(salact) AS saldo FROM web_2101 WHERE cdgcli='$cdgcli' AND salact > 0 "); 
		$row = mysql_fetch_assoc($result); 
		$salact = $row['saldo'];
		
		$nuevo_saldo="UPDATE web_0301 SET  salact='$salact' WHERE cdgcli='$cdgcli'";
		$nuevo_saldo=mysql_query($nuevo_saldo);
 
  }

		$query2 = "delete from facturas where codfactura = '$codfactura' "; 
		$result2 = mysql_query($query2);

		
		
	?>
<html>
	<head>
		<title>Factura Nula</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<link href="../calendario/calendar-blue.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="../funciones/validar.js"></script>
		<script type="text/JavaScript" language="javascript" src="../calendario/calendar.js"></script>
		<script type="text/JavaScript" language="javascript" src="../calendario/lang/calendar-sp.js"></script>
		<script type="text/JavaScript" language="javascript" src="../calendario/calendar-setup.js"></script>
		<script language="javascript">
		var cursor;
		if (document.all) {
		// Está utilizando EXPLORER
		cursor='hand';
		} else {
		// Está utilizando MOZILLA/NETSCAPE
		cursor='pointer';
		}
		
	
	    function cancelar() {
			location.href="../Factura/index.php?cadena_busqueda=<? echo $cadena_busqueda?>";
		}
		
				function nobackbutton(){	
   window.location.hash="no-back-button";	
   window.location.hash="Again-No-back-button" //chrome	
   window.onhashchange=function(){window.location.hash="no-back-button";}	
}


		</script>








</head>
	<body onLoad="nobackbutton();">
		<div id="">
			<div id="zonaContenido">
         	<div class="contenidoFactura">
			   <div align="center">
				<div id="tituloForm" class="header">
               Factura Anulada Exitosamente 
			   </div>
			    <br> </br>
				<table width="100%" border="0">
  <tr>
    <td colspan="4">&nbsp;</td>
    </tr>
</table>

				
			    
			  </div>
				<div id="botonBusquedaAWR">					
				
				<div id="" align="center">
					<img src="../img/Symbol-Check_128x128-32.png" width="128" height="128" onClick="cancelar()" border="0" onMouseOver="style.cursor=cursor" title="Salir">
			
			  </div>
				    
			   </div>
			  </div>
		  </div>
		</div>
	</body>
</html>


					
					