<?php
  include VIEWPATH.'includes/new_header.php';
  ?>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  
  <?php
  include VIEWPATH.'includes/new_top_menu.php';
  include VIEWPATH.'includes/new_menu_principal.php';
  ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    
    <?php 
    include 'includes/menu_mes_conge.php';
    ?>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
            <!-- /.card -->

            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Liste de mes cong&eacute;s</h3>
              </div>
              <!-- /.card-header -->
              <div class="card-body">
              
                <div class="card card-primary card-tabs">
              <div class="card-header p-0 pt-1">
                <ul class="nav nav-tabs" id="custom-tabs-one-tab" role="tablist">
                  <li class="nav-item">
                    <a class="nav-link active" id="custom-tabs-one-home-tab" data-toggle="pill" href="#custom-tabs-one-home" role="tab" aria-controls="custom-tabs-one-home" aria-selected="true">Congés déj&agrave; demandés</a>
                  </li>
                  <li class="nav-item">
                    <a class="nav-link" id="custom-tabs-one-profile-tab" data-toggle="pill" href="#custom-tabs-one-profile" role="tab" aria-controls="custom-tabs-one-profile" aria-selected="false">Mes Crédit Congé</a>
                  </li>
                </ul>
              </div>
              <div class="card-body">
                <div class="tab-content" id="custom-tabs-one-tabContent">
                  <div class="tab-pane fade show active" id="custom-tabs-one-home" role="tabpanel" aria-labelledby="custom-tabs-one-home-tab">
                     

                    
                     <table id="example1" class="table table-bordered table-striped table-hover">
                  <thead>
                  <tr>
                    <th>Exercice</th>
                    <th>Type conge</th>
                    <th>Date Demande</th>
                    <th>Nb jours</th>
                    <th>Status</th>
                    <th></th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php

                  $status_accorde = array(2,5,8,10,11,13);
                  $status_demande = array(1,4,7);

                    foreach ($listconge as $key) 
                    {

                      

                      $conge = $this->Model->getRequeteOne('SELECT config_exercice.DESCRIPTION AS EXERCICE, conge_demande_conge.DATE_DEMANDE, conge_demande_conge.DATE_SYSTEME_DEMANDE, conge_status_conge.DESCRIPTION AS STATUS_CONGE, conge_demande_conge.NB_JOURS_DEMANDE, conge_demande_conge.NB_JOURS_ACCORDE, conge_demande_conge.DATE_DERNIER_REPOSE, config_type_conge.NOM_CONGE, conge_demande_conge.DATE_DEBUT_CONGE_DEMANDE, conge_demande_conge.DATE_FIN_CONGE_DEMANDE, conge_demande_conge.DATE_DEBUT_CONGE_ACCORDE, conge_demande_conge.DATE_FIN_CONGE_ACCORDE FROM conge_demande_conge JOIN config_exercice ON config_exercice.ID_EXERCICE = conge_demande_conge.ID_EXERCICE JOIN conge_status_conge ON conge_status_conge.STATUS_CONGE = conge_demande_conge.STATUS_CONGE JOIN config_type_conge ON config_type_conge.ID_TYPE_CONGE = conge_demande_conge.ID_TYPE_CONGE WHERE 1 AND conge_demande_conge.ID_DEMANDE_CONGE =  '.$key['ID_DEMANDE_CONGE'].'');
                      $historique = $this->Model->getRequete('SELECT DATE_TRAITEMENT, organigramme_direction.DESCRIPTION AS DIRECTION, organigramme_section.DESCRIPTION AS SECTION, organigramme_service.DESCRIPTION AS SERVICE, rh_employe.NOM, rh_employe.PRENOM, conge_status_conge.DESCRIPTION AS STATUS_CONGE, NB_JOURS_ACCORDE, COMMENTAIRE, DATE_DEBUT_CONGE_ACCORDE, DATE_FIN_CONGE_ACCORDE FROM `conge_traitement_conge` JOIN organigramme_direction ON organigramme_direction.ID_DIRECTION = conge_traitement_conge.ID_DIRECTION LEFT JOIN organigramme_section ON organigramme_section.ID_SECTION = conge_traitement_conge.ID_SERVICE LEFT JOIN organigramme_service ON organigramme_service.ID_SERVICE = conge_traitement_conge.ID_DEPARTEMENT JOIN rh_employe ON rh_employe.ID_EMPLOYE = conge_traitement_conge.ID_EMPLOYE_TRAITANT JOIN conge_status_conge ON conge_status_conge.STATUS_CONGE = conge_traitement_conge.STATUS_CONGE WHERE 1 AND conge_traitement_conge.ID_DEMANDE_CONGE =  '.$key['ID_DEMANDE_CONGE'].' ORDER BY DATE_TRAITEMENT DESC');
                      $rows ='';
                      foreach ($historique as $histo) {
                        $rows .='<tr>
                                  <td>'.$histo['DATE_TRAITEMENT'].'</td>
                                  <td>'.$histo['NOM'].' '.$histo['PRENOM'].'</td>
                                  <td>'.$histo['DIRECTION'].'</td>
                                  <td>'.$histo['SERVICE'].'</td>
                                  <td>'.$histo['SECTION'].'</td>
                                  <td>'.$histo['STATUS_CONGE'].'</td>
                                  <td>'.$histo['NB_JOURS_ACCORDE'].'</td>
                                  <td>'.$histo['DATE_DEBUT_CONGE_ACCORDE'].'</td>
                                  <td>'.$histo['DATE_FIN_CONGE_ACCORDE'].'</td>
                                  <td>'.$histo['COMMENTAIRE'].'</td>
                                </tr>';
                      }
                      if (in_array($key['STATUS_CONGE'], $status_accorde)) {
                        $back_collors="bg-success";
                        // $back_texte="Accordé";                        
                      }
                      elseif (in_array($key['STATUS_CONGE'], $status_demande)) {
                        $back_collors="bg-warning";                    
                      }
                      else{
                        $back_collors="bg-danger";
                      }
                     echo "<tr>
                     <td>".$key['EXERCICE']."</td>
                     <td>".$key['NOM_CONGE']."</td>
                     <td>".$key['DATE_SYSTEME_DEMANDE']."</td>                
                     <td>".$key['NB_JOURS_ACCORDE']."</td>
                     <td><div class='".$back_collors." color-palette'>".$key['DESCRIPTION']."</div></td>
                     <td>";

                     echo "<div class='dropdown '>
                                       <a class='btn btn-primary btn-sm dropdown-toggle' data-toggle='dropdown'>Actions
                                       <span class='caret'></span></a>
                                       <ul class='dropdown-menu dropdown-menu-right'>";

                                      echo'<li><a class="dropdown-item" data-toggle="modal" data-target="#modaldetails'.$key['ID_DEMANDE_CONGE'].'" href="#"> Details </a> </li>';
                                      echo'<li><a class="dropdown-item" data-toggle="modal" data-target="#modalhisto'.$key['ID_DEMANDE_CONGE'].'" href="#"> Historique </a> </li>';
                                                                           
                                       echo "</ul>
                                     </div>";

                     echo'<div class="modal fade" id="modaldetails'.$key['ID_DEMANDE_CONGE'].'">
        <div class="modal-dialog modal-xl">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Details du cong&eacute;</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <table class="table">
                <tr>
                  <td>Exercice</td>
                  <td><b>'.$conge['EXERCICE'].'</td>
                  <td>Type Congé</td>
                  <td><b>'.$conge['NOM_CONGE'].'</td>
                </tr>
                <tr>
                  <td>Date de demande</td>
                  <td><b>'.$conge['DATE_SYSTEME_DEMANDE'].'</td>
                  <td>Dernière réponse</td>
                  <td><b>'.$conge['DATE_DERNIER_REPOSE'].'</td>
                </tr>
                <tr>
                  <td>Date demandée</td>
                  <td><b>'.$conge['DATE_DEBUT_CONGE_DEMANDE'].' - '.$conge['DATE_FIN_CONGE_DEMANDE'].'</td>
                  <td>Nb Jours</td>
                  <td><b>'.$conge['NB_JOURS_DEMANDE'].'</td>
                </tr>
                <tr>
                  <td>Date accordée</td>
                  <td><b>'.$conge['DATE_DEBUT_CONGE_ACCORDE'].' - '.$conge['DATE_FIN_CONGE_ACCORDE'].'</td>
                  <td>Nb Jours</td>
                  <td><b>'.$conge['NB_JOURS_ACCORDE'].'</td>
                </tr>
                <tr>
                  <td>Status</td>
                  <td colspan="3"><b>'.$conge['STATUS_CONGE'].'</td>
                </tr>
              </table>

              
            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
            </div>
          </div>
        </div>
      </div>';

      echo'<div class="modal fade" id="modalhisto'.$key['ID_DEMANDE_CONGE'].'">
        <div class="modal-dialog modal-xl">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Historique de traitement de ce congé</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <table class="table">
                  <tr>
                    <td>Date de demande</td>
                    <td>Traité par</td>
                    <td>Direction</td>
                    <td>Département</td>
                    <td>Service</td>
                    <td>Status</td>
                    <td>Nb Jours Accordé</td>
                    <td>Début</td>
                    <td>Fin</td>
                    <td>Commentaire</td>
                  </tr>
                  '.$rows.'
              </table>

            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
            </div>
          </div>
        </div>
      </div>';
                     echo"</td>
                   </tr>";
                }
                  ?>
                  </tbody>
                </table>

                  </div>
                  <div class="tab-pane fade" id="custom-tabs-one-profile" role="tabpanel" aria-labelledby="custom-tabs-one-profile-tab">
                    

                    <table id="example2" class="table table-bordered table-striped table-hover">
                  <thead>
                  <tr>
                    <th>Exercice</th>
                    <th>Date debut</th>
                    <th>Date fin</th>
                    <th>Type conge</th>
                    <th>Nb jours credit&eacute;</th>
                    <th>Nb jours restants</th>
                    <th>Status</th>
                  </tr>
                  </thead>
                  <tbody>

                  <?php
                    foreach ($creditconge as $key) 
                    {

                     echo "<tr>
                     <td>".$key['EXERCICE']."</td>
                     <td>".$key['DEBUT_CREDIT']."</td>
                     <td>".$key['FIN_CREDIT']."</td>
                     <td>".$key['NOM_CONGE']."</td>
                     <td>".$key['NB_JOURS_CREDITE']."</td>
                     <td>".$key['NB_JOURS_RESTANT']."</td>
                     <td>".$key['STATUS']."</td>
                   </tr>";
                }
                  ?>
                  </tbody>
                </table>

                  </div>
                </div>
              </div>
              <!-- /.card -->
            </div>


                


                
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php
 include VIEWPATH.'includes/new_copy_footer.php';  
  ?>
  

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>

<!-- ./wrapper -->
<?php
  include VIEWPATH.'includes/new_script.php';
  ?>

<!-- Page specific script -->
<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,"ordering": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper  .col-md-6:eq(0)');
   
  });
</script>
<script>
  $(function () {
    $("#example2").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example2_wrapper  .col-md-6:eq(0)');
   
  });
</script>
</body>
</html>
