	<style type="text/css">
		table,td,th{
		 border:gray 1px dotted;
		 border-collapse: collapse;
	
		 
	}
	
	*{
	    font-family:Verdana;
	    font-size:14px;
	}
	</style>
	<?php

        include_once("../php/config.php");
        include_once("../php/fechas.php");
        include_once("../php/formatos.php");
       $id_prestamo = $_GET['id_prestamo'];
        mysql_query("update cuotas set mora=0 where mora<0 and id_prestamo='$id_prestamo'") or die(mysql_error());
		mysql_query("update cuotas set balance_capital=0 where balance_capital<0 and id_prestamo='$id_prestamo'") or die(mysql_error());
		mysql_query("update cuotas set balance_interes=0 where balance_interes<0 and id_prestamo='$id_prestamo'") or die(mysql_error());
		mysql_query("update cuotas set balance=mora+balance_capital+balance_interes where id_prestamo='$id_prestamo'") or die(mysql_error());
        $sql = mysql_query("select * from cuotas where id_prestamo='".$_GET['id_prestamo']."'") or die(mysql_error());
        $atrasadas = mysql_query("select * from cuotas where vence<'$hoy' and  id_prestamo='".$_GET['id_prestamo']."'") or die(mysql_error());
        $cliente = $_COOKIE["cliente"];
        $prestamo = $_COOKIE["prestamo"];
        $prestado = $_COOKIE["prestado"];
	?>


 <b>Cliente:</b> <?php echo $cliente;?> 
<b>Prestamo #:</b> <?php echo decimal($prestamo);?> 
<b>Capital prestado #:</b> <?php echo decimal($prestado);?> 
		<div class="row">
			<div class="col-md-12">
			    <h3>Cuotas</h3>
				
<div class="table-responsive">
					<table class="table table-sm table-borderred" border="1">
						<thead>
							<th># cuota</th>
                            <th>Fecha de pago</th>
                            <th>Capital pagado</th>
                            <th>Interes pagado</th>
                            <th>Total pagado</th>
                             <th>Descuento</th>
							<th>Balance capital</th>
                            <th>Balance interes </th>
                            <th>mora</th>
                           
							<th>Balance pendiente</th>
							
                         
						</thead>
						<tbody>
                           <?php while($r=mysql_fetch_array($sql)){
                           		if($r["balance"]>0.1){$c_pendiente++;$balance_pendiente+=$r["balance"];}
                           		if($r["balance"]<=0.1){$c_pagadas++;$balance_pagado+=$r["pagado"];}
                                        $mora+=$r["mora"];
                                        
                           	?>
							<tr>
								
								<td><?php echo $r["numero"]?></td>
								<td><?php echo fecha($r["vence"])?></td>
							    <td><?php echo decimal($r["capital_pagado"])?></td>
                                <td><?php echo decimal($r["interes_pagado"])?></td>
                                <td><?php echo decimal($r["pagado"])?></td>
                                 <td><?php echo decimal($r["descuento"])?></td>
								<td><?php echo decimal($r["balance_capital"])?></td>
                                <td><?php echo decimal($r["balance_interes"])?></td>
								<td><?php echo decimal($r["mora"])?></td>
								<td><?php echo decimal($r["balance"])?></td>
								
							</tr>
                                                        <?php }?>
						</tbody>
					</table>
					<?php
					while($r2=mysql_fetch_array($atrasadas)){
						$balance_vencida+=$r2["balance"];
						$vencidas.=",".$r2["numero"];
						$c_atrasadas++;
					}

					?>
					
					<br>
					<table border="0">
					<td>Cuotas pagadas:</td><td><?php echo decimal($c_pagadas)." = ".decimal($balance_pagado);?><td><tr>
					<td>Cuotas pendiente:</td><td><?php echo decimal($c_pendiente)." = ".decimal($balance_pendiente);?><td><tr>
					<td>Cuotas atrasadas:</td><td><?php echo decimal($c_atrasadas)." = ".decimal($balance_vencida);?><td><tr>
					<td>Vencidas:</td><td><?php echo decimal($vencidas);?><td><tr>
					<td>Mora:</td><td><?php echo decimal($mora);?><td><tr>
			    	</table>
                                        
				</div>
      </div>
    </div>

	
