<?php include "includes/header.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-->
        <div class="row">
       
	   <?php
       if(isset($_GET['id']) && !empty($_GET['id'])){
		   
		   $id_cliente = $_GET['id'];
		   
		  $buscar = "SELECT * FROM creditos WHERE id='$id_cliente'";
		  $ninguem_taco = mysqli_query($con,$buscar);
		  $row = mysqli_fetch_assoc($ninguem_taco);
			  
			  $cliente = $row['cliente'];
			  
			  
			  ?>
			  
		<h2><font color='green'>Plano de amortização de</font> <font color='red'><?php echo $cliente;?></font></h2>
		
		<div class="container">
		 <div class="col-sm-4">
		  
		  <form action="" method="post">
		   <?php 
		   	 if(isset($_POST['submit_pendentes'])){
		
		      $valor = $_POST['valor'];
		     
			  
			  $user = $_SESSION['nome'];
		      $now = date('Y-m-d');
		      $hora = date("H:i", mktime(gmdate("H")+2, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d"), gmdate("Y")));
			  
			  $insere_pagamentos = "INSERT INTO pagamentos_pendentes(nome_cliente,id_credito,valor,data,hora,status)
			  VALUES('$cliente',' $id_cliente','$valor','$now','$hora','pendente')";
			  $query = mysqli_query($con,$insere_pagamentos);
			  
			  if($query){
				  
				  echo "<script>alert('Pagamento efectuado com sucesso, aguarde a confirmação do Administrador','')</script>";
				  echo "<script>window.open('pagar_2.php?id=$id_cliente','_self')</script>";
			  }else{
				  
				   echo "<script>alert('Ocorreu um erro contacte o Administrador','')</script>";
				  echo "<script>window.open('pagar_2.php?id=$id_cliente','_self')</script>";
			  }
			 
	
	
}
		   
		   
		   ?>
		   
		   <div class="form-group">
		    <label for="valor">Valor deposito</label>
			 <input type="number" name="valor" class="form-control" autocomplete="off" required/>
		   </div>
		   
		   <div class="form-group">		    
			 <input type="submit" name="submit_pendentes" class="btn btn-info btn-block" value="Pagar"/>
		   </div>
		    </form>
		  </div>
		
		</div>
		

	   
        </div>

      </div>
	  
	  
	    
				<style>
table, th, td {
  border: 1px solid black;
 
}
</style>
			
			<table>
			 <thead>
			  <tr>
			  
			   <th>Valor pago</th>
			   <th>Saldo</th>
			   <th>Data</th>
			      </tr>
			 </thead>
			 
			 <tbody>
			 <?php
			 
            $levar = "SELECT * FROM pagamentos WHERE id_pagamento='$id_cliente'";
			$conete = mysqli_query($con,$levar);
			while($row = mysqli_fetch_assoc($conete)){
			$id = $row['id'];
			$valor_pago = $row['valor_pago'];
			$saldo_pago = $row['saldo'];
			$data = $row['data'];
			$estado = $row['status'];
			$nome = $row['nome_cliente'];
			
			
			 
			 ?>
			 
			
			  <tr>
			 
			  <td><?php echo number_format($valor_pago,2,",",".");?></td>
			  <td><?php echo number_format($saldo_pago,2,",",".");?></td>
			  <td><?php echo $data;?></td>

		  
			 
			  </tr>
	   <?php }
	   
	   }?>
			 </tbody>
			 
			</table>

 
<button type="button" class="btn btn-success btn-sm"><a href="relatorio_cliente.php?id=<?php echo $id_cliente;?>"
style="text-decoration:none; color:white;"><span>Extracto</span></a></button>	
	
	
	  
	   
      <!-- /.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";?>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Page level plugin JavaScript-->
  <script src="vendor/chart.js/Chart.min.js"></script>
  <script src="vendor/datatables/jquery.dataTables.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin.min.js"></script>

  <!-- Demo scripts for this page-->
  <script src="js/demo/datatables-demo.js"></script>
  <script src="js/demo/chart-area-demo.js"></script>

</body>

</html>
