<?php

header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: filename=ReporteAbonos.xls");
header("Pragma: no-cache");
header("Expires: 0");

include "../conexion.php";
$fechai=$_REQUEST["fechai"];
$fechaf=$_REQUEST["fechaf"];

		if($fechai<>"" && $fechaf<>""){$sqlfecha=" and venta_credito.fecsis between '".$fechai."' and '".$fechaf."'";}else{$sqlfecha="";}

		  $sql_datosrs=mysqli_query($conexion,"SELECT count(*) from venta_credito
									where id>=0
									$sqlfecha");
		   while($datosrs= mysqli_fetch_row($sql_datosrs)){ $contar=$datosrs[0];}
		  if($contar>=1)
		  {
			 echo "<center> <table width='100%' border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' >";
						echo "<tr>";
						echo "<td bgcolor='#E0F096'>Factura</td>";
						echo "<td bgcolor='#E0F096'>Cliente</td>";
						echo "<td bgcolor='#E0F096'>Valor</td>";
						echo "<td bgcolor='#E0F096'>Fecha</td>";
						echo "<td bgcolor='#E0F096'>Hora</td>";
						echo "</tr>";
			  
			     $sql_datospf=mysqli_query($conexion,"SELECT factura,cliente,valor,fecsis,hora from venta_credito
													  where id>=0
													  $sqlfecha");
				$c=1;$sumag=0;$sumapu=0;$sumaput=0;$sumaI=0;$sumaef=0;$sumacr=0;
				 while($datospf= mysqli_fetch_row($sql_datospf))//01
					{
					  $factura=$datospf[0];  
					  $cliente=$datospf[1];
					  $valor=$datospf[2];
					  $fecsis=$datospf[3];
					  $hora=$datospf[4];
					  
					 $ncliente="";
					 $rs_producto_familia=mysqli_query($conexion,"SELECT id,nombre FROM cliente where id='".$cliente."'");
					 while($datosrs= mysqli_fetch_row($rs_producto_familia)){ $ncliente=$datosrs[1];}
								 
					  echo "<tr>";
						  echo "																					
						  <td >$factura</td>
						  <td >$ncliente</td>
						  <td ><div align='right'>".number_format($valor)."</div></td>
						  <td >$fecsis</td>
						  <td >$hora</td>
						</tr>";
							$sumag=$sumag+$valor;	
					}//01				
				 echo "<tr >";
						  echo "																					
						  <td colspan=2><div align='right'>TOTAL ABONOS</div></td>
						  <td ><div align='right'><font size='5'><strong>".number_format($sumag)."</strong></font></div></td>
						  <td colspan=2></td>
						</tr>";
				 echo "</table></center>";
		  }
?>
