<?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_requisition.php';
    include 'includes/menu_requisition_externe.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 requisition</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <?php 
              // echo $this->session->userdata('SOCAR_ID_USER');
              $employe= $this->Model->getRequeteOne("SELECT rh_employe_affectation.ID_DIRECTION, organigramme_direction.DESCRIPTION AS DIRECTION, rh_employe_affectation.ID_RESPONSABILITE, rh_employe_affectation.ID_SERVICE, organigramme_service.DESCRIPTION AS DEPARTEMENT, rh_employe_affectation.ID_SECTION, organigramme_section.DESCRIPTION AS SERVICE, rh_employe.NOM, rh_employe.PRENOM , rh_employe.ID_EMPLOYE FROM rh_employe_affectation JOIN organigramme_direction ON organigramme_direction.ID_DIRECTION = rh_employe_affectation.ID_DIRECTION LEFT JOIN organigramme_service ON organigramme_service.ID_SERVICE = rh_employe_affectation.ID_SERVICE LEFT JOIN organigramme_section ON organigramme_section.ID_SECTION = rh_employe_affectation.ID_SECTION JOIN rh_employe ON rh_employe.ID_EMPLOYE = rh_employe_affectation.ID_EMPLOYE JOIN config_user ON config_user.ID_EMPLOYE = rh_employe.ID_EMPLOYE WHERE rh_employe_affectation.STATUS_AFFECTATION = 1 AND config_user.ID_USER = ".$this->session->userdata('SOCAR_ID_USER')." ");

            
              $niveau = '';
              $sniveau = '';

              $etape_c=$this->Model->getRequete('SELECT * FROM `req_externe_etape` WHERE 1 AND ID_REQ_ETAPE_DOC_INTERNE='.$data['ID_REQ_ETAPE_DOC_INTERNE'].' ');
              $action_c=$this->Model->getRequete('SELECT * FROM `req_externe_action` WHERE 1 AND ID_REQ_ETAPE_DOC_INTERNE='.$data['ID_REQ_ETAPE_DOC_INTERNE'].' AND STATUS = 1 ');

              

              ?>
                <div class="card-body row">
                <div class="form-group col-lg-12 text-center">
                  <h3>Traitement Requisition</h3>
                </div>
               
                <div class="form-group col-lg-12">
                  <!-- <h5>Details d</h5> -->
                  <table class="table table-striped">
                    <tr>
                      <td>Type</td>
                      <td></td> 
                      <td>Employ&eacute; demandeur</td>
                      <td><?php echo $data['NOM']?> <?php echo $data['PRENOM']?></td> 
                    </tr>
                    
                    <tr>
                      <td>Etape Actuel</td>
                      <td><?php echo $data['ETAPE']?> </td> 
                      <td>Montant T</td>
                      <td><?php echo $data['MONTANT_TOTAL']?> </td> 
                    </tr>
                    <tr>
                      <td colspan="4">Motivation</td>
                    </tr>
                    <tr>
                      <td colspan="4"><?php echo $data['MOTIVATION']?> </td> 
                    </tr>

                    <tr>
                      <td>Piece</td>
                      <td>
<a  data-toggle="modal" data-target="#opens_path_cni" class="btn btn-default btn-sm"><span class="fa fa-image"></span></a>


<div class="modal fade" id="opens_path_cni" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" data-backdrop="static">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel"><b></b></h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">

        <?php
        

        
        foreach ($fichier_demande as $fichier) {

          $path='uploads/fichier_demande_interne/'.$fichier['FICHIERS']; 
          ?>

        <div class="col-md-12"><embed src="<?php echo $nouveau_url.''.$path?>" type="application/pdf"   scrolling="auto" height="400px" width="100%"></div>
          <?php
        }
        ?>
          
     </div>


   </div>
 </div>
