<?php
date_default_timezone_set('America/Costa_Rica');
		include('../conexion.php');
		
		session_start();
		 
		if($_SESSION['tipo_usu']=='a' or $_SESSION['tipo_usu']=='u'  or $_SESSION['tipo_usu']=='c'   or $_SESSION['tipo_usu']=='s'){
		}else{
			header('location:acceso_denegado.php');
		}


 $usu=$_SESSION['username'];
 
		
$consulta = "SELECT * FROM usuarios WHERE usu='$usu'";
$result = $mysqli->query($consulta);
$row = $result->fetch_array();
 $nomusu = $row["usu"];
 $cod = $row["codusu"];
 
 		
$accion=$_POST["accion"];
if (!isset($accion)) { $accion=$_GET["accion"]; }


$cdgcli=$_POST["cdgcli"];
$dsccli=strtoupper($_POST["dsccli"]);
$fecfac=$_POST["fecfac"];
$fecfac= implode("-", array_reverse(explode("-", $fecfac))); 
$cdgtipven=2;
$numfac=$_POST["numfac"];
$subexe=$_POST["subexe"];
$subexe = str_replace (",","",$subexe);
$subgra=$_POST["subgra"];
$subgra = str_replace (",","",$subgra);
$subfac=$subexe+$subgra;
$desfactot=$_POST["desfactot"];
$desfactot = str_replace (",","",$desfactot);
$impfac=$_POST["impfac"];
$impfac = str_replace (",","",$impfac);
//$flefac=$_POST["flefac"];
//$flefac = str_replace (",","",$flefac);
//$otrfac=$_POST["otrfac"];
//$otrfac = str_replace (",","",$otrfac);
$totfac=$_POST["totfac"];
$detpro="CXC";
$cdgusu=$cod;
	
$minimo=0;


	//************************************************ Seleción del plazo del cliente *********************************

		$query_plazo="SELECT * FROM web_0301 WHERE cdgcli='$cdgcli'";
        $resultado = $mysqli->query($query_plazo);
        $row = $resultado->fetch_array();
        $dsccli = $row["DSCCLI"];
	  	$cedcli = $row["CEDCLI"];
	    $pladia = $row["CDGPLA"];

// calculo de la fecha de vencimiento **

		$vencimiento= "+".$pladia." day" ;
		
		$fecven = strtotime ( $vencimiento , strtotime ( $fecfac ) ) ;
		$fecven = date ( 'Y-m-d' , $fecven );
	

	//************************************************ Insert 2101 CxC y proveedores  saldo actual*******************************
			

		$query_operacion1="INSERT INTO web_2101 ( fecfac,  cdgcli, dsccli, cdgven, pladia, fecven, numfac,  monsub,mondes, impvta, totnet, salact, modpro ) VALUES ('$fecfac', '$cdgcli', '$dsccli', '$cdgusu','$pladia','$fecven','$numfac','$subfac', '$desfactot','$impfac','$totfac' ,'$totfac','$detpro')";	
		$mysqli->query($query_operacion1);


		$saldo="SELECT SUM(salact) AS saldo FROM web_2101 WHERE cdgcli='$cdgcli' AND salact > 0 ";
        $result = $mysqli->query($saldo);
        $fila = $result->fetch_array();
        $salact = $fila["saldo"];

		$nuevo_saldo="UPDATE web_0301 SET  salact='$salact' WHERE cdgcli='$cdgcli'";
		$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">
               Operacion completada satisfactoriamente
			   </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>





					
					