<?php
  include VIEWPATH.'includes/new_header.php';
  ?>
  
<body class="hold-transition sidebar-mini">
<!-- Site wrapper -->
<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_traitement_courier.php';
    ?>

    <!-- Main content -->
    <section class="content">

      <!-- Default box -->
      <div class="card">
      
      <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Traitement du courier recu</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
                <?php 
                          if(!empty($this->session->flashdata('message')))
                             echo $this->session->flashdata('message');
            ?>
            
            
                <div class="card-body row">
                  <div class="form-group col-lg-2"> <label for="exampleInputEmail1">Type de courier : </label> </div>
                  <div class="form-group col-lg-4"> <?php echo $resultat['TYPE_COURIER']?> </div>
                  <div class="form-group col-lg-2"> <label for="exampleInputEmail1">Nature du courier : </label> </div>
                  <div class="form-group col-lg-4"><?php echo $resultat['NOM_CORRESPONDANT']?></div>
                  <div class="form-group col-lg-2">
                    <label for="exampleInputEmail1">Référence du courier : </label>  </div>
                  <div class="form-group col-lg-4"><?php echo $resultat['NUM_COURIER']?> </div>
                  <div class="form-group col-lg-2"><label for="exampleInputEmail1">Personne en copie : </label></div>
                 
                  <div class="form-group col-lg-4">
                  <?php foreach ($resultatcopie as $key => $value) {
                      echo $value['DESTINATAIRE_COPIE'].'<br>';
                    } ?>
                  </div>
                    
                   
                  
                  <div class="form-group col-lg-2">
                    <label for="exampleInputEmail1">Objet du courier : </label> </div>
                  <div class="form-group col-lg-4"><?php echo $resultat['OBJET_COURIER']?> </div>
                  <div class="form-group col-lg-2">
                    <label for="exampleInputEmail1">Date reception du courier : </label> </div>
                  <div class="form-group col-lg-4"><?php echo $resultat['DATE_TIME_ENREGISTREMENT']?> </div>
                  <div class="form-group col-lg-2">
                    <label for="exampleInputEmail1">Commentaire : </label> </div>
                  <div class="form-group col-lg-4"><?php echo $resultat['COMMENTAIRE']?> </div>
                  <div class="form-group col-lg-2">
                    <label for="exampleInputEmail1">Affectation actuel : </label> </div>
                  <div class="form-group col-lg-4"><?php echo $resultat['AFFECTATION_ACTUEL']?> </div>

                  <div class="form-group col-lg-2">
                    <label for="exampleInputEmail1">Voir documents : </label> 
                    
                    
                  </div>

                  <div class="form-group col-lg-4">
                  <button type="button" style="" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModalalldoc">
                        Documents
                      </button>
                      <div class="modal fade" id="myModalalldoc" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog modal-lg" role="document" style="max-width: 80%;">
                          <div class="modal-content">
                         
                            <div class="modal-body">
                              <?php
                        $urlpass = base_url();
                        $elementspas = explode("/", $urlpass);
                        $nouveau_urlpass = null ;
                          $indicepass = sizeof($elementspas);
                          for ($i = 0; $i < ($indicepass - 2); $i++) {
                              $nouveau_urlpass .=$elementspas[$i] . '/';
                            }

                          ?>
                          <div class="text-center"><h6>Scan du document</h6></div>

                        <embed src="<?=$nouveau_urlpass?>/uploads/scandocument/<?=$resultat['SCAN_ORIGINAL']?>" type="application/pdf" scrolling="auto" height="500px" width="100%">

                            </div>
                            <div class="modal-footer">
                              <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                            </div>
                          </div>
                        </div>
                      </div>
                
                </div>
                <div class="form-group col-lg-12 text-center">
                    <label for="exampleInputEmail1">Historique de traitement</label> 
                  </div> 
                  <div class="form-group col-lg-12">
                  <table id="example1" class="table table-bordered table-striped table-hover">
                  <thead>
                  <tr>
                    <th>Date Traitement</th>
                    <th>Avis</th>
                    <th>Traitant</th>
                    <!-- <th>Attachement</th> -->
                    <th>Commentaire</th>
                    <th>Personnel Designe</th>
                    <th>En copie</th>
                    <th>Deadline</th>
                    <th>Fichier</th>
                    <!-- <th></th> -->
                    
                  </tr>
                  </thead>
                  <tbody>

                  <?php
                    foreach ($historique as $key) 
                    {
                       
                      $urlpass = base_url();
                      $elementspas = explode("/", $urlpass);
                      $nouveau_urlpass = null ;
                        $indicepass = sizeof($elementspas);
                        for ($i = 0; $i < ($indicepass - 2); $i++) {
                            $nouveau_urlpass .=$elementspas[$i] . '/';
                          }
                          if ($key['ATTACHEMENT'] != NULL) {
                            $buttons = "<button type='button' class='btn btn-primary btn-xs' data-toggle='modal' data-target='#myModalDoc".$key['ID_COURIER_HISTORIQUE']."'>
                        Attachement
                      </button>";
                          }
                          else{
                            $buttons = '';
                          }
                          
                          $list = $this->Model->getRequete('SELECT rh_employe.NOM, rh_employe.PRENOM FROM `cour_courier_en_copie_traitement` JOIN rh_employe ON rh_employe.ID_EMPLOYE = cour_courier_en_copie_traitement.ID_RH_COPIE WHERE ID_COURIER_HISTORIQUE = '.$key['ID_COURIER_HISTORIQUE'].'');
                          $lcopie ='';
                          foreach ($list as $encopie) {
                            $lcopie .=$encopie['NOM'].' '.$encopie['PRENOM'].'<br>';
                          }


                          $encopie = "<button type='button' class='btn btn-primary btn-xs' data-toggle='modal' data-target='#myModalCopie".$key['ID_COURIER_HISTORIQUE']."'>
                        En copie
                      </button>
                      <div class='modal fade' id='myModalCopie".$key['ID_COURIER_HISTORIQUE']."' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>
                        <div class='modal-dialog' role='document'>
                          <div class='modal-content'>
                         
                            <div class='modal-body'>
                          <div class='text-center'><h6>Personne en copie</h6></div>

                        ".$lcopie."

                            </div>
                            <div class='modal-footer'>
                              <button type='button' class='btn btn-default' data-dismiss='modal'>Fermer</button>
                            </div>
                          </div>
                        </div>
                      </div>";
                    $date_enregistrement = $key['DATE_TRAITEMENT'];
                    $date_formattee = date('h:i d/m/Y', strtotime($date_enregistrement));

                    $date_traitement= $key['DEADLINE'];
                    $date_fo_traitement = date('h:i d/m/Y', strtotime($date_traitement));
                     echo "<tr>
                     <td>".$date_formattee."</td>
                     <td>".$key['ID_STATUS_COURIER']."</td>
                     <td>".$key['ID_RH_TRAITANT']."</td>
                     <td>".$key['COMMENTAIRE']."</td>
                     <td>".$key['PERSONNEL_DESIGNE']."</td>
                     <td>".$encopie."</td>
                     <td>".$date_fo_traitement."</td>
                     <td>
                     ".$buttons."
                      <div class='modal fade' id='myModalDoc".$key['ID_COURIER_HISTORIQUE']."' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'>
                        <div class='modal-dialog modal-lg' role='document' style='max-width: 80%;'>
                          <div class='modal-content'>
                         
                            <div class='modal-body'>
                          <div class='text-center'><h6>Scan du document</h6></div>

                        <embed src='".$nouveau_urlpass."/uploads/scandocument/".$key['ATTACHEMENT']."' type='application/pdf' scrolling='auto' height='500px' width='100%'>

                            </div>
                            <div class='modal-footer'>
                              <button type='button' class='btn btn-default' data-dismiss='modal'>Fermer</button>
                            </div>
                          </div>
                        </div>
                      </div>
                     
                     </td>
                   </tr>";
           
                }
                  ?>
                  
                  </tfoot>
                </table>
                  </div> 
                
                
                  
                  
                 
                 
                  
                 
                <!-- /.card-body -->

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

            </div>
        
        
        <!-- /.card-body -->
        <!-- <div class="card-footer">
          Footer
        </div> -->
        <!-- /.card-footer-->
      </div>
      <!-- /.card -->

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php
 include VIEWPATH.'includes/new_copy_footer.php';  
  ?>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<?php
  include VIEWPATH.'includes/new_script.php';
  ?>

