<?php
date_default_timezone_set('America/Costa_Rica');

session_start();

 $usu=$_SESSION['username'];
 

		include('../conexion.php'); 
		if($_SESSION['tipo_usu']=='a' or $_SESSION['tipo_usu']=='s' ){
		}else{
		header('location:acceso_denegado.php');
		}


$consulta = "SELECT * FROM usuarios WHERE usu='$usu'";
$resultado = $mysqli->query($consulta);
$row = $resultado->fetch_array();
$cod = $row["codusu"];


  $codmov=$_GET["codmov"];
  $codigo=$_GET["codigo"];



$consulta = "SELECT * FROM movimientos_caja WHERE codmov='$codmov' and codigo='$codigo'  ";
$resultado = $mysqli->query($consulta);
$row = $resultado->fetch_array();

$codigo = $row["codigo"];
$nombre = $row["nombre"];
$fecfac = $row["fecha"];
$fecfac = implode("-", array_reverse(explode("-", $fecfac)));  
$numdoc = $row["numdoc"];
$total  = $row["total"];
$detmov = $row["detmov"];
$tipmov = $row["tipmov"];
$cdgcaj = $row["cdgcaj"];


		$query2 =  "delete from movimientos_caja where codigo = '$codigo' AND  codmov = '$codmov'"; 
		$mysqli->query($query2);


	//************************************************ CALCULO SALDO ACTUAL  *********************************
 if ($tipmov=="VAL") { 
 

 
		 $query = "delete from web_2101 where cdgcli = '$codigo' AND  numfac = '$numdoc'"; 
		 $mysqli->query($query);
 
		$consulta = "SELECT SUM(salact) AS saldo FROM web_2101 WHERE cdgcli='$codigo' AND salact > 0 ";
		$resultado = $mysqli->query($consulta);
		$row = $resultado->fetch_array();
		$salact = $row["saldo"];
		

		
		$nuevo_saldo="UPDATE web_0301 SET  salact='$salact' WHERE cdgcli='$codigo'";
		$mysqli->query($nuevo_saldo);
 
  }
  
  
  
  	//************************************************ CALCULO SALDO A FAVOR  0301 *********************************
 if ($tipmov=="REC") { 
 

	$consulta = "SELECT SUM(salact) AS saldo FROM movimientos_caja  WHERE codigo='$codigo'  ";
    $resultado = $mysqli->query($consulta);
    $row = $resultado->fetch_array();
    $salact = $row["saldo"];


	$nuevo_saldo="UPDATE web_0301 SET  salfav='$salact' WHERE cdgcli='$codigo'";
	$mysqli->query($nuevo_saldo);

 
  }
  
  
  



 
		
		
	?>
<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="index.php";
		}
		
				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">
         DOCUMENTO ANULADO 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>


					
					