<?php
	
	/* Connect To Database*/
	require_once ("config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
	require_once ("config/conexion.php");//Contiene funcion que conecta a la base de datos
	
	 	include 'ajax/pagination.php'; //include pagination file
		//pagination variables
		$page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
		$per_page = 10; //how much records you want to show
		$adjacents  = 4; //gap between pages after number of adjacents
		$offset = ($page - 1) * $per_page;
		//Count the total number of row in your table*/
		$count_query   = mysqli_query($con, "SELECT count(*) AS numrows FROM compras ORDER BY cantidad DESC");
		$row= mysqli_fetch_array($count_query);
		$numrows = $row['numrows'];
		$total_pages = ceil($numrows/$per_page);
		$reload = './reportes.php';
		//main query to fetch the data
		$sql="SELECT * FROM  compras ORDER BY cantidad DESC LIMIT $offset,$per_page";
		$query = mysqli_query($con, $sql);
		//loop through fetched data
	if ($numrows>0)
	{	
	?>
	
	<div>
	<div class="panel panel-info">
		<div class="panel-heading">
        <div class="btn-group pull-right">
			</div>
			<h4><i class='glyphicon glyphicon-list'></i>  Productos mas Comprados</h4>
		</div>
		<div class="panel-body" style="font-size:10px">
		
<div class="table-responsive" align="center">
			  <table class="table">
              <tr>
              <td colspan="7" class='text-right'>
               <a href="imp_compras.php?q=<?php echo $q?>"><button type='button' class="btn btn-info"><span class="glyphicon glyphicon-print" ></span> Descargar PDF</button></a>
              </td>
              </tr>
				<tr  class="info">
    <td><strong>#</strong></td> 
    <td><strong>PROVEEDOR</strong></td>
    <td><strong>PRODUCTO</strong></td>
    <td><strong>UNIDADES</strong></td>
    <td><strong>PRECIO POR UNIDAD</strong></td>
	<td><strong>MONTO</strong></td>
    <td><strong>FECHA DE RECEPCION</strong></td>
	</tr>
  
  <?php
  $item=0;
  while ($dato=mysqli_fetch_array($query)){
	$item++;
	$pro=$dato['proveedor'];
	$consulta2=mysqli_query($con,"select * from proveedores where id_pro='$pro'");
	$dato2=mysqli_fetch_array($consulta2);
		
?>
<tr>
<td><?php echo $item; ?></td>
    <td><?php echo $dato2['nombre_proveedor']; ?></td>
    <td><?php echo $dato['producto']; ?></td>
    <td><?php echo $dato['cantidad']; ?></td>
    <td><?php echo "$. ".$dato['costo_uni']; ?></td>
	<td><?php echo "$. ".$dato['total']; ?></td>
    <td><?php echo $dato['fecha']; ?></td>
	
</tr>
<?php 
}
}
?>
	<tr>
					<td colspan=8><span class="pull-right">
					<?php
					 echo paginate($reload, $page, $total_pages, $adjacents);
					?></span></td>
				</tr>
</table>
</div>
</div>
</div>
</div>
