<?php $__env->startSection('title', 'Manage Company Employees'); ?>


<?php $__env->startSection('internal-js'); ?>
    <script>
        $(document).ready(function () {
            $('#active-table').dataTable({
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons' },
                    { extend: 'pdf', className: 'download-buttons' }
                ],
                "paging":   false,
            } );

            $('.activate-deactivate-payroll').click(function (){
                let user = $(this).val();
                let selected = 0;
                if($(this).is(':checked')){
                    selected = 1;
                }
                var hints_url = '/activate-deactivate-user-payroll/'+user+'/'+selected;
                $.ajax({
                    type: 'GET',
                    url: hints_url,
                    data: selected ,
                    success: function (res) {
                        if(res == 'error'){
                            alert('An Error occurred while trying to update Payroll Functions');
                        }
                    }
                });
            });
        });

        
        function addNewEmployee(){
            var route_link = '/add-company-employee';

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 500,
                title: "Add New User(s) to Company Employees List",

                buttons: [
                    {
                        text: "Save Details",
                        icon: "ui-icon-check",
                        id: "my-button-1",
                        click: function(e) {
                            if(confirm('Are you sure to Save Entered Details?')){
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = $('#add-users-to-employee-list').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'success'){
                                            window.location = '/view-company-employees?updateUser=true';
                                        }else if(res == 'empty list'){
                                            alert('Please Select at least one User from the Provided List');
                                            $("#my-button-1").attr('disabled', false).text('Save Details');
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function updateEmployeeNumber(id) {
            var route_link = '/update-employee-number/' + id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 500,
                title: "Update Employee Number",

                buttons: [
                    {
                        text: "Save Details",
                        icon: "ui-icon-check",
                        id: "my-button-1",
                        click: function (e) {
                            if (confirm('Are you sure to Save Entered Details?')) {
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = $('#update-employee-number').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res) {
                                        if (res == 'success') {
                                            window.location = '/view-company-employees?updateEmployeeNumber=true';
                                        } else if (res == 'empty number') {
                                            alert('Please Provide Employee Number to Save Details');
                                            $("#my-button-1").attr('disabled', false).text('Save Details');
                                        } else {
                                            alert('System Encountered an Error. Please Contact System Admin');
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function () {
                    $(this).parent().css({'top': 50});
                }
            });
        }
    </script>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('internal-css'); ?>
    <style>
        #active-table th, td {
            text-align: left;
            padding: 4px;
        }
        #active-table tr:hover {background-color: #cbd1f8;}
        .switch-certificate {
            position: relative;
            display: inline-block;
            width: 38px;
            height: 17px;
        }
    </style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('headers'); ?>
    <?php echo $__env->make('headers.hr-header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('heading', 'Company Employees Listing'); ?>


<?php $__env->startSection('content'); ?>
    <?php if(isset($_GET['updateUser'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['updateUser'] == 'true'): ?>
                <div class="yesFound">User Account(s) Added to Employees List Successfully</div><br>
            <?php elseif($_GET['updateUser'] == 'false'): ?>
                <div class="notFound">There was an error while trying to update Employee Number</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <?php if(isset($_GET['updateEmployeeNumber'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['updateEmployeeNumber'] == 'true'): ?>
                <div class="yesFound">Employee Number Updated Successfully</div><br>
            <?php elseif($_GET['updateEmployeeNumber'] == 'false'): ?>
                <div class="notFound">There was an error while trying to update User Account</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'employees')" id="defaultOpen">Active Employees</button>
    </div>

    <div id="employees" class="tabcontent">
        <h3 class="error">
            Company's Active Employees List
            <button onclick="addNewEmployee()" class="section-button">+ Add New Employee</button>
        </h3>
        <table id="active-table" class="display" style="width: 100%; border-collapse: collapse; ">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Employee No:</th>
                <th>Branch</th>
                <th>Full Name(s)</th>
                <th>Username</th>
                <th>Phone</th>
                <th>Access</th>
                <th>Appear on Payroll</th>
                <th>Manage Payroll</th>
                <th>View Employee Profile</th>
            </tr>
            </thead>
            <tbody>
            <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $active): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td class="ar"></td>
                    <td><b class="error"><?php echo $active->e_no ?? '-'; ?></b><a onclick="updateEmployeeNumber('<?php echo e($active->id); ?>')" class="inner" title="Update Employee Number" style="cursor: pointer; margin-left: 10px"><b class="error"><i class="fa fa-pencil" style="font-size: 14px"></i></b></a></td>
                    <td>
                        <?php if($active->branchDetails != null): ?>
                            <?php echo $active->branchDetails->name; ?>

                        <?php endif; ?>
                    </td>
                    <td><?php echo $active->firstName." ".$active->lastName; ?></td>
                    <td><?php echo $active->email; ?></td>
                    <td><?php echo $active->phone; ?></td>
                    <td><?php echo $active->accessType($active->access); ?></td>
                    <td>
                        <label class="switch-certificate">
                            <input class="activate-deactivate-payroll" name="turn-clock" type="checkbox" <?php if($active->is_on_payroll == 1): ?> checked <?php endif; ?> value="<?php echo e($active->id); ?>">
                            <span class="slider round" ><span style="margin-left: 2px; color: white">On</span></span>
                        </label>
                    </td>
                    <td>
                        <?php if($active->is_on_payroll == 1): ?>
                            <a href="<?php echo e(url('manage-employee-payroll/'.$active->stamp)); ?>" title="Manage Employee Payroll" style="cursor: pointer" target="_blank" class="inner"><b><i class="fa fa-cogs" style="font-size: 14px"></i></b></a>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if(auth()->user()->admin == 1 || auth()->user()->hr == 1): ?>
                            <a href="<?php echo e(url('employee-file-admin/'.$active->stamp.'?type=active')); ?>" title="View Employee Profile" style="cursor: pointer" target="_blank" class="inner"><b><i class="fa fa-eye error" style="font-size: 16px"></i></b></a>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Employee No:</th>
                <th>Branch</th>
                <th>Full Name(s)</th>
                <th>Username</th>
                <th>Phone</th>
                <th>Access</th>
                <th>Appear on Payroll</th>
                <th>Manage Payroll</th>
                <th>View Employee Profile</th>
            </tr>
            </tfoot>
        </table>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('modal_heading'); ?>
    <h1>Manage Company Employees</h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View all Company Employees </li>
            <li>Activate/Deactivate an Employee from Payroll</li>
        </ol>
    </b>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/zedarroot/public_html/edwulp/resources/views/hr/employees/view-company-employees.blade.php ENDPATH**/ ?>