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

	include_once("header.php");
        include_once("../../php/config.php");
    $fecha1 = $_POST["fecha1"];    
    $fecha2 = $_POST["fecha2"];  
        $sql = mysql_query("select * from cobros where fecha between '$fecha1' and '$fecha2' and usuario='$usuario'") or die(mysql_error());
	?>

    <div class="container">
       <?php include_once("header.php")?>  
    
    <div class="row">
        	<div class="col-md-12">
      
        <a class="btn  btn-default mt-2" href="menu.php"><i class="fa fa-home"></i> Salir</a>
				<hr>
	</div>
	<form method="POST" action="" name="frm">
        <div class="col-md-2 mb-2">
             <input type="Date" name="fecha1" class="form-control mt-2" value="<?php echo $hoy?>">
        </div>
	    <div class="col-md-2 mb-2">       
		<input type="Date" name="fecha2" class="form-control mt-2" value="<?php echo $hoy?>">
		
        </div>
        
        <div class="col-md-2 mb-2 mt-2">       
	        <button class="btn btn-primary"> Buscar</button>
		
        </div>
    </div>
     
        
		<div class="row">
	  
			<div class="col-md-12">
			   
					
				<div class="table-responsive">
					<table class="table table-sm table-borderred" data-page-length='8'>
						<thead>
							<th># Prestamo</th>
                             <th>Fecha</th>
							<th>Nombre/Apell.</th>
                            	<th>Monto</th>
                            	<th>Capital</th>
                            	<th>Interes</th>
							<th>Aplicado por</th>
						
                            <th>Accion</th>
						</thead>
						<tbody>
                                                        <?php while($r=mysql_fetch_array($sql)){
                                          $id_cobro=$r["id_cobro"]; 
										  $id_prestamo=$r["id_prestamo"]; 
                                          $c++;
                                          $monto+=$r["total"];
                                
                                          $capital+=$r["capital"];
                                          $interes+=$r["interes"];
                                         
                                          
                                          
										  
                                          
                                                        ?>
							<tr>
								<td><?php echo $r["id_prestamo"]?></td>
								<td><?php echo fecha($r["fecha"])?></td>
								<td><?php echo $r["cliente"]?></td>
							
								<td><?php echo decimal($r["total"])?></td>
								<td><?php echo decimal($r["capital"])?></td>
								<td><?php echo decimal($r["interes"])?></td>
								<td><?php echo ($r["usuario"])?></td>
								<td><?php echo "<a href='datos_pago_prestamo.php?id_prestamo=$id_prestamo&id_cobro=$id_cobro'> Ver</a>"?>
														<?php }?>
						</tbody>
						<tfoot>
						     <th>Cant. cobros </th>
						     <th>Capital </th>
						     <th>Interes </th>
						    <th>Total</th>
						    
						  
						    <tr>
						         <td><?php echo decimal($c)?></td>
						          <td><?php echo decimal($capital)?></td>
						           <td><?php echo decimal($interes)?></td>
						        <td><?php echo "<b class='text-primary'>".decimal($monto)."</b>"?></td>
						       
						         
						       
						    </tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</form>	
        </div>

      


          
</div>
    </div>



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

