@extends(branchMenu())
@section('content')
    <?php Fun::lang()?>
    <style>
        .table.table-striped.table-hover{
            width: 100%;
        }
    </style>
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.report_transfers_stock')}}</h3>
                            </div>
                            <div class="pull-right">
                                @include('administrator.reportpurchases.sub-menu')
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group padding-0">
                        <div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.warehouse')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('to_warehouse_id', $warehouse, null, array('class' => 'form-control select2 warehouse', 'placeholder' =>  __('administrator.please_select_warehouse'))) !!}
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    {{__('administrator.branch')}}
                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    {!! Form::select('branch_id', $branch, null, array('class' => 'form-control select2 branch', 'placeholder' =>  __('administrator.please_select'))) !!}
                                </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-sm-offset-6 col-sm-6">
                                <button class=" button_success pull-right print_button" type="button" data-text="{{__('administrator.report_stock')}}"><i class="fa fa-print" ></i> {{__('administrator.print')}}</button>
                                <button class=" button_primary pull-right" id="search" type="submit"> {{__('administrator.search')}}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table" class="table table-striped table-hover  ">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>{{__('administrator.date')}}</th>
                        <th>{{__('administrator.invoice_number')}}</th>
                        <th>{{__('administrator.from_warehouse')}}</th>
                        <th>{{__('administrator.to_warehouse')}}</th>
                    </tr>
                    </thead>
                    <tbody class="tbody">
                    </tbody>
                </table>
            </div>
        </div>
        @endsection
        @section('script')
            <script type="text/javascript">
             $(document).ready(function () {
                dataTableFilter()
             });
                function dataTableFilter(to_warehouse_id ='',branch_id='',start_date = '', end_date = ''){
                    $('#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: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                        ajax: {
                            url:"{{route('report-transfer-stock-to-warehouse.index')}}",
                            data:{
                                to_warehouse_id:to_warehouse_id,
                                branch_id:branch_id,
                                start_date: start_date,
                                end_date: end_date,
                            },
                        },
                        columns:
                            [
                                {data: 'DT_RowIndex', 'searchable': false},
                                {data: 'date', 'searchable': false},
                                {data: 'invoice_number', 'name': 'nso007_transfer_stock.invoice_number'},
                                {data: 'from_warehouse_id', 'searchable': false},
                                {data: 'to_warehouse_id', 'searchable': false},
                            ],
                        "footerCallback": function (row, data, start, end, display) {

                        },
                    });
                }
                $(document).on('click', '#search', function () {
                    let to_warehouse_id = $('select[name="to_warehouse_id"]').val();
                    let branch_id = $('select[name="branch_id"]').val();
                    let start_date = $('input[name="from_date"]').val();
                    let end_date = $('input[name="to_date"]').val();
                    $('#print_table').DataTable().destroy();
                    dataTableFilter(to_warehouse_id,branch_id, start_date, end_date);
                });
            </script>
@stop



