@extends('layouts.layout-2')

@section('content')


    <h4 class="font-weight-bold py-2 mb-2">
        {{ __('Bestellungen Kunden') }}
    </h4>
    <div class="card">
        <div class="card-header">
            <div class="form-row align-items-center">

                <div class="col-sm-6 col-md-4 col-lg-3 mb-2">
                    <label class="form-label" for="filter_member_id">Filter zugewiesener Vertriebspartner</label>
                    <select class="custom-select" name="filter_member_id" id="filter_member_id">
                        <option value="">Filter aus</option>
                        @foreach($filter_members as $member)
                            <option value="{{$member->id}}" @if(get_user_attr('filter_member_id') == $member->id) selected @endif>{{$member->first_name}} {{$member->last_name}} |{{$member->email}}</option>
                        @endforeach
                    </select>
                </div>
              
                <div class="col-sm-6 col-md-4 col-lg-3 mb-2">
                    <label class="form-label" for="filter_txaction">Filter Status</label>
                    <select class="custom-select" name="filter_txaction" id="filter_txaction">
                        <option value="">Filter aus</option>
                        @foreach(\App\Services\Payment::$txaction_text as $id=>$name)
                            <option value="{{$id}}" @if(get_user_attr('filter_txaction') == $id) selected @endif>{{$name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-sm-6 col-md-4 col-lg-3 mb-2">
                    <label class="form-label" for="filter_shipped">Filter Versand</label>
                    <select class="custom-select" name="filter_shipped" id="filter_shipped">
                        <option value="">Filter aus</option>
                        @foreach(\App\Models\ShoppingOrder::$shippedTypes as $id=>$name)
                            <option value="{{$id}}" @if(get_user_attr('filter_shipped') === $id) selected @endif>{{$name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="col-sm-6 col-md-4 col-lg-2 mb-2">
                    <label class="form-label" for="filter_art">Filter Art</label>
                    <select class="custom-select" name="filter_art" id="filter_art">
                        <option value="">Filter aus</option>
                        @foreach(\App\Services\PaymentService::$txaction_art as $id=>$name)
                            <option value="{{$id}}" @if(get_user_attr('filter_art') == $id) selected @endif>{{$name}}</option>
                        @endforeach
                    </select>
            </div>
                <div class="col-sm-1 col-md-1 col-lg-1 mb-2 mt-4">
                    <a href="{{ route('admin_sales') }}?reset=filter"  data-toggle="tooltip" data-placement="top"  title="Reset Filter" 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="datatable-customers table table-striped table-bordered" id="datatable-customers">
                <thead>
                <tr>
                    <th>#</th>
                    <th>{{__('Datum')}}</th>
                    <th>{{__('Betrag')}}</th>
                    <th>{{__('Zahlung')}}</th>
                    <th>{{__('Status')}}</th>
                    <th>{{__('Versand')}}</th>
                    <th>{{__('Art')}}</th>
                    <th>{{__('First name')}}</th>
                    <th>{{__('Last name')}}</th>
                    <th>{{__('E-Mail')}}</th>
                    <th>{{__('zugewiesener Vertriebspartner')}}</th>
                    <th>{{__('Rf-Nr.')}}</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <script>
        $( document ).ready(function() {
            var oTable = $('#datatable-customers').DataTable({
                    "processing": true,
                    "serverSide": true,
                    ajax: {
                        url: '{!! route( 'admin_sales_datatable') !!}',
                        data: function(d) {
                            d.filter_member_id = $('select[name=filter_member_id]').val();
                            d.filter_txaction = $('select[name=filter_txaction]').val();
                            d.filter_art = $('select[name=filter_art]').val();
                            d.filter_shipped = $('select[name=filter_shipped]').val();
                        }
                    },
                    "order": [[0, "desc" ]],
                    "columns": [
                        { data: 'id', searchable: false },
                        { data: 'created_at', name: 'shopping_orders.created_at' },
                        { data: 'total_shipping', name: 'total_shipping' },
                        { data: 'payment', name: 'payment', orderable: false },
                        { data: 'txaction', name: 'txaction' },
                        { data: 'shipped', name: 'shipped' },
                        { data: 'payment_for', name: 'payment_for' },
                        { data: 'shopping_user.billing_firstname', name: 'shopping_user.billing_firstname' },
                        { data: 'shopping_user.billing_lastname', name: 'shopping_user.billing_lastname' },
                        { data: 'shopping_user.billing_email', name: 'shopping_user.billing_email' },
                        { data: 'member_id', name: 'member_id', searchable: false, orderable: false },
                        { data: 'reference', name: 'reference' },
                    ],
                    "bLengthChange": false,
                    "iDisplayLength": 100,
                    "language": {
                        "url": "/js/German.json"
                    }
                });
            $('#filter_member_id').on('change', function(){
                oTable.draw();
            });
            $('#filter_txaction').on('change', function(){
                oTable.draw();
            });
            $('#filter_art').on('change', function(){
                oTable.draw();
            });
            $('#filter_shipped').on('change', function(){
                oTable.draw();
            });
        });
    </script>
@endsection