<?php
  include VIEWPATH.'includes/new_header.php';
  ?>
<body class="hold-transition sidebar-mini">
<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">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
            <!-- /.card -->

            <div class="card">
              <div class="card-header">
                <!-- <h3 class="card-title">Liste de demande de requisition  </h3> -->
                <ul class="nav nav-pills">  
          <li class="nav-item">  
            <a class="nav-link <?php if($this->router->method == 'listing') echo 'active';?>" href="<?=base_url('document_interne/Requisition/listing')?>"> Toutes </a>  
          </li>  
          <li class="nav-item">  
            <a class="nav-link <?php if($this->router->method == 'atraiter') echo 'active';?>" href="<?=base_url('document_interne/Requisition/atraiter')?>"> A traiter </a>  
          </li>  
          <li class="nav-item">  
            <a class="nav-link <?php if($this->router->method == 'dejatraiter') echo 'active';?>" href="<?=base_url('document_interne/Requisition/dejatraiter')?>"> Traitées </a>  
          </li>  
          <!-- <li class="nav-item">  
            <a class="nav-link" href="<?=base_url('gestion_document/Demande_Document/listejson_atente')?>"> En attentes </a>  
          </li>    -->
        </ul> 
              </div>
              <!-- /.card-header -->
              <div class="card-body">

                               <!-- FILTRE -->

         


                <table id="example1" class="table table-bordered table-striped table-hover">


                  <thead>
                  <tr>
                    <th>Nom</th>
                    <th>Etape</th>
                    <th>Date demande</th>
                    <th>Type</th>
                    <!-- <th>Niveau</th> -->
                    <!-- <th>Status</th> -->
                    <th>Aff.</th>
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>

                  <?php
                 
                    foreach ($resultat as $key) 
                    {


                      $details_demande = $this->Model->getRequete('SELECT * FROM doc_interne_document_detail WHERE 1 AND ID_DOC_INTERNE = '.$key['ID_DOC_INTERNE'].'');
                      // print_r($details_demande);
                      $det = ''.$key['MOTIVATION'].'<br><table class="table">';
                      $det.='<tr><td>Article</td><td>Quantite</td><td>Prix U</td><td>Prix T</td></tr>';
                      foreach ($details_demande as $value) {
                        $det .="<tr><td>".$value['ARTICLE_ELEMENT']."</td><td class='text-right'>".$value['QUANTITE_DEMANDE']."</td><td class='text-right'>".$value['MONTANT_UNITAIRE_DEMANDE']."</td><td class='text-right'>".$value['MONTANT_TOTAL']."</td></tr>";
                      }
                      $det .='<tr><td></td><td></td><td></td><td class="text-right">'.$key['MONTANT_TOTAL'].'</td></tr></table>';
                     

                     if ($this->session->userdata('SOCAR_PROFIL_ID') == $key['ID_PROFIL']) {
                                        $link= "<li><a class='dropdown-item' href='".base_url("document_interne/Requisition/traitement/".$key['ID_DOC_INTERNE'])."'> Traiter </a> </li>";
                                        $quicklink = '<a class="btn btn-primary" href="'.base_url("document_interne/Requisition/traitement/".$key['ID_DOC_INTERNE']).'" role="button"> Traiter </a>';
                                        $stat = "<div class='bg-warning color-palette'>A traiter</div>";
                                        }
                                        elseif ($this->session->userdata('ID_EMPLOYE') == $key['ID_EMPLOYE_DESINGE']){
                                          $link= "<li><a class='dropdown-item' href='".base_url("document_interne/Requisition/traitement/".$key['ID_DOC_INTERNE'])."'> Traiter </a> </li>";
                                          $quicklink = '<a class="btn btn-primary" href="'.base_url("document_interne/Requisition/traitement/".$key['ID_DOC_INTERNE']).'" role="button"> Traiter </a>';
                                          $stat = "<div class='bg-warning color-palette'>En attente</div>";
                                        }                         
                                        else{
                                          $link='';
                                          $quicklink = '';
                                          $stat = "<div class='bg-success color-palette'>-</div>";
                                        }   
                                           
                                           
                                           if ($key['ON_PDF'] == 1) {
                                            $linka="<li><a class='dropdown-item' href='".base_url("pdf/".$key['PDF_CONTROLLERS']."/index/".$key['ID_DOC_INTERNE'])."' target='_blank'> PDF </a> </li>";;
                                           }
                                            else{
                                              $linka='';
                                            }
                 // ".$stat."
                     echo "<tr>
                     <td>".$key['NOM']." ".$key['PRENOM']."</td>
                     <td>".$key['ETAPE']."</td>
                     <td>".$key['DATE_DEMANDE']."</td>
                     <td>".$key['TYPE_DOCUMENT']."
                      
            <div class='modal fade' id='modaldetails0_".$key['ID_DOC_INTERNE']."'>
        <div class='modal-dialog modal-lg'>
          <div class='modal-content'>
            <div class='modal-header'>
              <h4 class='modal-title'>Details</h4>
              <button type='button' class='close' data-dismiss='modal' aria-label='Close'>
                <span aria-hidden='true'>&times;</span>
              </button>
            </div>
            <div class='modal-body'>            
            <div class='form-group col-lg-12'>
              ".$det."
              </div>
            </div>
            
            <div class='modal-footer justify-content-between'>
              <button type='button' class='btn btn-default' data-dismiss='modal'>Fermer</button>
              ".$quicklink."
            </div>
          </div>
        </div>
      </div>

     
                     </td>
                     <td>
                     <div class='modal fade' id='affectation".$key['ID_DOC_INTERNE']."'>
        <div class='modal-dialog'>
          <div class='modal-content'>
            <div class='modal-header'>
              <h4 class='modal-title'>Affectation de ".$key['NOM']." ".$key['PRENOM']."</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>".$key['ID_DIRECTION']."</td>
                     </tr>
                     <tr>
                      <td>Service</td>
                      <td>".$key['ID_SERVICE']."</td>
                     </tr>
                     <tr>
                      <td>Section</td>
                      <td>".$key['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>
        </div>
      </div>
                    <button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#affectation".$key['ID_DOC_INTERNE']."'>
                  <i class='fas fa-building'></i>
                </button>
                     </td>
                     <td><div class='dropdown '>
                                       <a class='btn btn-primary btn-sm dropdown-toggle' data-toggle='dropdown'>Actions
                                       <span class='caret'></span></a>
                                       <ul class='dropdown-menu dropdown-menu-right'>";

                                       echo'<li><a class="dropdown-item" data-toggle="modal" data-target="#modaldetails0_'.$key['ID_DOC_INTERNE'].'" href="#"> Details </a> </li>';       


                                          echo $link;

                                          echo $linka;
                                        // echo" <li><a class='dropdown-item' href='".base_url("document_interne/Requisition/index_update/".$key['ID_DOC_INTERNE'])."'> Modifier </a> </li>";
                                      
                                     
                                       
                                       echo "</ul>
                                     </div></td>
                   </tr>";
           
                     
                                     
                }
                  ?>
                  
                  </tfoot>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <?php
 include VIEWPATH.'includes/new_copy_footer.php';  
  ?>
  

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>

<!-- ./wrapper -->
<?php
  include VIEWPATH.'includes/new_script.php';
  ?>

<!-- Page specific script -->
<script>
  $(function () {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,"ordering": false,
      // "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper  .col-md-6:eq(0)');
   
  });
</script>
</body>
</html>

<script>


         function get_info() {
       
       myform.action= myform.action;
        myform.submit();
      } 
  

</script>
