
<?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 class="card-toolbar">
                    <?php if(permission('supplier-add')): ?>
                    <a href="javascript:void(0);" onclick="showFormModal('<?php echo e('Add New Supplier'); ?>','<?php echo e('Save'); ?>')" class="btn btn-primary btn-sm font-weight-bolder"><i class="fas fa-plus-circle"></i> <?php echo e('Add New'); ?></a>
                    <?php endif; ?>
                </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' => ''.e('Name').'','name' => 'name','col' => 'col-md-4']]); ?>
<?php $component->withName('form.textbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => ''.e('Name').'','name' => 'name','col' => 'col-md-4']); ?>
<?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' => ''.e('Mobile').'','name' => 'mobile','col' => 'col-md-4']]); ?>
<?php $component->withName('form.textbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => ''.e('Mobile').'','name' => 'mobile','col' => 'col-md-4']); ?>
<?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' => ''.e('Email').'','name' => 'email','col' => 'col-md-4']]); ?>
<?php $component->withName('form.textbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => ''.e('Email').'','name' => 'email','col' => 'col-md-4']); ?>
<?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.selectbox','data' => ['labelName' => ''.e('Status').'','name' => 'status','col' => 'col-md-4','class' => 'selectpicker']]); ?>
<?php $component->withName('form.selectbox'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php $component->withAttributes(['labelName' => ''.e('Status').'','name' => 'status','col' => 'col-md-4','class' => 'selectpicker']); ?>
                            <?php $__currentLoopData = STATUS; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($key); ?>"><?php echo e($value); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                         <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
                        <div class="col-md-4">
                            <div style="margin-top:30px;">
                                <button style="margin-right : 5px" id="btn-reset" class="btn btn-danger btn-sm btn-elevate btn-icon float-left" type="button" data-toggle="tooltip" data-theme="dark" title="<?php echo e(__('file.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-left" type="button" data-toggle="tooltip" data-theme="dark" title="<?php echo e(__('file.Search')); ?>"><i class="fas fa-search"></i></button>
                            </div>
                        </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><?php echo e('SL'); ?></th>
                                        <th><?php echo e('Name'); ?></th>
                                        <th><?php echo e('Address'); ?></th>
                                        <th><?php echo e('Mobile'); ?></th>
                                        <th><?php echo e('Email'); ?></th>
                                        <th><?php echo e('City'); ?></th>
                                        <th><?php echo e('Zipcode'); ?></th>
                                        <th><?php echo e('Status'); ?></th>
                                        <th><?php echo e('Balance'); ?></th>
                                        <th><?php echo e('Action'); ?></th>
                                    </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php echo $__env->make('supplier::modal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php echo $__env->make('supplier::viewModal', \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>
    let table;
    $(document).ready(function(){
        table = $('#dataTable').DataTable({
            "processing": true,
            "serverSide": true,
            "order"     : [],
            "responsive": true,
            "bInfo"     : true,
            "bFilter"   : false,
            "lengthMenu": [
                [5, 10, 15, 25, 50, 100, 1000, 10000, -1],
                [5, 10, 15, 25, 50, 100, 1000, 10000, "All"]
            ],
            "pageLength": 25,
            "language"  : {
                processing: `<i class="fas fa-spinner fa-spin fa-3x fa-fw text-primary"></i> `,
                emptyTable: '<strong class="text-danger"><?php echo e('No Data Found'); ?></strong>',
                infoEmpty : '',
                zeroRecords: '<strong class="text-danger"><?php echo e('No Data Found'); ?></strong>'
            },
            "ajax"    : {
                "url" : "<?php echo e(route('supplier.datatable.data')); ?>",
                "type": "POST",
                "data": function (data) {
                    data.name   = $("#form-filter #name").val();
                    data.mobile = $("#form-filter #mobile").val();
                    data.email  = $("#form-filter #email").val();
                    data.type   = $("#form-filter #type").val();
                    data.status = $("#form-filter #status").val();
                    data._token = _token;
                }
            },
            "columnDefs": [{
                    "targets"  : [0,1,2,3,4,5,6,7,8,9],
                    "orderable": false,
                    "className": "text-center"
                }]});
        $('#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('supplier.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', '.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('supplier.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,#store_or_update_form #old_name').val(data.name);
                            $('#store_or_update_form #company_name').val(data.company_name);
                            $('#store_or_update_form #mobile').val(data.mobile);
                            $('#store_or_update_form #email').val(data.email);
                            $('#store_or_update_form #type').val(data.type);
                            $('#store_or_update_form #city').val(data.city);
                            $('#store_or_update_form #zipcode').val(data.zipcode);
                            $('#store_or_update_form #bank_name').val(data.bank_name);
                            $('#store_or_update_form #bank_account_no').val(data.bank_account_no);
                            $('#store_or_update_form #address').val(data.address);
                            $('#store_or_update_form #details').val(data.details);
                            $('#store_or_update_form #previous_balance, #store_or_update_form #old_previous_balance').val(data.previous_balance.credit);
                            $('#store_or_update_form #type.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-warning"></i> <span><?php echo e('Edit'); ?> ' + data.name + '</span>');
                            $('#store_or_update_modal #save-btn').text('<?php echo e('Update'); ?>');
                        }
                    },
                    error    : function (xhr, ajaxOption, thrownError) { console.log(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText); }
                });
            }
        });
        $(document).on('click', '.view_data', function () {
            let id = $(this).data('id');
            $('#view_form').find('.is-invalid').removeClass('is-invalid');
            $('#view_form').find('.error').remove();
            if (id) {
                $.ajax({
                    url     : "<?php echo e(route('supplier.edit')); ?>",
                    type    : "POST",
                    data    : { id: id,_token: _token},
                    dataType: "JSON",
                    success : function (data) {
                        if(data.status == 'error'){
                            notification(data.status,data.message)
                        }else{
                            $('#view_form #name,#store_or_update_form #old_name').val(data.name);
                            $('#view_form #company_name').val(data.company_name);
                            $('#view_form #mobile').val(data.mobile);
                            $('#view_form #email').val(data.email);
                            $('#view_form #type').val(data.type);
                            $('#view_form #city').val(data.city);
                            $('#view_form #zipcode').val(data.zipcode);
                            $('#view_form #bank_name').val(data.bank_name);
                            $('#view_form #bank_account_no').val(data.bank_account_no);
                            $('#view_form #address').val(data.address);
                            $('#view_form #details').val(data.details);
                            $('#view_form #previous_balance, #store_or_update_form #old_previous_balance').val(data.previous_balance.credit);
                            $('#view_form #type.selectpicker').selectpicker('refresh');
                            $('#view_modal').modal({
                                keyboard: false,
                                backdrop: 'static',
                            });
                            $('#view_modal .modal-title').html('<i class="fas fa-eye text-white"></i> <span><?php echo e('Details'); ?> ' + data.name + '</span>');
                        }
                    },
                    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('supplier.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('supplier.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/Supplier/Resources/views/index.blade.php ENDPATH**/ ?>