@extends('usuarios.clientes.master.layoutcliente')
@section('conteudo')
<style type="text/css">
    .flex
        {
         min-width: 100%;
        }
</style>
{{-- SELECT STYLE --}}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">


  <div class="container-fluid">
        <div class="page-header" width="100%">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">
                        
                        <i class="ik ik-clock bg-orange"></i>
                        <div class="d-inline">
                            <h4>Plano de Tarefas
                                </h4>
                          <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="#"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item"><a href="#">+ Referência de caixas</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Agendar tarefas</li>
                        </ol>
                    </nav>
                </div>
            </div>
          
 
            <div class="row">
                <div class="col-md-6 flex">
                    <div class="card">
                        <div class="card-header">

                                <nav class="breadcrumb-container" aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item">
                                            <a href="../index.html" id="sugestao"><i class="ik ik-info"></i> Sugestão de caixas</a>
                                        </li>
                                        <li class="breadcrumb-item"><a href="{{ route('us.admin.cliente.indexacao.sugestao.box.more') }}">ver mais</a></li>
                                    </ol>
                                </nav>
                            

                        </div>
                        <div class="card-body">
                            <form class="forms-sample" name="cadAgendarTarefas"  method="post">
                                @csrf

                                <div class="row">
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Quantidade de Caixas</label>
                                            <div class="input-group">
                                                <span class="input-group-prepend">
                                                    <label class="input-group-text"><i class="fa fa-box"></i></label>
                                                </span>
                                                <input type="number" name="Quantidade"  min=1 id="Quantidade" class="form-control">
                                            </div>

                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Número da Caixa Inicial</label>
                                            <div class="input-group">
                                                <span class="input-group-prepend">
                                                    <label class="input-group-text"><i class="fa fa-box"></i></label>
                                                </span>
                                                <input type="number" name="numerodacaixa"  id="numerodacaixa" class="form-control">
                                            </div>

                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Número da Caixa Final</label>
                                            <div class="input-group">
                                                <span class="input-group-prepend">
                                                    <label class="input-group-text"><i class="fa fa-box"></i></label>
                                                </span>
                                                <input type="number" name="numerodecaixafinal" id="numerodecaixafinal" class="form-control">
                                            </div>

                                           
                                            
                                        </div>
                                    </div>
                                    

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="exampleSelectGender">Operador</label>
                                            <select  name="funcionario_id" class="form-control" id="funcionario_id" required>
                                                @php
                                                    $dados=\App\Models\User::join('pessoas','pessoas.id','users.pessoa_id')
                                                                            ->join('funcionarioclientes','funcionarioclientes.user_id','users.id')
                                                                            ->join('clientes','clientes.id','funcionarioclientes.cliente_id')
                                                                            //->where('users.id','!=',Auth::id())
                                                                            ->where('clientes.id',$empresa_cliente_id)
                                                                            ->select('pessoas.nome','users.id')->get();

                                                @endphp
                                                
                                                @forelse($dados as $data)
                                                <option value="{{$data->id}}">{{$data->nome}}</option>
                                                @empty
                                                <option>Sem Funcionário cadastrado</option>
                                                @endforelse
                                            </select>
                                        </div>
                                    </div>


                                </div>

                            

                                <div class="row">
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Orgão de Estrututra</label>

                                            <select  name="OE" class="form-control" id="OE" required>
                                                @php
                                                    $orgaoEstrutur=\App\Models\OrgaosDeEstrutura::join('clientes','clientes.id','orgaosdeestrutura.cliente_id')
                                                                                        ->where('clientes.id',$empresa_cliente_id)
                                                                                        ->select('orgaosdeestrutura.*')->get();

                                                @endphp
                                                 <option selected>Selecione um Orgao de Estrutura</option>
                                                @forelse($orgaoEstrutur as $dataorgao)
                                                <option value="{{$dataorgao->id}}">{{$dataorgao->orgao}}</option>
                                                @empty
                                                <option>Sem Orgãos de Estrutura</option>
                                                @endforelse
                                            </select>

                                        </div>
                                    </div>
                                    <!----
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Sére Documental</label>
                                            <input type="text" name="seriedoc" class="form-control" id="seriedoc" placeholder="Kilamba">
                                        </div>
                                    </div>
                                    ---->
                                    <!--- <input type="text" name="telefone" data-mask="000-000-000" class="form-control" id="exampleInputEmail3" placeholder="000-000-000" required> ---->
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label for="exampleSelectGender">Departamento</label>
                                            <select name="dep" class="form-control" id="dep" required>
                                                <option value="0">sem Departemntos Cadastrados</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Data Indexação</label>
                                            <input type="text" name="autor" id="autor" value="CLIENTE" hidden required>
                                            <input type="date" name="Data" id="Data" class="form-control" id="exampleInputEmail3" placeholder="Email">
                                        </div>
                                    </div>
                                </div>

                                
                              {{---  <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="exampleInputEmail3">Email</label>
                                            <input type="email" name="email" class="form-control" id="exampleInputEmail3" placeholder="Email@email">
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label for="exampleSelectGender">Categoria/Area</label>
                                            <select name="categoria" class="form-control" id="exampleSelectGender" required>
                                                
                                            </select>
                                        </div>
                                </div>
                                </div> ----}}

                                <button type="submit" class="btn btn-primary mr-2">Agendar Tarefa</button>
                                
                            </form>
                        </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 type="text/javascript" src="{{url('js/locastyle.js')}}"></script>




