<?php $__env->startSection('maincontent'); ?>
<?php $__env->startSection('title'); ?>
    <?php echo e(env('APP_NAME')); ?>- Subcategory
<?php $__env->stopSection(); ?>
<style>
    div#roleinfo_length {
        color: red;
    }

    div#roleinfo_filter {
        color: red;
    }

    div#roleinfo_info {
        color: red;
    }
</style>

<div class="container-fluid pt-4 px-4">
    <div class="row">
        <div class="col-sm-12 col-md-12 col-xl-12">
            <div class="h-100 bg-secondary rounded p-4 pb-0">
                <div class="d-flex align-items-center justify-content-between" style="width: 50%;float:left;">
                    <h6 class="mb-0">ALL Withdraw Requst List</h6>
                </div>
               
            </div>
        </div>

        <div class="col-sm-12 col-md-12 col-xl-12">
            <div class="bg-secondary rounded h-100 p-4">
                <div class="data-tables">
                    <table class="table table-dark" id="subcategoryinfo" width="100%" style="text-align: center;">
                        <thead class="thead-light">
                            <tr>
                                <th>SL</th>
                                <th>Name</th>
                                <th>Account Number</th>
                                <th>Amount</th>
                                <th>Payment Methods</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>



        
        <div class="modal fade" id="editmainSubcategory" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content bg-secondary rounded h-100">
                    <div class="modal-header">
                        <h5 class="modal-title" style="color: red;">Edit Subcategory</h5>
                        <button type="button" class="btn-dark btn-close" data-bs-dismiss="modal"
                            aria-label="Close"></button>
                    </div>
                    <div class="modal-body">
                        <form name="form" id="EditSubcategory" enctype="multipart/form-data">
                            <?php echo csrf_field(); ?>
                           
                            
                            <div class="col-12 mb-3">
                                <label for="customerName" class="form-label">Customer Name</label>
                                <input type="text" id="customerName" class="form-control" readonly>
                            </div>
                        
                            
                            <div class="col-12 mb-3">
                                <label for="withdrawAmount" class="form-label">Amount</label>
                                <input type="text" id="withdrawAmount" class="form-control" readonly>
                            </div>
                            
                             <div class="col-12 mb-3">
                                <label for="payment_methods" class="form-label">Payment Methods</label>
                                <input type="text" id="payment_methods" class="form-control"  readonly>
                            </div>
                        
                            
                            <div class="col-12 mb-3">
                                <label for="accountNumber" class="form-label">Account Number</label>
                                <input type="text" id="accountNumber" class="form-control" readonly>
                            </div>
                        
                            
                            <div class="col-12 mb-3">
                                <label for="note" class="form-label">Note</label>
                                <textarea name="note" id="note" class="form-control" rows="2" placeholder="Write your note here..."></textarea>
                                <?php $__errorArgs = ['note'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <span class="text-danger small"><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            
                           <div class="col-12 mb-3">
                                <label for="status" class="form-label">Status</label>
                                <select name="status" id="status" class="form-select" required style="display: block !important;">
                                    <option value="1">Pending</option>
                                    <option value="2">Received</option>
                                    <option value="3">Declined</option>
                                </select>
                                <?php $__errorArgs = ['status'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <span class="text-danger small"><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                          
                            <div class="col-12 mb-3">
                                <label for="proof" class="form-label">Proof (Image)</label>
                                <input type="file" name="proof" id="proof" class="form-control" accept="image/*">
                            
                                <div class="mt-2" id="proofPreview" style="display:none;">
                                    <p class="mb-1 small">Current Proof:</p>
                                    <img id="proofImage" src="" alt="Proof Image" class="img-thumbnail" style="max-width: 150px;">
                                </div>
                            
                                <?php $__errorArgs = ['proof'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <span class="text-danger small"><?php echo e($message); ?></span>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                            <input type="text" name="withdraw_id" id="withdraw_id" hidden>
                            <br>
                            <div class="form-group mt-2" style="text-align: right">
                                <div class="submitBtnSCourse">
                                    <button type="submit" name="btn" data-bs-dismiss="modal"   class="btn btn-dark btn-block" style="float: left">Close</button>
                                    <button type="submit" name="btn" class="btn btn-primary AddCourierBtn btn-block">Update</button>
                                </div>
                            </div>
                        </form>

                    </div>

                </div>
            </div>
        </div><!-- End popup Modal-->
        <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>" />
    </div>
</div>

<script>
    $(document).ready(function() {
        var token = $("input[name='_token']").val();

        var subcategoryinfo = $('#subcategoryinfo').DataTable({
            order: [
                [0, 'desc']
            ],
            processing: true,
            serverSide: true,
            ajax: '<?php echo route('admin-all_withdraw-requst'); ?>',
            columns: [{
                     data: 'id'
                }, {
                    data: 'vandors.name',
                },
                {
                    data: 'account_number'
                },
                {
                    data: 'amount'
                },
                {
                    data: 'payment_methods'
                },
                {
                  data: 'status',
                    render: function (data, type, row) {
                        if (data == 1) {
                            return '<span class="badge bg-warning text-dark">Pending</span>';
                        } else if (data == 2) {
                            return '<span class="badge bg-success">Vandor Received</span>';
                        } else if (data == 3) {
                            return '<span class="badge bg-danger">Declined</span>';
                        } else {
                            return '<span class="badge bg-secondary">Unknown</span>';
                        }
                    }
                },
                {
                    data: 'action',
                    name: 'action',
                    orderable: false,
                    searchable: false
                },

            ]
        });


        //add subcategory

        $('#AddSubcategory').submit(function(e) {
            e.preventDefault();

            $.ajax({
                type: 'POST',
                uploadUrl: '<?php echo e(route('admin.subcategorys.store')); ?>',
                processData: false,
                contentType: false,
                data: new FormData(this),

                success: function(data) {
                    $('#sub_category_name').val('');
                    $('#category_id').val('');

                    swal({
                        title: "Success!",
                        icon: "success",
                    });
                    subcategoryinfo.ajax.reload();
                },
                error: function(error) {
                    console.log('error');
                }
            });
        });

        //edit subcategory
        $(document).on('click', '#editSubcategoryBtn', function() {
          let withdrawId = $(this).data('id');
            $.ajax({
                type: 'GET',
                url: '/admin/withdraw/request/' + withdrawId + '/edit',
               success: function(data) {
                    $('#EditSubcategory').find('#customerName').val(data.vandors.name);
                    $('#EditSubcategory').find('#withdrawAmount').val(data.amount);
                    $('#EditSubcategory').find('#payment_methods').val(data.payment_methods);
                    $('#EditSubcategory').find('#accountNumber').val(data.account_number);
                    $('#EditSubcategory').find('#note').val(data.note);
                    $('#EditSubcategory').find('#status').val(data.status);
                    $('#EditSubcategory').find('#withdraw_id').val(data.id);
                    // Proof image set
                    if (data.proof) {
                        $('#proofPreview').show();
                        $('#proofImage').attr('src', '/' + data.proof);
                    } else {
                        $('#proofPreview').hide();
                    }
                    $('#EditSubcategory').attr('data-id', data.id);
                },
                error: function(error) {
                    console.log('error');
                }
            });
        });


        //update subcategory
        $('#EditSubcategory').submit(function(e) {
            e.preventDefault();
            let withdrawId = $('#withdraw_id').val();
            $.ajax({
                type: 'POST',
                url: '/admin/withdraw/request/update/' + withdrawId,
                processData: false,
                contentType: false,
                data: new FormData(this),

                success: function(data) {
                    $('#EditSubcategory').find('#customerName').val('');
                    $('#EditSubcategory').find('#withdraw_id').val('');
                    swal({
                        title: "Subcategory update successfully !",
                        icon: "success",
                        showCancelButton: true,
                        focusConfirm: false,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "Yes",
                        cancelButtonText: "No",
                    });
                    subcategoryinfo.ajax.reload();
                },
                error: function(error) {
                    console.log('error');
                }
            });
        });

        // delete subcategory

        $(document).on('click', '#deleteSubcategoryBtn', function() {
            let subcategoryId = $(this).data('id');
            swal({
                    title: "Are you sure?",
                    text: "Once deleted, you will not be able to recover this !",
                    icon: "warning",
                    buttons: true,
                    dangerMode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        $.ajax({
                            type: 'DELETE',
                            url: 'subcategorys/' + subcategoryId,
                            data: {
                                '_token': token
                            },
                            success: function(data) {
                                swal("Subcategory has been deleted!", {
                                    icon: "success",
                                });
                                subcategoryinfo.ajax.reload();
                            },
                            error: function(error) {
                                console.log('error');
                            }
                        });
                    } else {
                        swal("Your data is safe!");
                    }
                });

        });

        // status update

        $(document).on('click', '#subcategorystatusBtn', function() {
            let subcategoryId = $(this).data('id');
            let subcategoryStatus = $(this).data('status');

            $.ajax({
                type: 'PUT',
                url: 'subcategory/status',
                data: {
                    withdraw_id: subcategoryId,
                    status: subcategoryStatus,
                    '_token': token
                },

                success: function(data) {
                    swal({
                        title: "Status updated !",
                        icon: "success",
                        showCancelButton: true,
                        focusConfirm: false,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "Yes",
                        cancelButtonText: "No",
                    });
                    subcategoryinfo.ajax.reload();
                },
                error: function(error) {
                    console.log('error');
                }

            });
        });

    });
</script>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('backend.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/falconen/multivendor.falconenterprisebd.com/resources/views/backend/content/withdraw/all_requst.blade.php ENDPATH**/ ?>