<?php
	$usuario = $_COOKIE["usuario"];
$nivel = $_COOKIE["nivel"];
if($nivel=="administrador"){$usuario="";}
    $id = $_GET["id_prestamo"];
	include_once("../header.php");
        include_once("../php/config.php");
        $sql = mysql_query("select * from cobros where id_prestamo='$id'") or die(mysql_error());
	?>

    <div class="container">
       <?php include_once("../header.php")?>  
        
		<div class="row">
			<div class="col-md-12">
			  
				<a class="btn  btn-primary mt-2" href="prestamos.php"><i class="fa fa-plus"></i> Registrar un  cobro</a>
				 <a class="btn  btn-default mt-2" href="prestamos.php?id_prestamo=<?php echo $id?>"><i class="fa fa-pencil"></i> Salir</a>
				<hr>
				<div class="table-responsive col-md-7">
					<table class="table table-sm table-borderred table-striped" data-page-length='8'>
						<theads>
							<th># Prestamo</th>
                             <th>Fecha</th>
							<th>Nombre/Apell.</th>
                            
							<th>Total pagado</th>
                            <th>Capital</th>
                            <th>Interes</th>
							<th>Accion</th>
						</thead>
						<tbody>
                                 <?php while($r=mysql_fetch_array($sql)){
                                          $id_prestamo=$r["id_prestamo"]; 
										  $id_cobro=$r["id_cobro"]; 
                                          $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 "<a href='datos_pago_prestamo.php?id_prestamo=$id_prestamo&id_cobro=$id_cobro'> Ver</a>"?>

                                
	
								
							</tr>
                                                        <?php }?>
						</tbody>
						<tfoot>
						     <th>Cant. cobros </th>
						    <th>Total cobrado</th>
                            <th>Capital cobrado</th>
                            <th>Interes cobrado</th>
						    
						    
						    <tr>
							
						         <td><?php echo decimal($c)?></td>
						        <td><?php echo decimal($monto)?></td>
                                <td><?php echo decimal($capital)?></td>
                                <td><?php echo decimal($interes)?></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>

