<?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
	
	
	     $aColumns = array('numero_factura', 'fecha_pago');//Columnas de busqueda
		 $sTable = "cuentas_pagadas";
		 $sWhere = "";
		 $sWhere.=" order by id_pago desc";
		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 $sTable  $sWhere");
		$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  $sTable $sWhere LIMIT $offset,$per_page";
		$query = mysqli_query($con, $sql);
		//loop through fetched data
		if ($numrows>0){
			
			?>
			<div class="table-responsive">
			  <table class="table">
				<tr  class="info">
					<td>#</strong></td> 
    <td><strong>FACTURA N°</strong></td>
    <td><strong>MONTO</strong></td>
    <td><strong>FECHA DE PAGO</strong></td>
    </tr>
				</tr>
				<?php
				$item=0;
				$total=0;
				while ($dato=mysqli_fetch_array($query)){
						$item++;
	$id=$dato['id_pago'];
	$num=$dato['numero_factura'];
	$pro=$dato['monto'];
	$fecha=$dato['fecha_pago'];												
					?>
					
					<input type="hidden" value="<?php echo $num;?>" id="num<?php echo $id_cta;?>">
					<input type="hidden" value="<?php echo $pro;?>" id="pro<?php echo $id_cta;?>">
                    <input type="hidden" value="<?php echo $fecha;?>" id="fecha<?php echo $id_cta;?>">
					<tr>
						
						<td><?php echo $item; ?></td>
    <td><?php echo $num; ?></td>
    <td><?php echo "Bsf. ".$pro; ?></td>
    <td><?php echo $fecha; ?></td>
    
		</tr>
<?php
$total=$total+$pro;
}
			
				?>
		    <tr>
<td>
</td>
<td>
Monto en Pagos Realizados
</td>
<td>
Bsf. <?php echo $total; ?>
</td>
</tr>    <?php
				}
				?>
				<tr>
					<td colspan=8><span class="pull-right">
					<?php
					 echo paginate($reload, $page, $total_pages, $adjacents);
					?></span></td>
				</tr>
			  </table>
			</div>
			