<?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_expedition_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">Expédition du courrier</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form id="FormData" action="<?php echo base_url()?>courier/Expedier_Courier/add" method="POST" accept-charset="utf-8" enctype="multipart/form-data">
              <input type="hidden" name="NUM_GENERATED" id="NUM_GENERATED" value="<?=$NUM_GENERATED?>">

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

                <div class="card-body row">
                <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Type de courier <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_TYPE_COURIER" id="ID_TYPE_COURIER">
                          <option>-- Select --</option>
                          <?php
                          foreach ($type_courier as $type_docs) {
                           echo"<option value='".$type_docs['ID_TYPE_COURIER']."'>".$type_docs['DESCRIPTION']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_TYPE_COURIER', '<div class="text-danger">', '</div>'); ?>
                  </div> 
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Nature du courier <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_NATURE_COURIER" id="ID_NATURE_COURIER">
                          <option>-- Select --</option>
                          <?php
                          foreach ($nature_courier as $nature) {
                           echo"<option value='".$nature['ID_NATURE_COURIER']."'>".$nature['DESCRIPTION']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_NATURE_COURIER', '<div class="text-danger">', '</div>'); ?>
                  </div> 
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Destinataire du courier <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_CORRESPONDANT" id="ID_CORRESPONDANT">
                          <option>-- Select --</option>
                          <?php
                          foreach ($corresponndant as $coresp) {
                           echo"<option value='".$coresp['ID_CORRESPONDANT']."'>".$coresp['NOM_CORRESPONDANT']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_CORRESPONDANT', '<div class="text-danger">', '</div>'); ?>
                  </div>
                  <div class="form-group col-lg-6">
                    <label for="exampleInputEmail1">Référence du courier <spam class="text-danger">*</spam></label>
                    <input type="text" id="NUM_COURIER" class="form-control" name="NUM_COURIER" value="<?php echo $refgen;?>">
                  </div>
                  
                  <div class="form-group col-lg-6">
                  <label for="exampleInputEmail1">Fichier scan (.pdf) <spam class="text-danger">*</spam></label>
                  <input type="file" name="PDF_SCAN" class="form-control" accept=".pdf">
                    
                    <?php echo form_error('PDF_SCAN', '<div class="text-danger">', '</div>'); ?>
                  </div>
                  
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Direction de l'expediteur du courier <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 $direct) {
                           echo"<option value='".$direct['ID_DIRECTION']."'>".$direct['DESCRIPTION']."</option>";
                          }
                          ?>
                        </select>
                    <?php echo form_error('ID_DIRECTION', '<div class="text-danger">', '</div>'); ?>
                  </div> 
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Service de l'expediteur du courier </label>
                    <select class="custom-select" name="ID_SERVICE" id="ID_SERVICE" onchange="get_service(this)">
                          <option>-- Select --</option>
                          
                        </select>
                  </div> 
                  <div class="form-group col-lg-4 ">
                    <label for="exampleInputEmail1">Expediteur du courier <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="DESTINATAIRE_PRINCIPAL" id="DESTINATAIRE_PRINCIPAL">
                          
                        </select>
                    <?php echo form_error('DESTINATAIRE_PRINCIPAL', '<div class="text-danger">', '</div>'); ?>
                  </div> 
                  
                  <div class="form-group col-lg-12">
                    <label for="exampleInputEmail1">Personne en copie</label>
                  </div>
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Direction  en copie du courier <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_DIRECTIONC" id="ID_DIRECTIONC" onchange="get_departementc(this)">
                          <option>-- Select --</option>
                          <?php
                          foreach ($direction as $direct) {
                           echo"<option value='".$direct['ID_DIRECTION']."'>".$direct['DESCRIPTION']."</option>";
                          }
                          ?>
                        </select>
                  </div> 
                  <div class="form-group col-lg-3">
                    <label for="exampleInputEmail1">Service en copie du courier </label>
                    <select class="custom-select" name="ID_SERVICEC" id="ID_SERVICEC" onchange="get_servicec(this)">
                          <option>-- Select --</option>
                          
                        </select>
                  </div> 
                  <div class="form-group col-lg-4">
                    <label for="exampleInputEmail1">Destinataire en copie courier <spam class="text-danger">*</spam></label>
                    <select class="custom-select" name="ID_RH_COPIE" id="ID_RH_COPIE">
                          
                        </select>
                  </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 class="form-group col-lg-12">
                    <label for="exampleInputEmail1">Objet du courier <spam class="text-danger">*</spam></label>
                    <input type="text" id="OBJET_COURIER" class="form-control" name="OBJET_COURIER" value="">
                  </div>
                  
                  
                  <div class="form-group col-lg-12">
                    <label for="exampleInputEmail1">Commentaire </label>
                    <textarea class="form-control" rows="3" name="COMMENTAIRE" id="COMMENTAIRE"></textarea>
                    <?php echo form_error('COMMENTAIRE', '<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('courier/Expedier_Courier/get_departement')?>',
     {ID_DIRECTION:ID_DIRECTION},
     function(data){
       $('#ID_SERVICE').html(data);
     });
$.post('<?php echo base_url('courier/Expedier_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/Expedier_Courier/get_destinataire_ser')?>',
     {ID_SERVICE:ID_SERVICE},
     function(data){
       $('#DESTINATAIRE_PRINCIPAL').html(data);
     });
}
</script>

<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>

function get_servicec(va){
 var ID_SERVICE= $(va).val();
 $.post('<?php echo base_url('courier/Expedier_Courier/get_destinataire_ser')?>',
     {ID_SERVICE:ID_SERVICE},
     function(data){
       $('#ID_RH_COPIE').html(data);
     });
}
</script>



<script type="text/javascript">
  function addElement() {
   
    var ID_RH_COPIE= $('#ID_RH_COPIE').val();
    var NUM_GENERATED= $('#NUM_GENERATED').val();

    $.post('<?php echo base_url('courier/Expedier_Courier/save_element')?>',
          {
            ID_RH_COPIE:ID_RH_COPIE,
            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('courier/Expedier_Courier/removeElement')?>',
          {
            ID_COURIER_COPIE:va,
            NUM_GENERATED:NUM_GENERATED
          },
          function(data){
            // alert(data);
            $('#resultattablea').html(data); 
            
          });
  }
</script>

</body>
</html>
