<?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">
       
	   
	   <table class="table">
	    <thead>
		 <tr>
		  <th>Item</th>
		  <th>Nome do vendedor</th>
		  <th>Valor da comissão</th>
		  <th>Nome do cliente</th>
		  <th>Data</th>
		   <th>Acção</th>
		 </tr>
		</thead>
		
		<tbody>
		
		<?php
		
		 $item=1;
		 
		 if($_SESSION['nivel'] ==1 || $_SESSION['nivel']==2){
		 
         $busca_comissao = "SELECT * FROM comissoes";
		 $sim = mysqli_query($con,$busca_comissao);
          while($row = mysqli_fetch_assoc($sim)){
			  
			  $id = $row['id'];
			  $vendedor = $row['nome_gestor'];
			  $valor = $row['valor_comissao'];
			  $nome_cliente = $row['nome_cliente'];
			  $data = $row['data'];
			  $status = $row['status'];
			  
			 
			  
		   
		?>
		 
		  <tr>
		   <td><?php echo $item++;?></td>
		   <td><?php echo $vendedor;?></td>
		   <td><?php echo $valor;?></td>
		   <td><?php echo $nome_cliente;?></td>
		   <td><?php echo $data;?></td>
		   
		   <?php 
		   if($status == "pendente"){
			   ?>
			  <td><button type="submit" class="btn btn-info btn-sm"><a href="pagar_com.php?pagar=<?php echo $id;?>" 
		   style="text-decoration:none; color:white;"><span>Pagar</span></a></button></td> 
			   
		   <?php }else{
			   
			   echo "<td><font color='green'>Pago</font></td>";
		   }
		   ?>
		   
		   
		   
		  
		  </tr>
		<?php }
		
		 }else{
			 
			 $gestor = $_SESSION['nome'];
			 
			 $busca_comissao = "SELECT * FROM comissoes WHERE nome_gestor='$gestor'";
		 $sim = mysqli_query($con,$busca_comissao);
          while($row = mysqli_fetch_assoc($sim)){
			  
			  $id = $row['id'];
			  $vendedor = $row['nome_gestor'];
			  $valor = $row['valor_comissao'];
			  $nome_cliente = $row['nome_cliente'];
			  $data = $row['data'];
			  $status = $row['status'];
			  
			 
			  
		   
		?>
		 
		  <tr>
		   <td><?php echo $item++;?></td>
		   <td><?php echo $vendedor;?></td>
		   <td><?php echo $valor;?></td>
		   <td><?php echo $nome_cliente;?></td>
		   <td><?php echo $data;?></td>
		   
		   <?php 
		   if($_SESSION['nivel']==1 || $_SESSION['nivel']==2){
		   
		   if($status == "pendente"){
			   ?>
			  <td><button type="submit" class="btn btn-info btn-sm"><a href="pagar_com.php?pagar=<?php echo $id;?>" 
		   style="text-decoration:none; color:white;"><span>Pagar</span></a></button></td> 
			   
		   <?php }else{
			   
			   echo "<td><font color='green'>Pago</font></td>";
		   }
		   
		   }else{
			   
			   echo "<td>$status</td>";
		   } 
		   ?>
		   
		   
		   
		  
		  </tr>
		<?php }
			 
			 
		 }
		
		
		?>
		
		</tbody>
		
	   
	   </table>
        
        
        </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";?>

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