@extends('usuarios.clientes.master.layoutcliente')
@section('conteudo')
<script src="{{asset('js/jquery.dataTables.min.js') }}"></script>
{{-- SELECT STYLE --}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">
@php $i=1; @endphp

    <div class="container-fluid">
        <div class="page-header">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">
                           <div class="card-body"> 
                            <a  href="#"><i class="ik ik-map bg-blue"></i><h4>Mapa Geral de Indexação </h4></a>
                        </div>
                        <div class="d-inline">
                           
                      <br/>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="../index.html"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item">
                                <a href="#">mapa geral</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">listagem</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>
                               
        <nav class="d-none">
        
            {{ $refCaixa=\App\Models\ReferenciaCaixa::where('estado','Concluido')->where('cliente_id',$empresa_cliente_id)->get()}}
            {{ $camposMapa = \App\Models\CampoMapa::where('origem','Geral')->orderBy('prioridade','Asc')->get()}}
                       
        </nav>

        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-body"> 
                        <div class="table-responsive">
                                    <table id="example1" class="table container  table-striped table-hover">
                                        <thead>
                                            <tr class="tHeadyTr">
                                                
                                                 @foreach($camposMapa as $cMapa)
                                                     @if($cMapa->descricao=="Código da recolha")
                         
                                                     @elseif($cMapa->descricao=="C. Q.")
                                                     
                                                     @elseif($cMapa->nome=="funcionario_id")
                                                     
                                                    
                                                     @else
                                                     <th>{{$cMapa->nome}}</th>
                                                     @endif
                                                 @endforeach
                                                 <th>Funcionario</th>
                                                 <th>Cliente</th>
                                                 <th>Ver Mais</th>
                                                 
                                            </tr>
                                         </thead>
                                         <tbody class="tBody">
                                                 @foreach($refCaixa as $refC)
                                                     <tr class="tHeadyTr">
                                                         @foreach($camposMapa as $cMapa)
                                                             <nav class="d-none">
                                                                 {{$linhaIndex=\App\Models\LinhaIndexacao::where('campomapa_id',$cMapa->id)->where('referenciacaixa_id',$refC->id)->first()}}
                                                                
                                                                 
                                                             </nav>
                                                             @if($linhaIndex)
                                                                 @if($cMapa->nome=='orgaoestrutura_id')
                                                                     <nav class="d-none">
                                                                         {{ $OE1=\App\Models\OrgaosDeEstrutura::where('id',$linhaIndex->conteudo)->first()}}
                                                                     </nav>
                                                                     <th>{{$OE1->orgao}}</th>
                                                                 @elseif($cMapa->nome=='departamento_id')
                                                                     <nav class="d-none">
                                                                         {{ $Dep= \App\Models\DepCliente::where('id',$linhaIndex->conteudo)->first()}}
                                                                         
                                                                     </nav>
                                                                     <th>{{$Dep->departamento}}</th>
                                                                 @elseif($cMapa->nome=='seriedocumental_id')
                                                                     <nav class="d-none">
                                                                         {{ $SD1=\App\Models\ParametroDocumental::where('id',$linhaIndex->conteudo)->first()}}
                                                                     </nav>
                                                                     <th>{{$SD1->seriedoc}}</th>
                                                                 
                                                                 @elseif($cMapa->prioridade>=15)
                                                                     <th>{{$linhaIndex->conteudo}}</th>
                                                                     <th>{{$linhaIndex->getUser->getPessoa->nome}}</th>
                                                                     <th>{{$linhaIndex->getCliente->getUser->getPessoa->nome}}</th>
                                                                 @else
                                                                     <th>{{$linhaIndex->conteudo}}</th>
                                                                 
                                                                 @endif
                                                                 
                                                                 
                                                             @endif
                                                           
                                                         @endforeach
                                                         <th>
                                                                       
                                                                        
                                                                            @php 
                                                                        //use Illuminate\Support\Facades\Crypt;
                                                                      
                                                                        try {
                                                                             
                                                                        $decrypted =Crypt::encryptString($refC->id);
                                                                         
                                                                        } catch (DecryptException $e) {
                                                                            $decrypted=0;
                                                                        }  
                                                                        @endphp
                                                                       
                                                                        @if($refC->estado!="Concluido")
                                                                        <form  action="{{route('us.admin.cliente.indexacao.show.Indexar')}}" method="post">
                                                                            @csrf
                                                                            <input type="text" value="{{$decrypted}}" hidden  name="myidshowIndex" >
                                                                            <button  class="btn btn-sm btn-outline-success" type="submit"> <i class="fa fa-eye"></i></button>
                                                                        </form>
                                                                             
                                                                            @else
                                                                            <form  action="{{route('us.admin.cliente.indexacao.show.finish.Indexada')}}" method="post">
                                                                                @csrf
                                                                                <input type="text" value="{{$decrypted}}" hidden  name="myidshowIndex" >
                                                                                <button  class="btn btn-sm btn-outline-success" type="submit"> <i class="fa fa-eye"></i></button>
                                                                            </form>
                                                                        @endif
                                                                        
                                                                
                                                             
                                                             
                                                             
                                                             
                                                         </th>
                                                     </tr>
                                                 @endforeach
                                         </tbody>
                                        <tfoot></tfoot>
                                    </table>
                            
                    
                        </div>
                    </div>
                </div>
            </div>
        
        </div>
        
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/bootstrap-select.min.js"></script>

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/js/i18n/defaults-*.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.js"></script>
<script src="//cdn.jsdelivr.net/npm/sweetalert2@10"></script>

<script>
 
    $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
            "paging": true,
            "lengthChange": false,
            "searching": true,
            "ordering": true,
            "info": true,
            "autoWidth": false,
        });
    });
    </script>

    <script>
            $(function () {
                $("#tabela").DataTable();
                $('#example2').DataTable({
                    "paging": true,
                    "lengthChange": false,
                    "searching": false,
                    "ordering": true,
                    "info": true,
                    "autoWidth": true,
                });
            });

  </script>

@endsection