@extends('template.layout')

@section('content')
    @include('sweet::alert')
    <h1 class="page-title">
        Reporte de cierre de caja
    </h1>
    <div class="portlet light portlet-fit portlet-datatable bordered">

        <div class="portlet-body">

            <div class="tab-content">

                <div style="padding: 6% 6% 6% 6%;">
                    <table class="table table-hover nowrap dataTable dtr-inline collapsed tbcierredecajas"
                           id="tbcierredecajas" width="100%" role="grid"
                           aria-describedby="tbcierredecajas_info">
                        <thead class="thead-default">
                        <tr>
                            <th> Nombre usuario</th>
                            <th> Cantidad de pagos </th>
                            <th> Fecha </th>
                            <th> Monto </th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($cierrecaja as $item)
                            <tr>
                                <td> {{ $item->apellido_paterno }} {{ $item->apellido_materno }}
                                    , {{ $item->nombres }}</td>
                                <td> {{ $item->cantpagos }} </td>
                                <td> {{  \Carbon\Carbon::parse( $item->created_at)->format('d-m-Y')   }} </td>
                                <td>
                                    <a class="labelobs"
                                       onclick="callmodel({{$item->id}})">  {{ $item->monto }}   </a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>

            </div>

        </div>

    </div>

    <div id="modalObs" class="modal fade" tabindex="-1" aria-hidden="true" style="display: none; padding-right: 17px;">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h4 class="modal-title">Detalle cierre de caja</h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div id="mbody"></div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" data-dismiss="modal" class="btn dark btn-outline">cerrar</button>
                </div>
            </div>
        </div>
    </div>

@endsection
@section('scripts')
    <script>

        $('#tbcierredecajas').DataTable({
            "lengthMenu": [[25, 20, 50, -1], [25, 20, 50, "Todas"]],
            bFilter: true,
            "bLengthChange": false,
            bInfo: true,
            responsive: true,
            "autoWidth": true,
            "language": {
                "lengthMenu": "Mostrar _MENU_ Entradas",
                "zeroRecords": "No se encontraron registros",
                "info": "Mostrando la página _PAGE_ de _PAGES_",
                "infoEmpty": "No hay registros disponibles",
                "infoFiltered": "(filtrado de _MAX_ registros totales)",
                "search": "Buscar: ",
                "paginate": {
                    "first": "Primero",
                    "last": "Último",
                    "next": "Siguiente",
                    "previous": "Anterior"
                },
            },
            "order": [],
            "aoColumns": [
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": true},
                {"bSearchable": false},
            ],
            "columns": [
                {"orderable": true},
                {"orderable": true},
                {"orderable": true},
                {"orderable": false},
            ],
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'excel',
                    title: 'Reporte de cierre de caja'
                }, {
                    extend: 'pdf',
                    title: 'Reporte de cierre de caja'
                }

            ]
        });

        function callmodel(idcierrecaja) {

            $.ajax({

                url: "{{url('reportetesoreria/cierredeturno/detalle')}}" + "/" + idcierrecaja,

                success: function (data) {
                    $("#mbody").empty();
                    $("#mbody").html(data);
                }

            });

            $("#modalObs").modal('show');
        };

    </script>
@endsection
