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

    <div class="container-fluid">
        <div class="">
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.other_income_expense')}} </h3>
                            </div>
                            <div class="pull-right">
                                @can('Other Income Expense Create')
                                    <a data-href="{{route('other-income-expenses.create')}}" class="button_primary getHtmlForm">
                                        <span class="fa fa-plus"></span> {{__('administrator.income')}} / {{__('administrator.expense')}}
                                    </a>
                                @endcan
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <form class="row form_data" style="padding-top: 20px;padding-bottom: 20px">
                    <div class="col-lg-3">
                        <label class="required">@lang('administrator.from_date')</label>
                        {!! Form::text('from_date', date('01-m-Y'), array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker')) !!}
                    </div>
                    <div class="col-lg-3">
                        <label class="required">@lang('administrator.to_date')</label>
                        {!! Form::text('to_date', date('d-m-Y'), array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker')) !!}
                    </div>
                    <div class="col-lg-3">
                        <label class="required">@lang('administrator.type')</label>
                        {!! Form::select('type', ['income'=>__('administrator.income'),'expense'=>__('administrator.expense')],null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control')) !!}
                    </div>
                    <div class="col-lg-3">
                        <label class="required">@lang('administrator.user')</label>
                        <?php
                            $user = \App\Model\OtherIncomeExpense::groupBy('user_id')->pluck('user_id');
                            $user = \App\User::whereIn('id',$user)->pluck('name','id');
                        ?>
                        {!! Form::select('user_id',$user,null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control')) !!}
                    </div>
                </form>
                <table id="datatable_products" class="table  table-striped table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>{{__('administrator.type')}}</th>
                        <th>{{__('administrator.title')}}</th>
                        <th>{{__('administrator.amount')}}</th>
                        <th>{{__('administrator.date')}}</th>
                        <th>{{__('administrator.description')}}</th>
                        <th>{{__('administrator.user')}}</th>
                        <th>{{__('administrator.action')}}</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $(document).ready(function(){
            $('.form_data').on('change','input,select',function () {
                getTable();
            })
            getTable();
        })
        function getTable() {
            $('#datatable_products').DataTable().destroy()
            $('#datatable_products').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: true,
                serverSide: true,
                lengthMenu: tbLeng,
                ajax: {
                    url: "?"+$('.form_data').serialize(),
                },
                columns:
                    [
                        {data: 'DT_RowIndex', searchable: false, "orderable": "false"},
                        {data: 'type'},
                        {data: 'title'},
                        {data: 'amount'},
                        {data: 'date'},
                        {data: 'note'},
                        {data: 'user_id'},
                        {data: 'action',searchable:false},

                    ],
                "initComplete": function (settings, json) {
                }

            });

        }
    </script>
@endsection


