<?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">
       
	   
	  
	   
	   <div class="container">
	       <div class="col-sm-4">
	            <h3><font color="red">Juros de Mora</font></h3>
	           
	           
	           <form action="" method="post">
	               
	               <?php 
	               if(isset($_POST['submit'])){
	                   
	                   $cliente = $_POST['cliente'];
	                   $valor = $_POST['valor'];
	                   $now = date('Y-m-d');
	                   
	                   
	                   $insere_juros = "INSERT INTO juros_mora(cliente,valor,data) VALUES('$cliente','$valor','$now')";
	                   $link_it = mysqli_query($con,$insere_juros);
	                   
	                   if($link_it){
	                       
	                       echo "<script>alert('Juros de mora de $cliente no valor de $valor lanacado com successo.')</script>";
	                       echo "<script>window.open('juros_de_mora.php','_self')</script>";

	                       
	                   }else{
	                        echo "<script>alert('Ocorreu um erro.')</script>";
	                       echo "<script>window.open('juros_de_mora.php','_self')</script>";
	                       
	                   }
	                   
	                   
	                   
	               }
	               
	               ?>
	               
	               
	               
	               <div class="form-group">
	                   <label for="cliente">Nome do cliente</label>
	                   <select required name="cliente" class="form-control">
	                       <option></option>
	                   <?php buscaCliente();?>
	               </select>
	               </div>
	          
	           <div class="form-group">
	             <label for="valor">Valor</label>
	              <input type="number" name="valor" class="form-control" autocomplete="off" required/>
	           </div>
	           
	           <input type="submit" name="submit" class="btn btn-info btn-block" value="submit"/>
	               
	           </form>
	           
	           
	       </div>
	          </div>

	   </div>
	   
	   <div class="space">
	       <br><br><br>
	   </div>
	   
	   <div class="container-jonas">
	       <div class="col-sm-8">

	 <table class="table">
	     <thead>
	         <tr>
	         <th>Item</th>
	         <th>Cliente</th>
	         <th>Valor</th>
	         <th>Recibo</th>
	         <th>Apagar</th>
	          </thead>
	          </tr>
	    <tbody>
	        
	       <?php 
	       $item=1;
	       $tira = "SELECT * FROM juros_mora";
	       $liga_juros = mysqli_query($con,$tira);
	       while($row = mysqli_fetch_assoc($liga_juros)){
	       $id_juro = $row['id'];
	       ?> 
	        
	        <tr>
	          <td><?php echo $item++;?></td>   
	          <td><?php echo $row['cliente'];?></td>
	          <td><?php echo number_format($row['valor'],2,",",".");?></td>
	          <td><button type="button" class="btn btn-success btn-sm"><a href="recibo_juros.php?id_recibo=<?php echo $id_juro;?>"style='text-decoration:none; color:white;'><span>Recibo</span></a></button></td>
	          
	          <td><button type="button" class="btn btn-danger btn-sm"><a href="juros_de_mora.php?apagar=<?php echo $id_juro;?>" style='text-decoration:none; color:white;'><span>Apagar</span></a></button></td>
	        </tr>
	    <?php }  ?> 
	        
	    </tbody>
	 </table>  
          </div>
	       
	   </div>
	   
	   <div class="absolute">
	       <button type="button" class="btn btn-info btn-block"><a href="extracto_juros.php" style="text-decoration:none;color:white;"><span>Historico</span></a></button>
	   </div>
        
        
        
<?php
if(isset($_GET['apagar']) && !empty($_GET['apagar'])){
    
    $id_apagar = $_GET['apagar'];
    
    $del = "DELETE FROM juros_mora WHERE id='$id_apagar'";
    $confirm = mysqli_query($con,$del);
    
    if($confirm){
        
        echo "<script>alert('Eliminado com sucesso')</script>";
        echo "<script>window.open('juros_de_mora.php','_self')</script>";
    }else{
        
        echo "<script>alert('Ocoreu um erro')</script>";
        echo "<script>window.open('juros_de_mora.php','_self')</script>";
    }
    
}

?>        
        
        
     
     
        

      </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";?>

  <!-- 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>
