@extends('layouts.layout-2')

@section('content')
    <h4 class="font-weight-bold py-3 mb-1">
        Leistungsträger-Zahlungen
        <a class="btn btn-default btn-sm float-right" href="{{ make_old_url('backend.php') }}" > zurück ins v1 CRM</a>
    </h4>
    <div class="card">
        {!! Form::open(['url' => route('admin_report_export_providers'), 'class' => '']) !!}
        {!! Form::hidden('order', '[[8, "asc"]]', ['id'=>'order_table']) !!}
        <div class="ui-bordered px-4 pt-3 mb-0">
            <div class="form-row align-items-center">
                <div class="col-12 col-md-4 mb-4">
                    <label class="form-label" for="filter_service_provider_id">Leistungsträger</label>
                    <select class="custom-select" name="filter_service_provider_id" id="filter_service_provider_id">
                        <option value="">Filter aus</option>
                        @foreach($serviceProviders as $serviceProvider)
                            <option value="{{$serviceProvider->id}}">{{$serviceProvider->name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-12 col-md-4 mb-4">
                    <label class="form-label">Reisedatum</label>
                    <div class="row">
                        <div class="input-group col-6 pr-0">
                            <div class="input-group-prepend">
                                <span class="input-group-text">von</span>
                            </div>
                            <input class="form-control datepicker-base" name="filter_travel_date_from" type="text" value="">
                        </div>

                        <div class="input-group col-6 pl-1">
                            <div class="input-group-prepend">
                                <span class="input-group-text">bis</span>
                            </div>
                            <input class="form-control datepicker-base" name="filter_travel_date_to" type="text" value="">
                        </div>
                    </div>
                </div>
                <div class="col-6 col-md-3 mb-4">
                    <label class="form-label" for="filter_is_cleared">Bezahlt</label>
                    <select class="custom-select" name="filter_is_cleared" id="filter_is_cleared">
                        <option value="">Filter aus</option>
                        <option value="1">Ja</option>
                        <option value="0">Nein</option>
                    </select>
                </div>
                <div class="col-6 col-md-1 mb-4 mt-4">
                    <a href="{{ route('admin_report_providers') }}" class="btn icon-btn btn-sm btn-outline-dark float-right">
                        <span class="fa fa-sync"></span>
                    </a>
                </div>
            </div>
        </div>

        <div class="card-datatable table-responsive">
            <table class="datatables-report table table-striped table-bordered">
                <thead>
                <tr>
                    <th>SPE ID</th>
                    <th>BuchungsID</th>
                    <th>{{__('Reiseveranstalter')}}</th>
                    <th>{{__('MyJack Nr.')}}</th>
                    <th>{{__('Organisation')}}</th>
                    <th>{{__('Reisepreis')}}</th>
                    <th>{{__('Erlös')}}</th>
                    <th>{{__('Kunde')}}</th>
                    <th>{{__('Reisedatum')}}</th>
                    <th>{{__('bis')}}</th>
                    <th>{{__('bezahlt')}}</th>
                </tr>
                </thead>
                <tbody></tbody>
                <tfoot>
                <tr>
                    <td colspan="4">Total</td>
                    <td id="price_total_sum">0</td>
                    <td id="price_total_total_sum">0</td>
                    <td id="proceed_total_sum">0</td>
                    <td colspan="3"></td>
                </tr>
                </tfoot>
            </table>

            <div class="mt-4 col">
                <button type="submit" name="export" value="export" class="btn btn-primary"><i class="ion"></i> Export </button>
                <button type="submit" name="export" value="export_lt" class="btn btn-primary"><i class="ion"></i> Export LT </button>
            </div>
        </div>
        {!! Form::close() !!}
    </div>

    <script>
        $( document ).ready(function() {
            var table = $('.datatables-report').DataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {
                    "url": '{!! route( 'admin_report_providers_datatable' ) !!}',
                    "data": function(d) {
                        d.filter_sort_by = $('select[name=filter_sort_by]').val();
                        d.filter_service_provider_id = $('select[name=filter_service_provider_id]').val();
                        d.filter_travel_date_from = $('input[name=filter_travel_date_from]').val();
                        d.filter_travel_date_to = $('input[name=filter_travel_date_to]').val();
                        d.filter_is_cleared = $('select[name=filter_is_cleared]').val();
                    }
                },
                "columns": [
                    { data: 'id', name: 'id' },
                    { data: 'booking.id', name: 'booking.id' },
                    { data: 'service_provider.name', name: 'service_provider.name', orderable: false },
                    { data: 'booking.merlin_order_number', name: 'booking.merlin_order_number' },
                    { data: 'booking.price', name: 'booking.price' },
                    { data: 'booking.price_total', name: 'booking.price_total' },
                    { data: 'booking.proceeds', name: 'booking.proceeds', orderable: false },
                    { data: 'booking.customer.fullName', name: 'booking.customer.fullName' },
                    { data: 'booking.start_date', name: 'booking.start_date' },
                    { data: 'booking.end_date', name: 'booking.end_date' },
                    { data: 'is_cleared', name: 'is_cleared' },
                ],
                "order": [[ 8, "asc" ]],
                "orderSequence": ["desc", "asc"],
                "bLengthChange": false,
                "iDisplayLength": 100,
                "language": {
                    "url": "/js/German.json"
                },
                drawCallback: function (settings) {
                    $('#order_table').val(table.order());
                    $('#price_total_sum').html(settings.json.price_total_sum);
                    $('#price_total_total_sum').html(settings.json.price_total_total_sum);
                    $('#proceed_total_sum').html(settings.json.proceed_total_sum);
                }
            });

            $('#filter_service_provider_id, #filter_is_cleared, #filter_sort_by').on('change', function(){
                table.order( [ 8, 'asc' ] ).draw();
            });

            $('.datepicker-base').on('change', function(){
                table.order( [ 8, 'asc' ] ).draw();
            });
        });
    </script>
@endsection