<?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('requisition_externe/Traite_Requisition_Externe/listing')?>"> Toutes </a>  
          </li>   -->
          <li class="nav-item">  
            <a class="nav-link <?php if($this->router->method == 'index') echo 'active';?>" href="<?=base_url('requisition_externe/Traite_Requisition_Externe/index')?>"> A traiter </a>  
          </li>  
         <?php if (in_array('32',$this->session->userdata('SOCAR_DROIT'))){ ?>
          <li class="nav-item">  
            <a class="nav-link <?php if($this->router->method == 'dejatraiter') echo 'active';?>" href="<?=base_url('requisition_externe/Traite_Requisition_Externe/dejatraiter')?>"> Traitées </a>  
          </li>  
         <?php }
          ?>
          <!-- <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>Demandeur</th>
                    <th>Etape</th>
                    <th>Date demande</th>
                    <th>Rubrique</th>
                    <th>Fournisseur</th>
                    <th>Montant Total</th>
                    <th>Details</th>
                    <th>Aff.</th>
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>

                  <?php
                 
                    foreach ($resultat as $key) 
                    {
                      // ID_REQ_EXTERNE, req_externe_document.DATE_DEMANDE, req_externe_document.ID_EMPLOYE_DEMANDEUR, rh_employe.NOM, rh_employe.PRENOM, req_externe_document.ID_REQ_ETAPE_DOC_INTERNE, req_externe_etape.DESCRIPTION, req_externe_document.ID_DIRECTION, organigramme_direction.DESCRIPTION AS DIRECTION , req_externe_document.ID_SERVICE, organigramme_service.DESCRIPTION AS SERVICE, req_externe_document.MONTANT_TOTAL, req_externe_document.ID_BUDGE_PLANNIFIE, req_externe_budge_plannifie.RUBRIQUE, req_externe_document.ID_FOURNISSEUR, req_externe_fournisseur.NOM_FOURNISSEUR

                      $details_demande = $this->Model->getRequete('SELECT * FROM req_externe_document_detail WHERE 1 AND ID_REQ_EXTERNE = '.$key['ID_REQ_EXTERNE'].'');
                      
                      $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("requisition_externe/Traite_Requisition_Externe/traitement/".$key['ID_REQ_EXTERNE'])."'> Traiter </a> </li>";
                                        $quicklink = '<a class="btn btn-primary" href="'.base_url("requisition_externe/Traite_Requisition_Externe/traitement/".$key['ID_REQ_EXTERNE']).'" 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("requisition_externe/Traite_Requisition_Externe/traitement/".$key['ID_REQ_EXTERNE'])."'> Traiter </a> </li>";
                                          $quicklink = '<a class="btn btn-primary" href="'.base_url("requisition_externe/Traite_Requisition_Externe/traitement/".$key['ID_REQ_EXTERNE']).'" 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_REQ_EXTERNE'])."' 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['RUBRIQUE']."</td>
                     <td>".$key['NOM_FOURNISSEUR']."</td>
                     <td>".$key['MONTANT_TOTAL']."</td>                     
                     <td>
                      
            <div class='modal fade' id='modaldetails0_".$key['ID_REQ_EXTERNE']."'>
        <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>
      <button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-target='#modaldetails0_".$key['ID_REQ_EXTERNE']."'>
                  <i class='fas fa-building'></i>
                </button>

     
                     </td>
                     <td>
                     <div class='modal fade' id='affectation".$key['ID_REQ_EXTERNE']."'>
        <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_REQ_EXTERNE']."'>
                  <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_REQ_EXTERNE'].'" 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>
