<?php
declare(strict_types=1);ini_set('display_errors','0');header('Cache-Control: private, no-store, max-age=0');
require_once __DIR__.'/../includes/aclhelper.php';require_login();require_acl('can_view','salary-config/gross-salary-report.php');require_once __DIR__.'/gross-salary-report-common.php';$errors=[];$access=gsr_access($con);[$filters,$payrolls,$categories,$months,$years,$salaryTypes,$employees]=gsr_filters($con,$access,$errors);$rows=$errors?[]:gsr_query($con,$access,$filters);function gsr_label(array $rows,int $id):string{foreach($rows as $r)if((int)$r['id']===$id)return(string)$r['name'];return'All';}$summary=['Employee'=>gsr_label($employees,$filters['filter_emp']),'Payroll Location'=>gsr_label($payrolls,$filters['filter_orglocation']),'Category'=>gsr_label($categories,$filters['filt_cat']),'Month'=>gsr_label($months,$filters['filt_month']),'Year'=>gsr_label($years,$filters['filt_year']),'Salary Type'=>gsr_label($salaryTypes,$filters['filt_salary'])];
?><!doctype html><html><head><meta charset="utf-8"><title>Gross Salary Report</title><style>body{font:12px Arial;color:#111;margin:24px}h1{text-align:center;font-size:20px}.summary{margin:15px 0;display:flex;flex-wrap:wrap;gap:8px 18px}.summary b{font-size:11px}table{width:100%;border-collapse:collapse}th,td{border:1px solid #222;padding:7px}th{background:#eee;text-align:left}.num{text-align:right}@media print{button{display:none}body{margin:0}}</style></head><body><h1>Employee Gross Salary Report</h1><div class="summary"><?php foreach($summary as $k=>$v):?><span><b><?=h($k)?>:</b> <?=h($v)?></span><?php endforeach;?></div><?php if($errors):?><p><?=h(implode(' ',$errors))?></p><?php else:?><table><thead><tr><th>Sr No</th><th>Employee Name</th><th>Month</th><th>Year</th><th>Salary Type</th><th class="num">Gross Salary</th><th class="num">Rate Per Day</th><th class="num">Rate Per Hour</th></tr></thead><tbody><?php if(!$rows):?><tr><td colspan="8">No gross salary records found.</td></tr><?php endif;?><?php foreach($rows as $i=>$r):?><tr><td><?=$i+1?></td><td><?=h($r['employee_name'])?></td><td><?=h(gsr_month_name($r['month']))?></td><td><?=h($r['year'])?></td><td><?=h($r['salary_type'])?></td><td class="num"><?=h($r['grosspay'])?></td><td class="num"><?=h($r['rateperday'])?></td><td class="num"><?=h($r['rateperhr'])?></td></tr><?php endforeach;?></tbody></table><script>window.addEventListener('load',()=>window.print());</script><?php endif;?></body></html>
