<?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="container-fluid">
 
<!-- Breadcrumbs-->

<!-- DataTables Example -->
<div class="card mb-3">
  <div class="card-header">
    <i class="fas fa-table"></i>
    <b>Gestão de ferias</b></div>
  <div class="card-body">
    <div class="table-responsive">
      <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
        <thead>
          <tr>
            <th>Item</th>
            <th>Nome</th>
            <th>Data de ingresso</th>
            <th>Dias de trabalho</th>
             <th>Ferias para o ano</th>
            <th>Ferias gozadas</th>
            <th>Gestao</th>

          </tr>
        </thead>
       
        <tbody>
            
          <?php 
          $item =1;
          $functionarios = $database->query("SELECT * FROM funcionarios");
          while($row = $database->fetch_assoc($functionarios)){
            
            $id = $row['id'];
            $estado = $row['status'];
            $siku = $row['data_contracto'];
            
            $nome = $row['nome'];
	  
            $now = date('Y-m-d');
           $date1=date_create($siku);
            $date2=date_create($now);
           $diff=date_diff($date1,$date2);
           
                          
              $diasTrabalho =  $diff->format("%a");
            
            
            $ferias = $database->query("SELECT SUM(numero_dias) as soma FROM ferias WHERE nome='$nome' AND ano='$ano'");
            while($total = $database->fetch_assoc($ferias)){
                $totalFerias = $total['soma'];
            }


            ?>
           <tr>   
            <td><?php echo $item++;?></td>
            <td><?php echo $row['nome'];?></td>
            <td><?php echo $row['data_contracto'];?></td>
            <td><?php echo $diasTrabalho;?></td>
            
           




                                  <!-- Button trigger modal -->
<td>30</td>

<td><?php 
if($totalFerias){
    echo $totalFerias;
}else{
    echo '0';
}
?></td>
<td><button type="button" class="btn btn-info btn-sm"><a href="gerirFereas.php?func=<?php echo $row['nome'];?>" style="text-decoration:none;color:white;"><span>Ver</span></a></button></td>
        </tr>
        
        <?php }
          
          ?>  

         
      
   
               </tbody>
      </table>
    </div>
  </div>
  <div class="card-footer small text-muted">Jonas Dinis Chambela</div>
</div>



</div>

        </div>
      </div>
      <!-- /.container-fluid -->
		  </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";?>

