<?php
header('Cache-Control: no-cache');
header('Pragma: no-cache'); 
?>
<html>
<head>
<link href="../estilos/estilos.css" type="text/css" rel="stylesheet">
</head>
<script language="javascript">

function pon_prefijo(cdgcli,dscpro,combotipoventa) {
	parent.opener.document.form_busqueda.cdgcli.value=cdgcli;
	parent.opener.document.form_busqueda.dscpro.value=dscpro;
	parent.opener.buscar();
	parent.window.close();

	


}

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


//$dscpro=strtoupper($_POST["dscpro"]);

$numfac=$_POST["numfac"];
$cdgcli=$_POST["cdgcli"];



	$pagos   = 0;
	$notas   = 0;
	$cuantos = 0;

?>
<body>
<?php


		$factura = "SELECT * FROM facturas WHERE codfactura = '$numfac' ";
       $result_factura = $mysqli->query($factura);
       $row_factura = $result_factura->fetch_array();
	   $numfac =  $row_factura["numfactura"];	
	    $cdgclave =  $row_factura["cdgclave"];	
	   
	   
	   	






   if ($result = $mysqli->query("SELECT * FROM pagos_clientes_recibos_lineas  WHERE cdgcli='$cdgcli' AND numfac ='$numfac' AND borrado='0' ")) {
   $pagos = $result->num_rows;
   $result->close();
}

   if ($result = $mysqli->query("SELECT * FROM facturas_notas  WHERE cdgcli='$cdgcli' AND clanumref ='$cdgclave' AND borrado='0'")) {
   $notas = $result->num_rows;
   $result->close();
}


$cuantos = $pagos + $notas;

?>
<div id="tituloForm2" >
<form id="form1" name="form1">
<?php  if ($cuantos>0) { ?>
		<table class="fuente8" width="100%" cellspacing=0 cellpadding=3 border=0>
		  <tr class="cabeceraTabla" >
			<td width="18%"><div align="center"><span class="cabeceraTabla"><b>DOCUMENTO</b></span></div></td>
			<td width="13%"><div align="center"><span class="cabeceraTabla"><b>FECHA</b></span></div></td>
			<td width="13%"><div align="center"><span class="cabeceraTabla"><b></b></span>MONTO</div></td>
            <td width="5%"><div align="center"><span class="cabeceraTabla"><b></b></span></div></td>
            <td width="47%"><div align="center"><span class="cabeceraTabla"><b>DETALLE </b></span></div></td>
			<td width="1%"><span class="totalResultado"></span></td>
		    <td width="3%"><div align="center">
			
		  </tr>
		<?php

	
	$consulta4= "SELECT * FROM pagos_clientes_recibos_lineas  WHERE cdgcli='$cdgcli' AND numfac ='$numfac' AND borrado='0' ";
	

	
	
	
		if ($resultado4 = $mysqli->query($consulta4)) {
        $count = 0;
 
  				while ($dato4 = $resultado4->fetch_assoc()) {

				$monabonado   = number_format($dato4['monabo'], 2);
				$numrec   = $dato4['numrec'];
				
			
			
		   $recibos = "SELECT * FROM pagos_clientes WHERE numrec = '$numrec' ";
       $result_recibos = $mysqli->query($recibos);
       $row_recibos = $result_recibos->fetch_array();

	   $fecrec =  $row_recibos["fecrec"];		
	   $fecrec    = implode("-", array_reverse(explode("-", $fecrec))); 
	   $detrec =  $row_recibos["detrec"];	
	   

	 
	   
	   		
		?>
			
				            
      <tr>
        <td width="18%">  <font size=2 ><?php echo 'Recibo N° '. $numrec ?></font></td>
        <td width="13%" align="center">  <font size=2 ><?php echo $fecrec ?></font></td>
   	    <td width="13%" align="right">  <font size="2"><?php echo $monabonado ?></font></td>
        <td width="5%" align="right">  <font size=2 ></font></td>
        <td width="47%" align="left">  <font size=2 > <?php echo $detrec ?></font></td>
         <td width="1%" align="right">  <font size=2 ></font></td>

                  </tr> 
				  
	<?php 
	}
	
	 }
	 
	 
	 
	 /*****************************************************************************************************************/
	 
	/////////////////////////////////////////////   seleciona las notas a compras /////////////////////////
	
	
	$consulta4= "SELECT * FROM facturas_notas  WHERE cdgcli='$cdgcli' AND clanumref ='$cdgclave' AND borrado='0'";
	
	
	
		if ($resultado4 = $mysqli->query($consulta4)) {
	
 
  				while ($dato4 = $resultado4->fetch_assoc()) {

				
				$monabonado   = number_format($dato4['totcompro'], 2);
				$numnot   = $dato4['codnota'];
				
				$fecnot=  $dato4["fecha"];		
				$fecnot    = implode("-", array_reverse(explode("-", $fecnot))); 
				
				$detnot =  $dato4["razref"];	

	   		
		?>
			
				            
      <tr>
        <td width="18%">  <font size=2 ><?php echo 'Nota N° '. $numnot ?></font></td>
        <td width="13%" align="center">  <font size=2 ><?php echo $fecnot ?></font></td>
   	    <td width="13%" align="right">  <font size="2"><?php echo $monabonado ?></font></td>
        <td width="5%" align="right">  <font size=2 ></font></td>
        <td width="47%" align="left">  <font size="2"><?php echo $detnot ?></font></td>
        <td width="1%" align="right">  <font size=2 ></font></td>
	
                  </tr> 
				  
	<?php }?>
    
            </table>
   

  		<?php 
		
		} 
		
		} else { ?>
					<table class="fuente8" width="87%" cellspacing=0 cellpadding=3 border=0>
						<tr>
							<td width="100%" class="mensaje"><?php echo "No existen  Documentos que cumpla con los criterios de b&uacute;squeda";?></td>
					    </tr>
					</table>					
					<?php } ?>	
  
  
<iframe id="frame_datos" name="frame_datos" width="0%" height="0" frameborder="0">
	<ilayer width="0" height="0" id="frame_datos" name="frame_datos"></ilayer>
</iframe>
<input type="hidden" id="accion" name="accion">
</form>
</div>
</body>
</html>
