<?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/daily-attendance-log.php';
$acl=require_acl('can_view',$pageLink);
require_once __DIR__.'/daily-attendance-log-common.php';
date_default_timezone_set('Asia/Kolkata');
$errors=[];
try{$options=dal_load_options($con);$filters=dal_filters($_GET);}catch(Throwable $e){$options=['shifts'=>[],'departments'=>[],'payrolls'=>[],'locations'=>[],'subbranches'=>[],'categories'=>[]];$filters=dal_filters([]);$errors[]='Unable to load report filters.';}
$settings=dal_table_exists($con,'jos_app_usersetting')?dal_rows($con,'SELECT subbranch,catonof FROM jos_app_usersetting LIMIT 1'):[];
$setting=$settings[0]??[];$showSub=!empty($setting['subbranch']);$showCategory=!empty($setting['catonof']);
$input='mt-2 w-full rounded-xl border border-slate-200 bg-white px-3 py-3 text-sm font-semibold text-slate-700 outline-none focus:border-brand-500 focus:ring-4 focus:ring-brand-100';
$selected=static fn(int $a,int $b):string=>$a===$b?'selected':'';
console_header('Daily Attendance Log Filters',$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><a href="/reports/attendance/daily-attendance-log.php">Daily Attendance Log</a><i class="fa-solid fa-chevron-right text-[9px]"></i><span class="text-brand-600">Filters</span></div><h1 class="text-2xl font-bold text-slate-900">Daily Attendance Log</h1><p class="mt-1 text-sm text-slate-500">Select report filters, then open the attendance results.</p></div>
<?php foreach($errors as $error):?><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($error)?></div><?php endforeach;?>
<section class="overflow-hidden rounded-2xl border border-slate-100 bg-white shadow-sm"><div class="border-b border-slate-100 px-5 py-4"><h2 class="text-lg font-bold text-slate-800">Report Filters</h2><p class="mt-1 text-sm font-medium text-slate-400">Results open on a separate report page.</p></div>
<form method="post" action="/reports/attendance/daily-attendance-log.php" class="grid gap-4 p-5 md:grid-cols-2 xl:grid-cols-4">
<label class="text-sm font-bold text-slate-700">Date<input required type="date" name="filter_date" value="<?=h($filters['date'])?>" class="<?=$input?>"></label>
<label class="text-sm font-bold text-slate-700">Select Shift<select name="filter_shift" class="<?=$input?>"><option value="0">-All-</option><?php foreach($options['shifts'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['shift'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label>
<label class="text-sm font-bold text-slate-700">Select Department<select name="filter_dept" class="<?=$input?>"><option value="0">-All-</option><?php foreach($options['departments'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['department'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label>
<label class="text-sm font-bold text-slate-700">Select Payroll Location<select name="filter_payrolllocation" class="<?=$input?>"><option value="0">-All-</option><?php foreach($options['payrolls'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['payroll'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label>
<label class="text-sm font-bold text-slate-700">Select Terminal Location<select name="filter_orglocation" class="<?=$input?>"><option value="0">-All-</option><?php foreach($options['locations'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['terminal'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label>
<label class="text-sm font-bold text-slate-700">Branch Location<select name="filter_branchlocation" class="<?=$input?>"><option value="0">Select Location</option><?php foreach($options['locations'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['branch'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label>
<?php if($showSub):?><label class="text-sm font-bold text-slate-700">Sub Branch Location<select name="filt_subbranch" class="<?=$input?>"><option value="0">-Select Location-</option><?php foreach($options['subbranches'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['subbranch'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label><?php endif;?>
<?php if($showCategory):?><label class="text-sm font-bold text-slate-700">Category<select name="filt_cat" class="<?=$input?>"><option value="0">Select category</option><?php foreach($options['categories'] as $o):?><option value="<?=(int)$o['id']?>" <?=$selected($filters['category'],(int)$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label><?php endif;?>
<div class="flex flex-wrap gap-2 md:col-span-2 xl:col-span-4"><button class="rounded-xl bg-brand-600 px-6 py-3 text-sm font-bold text-white"><i class="fa-solid fa-magnifying-glass mr-2"></i>Go</button><a href="/reports/attendance/daily-attendance-log.php" class="rounded-xl border border-slate-200 px-6 py-3 text-sm font-bold text-slate-600">Cancel</a></div>
</form></section>
<?php console_footer(); ?>
