 

<?php $__env->startSection('content'); ?>
<?php $__env->startSection('title','Payrolls'); ?>

<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header d-flex flex-column flex-md-row align-items-start align-items-md-center justify-content-between gap-2">
                <div class="flex-grow-1 min-w-0">
                    <h4 class="card-title mb-0 text-truncate">Payrolls</h4>
                </div>
                <div class="d-flex flex-wrap gap-2 justify-content-start justify-content-md-end w-100 w-md-auto">
                    <a href="<?php echo e(route('payrolls.export.excel')); ?>" class="btn btn-success">
                        <i class="ri-file-text-line me-1"></i> Export CSV
                    </a>

                    <label class="btn btn-outline-success mb-0" style="cursor:pointer;">
                        <i class="ri-upload-cloud-2-line me-1"></i> Import CSV
                        <input type="file" name="file" accept=".csv,text/csv" style="display:none;" onchange="importCsvAjax(this, '<?php echo e(route('payrolls.import.csv')); ?>');">
                    </label>

                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check("payrolls-create")): ?> 
                    <a href="<?php echo e(route('payrolls.create')); ?>" class='btn btn-primary'>
                        <i class="ri-add-line me-1"></i> Add Payrolls
                    </a>
                    <?php endif; ?>
                </div>
            </div>
            <div class="card-body">
                <!-- Search Form -->
                <form method="GET" action="<?php echo e(route('payrolls.index')); ?>" class="mb-3">
                    <div class="row g-2">
                        <div class="col-md-4">
                            <input type="text" 
                                   name="search" 
                                   class="form-control" 
                                   placeholder="Search..." 
                                   value="<?php echo e(request('search')); ?>">
                        </div>
                        <div class="col-md-2">
                            <button type="submit" class="btn btn-primary w-100">
                                <i class="ri-search-line"></i> Search
                            </button>
                        </div>
                        <?php if(request('search')): ?>
                            <div class="col-md-2">
                                <a href="<?php echo e(route('payrolls.index')); ?>" class="btn btn-secondary w-100">
                                    <i class="ri-close-line"></i> Clear
                                </a>
                            </div>
                        <?php endif; ?>
                    </div>
                    <!-- Preserve sort parameters -->
                    <?php if(request('sort_by')): ?>
                        <input type="hidden" name="sort_by" value="<?php echo e(request('sort_by')); ?>">
                    <?php endif; ?>
                    <?php if(request('sort_order')): ?>
                        <input type="hidden" name="sort_order" value="<?php echo e(request('sort_order')); ?>">
                    <?php endif; ?>
                </form>

                <div class="js-index-cards d-none"></div>

                <div class="table-responsive js-index-table d-none d-md-block">
                    <table class="table table-hover mb-0">
                        <thead class="table-light">
                            <tr>
                                <th style='width:5%'>
                                    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'id', 'sort_order' => request('sort_by') == 'id' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
                                       class="text-decoration-none text-dark">
                                        Sr.
                                        <?php echo renderSortIcon('id', 'id'); ?>

                                    </a>
                                </th>
                                <th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'client_id', 'sort_order' => request('sort_by') == 'client_id' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Client
        <?php echo renderSortIcon('client_id', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'employee_id', 'sort_order' => request('sort_by') == 'employee_id' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Employee
        <?php echo renderSortIcon('employee_id', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'payroll_month', 'sort_order' => request('sort_by') == 'payroll_month' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Payroll Month
        <?php echo renderSortIcon('payroll_month', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'payroll_year', 'sort_order' => request('sort_by') == 'payroll_year' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Payroll Year
        <?php echo renderSortIcon('payroll_year', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'basic_salary', 'sort_order' => request('sort_by') == 'basic_salary' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Basic Salary
        <?php echo renderSortIcon('basic_salary', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'gross_salary', 'sort_order' => request('sort_by') == 'gross_salary' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Gross Salary
        <?php echo renderSortIcon('gross_salary', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'net_salary', 'sort_order' => request('sort_by') == 'net_salary' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Net Salary
        <?php echo renderSortIcon('net_salary', 'id'); ?>

    </a>
</th>
<th>
    <a href="<?php echo e(route('payrolls.index', array_merge(request()->except(['sort_by', 'sort_order', 'page']), ['sort_by' => 'status', 'sort_order' => request('sort_by') == 'status' && request('sort_order') == 'asc' ? 'desc' : 'asc']))); ?>" 
       class="text-decoration-none text-dark">
        Status
        <?php echo renderSortIcon('status', 'id'); ?>

    </a>
</th>

                                <th class='text-end' style='width:10%'>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $__empty_1 = true; $__currentLoopData = $payrolls; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payroll): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                <tr id="row_<?php echo e($payroll->id); ?>">
                                    <td><?php echo e($payrolls->firstItem() + $loop->index); ?></td>
                                    <td><?php echo e($payroll->client ? $payroll->client->name : ''); ?></td>
<td><?php echo e($payroll->employee ? $payroll->employee->first_name : ''); ?></td>
<td>
    <?php
        $__monthNames = [1=>'January',2=>'February',3=>'March',4=>'April',5=>'May',6=>'June',7=>'July',8=>'August',9=>'September',10=>'October',11=>'November',12=>'December'];
        $__m = (int) ($payroll->payroll_month ?? 0);
    ?>
    <?php echo e($__monthNames[$__m] ?? ''); ?>

</td>
<td><?php echo e($payroll->payroll_year ?? ''); ?></td>
<td><?php echo e(number_format((float) ($payroll->basic_salary ?? 0), 2)); ?></td>
<td><?php echo e(number_format((float) ($payroll->gross_salary ?? 0), 2)); ?></td>
<td><?php echo e(number_format((float) ($payroll->net_salary ?? 0), 2)); ?></td>
<td>
    <?php if(!is_null($payroll->status)): ?>
        <span class="badge bg-soft-primary text-primary"><?php echo e($payroll->status); ?></span>
    <?php endif; ?>
</td>

                                    <td class="text-end">
                                        <div id="action_<?php echo e($payroll->id); ?>" class="d-flex gap-1 justify-content-end">
                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('payrolls-edit')): ?>
                                                <a href="<?php echo e(route('payrolls.edit', $payroll->id)); ?>" 
                                                   class="btn btn-sm btn-primary" 
                                                   title="Edit">
                                                    <i class="ri-pencil-line"></i>
                                                </a>
                                            <?php endif; ?>

                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('payrolls-delete')): ?>
                                                <a id="trash_<?php echo e($payroll->id); ?>"
                                                   class="btn btn-sm btn-danger"
                                                   title="Move to Trash"
                                                   onclick="suSoftDelete('<?php echo e($payroll->id); ?>', 'payrolls')">
                                                    <i class="ri-delete-bin-line"></i>
                                                </a>

                                                <a id="restore_<?php echo e($payroll->id); ?>"
                                                   class="btn btn-sm btn-success"
                                                   title="Restore"
                                                   onclick="suRestore('<?php echo e($payroll->id); ?>', 'payrolls')"
                                                   style="display:none;">
                                                    <i class="ri-restart-line"></i>
                                                </a>
                                            <?php endif; ?>
                                        </div>
                                    </td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                <tr>
                                    <td colspan="10" class="text-center">No records found.</td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>

                <!-- Pagination -->
                <?php if($payrolls->hasPages()): ?>
                <div class="mt-4 d-flex justify-content-between align-items-center flex-wrap">
                    <div class="mb-2">
                        <p class="text-muted mb-0">
                            Showing <?php echo e($payrolls->firstItem() ?? 0); ?> to <?php echo e($payrolls->lastItem() ?? 0); ?> of <?php echo e($payrolls->total()); ?> entries
                        </p>
                    </div>
                    <nav aria-label="Page navigation">
                        <ul class="pagination pagination-sm mb-0">
                            
                            <?php if($payrolls->onFirstPage()): ?>
                                <li class="page-item disabled">
                                    <span class="page-link">
                                        <i class="ri-arrow-left-s-line"></i>
                                    </span>
                                </li>
                            <?php else: ?>
                                <li class="page-item">
                                    <a class="page-link" href="<?php echo e($payrolls->appends(request()->except('page'))->previousPageUrl()); ?>" rel="prev">
                                        <i class="ri-arrow-left-s-line"></i>
                                    </a>
                                </li>
                            <?php endif; ?>

                            
                            <?php
                                $currentPage = $payrolls->currentPage();
                                $lastPage = $payrolls->lastPage();
                                $startPage = max(1, $currentPage - 2);
                                $endPage = min($lastPage, $currentPage + 2);
                            ?>

                            <?php if($startPage > 1): ?>
                                <li class="page-item">
                                    <a class="page-link" href="<?php echo e($payrolls->appends(request()->except('page'))->url(1)); ?>">1</a>
                                </li>
                                <?php if($startPage > 2): ?>
                                    <li class="page-item disabled">
                                        <span class="page-link">...</span>
                                    </li>
                                <?php endif; ?>
                            <?php endif; ?>

                            <?php for($page = $startPage; $page <= $endPage; $page++): ?>
                                <?php if($page == $currentPage): ?>
                                    <li class="page-item active">
                                        <span class="page-link"><?php echo e($page); ?></span>
                                    </li>
                                <?php else: ?>
                                    <li class="page-item">
                                        <a class="page-link" href="<?php echo e($payrolls->appends(request()->except('page'))->url($page)); ?>"><?php echo e($page); ?></a>
                                    </li>
                                <?php endif; ?>
                            <?php endfor; ?>

                            <?php if($endPage < $lastPage): ?>
                                <?php if($endPage < $lastPage - 1): ?>
                                    <li class="page-item disabled">
                                        <span class="page-link">...</span>
                                    </li>
                                <?php endif; ?>
                                <li class="page-item">
                                    <a class="page-link" href="<?php echo e($payrolls->appends(request()->except('page'))->url($lastPage)); ?>"><?php echo e($lastPage); ?></a>
                                </li>
                            <?php endif; ?>

                            
                            <?php if($payrolls->hasMorePages()): ?>
                                <li class="page-item">
                                    <a class="page-link" href="<?php echo e($payrolls->appends(request()->except('page'))->nextPageUrl()); ?>" rel="next">
                                        <i class="ri-arrow-right-s-line"></i>
                                    </a>
                                </li>
                            <?php else: ?>
                                <li class="page-item disabled">
                                    <span class="page-link">
                                        <i class="ri-arrow-right-s-line"></i>
                                    </span>
                                </li>
                            <?php endif; ?>
                        </ul>
                    </nav>
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

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

<?php echo $__env->make('layouts.metor.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/MAMP/htdocs/payroll/resources/views/payrolls/index.blade.php ENDPATH**/ ?>