<script type="text/javascript">
    $(function () {
        $('form[name="cadAgendarTarefas"]').submit(function (data) {
            data.preventDefault();

            $.ajax({
                url: "{{route('us.admin.cliente.indexacao.save')}}",
                type: "post",
                data: $(this).serialize(),
                dataType: 'json',
                success: function (msgs) {

                    if (msgs.success === true) {
                        const Toast = Swal.mixin({
                            toast: true,
                            position: 'top-end',
                            showConfirmButton: false,
                            timer: 2200,
                            timerProgressBar: true,

                            });

                            Toast.fire({
                            icon: 'success',
                            title: ''+msgs.message,
                                });
                       window.location.href = "{{route('us.admin.cliente.indexacao.listarAgendar')}}";

                    } else {
                        Swal.fire({ position: 'top-end',
                                    icon: 'error',
                                    text: ''+msgs.message,
                                    })
                        //$('.messagebox').removeClass('d-none').html(msgs.message);
                        //alert(msgs.message);
                    }
                    console.log(msgs);

                }

            });

        });
    });

    $("#sugestao").click(function(data)
    {   
        data.preventDefault();

        /***
        $.post("{{route('us.admin.cliente.indexacao.sugestao.box')}}",
                  {
                    '_token':'{{ csrf_token()  }}',
                  }
                  ,function (data) {
                  var dadosBD=$.parseJSON(data);
                    console.log(dadosBD);
                    alert("heyy");
                }).fail(function(){
            alert("Escolha o Tipo de caixa ");
                  });
          
      });
        ****/


      
        $.ajax({
                url: "{{ route('us.admin.cliente.indexacao.numeracoes.sugestoes') }}",
                method: "post",
                data: {
                    '_token':'{{ csrf_token()  }}',
                }
            }).done(function (data) {
                console.log(data);
                Swal.fire({
                        title: 'sugestão de caixas',
                        text:'Numeração de Caixas Disponiveis de '+data+" ate 3000",
                        showClass: {
                            popup: 'animate__animated animate__fadeInDown'
                        },
                        hideClass: {
                            popup: 'animate__animated animate__fadeOutUp'
                        }
                    })
            });
            

                   
    });


</script>
    <script type="text/javascript">
        $('#OE').change(function (event) {
            event.preventDefault();

            //alert("hayyy");
            var OrgEstrutur = document.getElementById("OE").value;
            $.ajax({
                url: "{{route('us.admin.cliente.indexacao.preencher.combobox')}}",
                method: "post",
                data: {
                    OrgEstrutur: OrgEstrutur,
                    '_token':'{{ csrf_token()  }}',
                }
            }).done(function (data) {
                $("#dep").find("option").remove();
                $('#dep').append(data);

            });

        });

        $('#myToast').on('hidden.bs.toast', function () {
        // do something...
        })


        $("#Quantidade").on('keypress change keyup keydown',function() {
                let quantidade=$(this).val();
                if (quantidade>0){
                    
                }else{
                    quantidade=0;
                }
                $.post( "{{ route('us.admin.cliente.indexacao.numeracoes.sugestoes') }}",
                { 
                    '_token':  '{{ csrf_token()  }}',
                    'cliente_id':$("#Cliente").val() 
                },
                function(data){
                    
                    let inicial=parseInt(data);
                    let final=0;
                    console.log(inicial);
                    //return ;
                     if(inicial==0)
                       { 
                           console.log(inicial)
                        console.log("hayy")
                           inicial=inicial+1;
                        
                     final=parseInt(inicial)+parseInt(quantidade)-1}
                    else{
                        console.log(inicial)
                        console.log("heyy")
                        inicial=inicial+1;
                         final=parseInt(inicial)+parseInt(quantidade)    
                    }
                    
                        
                    
                    $("#numerodacaixa").val(inicial);
                    $("#numerodecaixafinal").val(final);
                    
                }).fail(function(){
                    alert("Infelizmente falhou o acesso à esta função");
                });
            });
       
</script>

@endsection
