@extends('layouts.layout-2')

@section('content')
    <h4 class="font-weight-bold py-2 mb-2">
        {{ __('Vertriebspartner') }}
    </h4>

    <div class="card">
        <div class="card-header">
            {!! Form::open(['action' => route('admin_lead_download'), 'class' => '']) !!}
            <div class="form-row align-items-center">
                <div class="col-sm-5 col-md-5">
                    <label class="form-label" for="filter_user_shop_id">Art Vertriebspartner</label>
                    <select class="custom-select on_change_select_filter" name="filter_lead_type_id">
                        <option value="all">Alle Vertriebspartner</option>
                        {!! HTMLHelper::getLeadTypeOptions(session('filter_lead_type_id'), false) !!}
                    </select>
                </div>
                <div class="col-sm-4 col-md-4">
                </div>
                <div class="col-sm-3 col-md-3 text-right">
                    <button type="submit" name="action" value="export" class="btn btn-sm btn-primary mt-2"><i
                            class="ion ion-md-download"></i> &nbsp;Export als xls</button>
                </div>
            </div>
            {!! Form::close() !!}

        </div>
        <div class="card-datatable table-responsive">
            <table class="table table-striped table-bordered" id="datatables-leads">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{ __('E-Mail') }}</th>
                        <th>{{ __('Firma') }}</th>
                        <th>{{ __('Vorname') }}</th>
                        <th>{{ __('Nachname') }}</th>
                        <th>{{ __('Level') }}</th>
                        <th>{{ __('Art') }}</th>
                        <th>{{ __('Mitglied') }}</th>
                        <th>{{ __('bis') }}</th>
                        <th>{{ __('Umsatz') }}</th>
                        <th>{{ __('Sales') }}</th>
                        <th>{{ __('verifiziert') }}</th>
                        <th>{{ __('freigegeben') }}</th>
                        <th>{{ __('Einv.') }}</th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>

    <script>
        $(document).ready(function() {

            var oTable = $('#datatables-leads').DataTable({
                "processing": true,
                "serverSide": true,
                "stateSave": true,
                ajax: {
                    url: '{!! route('admin_leads_datatable') !!}',
                    data: function(d) {
                        d.filter_lead_type_id = $('select[name=filter_lead_type_id]').val();
                    }
                },
                "order": [
                    [0, "desc"]
                ],
                "columns": [{ data: 'id', searchable: false
                    },
                    { data: 'email', name: 'email' },
                    { data: 'company', name: 'account.company' },
                    { data: 'first_name', name: 'account.first_name' },
                    { data: 'last_name', name: 'account.last_name' },
                    { data: 'user_level', name: 'user_level' },
                    { data: 'lead_type', name: 'lead_type' },
                    { data: 'payment_account', name: 'payment_account' },
                    { data: 'payment_account_date', name: 'payment_account_date' },
                    { data: 'turnover', name: 'turnover' },
                    { data: 'sales_total', name: 'sales_total' },
                    { data: 'confirmed', name: 'confirmed' },
                    { data: 'active', name: 'active' },
                    { data: 'agreement', name: 'agreement' },
                ],
                "bLengthChange": false,
                "iDisplayLength": 50,
                "language": {
                    "url": "/js/German.json"
                }
            });

            $('select.on_change_select_filter').on('change', function(){
                oTable.draw();
            });

            $('input.on_keyup_input_filter').on('keyup', function(){
                oTable.draw();
            });


        });
    </script>
@endsection
