<?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();require_acl('can_view','reports/attendance/gatepass-pending-for-approval.php');require_once __DIR__.'/gatepass-pending-for-approval-common.php';date_default_timezone_set('Asia/Kolkata');$errors=[];$rows=[];
try{$id=dal_int($_GET['id']??0);if(!$id)throw new RuntimeException('invalid');$scope=gpa_scope($con);$types='i';$params=[$id];$where=array_merge(['g.id=?'],gpa_employee_where($scope,$types,$params));$base=dal_rows($con,'SELECT DATE(g.gatepassdate) gatepassdate,g.status,g.empid FROM jos_app_gatepass_request_log g INNER JOIN jos_app_employee e ON e.id=g.empid WHERE '.implode(' AND ',$where).' LIMIT 1',$types,$params);if(!$base)throw new RuntimeException('not found');$f=['from'=>$base[0]['gatepassdate'],'to'=>$base[0]['gatepassdate'],'status'=>(int)$base[0]['status'],'employee'=>(int)$base[0]['empid']];$rows=array_values(array_filter(gpa_report($con,$f,$scope),fn($r)=>(int)$r['id']===$id));if(!$rows)throw new RuntimeException('not found');}catch(Throwable $e){http_response_code(404);$errors[]='Gatepass request was not found or is not authorized.';}?><!doctype html><html><head><meta charset="utf-8"><title>Gatepass Request</title><style>@page{margin:10mm}body{font:12px Arial;color:#172033}.grid{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}.p-5{padding:16px}.text-xs{font-size:10px}.text-sm{font-size:11px}.font-bold,b{font-weight:700}.uppercase{text-transform:uppercase}.text-slate-400,.text-slate-500{color:#64748b}.rounded-xl{border:1px solid #ddd}.no-print{display:none}button{margin-bottom:10px}@media print{button{display:none}}</style></head><body><button onclick="window.print()">Print</button><h1 style="text-align:center">Gatepass Pending for Approval</h1><?php if($errors):?><p><?=h(implode(' ',$errors))?></p><?php else:gpa_render($rows);?><script>addEventListener('load',()=>window.print())</script><?php endif;?></body></html>