<script>

function get_departement(va){
 var ID_DIRECTION= $(va).val();
 $.post('<?php echo base_url('courier/Enregistrement_Courier/get_departement')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#ID_SERVICE').html(data);
     });
$.post('<?php echo base_url('courier/Enregistrement_Courier/get_destinataire')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#DESTINATAIRE_PRINCIPAL').html(data);
     });
}
</script>

<script>

function get_service(va){
 var ID_SERVICE= $(va).val();
 $.post('<?php echo base_url('courier/Enregistrement_Courier/get_destinataire_ser')?>',
     {ID_SERVICE:ID_SERVICE},
     function(data){
       $('#DESTINATAIRE_PRINCIPAL').html(data);
     });
}
</script>
<!-- <script>
$(document).ready(function() {
  $('#datemask').inputmask();
});
</script> -->
<!-- <script>
$(document).ready(function() {
  $('#datemask').inputmask({
    alias: 'datetime',
    inputFormat: 'dd/mm/yyyy HH:MM',
    placeholder: 'dd/mm/yyyy HH:MM',
    regex: "([0-3][0-9])/([0-1][0-9])/(20[2-9][0-9]) ([0-2][0-9]):([0-5][0-9])",
    showMaskOnHover: false
  });

  $('#datemask').on('change', function() {
    var inputDate = $(this).val();
    var currentDate = new Date();
    var selectedDate = new Date(inputDate.split('/').reverse().join('/'));

    if (selectedDate < currentDate) {
      alert('Veuillez sélectionner une date ultérieure à la date actuelle.');
      $(this).val(''); // Efface la date saisie
    }
  });
});
</script> -->

