	<?php
	$usuario = $_COOKIE["usuario"];
$nivel = $_COOKIE["nivel"];

if($nivel=="administrador"){$usuario="";}

	include_once("header.php");
        include_once("../../php/config.php");
        $sql = mysql_query("select prestamos.id_prestamo, prestamos.monto_prestado, prestamos.fecha_prestamo, prestamos.balance_capital, prestamos.balance_interes, prestamos.balance,clientes.cedula, clientes.telefono, clientes.nombre
            from prestamos inner join clientes on clientes.id_cliente = prestamos.id_cliente where prestamos.balance>1 and prestamos.cobrador='$usuario' order by clientes.nombre desc") or die(mysql_error());
	?>


    <div class="container">
       
        
		<div class="row mt-2">
			<div class="col-md-12">
				
				 <a class="btn  btn-default mt-2" href="menu.php"><i class="fa fa-pencil"></i> Salir</a>
				<br>
				<div class="table-responsive mt-2">
					<table class="table table-sm table-borderred table-striped" data-page-length='8'>
						<thead>
							<th># Financiamiento</th>
                             
							<th>Nombre/Apell.</th>
							
							<th>Telefono</th>
                            
							
								<th>Balance</th>
							
                     
						</thead>
						<tbody>
                                                        <?php while($r=mysql_fetch_array($sql)){
                                          $id_prestamo=$r["id_prestamo"]; 
                                          $c++;
                                          $prestado+=$r["monto_prestado"];
                                
                                          $capital+=$r["balance_capital"];
                                          $interes+=$r["balance_interes"];
                                          $balance+=$r["balance"];
                                          
                                          
                                          
                                                        ?>
							<tr>
								<td><b class='text-primary'><?php echo $r["id_prestamo"]?></b></td>
								
								<td><?php echo "<a href='cuotas.php?id=$id_prestamo'>"?><?php echo $r["nombre"]?></a></td>
								
								<td><?php echo $r["telefono"]?></td>
							
								
								<td class='text-success'><b><?php echo decimal($r["balance"])?></b></td>
								
								
								
								
							</tr>
                                                        <?php }?>
						</tbody>
						<tfoot>
						     <th><b>Cant. prestamos</b> </th>
						    <th><b>Total prestado</b></th>
						    
						    <th><b class="text-primary">BALANCE GENERAL</b></th>
						    <tr>
						         <td><?php echo decimal($c)?></td>
						       
						       
						         
						        <td class="bg-success"><b><?php echo decimal($balance)?></b></td>
						    </tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
		
        </div>

      


          
</div>
    </div>



	<?php
	include_once("footer.php");
	?>
	
	<script>
$(".table").DataTable({
	 "language": {
            "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Spanish.json"
        }
});
</script>

