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

 $numfac=$_GET["numfac"];
 $cdgpro=$_GET["cdgpro"];

$consulta1 = "SELECT * FROM facturas_compras WHERE numfac='$numfac' AND cdgpro='$cdgpro' ";
$resultado1 = $mysqli->query($consulta1);
$fila1 = $resultado1->fetch_array();

        $codfactura = $fila1["codfactura"];
        $falcal     = $fila1["falcal"];

if ($result = $mysqli->query("SELECT * FROM factulinea_compra WHERE codfactura='$codfactura'  AND PRE001 = 0  " )) {
   $filas = $result->num_rows;
   $result->close();
}

 
 if ($filas > 0 ){

 $falcal=1;
 	} 


$consulta = "SELECT * FROM web_2201 WHERE numfac='$numfac' AND cdgpro='$cdgpro'  ";
$resultado = $mysqli->query($consulta);
$row = $resultado->fetch_array();

$cdgusu   = $row["cdgusu"];
$cdgpro   = $row["cdgpro"];
$dscpro   = $row["dscpro"];
$fecfac   = $row["fecfac"];
$fecfac   = implode("-", array_reverse(explode("-", $fecfac))); 
$fecpro   = $row["fecpro"];
$fecpro   = implode("-", array_reverse(explode("-", $fecpro))); 
$numfac   = $row["numfac"];
$fecven   = $row["fecven"];
$pladia   = $row["pladia"];
$subexe   = $row["subexe"];
$subgra   = $row["subgra"];
$desfactot= $row["desfactot"];
$impfac   = $row["impfac"];
$flefac   = $row["flefac"];
$otrfac   = $row["otrfac"];
$totfac   = $row["totfac"];
$cdgtipven= $row["cdgtipven"];
$cdgtipcxp= $row["cdgtipcxp"];
$estado   = $row["estado"];
$marcaborrado = $row["borrado"];
$marcaestado  = $row["estado"];



  if ($marcaborrado == 1) { $borrado="Factura Anulada"; } else { $borrado=""; } 
					  ?> 

