<?php
declare(strict_types=1);ini_set('display_errors','0');header('Cache-Control: private, no-store, max-age=0');
require_once __DIR__.'/../includes/console_shell.php';require_login();$pageLink='salary-config/gross-salary-report.php';$acl=require_acl('can_view',$pageLink);require_once __DIR__.'/gross-salary-report-common.php';
$errors=[];$access=gsr_access($con);[$filters,$payrolls,$categories,$months,$years,$salaryTypes,$employees]=gsr_filters($con,$access,$errors);$page=max(1,(int)($_GET['page']??1));$perPage=25;$total=0;$rows=[];$pages=1;$offset=0;if(!$errors){$total=gsr_query($con,$access,$filters,0,0,true);$pages=max(1,(int)ceil($total/$perPage));$page=min($page,$pages);$offset=($page-1)*$perPage;$rows=gsr_query($con,$access,$filters,$perPage,$offset);}$query=gsr_query_string($filters);
console_header('Employee Gross Salary',$pageLink);
?>
<div class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between"><div><div class="mb-2 flex items-center gap-2 text-xs font-semibold text-slate-500"><a href="/dashboard.php">Dashboard</a><i class="fa-solid fa-chevron-right text-[9px]"></i><span>Salary Config</span><i class="fa-solid fa-chevron-right text-[9px]"></i><span class="text-brand-600">Employee Gross Salary</span></div><h1 class="text-2xl font-bold text-slate-900">Employee Gross Salary</h1><p class="mt-1 text-sm text-slate-500"><?=h((string)$total)?> matching records</p></div><div class="flex flex-wrap gap-2"><a href="/salary-config/gross-salary-report-filters.php" class="rounded-xl bg-brand-600 px-5 py-3 text-sm font-bold text-white hover:bg-brand-700"><i class="fa-solid fa-plus mr-2"></i>Add</a><?php if(!$errors):?><a target="_blank" href="/salary-config/gross-salary-report-print.php?<?=$query?>" class="rounded-xl bg-slate-900 px-5 py-3 text-sm font-bold text-white"><i class="fa-solid fa-print mr-2"></i>Print</a><?php endif;?></div></div>
<?php if($errors):?><div class="mb-5 rounded-xl border border-red-100 bg-red-50 px-5 py-4 text-sm font-semibold text-red-700"><?=h(implode(' ',$errors))?></div><?php endif;?>
<section class="overflow-hidden rounded-2xl border border-slate-100 bg-white shadow-sm"><div class="overflow-x-auto"><table class="w-full min-w-[1050px] text-left text-sm"><thead class="bg-slate-50 text-[10px] font-extrabold uppercase tracking-wider text-slate-700"><tr><th class="px-5 py-4">Sr No</th><th class="px-5 py-4">Employee Name</th><th class="px-5 py-4">Month</th><th class="px-5 py-4">Year</th><th class="px-5 py-4">Salary Type</th><th class="px-5 py-4 text-right">Gross Salary</th><th class="px-5 py-4 text-right">Rate Per Day</th><th class="px-5 py-4 text-right">Rate Per Hour</th></tr></thead><tbody class="divide-y divide-slate-100"><?php if(!$rows):?><tr><td colspan="8" class="px-5 py-16 text-center font-semibold text-slate-400">No gross salary records found.</td></tr><?php endif;?><?php foreach($rows as $i=>$r):?><tr class="hover:bg-slate-50/70"><td class="px-5 py-4"><?=$offset+$i+1?></td><td class="px-5 py-4 font-bold"><?=h($r['employee_name'])?></td><td class="px-5 py-4"><?=h(gsr_month_name($r['month']))?></td><td class="px-5 py-4"><?=h($r['year'])?></td><td class="px-5 py-4"><?=h($r['salary_type'])?></td><td class="px-5 py-4 text-right font-semibold"><?=h($r['grosspay'])?></td><td class="px-5 py-4 text-right"><?=h($r['rateperday'])?></td><td class="px-5 py-4 text-right"><?=h($r['rateperhr'])?></td></tr><?php endforeach;?></tbody></table></div><?php if($pages>1):?><div class="flex justify-between border-t px-5 py-4 text-sm"><span>Page <?=$page?> of <?=$pages?></span><div class="flex gap-2"><?php if($page>1):?><a class="rounded-lg border px-3 py-2" href="?<?=$query?>&page=<?=$page-1?>">Previous</a><?php endif;?><?php if($page<$pages):?><a class="rounded-lg border px-3 py-2" href="?<?=$query?>&page=<?=$page+1?>">Next</a><?php endif;?></div></div><?php endif;?></section>
<?php console_footer();
