
<?php $__env->startSection('title', $page_title); ?>
<?php $__env->startPush('styles'); ?>
    <link href="<?php echo e(asset('plugins/custom/datatables/datatables.bundle.css')); ?>" rel="stylesheet" type="text/css"/>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
    <div class="d-flex flex-column-fluid">
        <div class="container-fluid">
            <div class="card card-custom gutter-b">
                <div class="card-header flex-wrap py-5">
                    <div class="card-title"><h3 class="card-label"><i class="<?php echo e($page_icon); ?> text-primary"></i> <?php echo e($sub_title); ?></h3></div>
                </div>
            </div>
            <div class="card card-custom">
                <div class="card-header flex-wrap py-5">
                    <form method="POST" id="form-filter" class="col-md-12 px-0">
                        <div class="row">
                            <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.form.textbox','data' => ['labelName' => 'Reseller Name','name' => 'name','col' => 'col-md-3']]); ?>
<?php $component->withName('form.textbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => 'Reseller Name','name' => 'name','col' => 'col-md-3']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
                            <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = $__env->getContainer()->make(Illuminate\View\AnonymousComponent::class, ['view' => 'components.form.textbox','data' => ['labelName' => 'Phone','name' => 'phone','col' => 'col-md-3']]); ?>
<?php $component->withName('form.textbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => 'Phone','name' => 'phone','col' => 'col-md-3']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            <div class="col-md-3">
                                <button id="btn-reset" class="btn btn-danger btn-sm btn-elevate btn-icon float-right" type="button" data-toggle="tooltip" data-theme="dark" title="Reset"><i class="fas fa-undo-alt"></i></button>
                                <button id="btn-filter" class="btn btn-primary btn-sm btn-elevate btn-icon mr-2 float-right" type="button" data-toggle="tooltip" data-theme="dark" title="Search"><i class="fas fa-search"></i></button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="card-body">
                    <div id="kt_datatable_wrapper" class="dataTables_wrapper dt-bootstrap4 no-footer">
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="dataTable" class="table table-bordered table-hover">
                                    <thead class="bg-primary">
                                    <tr>
                                        <th>Sl</th>
                                        <th>Reseller Category</th>
                                        <th>Reseller Name</th>
                                        <th>Mobile No.</th>
                                        <th>Address</th>
                                        <th>Balance</th>
                                        <th>Money Request</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php echo $__env->make('reseller::modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('reseller::approveModal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    <?php echo $__env->make('reseller::approve_reqsModal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('plugins/custom/datatables/datatables.bundle.js')); ?>" type="text/javascript"></script>
    <script>
        var table;
        $(document).ready(function () {
            table = $('#dataTable').DataTable({
                "processing": true, //Feature control the processing indicator
                "serverSide": true, //Feature control DataTable server side processing mode
                "order": [], //Initial no order
                "responsive": true, //Make table responsive in mobile device
                "bInfo": true, //TO show the total number of data
                "bFilter": false, //For datatable default search box show/hide
                "lengthMenu": [
                    [5, 10, 15, 25, 50, 100, 1000, 10000, -1],
                    [5, 10, 15, 25, 50, 100, 1000, 10000, "All"]
                ],
                "pageLength": 25, //number of data show per page
                "language": {
                    processing: `<i class="fas fa-spinner fa-spin fa-3x fa-fw text-primary"></i> `,
                    emptyTable: '<strong class="text-danger">No Data Found</strong>',
                    infoEmpty: '',
                    zeroRecords: '<strong class="text-danger">No Data Found</strong>'
                },
                "ajax": {
                    "url": "<?php echo e(route('reseller.datatable.data')); ?>",
                    "type": "POST",
                    "data": function (data) {
                        data.name = $("#form-filter #name").val();
                        data.phone = $("#form-filter #phone").val();
                        data.status = $("#form-filter #status").val();
                        data._token = _token;
                    }
                },

                "dom": "<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6' <'float-right'B>>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'<'float-right'p>>>",
                "buttons": [
                    {
                        'extend': 'colvis', 'className': 'btn btn-secondary btn-sm text-white', 'text': 'Column', 'columns': ':gt(0)'
                    },
                    {
                        "extend": 'print',
                        'text': 'Print',
                        'className': 'btn btn-secondary btn-sm text-white',
                        "title": "<?php echo e($page_title); ?> List",
                        "orientation": "landscape", //portrait
                        "pageSize": "A4", //A3,A5,A6,legal,letter
                        "exportOptions": {
                            columns: ':visible:not(:eq(6),:eq(7),:eq(8))'
                        },
                        customize: function (win) {
                            $(win.document.body).addClass('bg-white');
                            $(win.document.body).find('table thead').css({'background': '#034d97'});
                            $(win.document.body).find('table tfoot tr').css({'background-color': '#034d97'});
                            $(win.document.body).find('h1').css('text-align', 'center');
                            $(win.document.body).find('h1').css('font-size', '15px');
                            $(win.document.body).find('table').css('font-size', 'inherit');
                        },
                    },
                    {
                        "extend": 'csv',
                        'text': 'CSV',
                        'className': 'btn btn-secondary btn-sm text-white',
                        "title": "<?php echo e($page_title); ?> List",
                        "filename": "<?php echo e(strtolower(str_replace(' ','-',$page_title))); ?>-list",
                        "exportOptions": {
                            <?php if(permission('customer-bulk-delete')): ?>
                                <?php if(empty(Auth::user()->warehouse_id)): ?>
                            columns: ':visible:not(:eq(0),:eq(9))'
                            <?php else: ?>
                            columns: ':visible:not(:eq(0),:eq(8))'
                            <?php endif; ?>
                                <?php else: ?>
                                <?php if(empty(Auth::user()->warehouse_id)): ?>
                            columns: ':visible:not(:eq(8))'
                            <?php else: ?>
                            columns: ':visible:not(:eq(7))'
                            <?php endif; ?>
                            <?php endif; ?>
                        }
                    },
                    {
                        "extend": 'excel',
                        'text': 'Excel',
                        'className': 'btn btn-secondary btn-sm text-white',
                        "title": "<?php echo e($page_title); ?> List",
                        "filename": "<?php echo e(strtolower(str_replace(' ','-',$page_title))); ?>-list",
                        "exportOptions": {
                            <?php if(permission('customer-bulk-delete')): ?>
                                <?php if(empty(Auth::user()->warehouse_id)): ?>
                            columns: ':visible:not(:eq(0),:eq(9))'
                            <?php else: ?>
                            columns: ':visible:not(:eq(0),:eq(8))'
                            <?php endif; ?>
                                <?php else: ?>
                                <?php if(empty(Auth::user()->warehouse_id)): ?>
                            columns: ':visible:not(:eq(8))'
                            <?php else: ?>
                            columns: ':visible:not(:eq(7))'
                            <?php endif; ?>
                            <?php endif; ?>
                        }
                    },
                    {
                        "extend": 'pdf',
                        'text': 'PDF',
                        'className': 'btn btn-secondary btn-sm text-white',
                        "title": "<?php echo e($page_title); ?> List",
                        "filename": "<?php echo e(strtolower(str_replace(' ','-',$page_title))); ?>-list",
                        "orientation": "landscape", //portrait
                        "pageSize": "A4", //A3,A5,A6,legal,letter
                        "exportOptions": {
                            <?php if(permission('customer-bulk-delete')): ?>
                                <?php if(empty(Auth::user()->warehouse_id)): ?>
                            columns: ':visible:not(:eq(0),:eq(9))'
                            <?php else: ?>
                            columns: ':visible:not(:eq(0),:eq(8))'
                            <?php endif; ?>
                                <?php else: ?>
                                <?php if(empty(Auth::user()->warehouse_id)): ?>
                            columns: ':visible:not(:eq(8))'
                            <?php else: ?>
                            columns: ':visible:not(:eq(7))'
                            <?php endif; ?>
                            <?php endif; ?>
                        },
                        customize: function (doc) {
                            doc.defaultStyle.fontSize = 7; //<-- set fontsize to 16 instead of 10
                            doc.styles.tableHeader.fontSize = 7;
                            doc.pageMargins = [5, 5, 5, 5];
                        }
                    },
                        <?php if(permission('customer-bulk-delete')): ?>
                    {
                        'className': 'btn btn-danger btn-sm delete_btn d-none text-white',
                        'text': 'Delete',
                        action: function (e, dt, node, config) {
                            multi_delete();
                        }
                    }
                    <?php endif; ?>
                ],
            });
            $('#btn-filter').click(function () {
                table.ajax.reload();
            });
            $('#btn-reset').click(function () {
                $('#form-filter')[0].reset();
                $('#form-filter .selectpicker').selectpicker('refresh');
                table.ajax.reload();
            });

            $(document).on('click', '#save-btn', function () {
                let form = document.getElementById('store_or_update_form');
                let formData = new FormData(form);
                let url = "<?php echo e(route('reseller.store.or.update')); ?>";
                let id = $('#update_id').val();
                let method;
                if (id) {
                    method = 'update';
                } else {
                    method = 'add';
                }
                store_or_update_data(table, method, url, formData);
            });

            $(document).on('click', '#approve-btn', function () {
                var update_id = $('#store_or_approve_form #update_id').val();
                var status = $('#store_or_approve_form #status').val();
                var discount = $('#store_or_approve_form #discount').val();
                var target_category_id = $('#store_or_approve_form #target_category_id').val();
                $.ajax({
                    url: "<?php echo e(route('reseller.status.approve')); ?>",
                    type: "POST",
                    data: {
                        update_id: update_id,
                        status: status,
                        discount: discount,
                        target_category_id: target_category_id,
                        _token: _token
                    },
                    dataType: "JSON",
                    beforeSend: function () {
                        $('#status-btn').addClass(
                            'kt-spinner kt-spinner--md kt-spinner--light');
                    },
                    complete: function () {
                        $('#status-btn').removeClass(
                            'kt-spinner kt-spinner--md kt-spinner--light');
                    },
                    success: function (data) {
                        notification(data.status, data.message);
                        if (data.status == 'success') {
                            $('#store_or_approve_modal').modal('hide');
                            table.ajax.reload(null, false);
                        }
                    },
                    error: function (xhr, ajaxOption, thrownError) {
                        console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr
                            .responseText);
                    }
                });
            });

            $(document).on('click', '.edit_data', function () {
                let id = $(this).data('id');
                $('#store_or_update_form')[0].reset();
                $('#store_or_update_form').find('.is-invalid').removeClass('is-invalid');
                $('#store_or_update_form').find('.error').remove();
                if (id) {
                    $.ajax({
                        url: "<?php echo e(route('reseller.edit')); ?>",
                        type: "POST",
                        data: {id: id, _token: _token},
                        dataType: "JSON",
                        success: function (data) {
                            if (data.status == 'error') {
                                notification(data.status, data.message)
                            } else {
                                $('#store_or_update_form #update_id').val(data.id);
                                $('#store_or_update_form #name').val(data.name);
                                $('#store_or_update_form #phone').val(data.phone);
                                $('#store_or_update_form #username').val(data.username);
                                $('#store_or_update_form #shop_name').val(data.shop_name);
                                $('#store_or_update_form #email').val(data.email);
                                $('#store_or_update_form #nid').val(data.nid);
                                $('#store_or_update_form #bkash').val(data.bkash);
                                $('#store_or_update_form #nagad').val(data.nagad);
                                $('#store_or_update_form #rocket').val(data.rocket);
                                $('#store_or_update_form #address').val(data.address);
                                $('#store_or_update_form .selectpicker').selectpicker('refresh');
                                $('#store_or_update_modal').modal({
                                    keyboard: false,
                                    backdrop: 'static',
                                });
                                $('#store_or_update_modal .modal-title').html(
                                    '<i class="fas fa-edit text-white"></i> <span>Edit ' + data.name + '</span>');
                                $('#store_or_update_modal #save-btn').text('Update');
                            }

                        },
                        error: function (xhr, ajaxOption, thrownError) {
                            console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
                        }
                    });
                }
            });

            $(document).on('click', '.approve_data', function () {
                let id = $(this).data('id');
                let discount = $(this).data('discount');
                let target_category_id = $(this).data('target_category_id');
                $('#store_or_approve_form')[0].reset();
                $('#store_or_approve_form').find('.is-invalid').removeClass('is-invalid');
                $('#store_or_approve_form').find('.error').remove();
                if (id) {
                    $.ajax({
                        url: "<?php echo e(route('reseller.change.status')); ?>",
                        type: "POST",
                        data: {id: id, discount: discount, target_category_id: target_category_id, _token: _token},
                        dataType: "JSON",
                        success: function (data) {

                            if (data.status == 'error') {
                                notification(data.status, data.message)
                            } else {
                                $('#store_or_approve_form #update_id').val(data.id);
                                $('#store_or_approve_form #status').val(data.status);
                                $('#store_or_approve_form #discount').val(data.discount);
                                $('#store_or_approve_form #target_category_id').val(data.target_category_id);
                                $('#store_or_approve_form .selectpicker').selectpicker('refresh');
                                $('#store_or_approve_modal').modal({
                                    keyboard: false,
                                    backdrop: 'static',
                                });
                                $('#store_or_approve_modal .modal-title').html(
                                    '<i class="fas fa-edit text-white"></i> <span>Edit ' + data.name + '</span>');
                                $('#store_or_approve_modal #save-btn').text('Update');
                            }

                        },
                        error: function (xhr, ajaxOption, thrownError) {
                            console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
                        }
                    });
                }
            });

            $(document).on('click', '.withdraw_reqs', function () {
                let id = $(this).data('id');
                let bkash = $(this).data('bkash');
                let status = $(this).data('status');
                let balance = $(this).data('balance') ?? 0;
                let req_amount = $(this).data('req_amount') ?? 0;
                let row = table.row($(this).parent('tr'));

                $('#withdraw_reqs_form #reseller_id').val(id);
                $('#withdraw_reqs_form #status').val(status);
                $('#withdraw_reqs_form #bkash').val(bkash);
                $('#withdraw_reqs_form #balance').val(balance);
                $('#withdraw_reqs_form #req_amount').val(req_amount);
                $('#withdraw_reqs_form #status.selectpicker').selectpicker('refresh');

                $('#withdraw_reqs_modal .modal-title').html('<span>Approve Money Request</span>');
                $('#withdraw_reqs_modal #withdraw-btn').prop('disabled', false);
                $('#withdraw_reqs_modal').modal({
                    keyboard: false,
                    backdrop: 'static',
                });
            });

            $(document).on('click', '.withdraw_alert', function () {
                notification('error', '⚠️ Withdraw Request is not Submitted Yet ⚠️');
            });

            $(document).on('click', '#withdraw-btn', function () {
                let id = $('#withdraw_reqs_form #reseller_id').val();
                let status = $('#withdraw_reqs_form #status').val();
                let balance = $('#withdraw_reqs_form #balance').val();
                let req_amount = $('#withdraw_reqs_form #req_amount').val();
                let url = "<?php echo e(route('reseller.approve.reqs')); ?>";

                if (status == 0) {
                    notification('error', '⚠️ Please Select Status ⚠️');
                } else {
                    $.ajax({
                        url: url,
                        type: "POST",
                        data: {reseller_id: id, status: status, balance: balance, req_amount: req_amount, _token: _token},
                        dataType: "JSON",
                        beforeSend: function () {
                            $('#submit-btn').addClass(
                                'kt-spinner kt-spinner--md kt-spinner--light');
                        },
                        complete: function () {
                            $('#submit-btn').removeClass(
                                'kt-spinner kt-spinner--md kt-spinner--light');
                        },
                        success: function (data) {
                            notification(data.status, data.message);
                            if (data.status == 'success') {
                                $('#withdraw_reqs_modal').modal('hide');
                                $('#withdraw_reqs_form')[0].reset();
                                table.ajax.reload(null, false);
                            }
                        },
                        error: function (xhr, ajaxOption, thrownError) {
                            console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
                        }
                    });
                }
            });

            $(document).on('click', '.delete_data', function () {
                let id = $(this).data('id');
                let name = $(this).data('name');
                let row = table.row($(this).parent('tr'));
                let url = "<?php echo e(route('customer.delete')); ?>";
                delete_data(id, url, table, row, name);
            });

            $(document).on('click', '.change_status', function () {
                let id = $(this).data('id');
                let name = $(this).data('name');
                let status = $(this).data('status');
                let row = table.row($(this).parent('tr'));
                let url = "<?php echo e(route('customer.change.status')); ?>";
                change_status(id, url, table, row, name, status);
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/iconshoppercom/iconshopper/Modules/Reseller/Resources/views/index.blade.php ENDPATH**/ ?>