<?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/daily-misspunch-log.php');require_once __DIR__.'/daily-misspunch-log-common.php';try{$o=dml_options($con);$f=dml_filters($_GET);$e=dml_validate($f,$o);if($e){http_response_code(400);exit('Invalid report filters.');}$rows=dml_report($con,$f);}catch(Throwable $x){http_response_code(500);exit('Unable to generate export.');}function dmlx($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 Misspunch Log.xls"');header('X-Content-Type-Options: nosniff');echo "\xEF\xBB\xBF";?><html><head><meta charset="utf-8"></head><body><h2>Daily Misspunch Log</h2><p><?=dmlx(date('d-m-Y',strtotime($f['from'])))?> to <?=dmlx(date('d-m-Y',strtotime($f['to'])))?></p><table border="1"><thead><tr><?php foreach(['Sr No','Employee Name','Date','Designation','Branch','Log']as$h):?><th><?=dmlx($h)?></th><?php endforeach;?></tr></thead><tbody><?php foreach($rows as$i=>$r):$e=$r['employee'];?><tr><td><?=$i+1?></td><td><?=dmlx($e['employee_name'])?></td><td><?=dmlx(date('d-m-Y',strtotime($r['date'])))?></td><td><?=dmlx($e['designation']??'')?></td><td><?=dmlx($e['branch_name']??'')?></td><td><?php $logs=[];foreach($r['punches']as$j=>$p)$logs[]=($j%2===0?'In - ':'Out - ').dal_display_time((string)$p);echo dmlx(implode(' / ',$logs));?></td></tr><?php endforeach;?></tbody></table></body></html>
