@extends("include")


<script type="text/javascript">
    $(document).ready(function () {

    });
</script>

@section("body")
    <div class="main-cont">
        <div class="new-pur">
            <h6>الاذونات الواردة الغير مستلمة</h6>
            <hr>
            <table id="example1" class="table table-striped table-bordered" style="width:100%">
                <thead>
                <tr>
                    <th>رقم الاذن</th>
                    <th>تاريخ الاذن</th>
                    <th>من فرع</th>
                    <th>مطابقة</th>
                </tr>
                </thead>
                <tbody>
                @foreach($pending as $doc)
                    <tr>
                        <td>{{$doc->stock_doc_id}}</td>
                        <td>{{$doc->stock_doc_date}}</td>
                        <td>{{$doc->branchfrom->branch_name}}</td>
                        <td>
                            <!-- Button trigger modal -->
                            <button type="button" class="btn btn-primary" data-toggle="modal"
                                    data-target="#exampleModal{{$doc->stock_doc_id}}">
                                مطابقة
                            </button>

                            <!-- Modal -->
                            <div class="modal fade bd-example-modal-lg" id="exampleModal{{$doc->stock_doc_id}}"
                                 tabindex="-1" role="dialog"
                                 aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog modal-lg" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel">مطابقة الاذن</h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <form action="{{url('/accept'.'/'.$doc->id)}}" method="get">
                                            @csrf
                                            <div class="modal-body">
                                                <table class="table">
                                                    <thead>
                                                    <tr>
                                                        <th>رقم المنتج</th>
                                                        <th>الكمية</th>
                                                        <th>مطابقة</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    @foreach($doc ->details as $item)
                                                        <tr>
                                                            <td id="serial{{$item->stock_doc_details_id}}">{{$item->item_serial}}</td>
                                                            <td>{{$item->item_quantity}}</td>
                                                            <td>
                                                                <input onchange="check({{$item->stock_doc_details_id}})" type="text" id="item{{$item->stock_doc_details_id}}" name="item[{{$item->stock_doc_details_id}}]">
                                                                <span id="append"></span>
                                                            </td>
                                                        </tr>
                                                    @endforeach
                                                    </tbody>
                                                </table>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-secondary" data-dismiss="modal">
                                                    Close
                                                </button>
                                                <button type="submit" class="btn btn-primary">Accept</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                @endforeach

                </tbody>
                <tfoot>
                <tr>
                    <th>رقم الاذن</th>
                    <th>تاريخ الاذن</th>
                    <th>من فرع</th>
                    <th>مطابقة</th>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>

    <div class="main-cont">
        <div class="new-pur">
            <h6>الاذونات الواردة</h6>
            <hr>
            <table id="example" class="table table-striped table-bordered" style="width:100%">
                <thead>
                <tr>
                    <th>رقم الاذن</th>
                    <th>تاريخ الاذن</th>
                    <th>من فرع</th>
                    <th>التفاصيل</th>
                </tr>
                </thead>
                <tbody>
                @foreach($docs as $doc)
                    <tr>
                        <td>{{$doc->stock_doc_id}}</td>
                        <td>{{$doc->stock_doc_date}}</td>
                        <td>{{$doc->branchfrom->branch_name}}</td>
                        <td>
                            <!-- Button trigger modal -->
                            <button type="button" class="btn btn-primary" data-toggle="modal"
                                    data-target="#exampleModal{{$doc->id}}">
                                التفاصيل
                            </button>

                            <!-- Modal -->
                            <div class="modal fade" id="exampleModal{{$doc->id}}" tabindex="-1" role="dialog"
                                 aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog" role="document">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title" id="exampleModalLabel">تفاصيل االاذن</h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body">
                                            <table class="table">
                                                <thead>
                                                <tr>
                                                    <th>رقم المنتج</th>
                                                    <th>الكمية</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                @foreach($doc->details as $item)
                                                    <tr>
                                                        <td>{{$item->item_serial}}</td>
                                                        <td>{{$item->item_quantity}}</td>
                                                        {{--                                                                <td>{{$item->branch_number}}</td>--}}
                                                    </tr>
                                                @endforeach
                                                </tbody>
                                            </table>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close
                                            </button>
                                            {{--                                                    <button type="button" class="btn btn-primary">Save changes</button>--}}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                @endforeach

                </tbody>
                <tfoot>
                <tr>
                    <th>رقم الاذن</th>
                    <th>تاريخ الاذن</th>
                    <th>من فرع</th>
                    <th>التفاصيل</th>
                </tr>
                </tfoot>
            </table>

        </div>

    </div>




    {{--    eeeeeeeeeeeee--}}


    <!-- add adress popup -------------------------------------------------------------------------->

    <!-- Main Section ------------------------------------------------------------------------------->







    <script type="text/javascript">

        $(document).ready(function () {
            var table = $('#example').DataTable();

            $('#example tbody ').on('click', 'tr', function () {
                $(this).toggleClass('selected');
                var checkbox = $(this).find("input[type='checkbox']");
                checkbox.prop('checked', !checkbox.prop("checked"));


            });

            $('#button').click(function () {
                alert(table.rows('.selected').data().length + ' row(s) selected');
            });
        });


        $(document).ready(function () {
            var table = $('#example2').DataTable();

            $('#example tbody ').on('click', 'tr', function () {
                $(this).toggleClass('selected');
                var checkbox = $(this).find("input[type='checkbox']");
                checkbox.prop('checked', !checkbox.prop("checked"));


            });

            $('#button').click(function () {
                alert(table.rows('.selected').data().length + ' row(s) selected');
            });
        });
    </script>
<script type="text/javascript" src="{{asset('Js/check.js')}}"></script>
@endsection
