
<?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
         	
	     $pendiente=2;
		 
	   $aColumns = array('numero_factura', 'estado_factura','id_cliente');//Columnas de busqueda
		 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 * from facturas where estado_factura='$pendiente'");
		$numrows = mysqli_num_rows($count_query);
		$total_pages = ceil($numrows/$per_page);
		$reload = './reportes.php';
		//main query to fetch the data
		$sql="SELECT * FROM facturas where estado_factura='$pendiente' order by id_factura 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">
		<a href="imp_ctas_cobrar.php"><button type='button' class="btn btn-info"><span class="glyphicon glyphicon-print" ></span> Imprimir</button></a>
	  </div>
		<h4><i class='glyphicon glyphicon-list'></i>  Cuentas Pagadas Proveedurias</h4>
	</div>
    <div class="panel-body" style="font-size:10px">
		
      <div class="table-responsive" align="center">
    <table class="table">
	<tr class="info">
	<td>#</strong></td> 
    <th>Proveeduria</th>
    <th>Organizacion</th>
    <th>Fecha factura</th>
	<th>Num factura</th>
	<th>Base imp</th>
	<th>Iva</th>
	<th>Total</th>
	<th>Fecha cotiz</th>
	<th>Num cotiz</th>
	<th>Despachado</th>
    </tr>
	<?php
	$item=0;
	$total=0;
	
	while ($dato=mysqli_fetch_array($query))
	{
	$cli=$dato['id_cliente'];
	$con_cliente = mysqli_query($con,"select * from clientes where id_cliente='$cli'");
	$da=mysqli_fetch_array($con_cliente);
	$tipo_cliente=$da['organizacion_cliente'];
	
	
	$dir_cliente=$da['direccion_cliente'];
	$nom_cliente=$da['nombre_cliente'];
	$fecha=$dato['fecha_factura'];
	$num=$dato['numero_factura'];
    $base=$dato['total_venta']/1.12;
	$iva=$base*0.12;
	$pro=$dato['total_venta'];
	$id=$dato['id_factura'];
	
	$con_coti = mysqli_query($con,"select * from proformas where numero_proforma='$num'");
	$dat=mysqli_fetch_array($con_coti);
	$fecha_coti=$dat['fecha_proforma'];
	
	$con_despacho = mysqli_query($con,"select * from despachos where factura='$num'");
	if(mysqli_num_rows($con_despacho)>0){
	$despachado="SI";
	}
	else{
	$despachado="NO";	
	}
	
	
	
	if($tipo_cliente=="Apoyo Institucional"){
		$item++;
    ?>		
	<tr>
    <td><?php echo $item; ?></td>
    <td><?php echo $dir_cliente; ?></td>
    <td><?php echo $nom_cliente; ?></td>
    <td><?php echo $fecha; ?></td>
    <td><?php echo $num; ?></td>
    <td><?php echo "Bsf. ".$base; ?></td>
    <td><?php echo "Bsf. ".$iva; ?></td>
    <td><?php echo "Bsf. ".$pro; ?></td>
    <td><?php echo $fecha_coti; ?></td>
    <td><?php echo $num; ?></td>
    <td><?php echo $despachado; ?></td>
    </tr>
    <?php
    $total=$total+$pro;
    }
	}
	?>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
Monto Cobrado
</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>
		</div>
        </div>	
        </div>
            