<html>
	<head>
		<title>Principal</title>
		<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
		<script language="javascript">
		var cursor;
		if (document.all) {
		// Está utilizando EXPLORER
		cursor='hand';
		} else {
		// Está utilizando MOZILLA/NETSCAPE
		cursor='pointer';
		}
		
		function inicio() {
			document.getElementById("formulario_lineas").submit();
		}
		
		
		//////////////////////////////////////////////   Funcion Anular Factura ///////////////////////////////

			
			
			

			
			
					function anular_factura(codfactura) {
			{
				
			var mensaje="";
	if (parseFloat(document.getElementById("salfac").value) < parseFloat ( document.getElementById("totfac").value )){ 
	  			
				
	alert("Atencion, Esta factura ya posee pagos no puede ser ANULADA su saldo actual es :\n\n"+document.getElementById("salfac").value);
		document.getElementById('bloquea').style.display='block';	
				} else {
					
		    if (confirm(" Desea anular esta factura ? ")){
			
			
		document.getElementById('bloquea').style.display='block';	   
		location.href="Anular_Factura.php?codfactura=" + codfactura;
		}
			    
			}
			}
					}	
			
			
			
	
			function cancelar() {
			location.href="index.php";
		}
		
	
	</script>
	</head>
	<body onLoad=" inicio(); ">
		<div id="">
			<div id="zonaVentanas">
         	<div class="contenidoFactura">
			   <div align="center">

			     <table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0>
							     <form id="formulario_lineas" name="formulario_lineas" method="post" action="frame_lineas_ver.php" target="frame_lineas" >	
			<input  name="marcaborrado" type="hidden"  id="marcaborrado"  value="<?php echo $marcaborrado?>" />
				<input  name="numfac" type="hidden"  id="numfac"  value="<?php echo $numfac?>" />
					<input  name="cdgpro" type="hidden"  id="cdgpro"  value="<?php echo $cdgpro	?>" />
						<input  name="codfactura2" type="hidden"  id="codfactura2"  value="<?php echo $codfactura	?>" />
								<input  name="salfac" type="hidden"  id="salfac"  value="<?php echo $salfac	?>" />
										<input  name="totfac" type="hidden"  id="totfac"  value="<?php echo $totfac?>" />
											 <input  name="aplica" type="hidden"  id="aplica"  value="" />
			
			     </form>	
						 
					   <tr>
					     <td>Proveedor</td>
					     <td><?php echo $cdgpro . " - " . $dscpro ?></td>
					     <td>&nbsp;</td>
					     <td>&nbsp;</td>
					     <td><div align="right">
		
				         <?php
						 
						 
						$query_tipoventa = "SELECT * FROM tipoventa WHERE cdgtipven='$cdgtipven' ";
                        $result = $mysqli->query($query_tipoventa);
                        $fila1 = $result->fetch_array();

     				    $cdgtipven = $fila1["dsctipven"];
    
						$query_tipocxp="SELECT * FROM tipo_cxp WHERE cdgcxp='$cdgtipcxp' ";
                        $result2 = $mysqli->query($query_tipocxp);
                        $fila2 = $result2->fetch_array();

     				    $cdgtipcxp = $fila2["dsccxp"];
					 
						
						if ($estado==0)  { 
						
						$estado=" FACTURA SIN APLICAR"; 
						
						} else { 
						
						$estado="FACTURA APLICADA";
						
						}
					  ?>
					  
				         </div></td>
					     <td><img src="../img/Symbol-Check_48x48-32.png" width="48" height="48" onClick="anular_factura(<?php echo $codfactura ?>)" border="0" onMouseOver="style.cursor=cursor" title="Anular"><img src="../img/Symbol-Delete_48x48-32.png" width="48" height="48" onClick="cancelar()" border="0" onMouseOver="style.cursor=cursor" title="Cancelar"></td>
		           </tr>
					   <tr>
					     <td>N. Factura </td>
					     <td><?php echo $numfac;?></td>
				         <td>Tipo</td>
				         <td><?php echo $cdgtipven?></td>
				         <td width="15%">Fecha Factura</td>
				         <td><?php echo $fecfac?></td>
				     </tr>
					   <tr>
						   <td width="11%" height="26">Cargada</td>
						   <td width="32%"><?php echo $cdgtipcxp;?></td>
							<td width="6%">Estado</td>
							<td width="19%"><?php echo $estado?></td>
							<td width="15%">Fecha Proceso</td>
							<td width="17%"><?php echo $fecpro?></td>
				       </tr>
					   <tr>
						   <td width="11%">&nbsp;</td>
					       <td>&nbsp;</td>
					       <td>Plazo</td>
					       <td><?php echo $pladia?></td>
					       <td>Fecha Vence </td>
					       <td><?php echo $fecven?></td>
				       </tr>
			         <br>
				     <tr>
					     <td></td>
					     <td colspan="5"></td>
				     </tr>
			     </table>
              </div>
					<table class="fuente8" width="100%" cellspacing=0 cellpadding=0 border=0 ID="Table1">
						<tr class="cabeceraTabla">
						
							<td width="8%"><span >CODIGO</span></td>
							<td width="11%"><span>CANTIDAD</span></td>
							<td width="26%"><span >DETALLE</span></td>
							<td width="8%"><span>COSTO</span></td>
							<td width="6%"><span >UT1</span></td>
							<td width="6%"><span>UT2</span></td>
							<td width="8%"><span>NORMAL</span></td>
							<td width="9%">MAYOREO</td>
							<td width="8%"><span>D.FAC</span></td>
                            <td width="8%"><span>D.PRO</span></td>
							<td width="7%"><span>MONTO</span></td>
					
						</tr>
				</table>
						<div id="lineaResultado2">
				  <iframe width="100%" height="370" id="frame_lineas" name="frame_lineas" frameborder="0">
                  <ilayer width="100%" height="335" id="frame_lineas" name="frame_lineas"></ilayer>
				  </iframe>
				</div>	
					
			  </div>
				<div id="botonBusquedaAWR">					<div align="center">
		     
		  <p>&nbsp;</p>

				        </div>
                        
                        
                   
      <div    style="display:none; position:absolute; top:10%;  left:50%;  height:15%;  width:30%; background-color:white"   id="VentanaEmergente">
           
		  <p>
        <form id="formulario_emergente" name="formulario_emergente"  >
				
			     <table class="fuente8" width="98%" cellspacing=0 cellpadding=3 border=0>
					   <tr>
					     <td colspan="27" align="center" >Factura ya fue anulada no puede ser impresa !!     Favor Verifique</td>
			       </tr>
					   <tr>
				
					    
					     <td  width="20%" align="center" >&nbsp;</td>
					     <td  width="63%" align="center"  ><input  type="botton" value="OK" id="boton"   border="0" onClick= "ocultarVentana()"  style='text-align:center;' onMouseOver="style.cursor=cursor"  /></td>
					     <td  width="17%" align="center" >&nbsp;</td>
			       </tr>
					   <tr>
					     <td colspan="12" align="center" ><input type="image" value="Botón" id="boton2"   src="../img/Symbol-Error_128x128-32.png"  width="128" height="128" border="0" onClick= "ocultarVentana()"  onMouseOver="style.cursor=cursor"  /> </td>
                         
                        
			       </tr>

                        
   <input id="codfactura" name="codfactura" value="<?php echo $codfactura?>"  onkeypress="chequearEnter(event)" type="hidden">	
							
		  </table>
		
	    </form>

</div>
                        
			   </div>
			  </div>
		  </div>
		</div>
		
			<div id="bloquea" class="cargando" style="display:none;">
	<img style="margin-left: 5%;margin-top: 15%" alt="Espere..." src="../img/procesando.gif" />
	</div>
	
	</body>
</html>
