@extends('layouts.app')
@section('content')
<div class="container">
    @if (Session::has('Mensaje'))
        <div class="alert alert-success" role="alert">
            {{ Session::get('Mensaje') }}
        </div>
    @endif

    <p>
        <h4 style="float: right"><b>Ventas Realizadas</b></h4>
    </p><br><br>

    <div class="input-group col-md-6 mb-3" style="padding:0;">
        <span type="submit" class="input-group-text border-0" id="search-addon">
            <i class="fas fa-search"></i>
        </span>
        <input type="text" class="form-control" placeholder="Buscar..." id="search" name="search">
    </div>

    <div class="table-responsive">
    <table class="table table-light table-hover">
        <thead class="thead-dark">
            <tr style="text-align: center">
                <th>#</th>
                <th>Personal Resp. De Venta</th>
                <th>Fecha de Venta</th>
                <th>Se Realizó La Venta A</th>
                <th>Total</th>   
                <th>Detalles</th>             
            </tr>
        </thead>
        <tbody class="generaldata">
            @foreach ($datos as $dato)
                <tr style="text-align: center">
                    <td>{{ $loop->iteration }}</td>
                    <td>{{ $dato->nombre.' '.$dato->apellidos }}</td>
                    <td>{{ Carbon\Carbon::parse($dato->fecha_venta)->format('d-m-Y') }}</td>
                    <td>{{ $dato->nombre_ven }}</td>
                    <td>{{ $dato->total }}</td>
                    <td>
                        <a href="{{ url('detalleVenta/'.$dato->id_venta) }}" class="btn btn-secondary">
                            <span class="far fa-info-circle"></span> Ver Detalle</a>
                    </td>
                </tr>
            @endforeach
        </tbody>
        <tbody id="content" class="ajaxdata"></tbody>
    </table>
    <div class="paginate_gnraldata">{{ $datos->links() }}</div>
    </div>
    
    <script>
        $(function(){
            $(document).on('keyup', '#search', function(){
                $value = $(this).val();
                if($value)
                {
                    $('.generaldata').hide();
                    $('.paginate_gnraldata').hide();
                    $('.ajaxdata').show();
                }
                else
                {
                    $('.generaldata').show();
                    $('.ajaxdata').hide();
                    $('.paginate_gnraldata').show();
                }
                $.ajax({
                    type:"GET",
                    url:"{{ url('SearchVenta') }}",
                    data:{'search':$value},
                    success:function(data){
                        $('#content').html(data);
                    }
                });
            });
        });
    </script>
</div>
@endsection