@extends(branchMenu())
@section('content')
    <?php Fun::lang()?>
    <div class="page">
        <div class=container-fluid>
            <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.manage_stock_in')}}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <br>&nbsp;
            <br>
            <div class="top-content">
                <form class="form_filter">
                <div class="row mt-3">
                    <div class="col-lg-12">
                        <div class="col-md-3 ">
                            {{__('administrator.from_date')}}
                            {!! Form::text('from_date',null, ['placeholder'=>__('administrator.from_date'),'class' => 'form-control date_picker']) !!}
                        </div>
                        <div class="col-md-3 ">
                            {{__('administrator.to_date')}}
                            {!! Form::text('to_date',null, ['placeholder'=>__('administrator.to_date'),'class' => 'form-control date_picker']) !!}
                        </div>
                        <div class="col-sm-3 col-md-3 ">
                            {{__('administrator.user')}}
                            {!! Form::select('user_id',$user, null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))) !!}
                        </div>
                        <div class="col-sm-3 col-md-3">
                            {{__('administrator.supplier')}}
                            {!! Form::select('supplier',$supplier, null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))) !!}

                        </div>
                    </div>
                    <div class="col-lg-12 mt-4">
                        <div class="col-sm-3 col-md-3">
                            {{__('administrator.type')}}
                            {!! Form::select('type',$type,null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))) !!}

                        </div>
                        <div class="col-sm-3 col-md-3">
                            {{__('administrator.warehouse')}}
                            {!! Form::select('warehouse',getWarehouse('item')->pluck('warehouse_name','id'),null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))) !!}

                        </div>
                        @can('Show Purchase Item Price')
                            <div class="col-sm-3 col-md-3">
                                {{__('administrator.status')}}
                                {!! Form::select('status', getPaymentStatus(), null, ['placeholder'=>__('administrator.please_select'),'class' => 'form-control status select2']) !!}

                            </div>
                        @endcan
                    </div>
                </div>
                </form>
            </div>
            <div class="wrapper-table">
                <table id="print_table" class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>{{__('administrator.type')}}</th>
                        <th>{{__('administrator.purchase_date')}}</th>
                        <th>{{__('administrator.invoice_number')}}</th>
                        <th>{{__('administrator.supplier_name')}}</th>
                        <th>{{__('administrator.supplier_phone')}}</th>
                        <th>{{__('administrator.warehouse')}}</th>
                        @can('Show Purchase Item Price')
                            <th>{{__('administrator.total')}}</th>
                            <th>{{__('administrator.paid')}}</th>
                            <th>{{__('administrator.remain_amount')}}</th>
                            <th>{{__('administrator.payment_status')}}</th>
                        @endcan
                        <th>{{__('administrator.user')}}</th>
                        <th>{{__('administrator.action')}}</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        function getTable() {
            $('#print_table').DataTable().destroy();
            $('#print_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,
                serverSide: true,
                lengthMenu: tbLeng,
                ajax: {
                    url: "{{ route('purchases.index') }}?"+$('.form_filter').serialize(),
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'type', 'searchable': false},
                        {data: 'purchase_date', 'name': 'nso007_purchases.purchase_date'},
                        {data: 'invoice_number', 'name': 'nso007_purchases.invoice_number'},
                        {data: 'supplier_name', 'searchable': false},
                        {data: 'supplier_phone', 'searchable': false},
                        {data: 'warehouse_id', 'searchable': false},
                            @can('Show Purchase Item Price')
                        {
                            data: 'total', 'searchable': false
                        },
                        {data: 'paid', 'searchable': false},
                        {data: 'remain', 'searchable': false},
                        {data: 'payment_status'},
                            @endcan
                        {
                            data: 'user_id', 'searchable': false
                        },
                        {
                            data: 'action', 'searchable': false
                        },

                    ],

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

        $(document).ready(function () {
            getTable();
            $('#print_table').on('click', '.btn_delete', function () {
                confirmForm($(this).data('href'));
            });
            $('.select2,.date_picker').on('change', function () {
                getTable();
            });
        });
    </script>
@stop
