<?php declare(strict_types=1);ini_set('display_errors','0');header('Cache-Control: private, no-store, no-cache, must-revalidate, max-age=0');header('Pragma:no-cache');require_once __DIR__.'/../../includes/console_shell.php';require_login();$pageLink='reports/mis/monthly-not-logged-out-report.php';require_acl('can_view',$pageLink);require_once __DIR__.'/monthly-not-logged-out-report-common.php';date_default_timezone_set('Asia/Kolkata');
$run=isset($_GET['run']);$errors=[];$rows=null;try{$scope=dnlo_scope($con);$options=mnlo_options($con,$scope);$filters=mnlo_filters($_GET);if($run){$errors=mnlo_validate($filters,$options);if(!$errors)$rows=mnlo_report($con,$filters,$scope);}}catch(Throwable $e){$options=$options??['branches'=>[],'subbranches'=>[],'show_subbranch'=>false,'company'=>APP_NAME,'export'=>false];$filters=mnlo_filters($_GET);$errors[]='Unable to generate the Monthly Not Logged Out Report.';}
$more=$filters['branch']||$filters['subbranch'];$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('Monthly Not Logged Out Report',$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>MIS Report</span><i class="fa-solid fa-chevron-right text-[9px]"></i><span class="text-brand-600">Monthly Not Logged Out Report</span></div><h1 class="text-2xl font-bold text-slate-900">Monthly Not Logged Out Report</h1><p class="mt-1 text-sm text-slate-500">Employees with one or more processed attendance records missing a logout.</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" id="mnlo-form" class="no-print 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 required type="date" name="filter_fromdate" value="<?=h($filters['from'])?>" class="<?=$input?>"></label><label class="text-sm font-bold">To Date<input required type="date" name="filter_todate" value="<?=h($filters['to'])?>" class="<?=$input?>"></label></div><div class="mt-4 flex flex-wrap items-center justify-between gap-3"><button type="button" id="mnlo-more" class="rounded-lg border border-slate-200 px-4 py-2.5 text-sm font-bold"><i class="fa-solid fa-sliders mr-2"></i><span><?=$more?'Hide Additional Filters':'Use Additional Filters'?></span></button><div class="flex flex-wrap gap-2"><button name="run" value="1" class="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><?php if($run&&!$errors):?><button name="run" value="1" formaction="/reports/mis/monthly-not-logged-out-report-print.php" formtarget="_blank" class="rounded-lg bg-red-500 px-5 py-2.5 text-sm font-bold text-white"><i class="fa-solid fa-print mr-2"></i>Print</button><?php if($options['export']):?><button name="run" value="1" formaction="/reports/mis/monthly-not-logged-out-report-export.php" class="rounded-lg bg-emerald-600 px-5 py-2.5 text-sm font-bold text-white"><i class="fa-solid fa-file-excel mr-2"></i>Export to XLS</button><?php endif;?><?php endif;?></div></div><div id="mnlo-extra" class="mt-4 <?=$more?'':'hidden'?> border-t border-slate-100 pt-4"><div class="grid gap-4 md:grid-cols-2 xl:grid-cols-4"><label class="text-sm font-bold">Branch Location<select name="filter_branchlocation" class="<?=$input?>"><option value="0">Select Location</option><?php foreach($options['branches']as$o):?><option value="<?=$o['id']?>" <?=$sel($filters['branch'],$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label><?php if($options['show_subbranch']):?><label class="text-sm font-bold">Sub Branch Location<select name="filt_subbranch" class="<?=$input?>"><option value="0">-Select Location-</option><?php foreach($options['subbranches']as$o):?><option value="<?=$o['id']?>" <?=$sel($filters['subbranch'],$o['id'])?>><?=h($o['name'])?></option><?php endforeach;?></select></label><?php endif;?></div></div></form>
<?php if($rows!==null):?><section class="overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm"><div class="p-5 text-center"><b><?=h((string)$options['company'])?></b><h2 class="text-lg font-bold">Monthly Not Loggedout Report - <?=h(date('d-m-Y',strtotime($filters['from'])))?> to <?=h(date('d-m-Y',strtotime($filters['to'])))?></h2><div class="mt-1 text-sm font-semibold text-slate-500">Dated on <?=h(date('d-m-Y'))?></div></div><?php mnlo_render($rows);?></section><?php endif;?><script>const b=document.getElementById('mnlo-more'),x=document.getElementById('mnlo-extra'),f=document.getElementById('mnlo-form');b?.addEventListener('click',()=>{const o=x.classList.contains('hidden');x.classList.toggle('hidden');b.querySelector('span').textContent=o?'Hide Additional Filters':'Use Additional Filters';});f?.querySelectorAll('input,select').forEach(el=>el.addEventListener('change',()=>document.querySelector('section')?.classList.add('hidden')));</script><?php console_footer();
