<?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';
    ?>

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

      <!-- Default box -->
      <div class="card">
      
      <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Demande interne</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form id="FormData" action="<?php echo base_url()?>document_interne/Requisition/add" method="POST" accept-charset="utf-8" enctype="multipart/form-data">

                <?php 
                          if(!empty($this->session->flashdata('message')))
                             echo $this->session->flashdata('message');
            ?>

                <input type="hidden" name="NUM_GENERATED" id="NUM_GENERATED" value="<?=$NUM_GENERATED?>">
                <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>  
                 

                  


                  <div class="form-group col-lg-6">
                    <label for="exampleInputEmail1">Type de demande <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_TYPE_DOC_INTERNE" id="ID_TYPE_DOC_INTERNE">
                          <option>-- Select --</option>
                          <?php
                          foreach ($type_doc as $type_docs) {
                           echo"<option value='".$type_docs['ID_TYPE_DOC_INTERNE']."'>".$type_docs['DESCRIPTION']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_TYPE_DOC_INTERNE', '<div class="text-danger">', '</div>'); ?>
                  </div> 
                  <div class="form-group col-lg-6">
                    <label for="exampleInputEmail1">Fichier (.pdf,.png, .jpg, .jpeg)</label>
                    <input type="file" name="files[]" id="FICHIERS" class="form-control" accept=".pdf,.png, .jpg, .jpeg" multiple>
                    <?php echo form_error('ID_TYPE_DOC_INTERNE', '<div class="text-danger">', '</div>'); ?>
                  </div> 

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




                  <div class="form-group col-lg-12">
                    <label for="exampleInputEmail1">Details de la demande (Composition)<spam class="text-danger">*</spam></label>
                  </div>

                  <div class="form-group col-md-7">
                        <label for="ARTICLE_ELEMENT">
                          Article-Elements de la demandes
                          <i class="text-danger"> *</i>
                        </label>
                  <input type="text" name="ARTICLE_ELEMENT" value="" class="form-control" id="ARTICLE_ELEMENT" placeholder="">
                        <?php echo form_error('ARTICLE_ELEMENT', '<div class="text-danger">', '</div>'); ?>
                      </div>

                      <div class="form-group col-md-2">
                        <label for="QUANTITE_DEMANDE">
                          Quantite voulue
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="QUANTITE_DEMANDE" value="" class="form-control" id="QUANTITE_DEMANDE" placeholder="" step="0.001">
                        <?php echo form_error('QUANTITE_DEMANDE', '<div class="text-danger">', '</div>'); ?>
                     </div>

                     <div class="form-group col-md-2">
                        <label for="MONTANT_UNITAIRE_DEMANDE">
                          Montant aprox
                          <i class="text-danger"> *</i>
                        </label>
                        <input type="number" name="MONTANT_UNITAIRE_DEMANDE" value="" class="form-control" id="MONTANT_UNITAIRE_DEMANDE" placeholder="Montant unitaire" step="0.001">
                        <?php echo form_error('MONTANT_UNITAIRE_DEMANDE', '<div class="text-danger">', '</div>'); ?>
                     </div>


                      <div class="form-group col-md-1">
                        <label for=""> _ </label>
                        <a  class="btn btn-primary btn-block" onclick="addElement()">+</a>

                      </div>





                  <div class="form-group col-lg-12" id="resultattablea">
                    
                  </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 type="text/javascript">
  function addElement() {

    // alert('This');
   
    var ARTICLE_ELEMENT= $('#ARTICLE_ELEMENT').val();
    var QUANTITE_DEMANDE= $('#QUANTITE_DEMANDE').val();
    var MONTANT_UNITAIRE_DEMANDE= $('#MONTANT_UNITAIRE_DEMANDE').val();
    var NUM_GENERATED= $('#NUM_GENERATED').val();

    $.post('<?php echo base_url('document_interne/Requisition/save_element')?>',
          {
            ARTICLE_ELEMENT:ARTICLE_ELEMENT,
            QUANTITE_DEMANDE:QUANTITE_DEMANDE,
            MONTANT_UNITAIRE_DEMANDE:MONTANT_UNITAIRE_DEMANDE,
            NUM_GENERATED:NUM_GENERATED
          },
          function(data){
            // alert(data);
            $('#resultattablea').html(data); 
            
          });
    // 
                      // 
                      // 
    // body...
  }
</script>

<script type="text/javascript">
  function removeElement(va) {
   var NUM_GENERATED= $('#NUM_GENERATED').val();
    $.post('<?php echo base_url('document_interne/Requisition/removeElement')?>',
          {
            ID_DOC_INTERNE_DETAIL:va,
            NUM_GENERATED:NUM_GENERATED
          },
          function(data){
            // alert(data);
            $('#resultattablea').html(data); 
            
          });
  }
</script>

</body>
</html>
