	<?php
	$usuario = $_COOKIE["usuario"];
$nivel = $_COOKIE["nivel"];
if($nivel=="administrador"){$usuario="";}

	include_once("header.php");
        include_once("../../php/config.php");
         include_once("set_mora.php");
        $sql = mysql_query("select * from prestamos where balance>1 and cobrador='$usuario' order by cliente desc") or die(mysql_error());
        
 $sql2 = mysql_query("select DISTINCT id_prestamo, cliente, balance, mora  from cuotas where vence<='$hoy' and balance>1 and cobrador='$usuario'") or die(mysql_error());

	?>
<style>

</style>
    <div class="container">
    
        
		<div class="row">
			<div class="col-md-12">
			  
				
				 <a class="btn  btn-default mt-2" href="menu.php"><i class="fa fa-pencil"></i> Salir</a>
				<hr>
				<div class="table-responsive col-md-8">
					<table class="table table-sm table-borderred table-striped" data-page-length='8'>
						<thead>
							<th># Prestamo</th>
                             
							<th width="200">Nombre/Apell.</th>
  
								<th>Cuota</th>
								<th>Mora</th>
							
                            <th>Accion</th>
						</thead>
						<tbody>
                                         <?php while($r=mysql_fetch_array($sql2)){
                                          $id_prestamo=$r["id_prestamo"]; 
                                          $c++;
                                          
                                         
                                          $balance+=$r["balance"];
                                          $mora+=$r["mora"];
                                          
                                          
                                          
                                                        ?>
							<tr>
								<td><?php echo $r["id_prestamo"]?></td>
							
								<td><?php echo $r["cliente"]?></td>
					
								<td><?php echo decimal($r["balance"])?></td>
								<td><?php echo decimal($r["mora"])?></td>
							
								
								<td>|
								 <?php echo "<a href='cobrar.php?id_prestamo=$id_prestamo'>Cobrar</a>"?></td>
							</tr>
                                                        <?php }?>
						</tbody>
						<tfoot>
						     <th>Cant. prestamos </th>
						    <th>Total prestado</th>
						    
						    <th>Total cuota</th>
						     <th>Mora</th>
						    <tr>
						         <td><?php echo decimal($c)?></td>
						        <td><?php echo decimal($prestado)?></td>
						       
						         
						        <td><?php echo decimal($balance)?></td>
						         <td text="text-danger"><?php echo decimal($mora)?></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>

