@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.stock_transfer_fabric')}}</h3>
                            </div>
                            <div class="pull-right">
                            @can('Request Stock Create')
                                <a href="{{route('transfer-stock-fabric.create')}}" class=" button_info"><span
                                            class="fa fa-plus"></span> {{__('administrator.add_new')}}</a>
                            @endcan
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <br>&nbsp;
            <br>
            <div class="wrapper-table">
                <table id="print_table" class="table table-striped table-hover ​​">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>{{__('administrator.date')}}</th>
                        <th>{{__('administrator.reference_number')}}</th>
                        <th>{{__('administrator.branch')}}</th>
                        <th>{{__('administrator.from_warehouse')}}</th>
                        <th>{{__('administrator.to_warehouse')}}</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: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
                ajax: {
                    url: "{{ route('transfer-stock-fabric.index') }}",
                    data: {}
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'date', 'searchable': false},
                        {data: 'invoice_number', 'name': 'nso007_transfer_stock.invoice_number'},
                        {data: 'branch_id', 'searchable': false},
                        {data: 'from_warehouse_id', 'searchable': false},
                        {data: 'to_warehouse_id', 'searchable': false},
                        {data: 'action', 'searchable': false},
                    ],
                "initComplete": function (settings, json) {
                }
            });
        }

        $(document).ready(function () {
            getTable();
            $('.select2').on('change', function () {
                let supplier = $('select[name=supplier]').val();
                let type = $('select[name=type]').val();
                getTable(supplier, type);
            });

            $(document).on('click', ' .show_request', function () {
                let id = $(this).data('id');
                let confirm_status = $(this).data('confirm_status');
                $.ajax({
                    url: $(this).data('href'),
                    method: 'get',
                    dataType: 'json',
                    success: function (data) {
                        $.confirm({
                            title: '',
                            theme: 'modern',
                            useBootstrap: false,
                            boxWidth: '50%',
                            content: data.view,
                            buttons: {
                                close: {
                                    text: '{{__('administrator.close')}}',
                                    btnClass: 'button_warning',
                                },
                                print: {
                                    text: '{{__('administrator.print')}}',
                                    btnClass: 'button_info',
                                    keys: ['enter'],
                                    action: function () {
                                        $('.page-purchases').printThis({
                                            loadCSS: "{{asset('assets/css/pos-invoice.css')}}",
                                            afterPrint: function () {
                                                window.location.reload();
                                            }
                                        });
                                        return false;
                                    },
                                },
                            },
                        });
                        setTimeout(function () {
                            if (confirm_status === 0) {
                                $('.confirm_status').remove();
                            }
                        },10);

                    }
                });
            });
        });
    </script>
@stop
