@extends(branchMenu())
@section('content')
    <?php Fun::lang()?>

    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="row">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        <h3>{{__('administrator.payment_by_agent')}}</h3>
                    </div>
                </div>
                <div class="container-fluid" style="background: white; padding:10px">
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.payment_by')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('payment_by',$pb,null, ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.request_by')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('user_id',@$seller?$seller:[],null, ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.customer')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('customer_id',[],null, ['placeholder'=>__('administrator.please_select'),'class' => 'search_customer form-control select2']) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.from_date')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::text('from_date', null, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.to_date')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::text('to_date', null, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')) !!}
                                </div>
                            </div>
                            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
                                <div class="col-sm-12">
                                    <button type="submit" id="search"
                                            class="button_info pull-right">{{__('administrator.search')}}</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table id="data_table" class="table table-hover" width="100%">
                            <thead>
                            <tr>
                                <th width="5%">#</th>
                                <th>{{__('administrator.payment_date')}}</th>
                                <th>{{__('administrator.sale_date')}}</th>
                                <th>{{__('administrator.invoice')}}</th>
                                <th>{{__('administrator.payment_by')}}</th>
                                <th>{{__('administrator.request_by')}}</th>
                                <th>{{__('administrator.customer')}}</th>
                                <th>{{__('administrator.paid_amount')}}</th>
                            </tr>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $(document).ready(function () {
            getTable();
            $(document).on('click', '#search', function () {
                getTable();
            });
        });

        function getTable() {
            let user_id = $('select[name="user_id"]').val();
            let customer_id = $('select[name="customer_id"]').val();
            let payment_by = $('select[name="payment_by"]').val();
            let start_date = $('input[name="from_date"]').val();
            let end_date = $('input[name="to_date"]').val();
            $('#data_table').DataTable().destroy();
            $('#data_table').DataTable({
                "oLanguage": {
                    "sSearch": "{{__('administrator.search')}}:",
                    "sLengthMenu": "{{__('administrator.display')}} _MENU_ {{__('administrator.record_per_page')}}",
                    "sZeroRecords": "{{__('administrator.Nothing_foundsorry')}}",
                    "sInfo": "{{__('administrator.showing')}} _START_ {{__('administrator.to')}} _END_ {{__('administrator.of')}} _TOTAL_ {{__('administrator.record')}}",
                    "sInfoEmpty": "{{__('administrator.showing')}} 0 {{__('administrator.to')}} 0 {{__('administrator.of')}} 0 {{__('administrator.record')}}",
                    "sInfoFiltered": "({{__('administrator.filter_form')}} _MAX_ {{__('administrator.total_records')}})",
                    "oPaginate": {
                        "sFirst": "{{__('administrator.first')}}",
                        "sLast": "{{__('administrator.last')}}",
                        "sNext": "{{__('administrator.next')}}",
                        "sPrevious": "{{__('administrator.previous')}}"
                    },
                },
                ordering: false,
                processing: false,
                serverSide: true,
                lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                ajax: {
                    url: "{{ route('get-payment-by-agent') }}",
                    data: {
                        user_id: user_id,
                        customer_id: customer_id,
                        payment_by: payment_by,
                        start_date: start_date,
                        end_date: end_date,
                    }
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'created_at'},
                        {data: 'payment_date'},
                        {data: 'invoice_number', 'name': 'nso007_sales.invoice_number'},
                        {data: 'payment_by', 'searchable': false},
                        {data: 'user_id', 'searchable': false},
                        {data: 'customer_name', 'searchable': false},
                        {data: 'paid_amount', 'searchable': false},
                    ],
                "initComplete": function (settings, json) {

                }

            });
        }
    </script>
@endsection
