	                                                                                                                                                                                                                        
<html>
<head>
<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
</head>
<script language="javascript">

function pon_prefijo(dsccli,cedcli,cliexe,cdgcli,limcre,salact,vencido) {
	parent.vencido2(vencido);
	//parent.document.formulario_lineas.cdgbar.focus();
	parent.document.formulario.cdgclifac.value=cdgcli;
	parent.document.formulario.cedcli.value=cedcli;
	parent.document.formulario.limcre.value=limcre;
	parent.document.formulario.salact.value=salact;
	parent.document.formulario.cliexe.value=cliexe;
	parent.document.formulario.vencido.value=vencido;
	parent.document.formulario_lineas.cliexe2.value=cliexe;
	parent.document.formulario_lineas.cdgclifac2.value=cdgcli;
	parent.document.formulario_lineas.cdgart.value="";
	parent.document.formulario_lineas.dscart.value="";
	parent.document.formulario_lineas.preivi.value="";
	parent.document.formulario_lineas.importe.value="";
	parent.document.formulario_lineas.descuento.value="";
	//parent.document.formulario_lineas.cdgbar.focus();

}

function limpiar() {
	parent.document.formulario.cdgcli.focus();
	parent.document.formulario_lineas.cdgclifac2.value="";
	parent.document.formulario.cdgclifac.value="";
	parent.document.formulario.dsccli.value="";
	parent.document.formulario.cedcli.value="";
	parent.document.formulario.cdgcli.value="";
	parent.document.formulario.cliexe.value="";
	parent.document.formulario.limcre.value="";
	parent.document.formulario.salact.value="";
	parent.document.formulario.vencido.value="";
	parent.document.formulario_lineas.cdgart.value="";
	parent.document.formulario_lineas.dscart.value="";
	parent.document.formulario_lineas.preivi.value="";
	parent.document.formulario_lineas.cantidad.value="";
	parent.document.formulario_lineas.importe.value="";
	parent.document.formulario_lineas.descuento.value="";
	parent.document.formulario_lineas.cliexe.value="";

}


</script>
<?php include ("../conexion.php"); ?>
<body>
<?php

	
	$cdgcli=$_GET["cdgcli"];

	
	
	$consulta = "SELECT  Sum(salact) AS totalfac FROM web_2101 WHERE cdgcli = $cdgcli ";
    $resultado = $mysqli->query($consulta);
    $row = $resultado->fetch_array();
    $salact = $row["totalfac"];
	


	
	
			if ($sel_verificacion = $mysqli->query("SELECT codfactura FROM web_2101 WHERE cdgcli = $cdgcli AND salact > 0 LIMIT 0,1" )) 
		 $lineas = $sel_verificacion->num_rows;

					$consulta2 = "SELECT  FECVEN FROM web_2101 WHERE cdgcli = $cdgcli AND salact > 0 LIMIT 0,1";
					$resultado2 = $mysqli->query($consulta2);
					$linea = $resultado2->fetch_array();

					if ($lineas > 0) {
				
					$fecven= $linea["FECVEN"];
					$fecact= date("Y-m-d");
					$diaven=strtotime ( $fecact ) - strtotime ( $fecven );
				     $diaven=intval($diaven/60/60/24);
					if ($fecven==""){ $diaven=0; }
				
					}

		
	
$consulta3 = "SELECT ESTCLI,CDGCLI, DSCCLI , PERCON, CEDCLI, CLIEXE, LIMCRE, SALACT, CHKVER,  CDGPLA FROM web_0301 WHERE cdgcli=$cdgcli or cedcli=$cdgcli";
$resultado3 = $mysqli->query($consulta3);
$filas= $resultado3->num_rows;
$fila = $resultado3->fetch_array();
$estcli = $fila["ESTCLI"];
        $cdgcli = $fila["CDGCLI"];
        $dsccli = $fila["DSCCLI"];
        $percon = $fila["PERCON"];
        $cedcli = $fila["CEDCLI"];
		$cliexe = $fila["CLIEXE"];
		$limcre = $fila["LIMCRE"];
		$salact = $fila["SALACT"];
		$chkver = $fila["CHKVER"];
		$cdgpla = $fila["CDGPLA"];

	if ($filas>0) {
		

		if ($estcli=="ACTIVO") {
		
      		if (($chkver == 1) && ($diaven > 8)){
				$vencido=1;
				?>
				<script>
				pon_prefijo("<?php echo $dsccli ?>","<?php echo $cedcli ?>","<?php echo $cliexe ?>","<?php echo $cdgcli ?>" ,"<?php echo $limcre ?>","<?php echo $salact ?>","<?php echo $vencido ?>");	
				</script>
       			<?php 
			} else {
				$vencido=0;
				?>
    			<script languaje="javascript">
				pon_prefijo("<?php echo $dsccli ?>","<?php echo $cedcli ?>","<?php echo $cliexe ?>","<?php echo $cdgcli ?>" ,"<?php echo $limcre ?>","<?php echo $salact ?>","<?php echo $vencido ?>");	
                </script>
				<?php
		   }
		   
		   
		} else {
			 ?>
			<script>
			alert ("Cliente Inactivo favor consulte con el Administrador");
			limpiar();
			</script>
			<?php
	     }
	
	} else {
		?>
		<script>
		alert ("No existe ningun cliente con ese codigo");
		limpiar();
		</script>
		<?php
	}
	
	
?>
</div>
</body>
</html>