</div>
                      </td> 
                      <td>Service demandeur</td>
                      <td>
                      <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal-default">
                  Affectation
                </button>
                  <div class="modal fade" id="modal-default">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h4 class="modal-title">Affectation</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>Direction</td>
                            <td><?php echo $data['ID_DIRECTION']?></td>
                          </tr>
                          <tr>
                            <td>Service</td>
                            <td><?php echo $data['ID_SERVICE']?></td>
                          </tr>
                          <tr>
                            <td>Section</td>
                            <td><?php echo $data['ID_SECTION']?></td>
                          </tr>
                        </table>
                      </div>
                      <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">Fermer</button>
                      </div>
                    </div>
                    <!-- /.modal-content -->
                  </div>
                  <!-- /.modal-dialog -->
                </div>
                      </td> 
                    </tr>
                    
                  </table>

                  
                </div>
                <div class="form-group col-lg-12">
                  <h5><b>Historique de traitement</b></h5>

                  <table class="table">
                    <thead>
                    <tr>
                      <th>Date Traitement</th>
                      <th>Direction</th>
                      <th>Service</th>
                      <th>Section</th>
                      <th>Employe</th>
                      <th>Status</th>
                      <th>Commentaire</th>
                    </tr>
                  </thead>
                    
                    <?php
                    foreach ($historique as $value) {                    
                    ?>

                    <tr>
                      <td><?php echo $value['DATE_TRAITEMENT']; ?></td>
                      <td><?php echo $value['DIRECTION']; ?></td>
                      <td><?php echo $value['SERVICE']; ?></td>
                      <td><?php echo $value['SECTION']; ?></td>
                      <td><?php echo $value['NOM']; ?> <?php echo $value['PRENOM']; ?></td>
                      <td><?php echo $value['DESCRIPTION']; ?></td>
                      <td><?php echo $value['COMMENTAIRE']; ?></td>
                    </tr>

                    <?php
                    }
                    ?>

                  </table>
                </div>

                <div class="form-group col-lg-12">
                  <h5>Details </h5>

                  <table class="table">
                    <thead>
                    <tr>
                      <th>Article</th>
                      <th>Quantite</th>
                      <th>Prix Unitaire</th>
                      <th>Prix Total</th>
                      <th> </th>
                    </tr>
                    </thead>
                    
                    <?php
                    foreach ($details_demande as $detai) {   

                    ?>

                    <tr>
                      <td><?php echo $detai['ARTICLE_ELEMENT']; ?></td>
                      <td><?php echo $detai['QUANTITE_DEMANDE']; ?></td>
                      <td><?php echo $detai['MONTANT_UNITAIRE_DEMANDE']; ?></td>
                      <td><?php echo $detai['MONTANT_TOTAL']; ?></td>
                      <td>
                        <!-- <div class="custom-control custom-checkbox">
                          <input class="custom-control-input" type="checkbox" id="custom<?php echo $detai['ID_DOC_INTERNE_DETAIL']; ?>" checked>
                          <label for="custom<?php echo $detai['ID_DOC_INTERNE_DETAIL']; ?>" class="custom-control-label"> </label>
                        </div> -->
                      </td>
                    </tr>

                    <?php
                    }
                    ?>

                  </table>
                </div>
                <div class="form-group col-lg-12 row">
                <div class="form-group col-md-10">
                  <h5><b>Detail sur la rubrique: <?php echo $data['RUBRIQUE']; ?></b></h5>
                  </div>

                  <div class="form-group col-md-2 text-right">
                  Historique rubrique
                  </div>
                
      <div class="form-group col-md-4 text-danger">
        <b>Total prévu <?php echo number_format($data['BUDGE_PREVU'],0,","," "); ?> BIF</b>                       
      </div>
      <div class="form-group col-md-4 text-danger">
        <b>Total Consomé <?php echo number_format($data['BUDGE_CONSOME'],0,","," "); ?> BIF</b>                       
      </div>
      <div class="form-group col-md-4 text-danger">
        <b>Total disponible maintenant <?php echo number_format($data['BUDGE_DISPONIBLE'],0,","," "); ?> BIF</b>                       
      </div>
      </div>



                <div class="form-group col-lg-12">
                  <h5><b>Traitement du requisition</b></h5>
                  <form id="FormData" action="<?php echo base_url()?>requisition_externe/Traite_Requisition_Externe/traiter" method="POST" enctype="multipart/form-data">

                  <div class="row">

                  <div class="form-group col-lg-3">
                    <label for="exampleInputEmail1">Etape Actuel</label>
                    <select class="custom-select" name="ID_REQ_ETAPE_DOC_INTERNE" id="ID_REQ_ETAPE_DOC_INTERNE">
                          <!-- <option>-- Select --</option> -->
                          <?php
                          foreach ($etape_c as $type_conges) {
                           echo"<option value='".$type_conges['ID_REQ_ETAPE_DOC_INTERNE']."'>".$type_conges['DESCRIPTION']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_REQ_ETAPE_DOC_INTERNE', '<div class="text-danger">', '</div>'); ?>
                  </div>

                  <div class="form-group col-lg-3">
                    <label for="exampleInputEmail1">Descision</label>
                  
                    <input type="hidden" id="ID_REQ_EXTERNE" name="ID_REQ_EXTERNE" placeholder="" value="<?php echo $data['ID_REQ_EXTERNE'];?>">
                    
                    <select class="custom-select" name="ID_REQ_EXTERNE_ACTION" id="ID_REQ_EXTERNE_ACTION">
                          <option value="">-- Select --</option>
                          <?php
                          
                          foreach ($action_c as $action) {

                           echo"<option value='".$action['ID_REQ_EXTERNE_ACTION']."'>".$action['DESCRIPTION']."</option>";
                          }
                          ?>
                    </select>
                    <?php echo form_error('ID_REQ_EXTERNE_ACTION', '<div class="text-danger">', '</div>'); ?>
                  </div>

                  <div class="form-group col-lg-3">
                    <label for="exampleInputEmail1">RH Designe</label>
                    <select class="custom-select" name="ID_EMPLOYE_DESINGE" id="ID_EMPLOYE_DESINGE">
                      <option value="">-- Select --</option> 
                          <?php
                          
                          $rh_employe=$this->Model->getRequete('SELECT * FROM `rh_employe` WHERE 1');
                          foreach ($rh_employe as $employes) {
                           echo"<option value='".$employes['ID_EMPLOYE']."'>".$employes['NOM']." ".$employes['PRENOM']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_EMPLOYE_DESINGE', '<div class="text-danger">', '</div>'); ?>
                  </div>
                   


                  <div class="form-group col-lg-3">
                    <label for="exampleInputPassword1">Montant Total</label>
                    <input type="text" id="MONTANT_TOTAL" class="form-control" name="MONTANT_TOTAL" placeholder="" value="<?php echo $data['MONTANT_TOTAL'];?>">
                    
                    <?php echo form_error('MONTANT_TOTAL', '<div class="text-danger">', '</div>'); ?>
                  </div>

                  <div class="form-group col-lg-12">
                    <label for="exampleInputPassword1">Commentaire</label>
                    <textarea class="form-control" name="COMMENTAIRE" id="COMMENTAIRE" rows="3"><?=set_value('COMMENTAIRE')?></textarea>
                    
                    <?php echo form_error('COMMENTAIRE', '<div class="text-danger">', '</div>'); ?>
                  </div>

                  <div class="form-group col-lg-12">
                    <label for="exampleInputEmail1">Employe connect&eacute;</label>
                  

                  <input type="text" class="form-control" value="<?php echo $employe['NOM']?> <?php echo $employe['PRENOM']?>" readonly="readonly">
                  <input type="hidden" id="ID_EMPLOYE" name="ID_EMPLOYE" value="<?php echo $employe['ID_EMPLOYE']?>">
                  
                    <?php echo form_error('ID_EMPLOYE', '<div class="text-danger">', '</div>'); ?>
                  </div>

                  
                  
                  
                  <div class="form-group col-lg-12">
                  <button type="submit" class="btn btn-primary btn-block">Enregistrer</button>
                  </div>
                  </div>
                  </form>
                </div>
                
                   
                  
                  
                       
                 
                  
                </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('rh/Employe/get_departement')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#ID_SERVICE').html(data);
     });
}
</script>

<script>

function get_service(va){
 var ID_SERVICE= $(va).val();
 $.post('<?php echo base_url('rh/Employe/get_service')?>',
     {ID_SERVICE:ID_SERVICE},
     function(data){
       $('#ID_SECTION').html(data);
     });
}
</script>
<script>
  $(function () {
   
    //Date picker
    $('#DATE_ENTRE_SERVICE').datetimepicker({
        format: 'L'
    });   

  })
 


</script>
<script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })
</script>



</body>
</html>
