<?php
declare(strict_types=1);
ini_set('display_errors','0');header('Cache-Control: private, no-store, no-cache, must-revalidate, max-age=0');
require_once __DIR__.'/../../includes/console_shell.php';require_login();$pageLink='reports/attendance/gatepass-pending-for-approval.php';require_acl('can_view',$pageLink);require_once __DIR__.'/gatepass-pending-for-approval-common.php';date_default_timezone_set('Asia/Kolkata');
$errors=[];$rows=[];try{$scope=gpa_scope($con);$filters=gpa_filters($_GET);$errors=gpa_validate($con,$filters,$scope);if(!$errors)$rows=gpa_report($con,$filters,$scope);}catch(Throwable $e){$filters=gpa_filters($_GET);$errors[]='Unable to generate the Gatepass Pending for Approval report.';}
$input='mt-1 w-full rounded-lg border border-slate-200 bg-white px-3 py-2.5 text-sm outline-none focus:border-brand-500 focus:ring-2 focus:ring-brand-100';$sel=fn($a,$b)=>$a==$b?'selected':'';console_header('Gatepass Pending for Approval',$pageLink);?>
<div class="mb-6"><div class="mb-2 flex items-center gap-2 text-xs font-semibold text-slate-500"><span>Reports</span><i class="fa-solid fa-chevron-right text-[9px]"></i><span>Attendance Report</span><i class="fa-solid fa-chevron-right text-[9px]"></i><span class="text-brand-600">Gatepass Pending for Approval</span></div><h1 class="text-2xl font-bold text-slate-900">Gatepass Pending for Approval</h1><p class="mt-1 text-sm text-slate-500">View gatepass requests and their approval history. This report is read-only.</p></div>
<?php foreach($errors as$e):?><div class="mb-4 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm font-semibold text-red-700"><?=h($e)?></div><?php endforeach;?>
<form method="get" class="mb-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm"><div class="grid gap-4 md:grid-cols-2 xl:grid-cols-4"><label class="text-sm font-bold">From Date<input type="date" required name="filter_fromdate" value="<?=h($filters['from'])?>" class="<?=$input?>"></label><label class="text-sm font-bold">To Date<input type="date" required name="filter_todate" value="<?=h($filters['to'])?>" class="<?=$input?>"></label><label class="relative text-sm font-bold">Employee Name<input type="text" name="filter_namevalue" id="gpa-employee-name" value="<?=h($filters['employee_name'])?>" placeholder="Employee name" autocomplete="off" class="<?=$input?>"><input type="hidden" name="filter_emp" id="gpa-employee-id" value="<?=$filters['employee']?>"><div id="gpa-suggestions" class="absolute z-20 mt-1 hidden max-h-60 w-full overflow-auto rounded-lg border border-slate-200 bg-white shadow-lg"></div></label><label class="text-sm font-bold">Status<select name="filt_status" class="<?=$input?>"><option value="0" <?=$sel($filters['status'],0)?>>Pending for Approval</option><option value="1" <?=$sel($filters['status'],1)?>>Approved</option><option value="2" <?=$sel($filters['status'],2)?>>Rejected</option></select></label></div><button class="mt-4 rounded-lg bg-red-500 px-5 py-2.5 text-sm font-bold text-white"><i class="fa-solid fa-filter mr-2"></i>Go</button></form>
<section class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm"><div class="border-b border-slate-200 p-5"><h2 class="text-lg font-bold">Gatepass Pending for Approval</h2><p class="mt-1 text-sm text-slate-500"><?=h(date('d-m-Y',strtotime($filters['from'])))?> to <?=h(date('d-m-Y',strtotime($filters['to'])))?> · <?=h(gpa_status_label($filters['status']))?></p></div><?php gpa_render($rows);?></section>
<script>(()=>{const n=document.getElementById('gpa-employee-name'),id=document.getElementById('gpa-employee-id'),box=document.getElementById('gpa-suggestions');let timer;n?.addEventListener('input',()=>{id.value='';clearTimeout(timer);const q=n.value.trim();if(q.length<2){box.classList.add('hidden');box.innerHTML='';return;}timer=setTimeout(async()=>{try{const r=await fetch('/reports/attendance/gatepass-pending-for-approval-employees.php?query='+encodeURIComponent(q),{credentials:'same-origin'}),j=await r.json();box.innerHTML='';for(const s of(j.suggestions||[])){const b=document.createElement('button');b.type='button';b.className='block w-full px-3 py-2 text-left text-sm hover:bg-slate-50';b.textContent=s.value;b.addEventListener('click',()=>{n.value=s.value;id.value=s.data;box.classList.add('hidden');});box.appendChild(b);}box.classList.toggle('hidden',!box.children.length);}catch(e){box.classList.add('hidden');}},250);});document.addEventListener('click',e=>{if(!box.contains(e.target)&&e.target!==n)box.classList.add('hidden');});})();</script><?php console_footer();