<script>
$(document).ready(function() {
  $('#datemask').inputmask({
    alias: 'datetime',
    inputFormat: 'dd/mm/yyyy HH:MM',
    placeholder: 'dd/mm/yyyy HH:MM',
    regex: "([0-3][0-9])/([0-1][0-9])/(20[2-9][0-9]) ([0-2][0-9]):([0-5][0-9])",
    showMaskOnHover: false
  });

  

  

});
</script>

<script>

// // Fonction de vérification de la date
// function checkDate(dateStr) {
//   alert(dateStr);
//   // function checkDate(dateStr) {
//     var currentDate = new Date();
//     var selectedDate = new Date(dateStr);

//     if (isNaN(selectedDate.getTime())) {
//       alert('La date saisie est invalide.');
//       $(this).val('');
//       return false;
//     }

//     if (selectedDate > currentDate) {
//       alert('Veuillez sélectionner une date ultérieure à la date actuelle.');
//       return false;
//     }

//     return true;
//   }

  // // Appel de la fonction de vérification de date
  // $('#datemask').on('change', function() {
  //   if (!checkDate($(this).val())) {
  //     $(this).val(''); // Efface la date saisie
  //   }
  // });

  // // Exemple d'appel de la fonction avec une date spécifique
  // var dateToCheck = '2024-11-15T14:30:00';
  // if (!checkDate(dateToCheck)) {
  //   alert('La date est antérieure à la date actuelle ou invalide.');
  // }
  // }
</script>

</body>
</html>

<script>

function get_departementc(va){
 var ID_DIRECTION= $(va).val();
 $.post('<?php echo base_url('courier/Expedier_Courier/get_departement')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#ID_SERVICEC').html(data);
     });
$.post('<?php echo base_url('courier/Expedier_Courier/get_destinataire')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#ID_RH_COPIE').html(data);
     });
}
</script>
<script type="text/javascript">
  function addElement() {
   
    var ID_RH_COPIE= $('#ID_RH_COPIE').val();
    var ID_COURIER= $('#ID_COURIER').val();

    $.post('<?php echo base_url('courier/Traitement_Courier/save_element')?>',
          {
            ID_RH_COPIE:ID_RH_COPIE,
            ID_COURIER:ID_COURIER
          },
          function(data){
            // alert(data);
            $('#resultattablea').html(data); 
            
          });
    // body...
  }
</script>