<?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_demande_conge.php';
    ?>

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

      <!-- Default box -->
      <div class="card">
      
      <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Demande d'un cong&eacute;</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form id="FormData" action="<?php echo base_url()?>conge/Demande_Conge/add" method="POST" accept-charset="utf-8" enctype="multipart/form-data">
                <div class="card-body row">
                <?php
                // if ($this->session->userdata('SOCAR_ID_USER') == 0) {
                  $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 WHERE rh_employe_affectation.STATUS_AFFECTATION = 1 AND rh_employe_affectation.ID_EMPLOYE = ".$this->session->userdata('ID_EMPLOYE')." ");
                  ?>
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Direction <spam class="text-danger">*</spam></label>
                    <input type="text" class="form-control" value="<?php echo $employe['DIRECTION']?>" readonly="readonly">
                    <input type="hidden" id="ID_DIRECTION" name="ID_DIRECTION" value="<?php echo $employe['ID_DIRECTION']?>">
                  </div> 
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Service</label>
                    <input type="text" class="form-control" value="<?php echo $employe['DEPARTEMENT']?>" readonly="readonly">
                    <input type="hidden" id="ID_SERVICE" name="ID_SERVICE" value="<?php echo $employe['ID_SERVICE']?>">
                  </div> 
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Section</label>
                    <input type="text" class="form-control" value="<?php echo $employe['SERVICE']?>" readonly="readonly">
                    <input type="hidden" id="ID_SECTION" name="ID_SECTION" value="<?php echo $employe['ID_SECTION']?>">
                  </div>
                  <div class="form-group col-lg-12">
                    <label for="exampleInputEmail1">Employ&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']?>">
                  </div>  
                  <?php
                // }
                // else{

                
                // <div class="form-group col-lg-4">
                //     <label for="exampleInputEmail1">Direction <spam class="text-danger">*</spam></label>
                //     <select class="custom-select" name="ID_DIRECTION" id="ID_DIRECTION" onchange="get_departement(this)">
                //           <option>-- Select --</option>
                //           <?php
                //           foreach ($direction as $directions) {
                //            echo"<option value='".$directions['ID_DIRECTION']."'>".$directions['DESCRIPTION']."</option>";
                //           }
                //         </select>
                    
                //   </div>
                //   <div class="form-group col-lg-4">
                //     <label for="exampleInputEmail1">Service</label>
                //     <select class="custom-select" name="ID_SERVICE" id="ID_SERVICE" onchange="get_service(this)" >
                          
                //         </select>
                    
                //   </div> 

                //   <div class="form-group col-lg-4">
                //     <label for="exampleInputEmail1">Section</label>
                //     <select class="custom-select" name="ID_SECTION" id="ID_SECTION" onchange="get_employe(this)">
                          
                //         </select>
                    
                //   </div>  

                  

                //   <div class="form-group col-lg-12">
                //     <label for="exampleInputEmail1">Employ&eacute; <spam class="text-danger">*</spam></label>
                //     <select class="form-control select2 select2-primary"  id="ID_EMPLOYE" name="ID_EMPLOYE" data-dropdown-css-class="select2-primary" style="width: 100%;">
                    
                //     <option>-- Select --</option>
                //   </select>

                //   </div> 

                //   <?php
                // }
                  ?>

                  

                  

                  

                <!-- <div class="col-lg-12">
                <h5 >Employ&eacute;</h5>
                </div> -->
                  

                  <div class="form-group col-lg-3">
                    <label for="exampleInputEmail1">Type conge <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_TYPE_CONGE" id="ID_TYPE_CONGE" onchange="get_credit_conge(this)">
                          <option>-- Select --</option>
                          <?php
                          foreach ($type_conge as $type_conges) {
                           echo"<option value='".$type_conges['ID_TYPE_CONGE']."'>".$type_conges['NOM_CONGE']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_TYPE_CONGE', '<div class="text-danger">', '</div>'); ?>
                  </div> 

                  <div class="form-group col-lg-3" id="resultas">
                    
                  </div> 

                  <div class="form-group col-lg-3">
                    <label for="exampleInputEmail1">Nb de jours demand&eacute; <spam class="text-danger">*</spam></label>
                    <input type="number" class="form-control" id="NB_JOURS_DEMANDE" name="NB_JOURS_DEMANDE" placeholder="" step=".01" value="<?=set_value('NB_JOURS_DEMANDE')?>">
                    <?php echo form_error('NB_JOURS_DEMANDE', '<div class="text-danger">', '</div>'); ?>
                  </div> 

                  <div class="form-group col-lg-3">
                    <label for="exampleInputPassword1">Date de debut <spam class="text-danger">*</spam></label>
                    <div class="input-group date" id="DATE_DEMANDE" data-target-input="nearest">
                        <input type="text" class="form-control datetimepicker-input" data-target="#DATE_DEMANDE" name="DATE_DEMANDE" value="<?=set_value('DATE_DEMANDE')?>"/>
                        <div class="input-group-append" data-target="#DATE_DEMANDE" data-toggle="datetimepicker">
                            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
                        </div>
                    </div>
                    <?php echo form_error('DATE_DEMANDE', '<div class="text-danger">', '</div>'); ?>
                  </div>

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

                <div class="card-footer">
                  <button type="submit" class="btn btn-primary btn-block">Enregistrer</button>
                </div>
              </form>
            </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);
     });

 $.post('<?php echo base_url('conge/Demande_Conge/get_departement')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#ID_EMPLOYE').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);
     });
 $.post('<?php echo base_url('conge/Demande_Conge/get_service')?>',
     {ID_SERVICE:ID_SERVICE},
     function(data){
       $('#ID_EMPLOYE').html(data);
     });
}
</script>

<script>

function get_employe(va){
 var ID_SECTION= $(va).val();
 
 $.post('<?php echo base_url('conge/Demande_Conge/get_employe')?>',
     {ID_SECTION:ID_SECTION},
     function(data){
       $('#ID_EMPLOYE').html(data);
     });
}
</script>

<script>

function get_credit_conge(va){

 $.post('<?php echo base_url('conge/Demande_Conge/get_credit_conge')?>',
     {
      ID_EMPLOYE:$('#ID_EMPLOYE').val(),
      ID_TYPE_CONGE:$('#ID_TYPE_CONGE').val()
     },
     function(data){
       $('#resultas').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>

<script>
  $(function () {
    //Date picker
    $('#DATE_DEMANDE').datetimepicker({
        format: 'L'
    });   
  })
</script>
</body>
</html>
