<?php
include_once "../src/conexion.php";

//Conexión con el servidor
$link=ConectarseServidor();

//Conexión con la base de datos
ConectarseBaseDatos($link);

$nro_credito = $_POST['nro_credito'];

$sql = "SELECT *  FROM amortizacion WHERE num_credito = ".$nro_credito;
$mod = consultas($sql);
			
			
//					
?>
  <h2>Amortizacion del Credito No. <?php echo str_pad($nro_credito,4,"0",STR_PAD_LEFT);?></h2>
  <p>Aqui encontrara el movimiento de los pagos realizados</p>            
  <table class="table">
    <thead>
      <tr>
        <th>Cuota</th>
        <th>Valor</th>
        <th>Interes</th>
        <th>Amortizacion</th>
        <th>Capital</th>
        <th>Vencimiento</th>
        <th>Pago ?</th>
      </tr>
    </thead>
    <tbody>
    <?php
	$saldo=0;
	while($result = mysql_fetch_object($mod)){
	?>
      <tr>
        <td><?php echo number_format($result->num_cuota,0,",",".")?></td>
        <td><?php echo number_format($result->valor_cuota,0,",","."); ?></td>
        <td><?php echo number_format($result->interes,0,",","."); ?></td>
        <td><?php echo number_format($result->amortizacion_capital,0,",","."); ?></td>
        <td><?php echo number_format($result->capital,0,",","."); ?></td>
        <td><?php echo $result->vencimiento; ?></td>
        <td><?php 
		  $pago = "No";
		  $saldo=  $saldo  + $result->interes + $result->amortizacion_capital;
		  if (($result->interes == 0)&&($result->amortizacion_capital == 0))
		  {
			  $pago = "Si";
		  }
		 echo $pago; ?></td>
      </tr>      
    <?php
	}
	
	?>
     <tr>
       <td colspan="7">
	   <strong>
	   <?php 
	   if($saldo == 0)
	   {
		   $msg= "El credito se encuentra al dia";
	   }else
	   {
		   $msg= "Tiene saldo pendiente por pagar de: ".number_format($saldo,0,",",".");
	   }	   
	   echo $msg; ?></strong></td>
     </tr>
    </tbody>
  </table>