<?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/mis/daily-not-logged-out-report.php');require_once __DIR__.'/daily-not-logged-out-report-common.php';date_default_timezone_set('Asia/Kolkata');try{if(!dnlo_export_enabled($con)){http_response_code(403);exit('Export is not enabled.');}$scope=dnlo_scope($con);$options=dnlo_options($con,$scope);$filters=dnlo_filters($_GET);$errors=dnlo_validate($filters,$options);if($errors){http_response_code(400);exit('Invalid report filters.');}$rows=dnlo_report($con,$filters,$scope);}catch(Throwable $e){http_response_code(500);exit('Unable to generate export.');}function dnlox($v):string{$v=(string)$v;if(preg_match('/^[=+\-@]/',$v))$v="'".$v;return h($v);}header('Content-Type: application/vnd.ms-excel; charset=UTF-8');header('Content-Disposition: attachment; filename="Daily Not Logged Out Report.xls"');header('X-Content-Type-Options: nosniff');echo "\xEF\xBB\xBF";?><html><head><meta charset="utf-8"></head><body><h2><?=dnlox($options['company'])?></h2><h3>Daily Not Logged Out Report</h3><p>Date: <?=dnlox(date('d-m-Y',strtotime($filters['date'])))?></p><table border="1"><thead><tr><th>Sr No</th><th>Name</th><th>Log In</th><th>Log Out</th><th>Not Logged Out</th></tr></thead><tbody><?php foreach($rows as$i=>$row):$ins=[];$outs=[];foreach($row['logs']as$log){if(trim((string)$log['in_time'])!=='')$ins[]=(string)$log['in_time'];if(trim((string)$log['out_time'])!=='')$outs[]=(string)$log['out_time'];}?><tr><td><?=$i+1?></td><td><?=dnlox($row['employee']['name'])?></td><td><?=dnlox(implode(' / ',$ins))?></td><td><?=dnlox(implode(' / ',$outs))?></td><td><?=dnlox(count($row['missing_dates']).' — '.implode(' / ',array_map(fn($d)=>date('d',strtotime((string)$d)),$row['missing_dates'])))?></td></tr><?php endforeach;?></tbody></table></body></html>
