 @extends('adminlte::page') @section('content')
<?php Fun::lang()?>
    <div class="alert-message alert-success" role="alert" style="display: none;">
        <h4 class="alert-heading">Well done!</h4>
        <hr>
        <p class="mb-0"> Approved successfully.</p>
    </div>

    <div class="alert-message alert-danger " role="alert" style="display: none;">
        <h4 class="alert-heading">Error!</h4>
        <hr>
        <p>Whoops Something went wrong!!</p>
    </div>

    <div class="title-page">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
                <li><a href="#">Manage Agency Wallet</a></li>
            </ul>
        </div>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>Regiser Wallet</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12">
                <div class="top-view pull-right">
                    @can('Wallet-Registration-Approve')
                    <button class="button_primary delete-all" data-url="" data-status="1">
                        <span class="fa fa-check">
                        </span> Approve All
                    </button>
                    <button class="button_danger  delete-all" data-url="" data-status="2">
                        <span class="fa fa-close"></span> Reject All
                    </button>
                    @endcan
                </div>
            </div>
        </div>
        <div class="box-body table-responsive">
            <table id="datatable_item" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                    <tr>
                        <th>No</th>
                        <th>
                            <label class="checkbox-list">
                                <input type="checkbox" id="check_all">
                                <span class="checkmark"></span></label>

                        </th>
                        <th>Requested Date</th>
                        <th>Agency Code</th>
                        <th>Agency Name</th>
                        <th>Account Number</th>
                        <th>Account Name</th>
                        <th>Status</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
   <!--  <div class="modal fade" id="popUpApprove" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content custom-pupup">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">Do you want to active account?</h4>
                </div>
                <div class="modal-body">
                    <div>
                        It will be activate this account!
                    </div>
                    <p class="statusMsg"></p>
                    <form role="form" method="POST" id="form_update_approve">
                        {{csrf_field()}}
                        <input type="text" name="status" id="status" hidden>
                        <div class="modal-footer">
                            <button type="button" class="fa fa-reply button_info" data-dismiss="modal"> Cancel</button>
                            <button type="submit" class="fa fa-check button_primary"> Yes</button>

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
 -->

    <div class="modal fade bs-modal-lg" id="popUpApprove" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h3 class="modal-title">Are you sure?</h3>
                </div>
                <br/>
                <form role="form" method="POST" id="form_update_approve">
                    {{csrf_field()}}
                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-10">
                                <h4>It will be activate this account!</h4>
                                <input type="text" name="status" id="status" hidden>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" data-dismiss="modal" class="button_danger"><i class="fa fa-close"></i> No</button>
                        <button type="submit" class="button_success" data-toggle="modal"><i class="fa fa-save"></i> OK</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

    <div class="modal fade bs-modal-lg" id="popUpReject" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h3 class="modal-title">Are you sure?</h3>
                </div>
                <br/>
                <form role="form" method="POST" id="form_update_reject">
                    {{csrf_field()}}
                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-10">
                                <h4>It will be deactivate this account!</h4>
                                 <input type="text" name="status" id="status" hidden>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" data-dismiss="modal" class="button_danger"><i class="fa fa-close"></i> No</button>
                        <button type="submit" class="button_success" data-toggle="modal"><i class="fa fa-save"></i> OK</button>
                    </div>
                </form>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>

<!-- 

    <div class="modal fade" id="popUpReject" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content custom-pupup">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                        <span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">Do you want to deactive account?</h4>
                </div>
                <div class="modal-body">
                    <div>
                        It will be deactivate this account!
                    </div>
                    <p class="statusMsg"></p>
                    <form role="form" method="POST" id="form_update_reject">
                        {{csrf_field()}}
                        <input type="text" name="status" id="status" hidden>
                        <div class="modal-footer">
                            <button type="button" class="fa fa-reply button_info" data-dismiss="modal"> Cancel</button>
                            <button type="submit" class="fa fa-check button_primary"> Yes</button>

                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div> -->

    @endsection @section('js')

    <script type="text/javascript">
        $(document).ready(function() {
            $('.main-spinner').show();
            $('#datatable_item').DataTable({
                ordering: false,
                serverSide: true,
                "lengthMenu": [
                    [20, 30, 50, 100, -1],
                    [20, 30, 50, 100, "All"]
                ],
                ajax: "{{ route('datatable.get_funds_request_account') }}",
                columns: [
                    {data: 'DT_RowIndex'},
                    {data: 'check_id', 'width': '3px'},
                    {data: 'created_at'},
                    {data: 'user_code'},
                    {data: 'fullname'},
                    {data: 'account_number'},
                    {data: 'account_name'},
                    {data: 'status'},
                ],

                "initComplete": function(settings, json) {
                    $('.main-spinner').hide();
                }
            });
            $.fn.dataTable.ext.errMode = 'throw';
        });

        $(document).on('click', '.viewPopUpApprove', function() {
            var id = $(this).data('id');

            var url = "/realty/approve-funds-register";
            $('#form_update_approve').attr('action', url + '/' + id);
            $('#popUpApprove').modal('show');

        });

        $(document).on('click', '.viewPopUpReject', function() {
            var id = $(this).data('id');

            var url = "/realty/reject-funds-register";
            $('#form_update_reject').attr('action', url + '/' + id);
            $('#popUpReject').modal('show');

        });

        $('#check_all').on('click', function(e) {
            if ($(this).is(':checked', true)) {
                $(".checkbox").prop('checked', true);
            } else {
                $(".checkbox").prop('checked', false);
            }
        });

        $('.checkbox').on('click', function() {
            if ($('.checkbox:checked').length == $('.checkbox').length) {
                $('#check_all').prop('checked', true);
            } else {
                $('#check_all').prop('checked', false);
            }
        });
        $('.delete-all').on('click', function(e) {
            var status = $(this).data('status');

            var idsArr = [];
            $(".checkbox:checked").each(function() {
                idsArr.push($(this).attr('data-id'));
            });
            if (idsArr.length <= 0) {
                $('.alert-danger').show();
            } else {
                if (confirm("Are you sure, you want to Approve the selected?")) {
                    var strIds = idsArr.join(",");
                    $.ajax({
                        url: "{{ route('multiple.register-approved-rejected') }}",
                        type: 'DELETE',
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        data: {
                            ids: strIds,
                            status: status,

                        },
                        success: function(data) {
                            if (data['status'] == true) {
                                $(".checkbox:checked").each(function() {
                                    $(this).parents("tr").remove();
                                });
                                $('.alert-success').show();
                                location.reload();

                            } else {
                                $('.alert-danger').show();
                            }
                        },
                        error: function(data) {
                            alert(data.responseText);
                        }
                    });

                }
            }
        });
        $('[data-toggle=confirmation]').confirmation({
            rootSelector: '[data-toggle=confirmation]',
            onConfirm: function(event, element) {
                element.closest('form').submit();
            }
        });
    </script>
    @endsection