<?php include "includes/header.php";?>
<?php include "config/init.php";?>


<?php include "includes/navbar.php";?>

  <div id="wrapper">

    <!-- Sidebar -->
   <?php include "includes/sidebar.php";?>

    <div id="content-wrapper">

      <div class="container-fluid">

        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          <li class="breadcrumb-item">
            <a href="#">Ola</a>
          </li>
          <li class="breadcrumb-item active"><?php echo $_SESSION['nome'];?></li>
        </ol>

        <!-- Icon Cards-->




<!--SIMULADOR DE CREDITO DE ACORDO COM A POLITICA DE TRABALHO DE CADA INSTITUICAO-->


 <!-- Button to Open the Modal INICIO  -->
<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#myModal1">
  Simulador de credito
</button>

<!-- The Modal -->
<div class="modal" id="myModal1">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Simulador de credito</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        <div class="col-sm-8">	   
	    <form action="" method="post">
	      
		 <div class="form-group">
		  <label for="cliente">Nome do cliente</label>
		  <select required name="nome" class="form-control">
		   <option></option>
		   <?php buscaCliente();?>
		  </select>
		 </div>
		 
		 <div class="form-group">
		  <label for="valor">Valor</label>
		  <input type="text" name="valor" class="form-control" autocomplete="off" required/>
		 </div>

		<div class="form-group">
		  <label for="tipo">Nome do credito</label>
		  <select required name="nome_credito" class="form-control">
		   <option></option>		  	   
	    <?php $loan->GetTypeLoan();?>	   
		   </select>
		 </div>
		 
		 <div class="form-group">
		  <label for="prestacoes">Prazo</label>
		  <select required name="prazo" class="form-control">
		   <option></option>		  	   
		   <?php $loan->prestacoesLimite();?>		   
		   
		     </select>
		 </div>
	 
		  <div class="form-group">
		  <label for="salario_bruto">Salario Bruto</label>
		  <input type="number" name="salario_bruto" class="form-control" required/>
		 </div>
		 
		  <div class="form-group">
		  <label for="descontos">Descontos OIC's</label>
		  <input type="number" name="descontos_oic" class="form-control" required/>
		 </div>
		 
		 <div class="form-group">
		  <input type="submit" name="simulador" class="btn btn-info btn-block" value="Submeter"/>
		 </div>
		
		</form>	   
	   </div>
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>



<!-- FIMMMM FIMMMM -->


<?php 
if(isset($_POST['simulador'])){
    
    $nome = $_POST['nome'];
    $valor = $_POST['valor'];
    $nome_credito = $_POST['nome_credito'];
    $prazo = $_POST['prazo'];
    $salario_bruto = $_POST['salario_bruto'];
    $descontos_oic = $_POST['descontos_oic'];
    
    $tipoCredito = mysqli_query($con,"SELECT * FROM tipos_creditos WHERE nome='$nome_credito'");
	$sql = mysqli_fetch_assoc($tipoCredito);

		$taxas = $sql['taxas_de_juros'];
		$tipo = $sql['tipo_credito'];
        $taxa_esforco = $sql['taxa_esforco'];
		$prazo_maximo = $sql['prazo_maximo'];
?>
      
      <div class="container">
          <table class="table">
              <thead>
                  <tr>
                      <th>Prestacao</th>
                      <th>Capital</th>
                      <th>Juros</th>
                      <th>Total</th>
                  </tr>
              </thead>
              <tbody>
                 <?php 
                 $item=1;
                 
         $tipoCredito = mysqli_query($con,"SELECT * FROM tipos_creditos WHERE nome='$nome_credito'");
	     while($sql = mysqli_fetch_assoc($tipoCredito)){

		$taxas = $sql['taxas_de_juros'];
		$tipo = $sql['tipo_credito'];
        $taxa_esforco = $sql['taxa_esforco'];
		$prazo_maximo = $sql['prazo_maximo'];
		
		$capital = $valor / $prazo;
		
		$juros = $capital * $taxas;
		$total = $capital + $juros;
		
		for($x=1; $x <=$prazo; $x++){
                 ?> 
                  
                  
                  <tr>
                      <td><?php echo $x;?></td>
                      <td><?php echo number_format($capital,2,",",".");?></td>
                      <td><?php echo number_format($juros,2,",",".");?></td>
                      <td><?php echo number_format($total,2,",",".");?></td>
                  </tr>
                  <?php }}?>
              </tbody>
          </table>
      </div>
     <?php 
     
     }?>

</div>

        </div>
      </div>
      <!-- /.container-fluid -->
		  </div>

		 </div>
        
        
        </div>
      </div>
      

      <!-- /.container-fluid -->

      <!-- Sticky Footer -->
      <?php include "includes/footer.php";?>

    </div>
    <!-- /.content-wrapper -->

  </div>
  <!-- /#wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Logout Modal-->
 <?php include "includes/logout_modal.php";?>
 <?php include "includes/sweatscripFooter.php";?>
