103 lines
5.4 KiB
PHP
103 lines
5.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once __DIR__ . '/db/config.php';
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
|
|
|
if (!isset($_SESSION['user_id']) || !isset($_SESSION['company_id']) || $_SESSION['role'] !== 'admin') {
|
|
header('Location: /login.php');
|
|
exit;
|
|
}
|
|
|
|
if (!isset($_GET['run_id'])) {
|
|
header('Location: /payroll_history.php');
|
|
exit;
|
|
}
|
|
|
|
$company_id = $_SESSION['company_id'];
|
|
$run_id = $_GET['run_id'];
|
|
|
|
// Fetch run details
|
|
$stmt = db()->prepare("SELECT * FROM payroll_runs WHERE id = ? AND company_id = ?");
|
|
$stmt->execute([$run_id, $company_id]);
|
|
$run = $stmt->fetch();
|
|
|
|
if (!$run) {
|
|
header('Location: /payroll_history.php');
|
|
exit;
|
|
}
|
|
|
|
// Fetch payslips for the run
|
|
$stmt = db()->prepare("SELECT p.*, e.first_name, e.last_name FROM payslips p JOIN employees e ON p.employee_id = e.id WHERE p.payroll_run_id = ?");
|
|
$stmt->execute([$run_id]);
|
|
$payslips = $stmt->fetchAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Payslips for <?= htmlspecialchars(date('F Y', mktime(0,0,0, (int)$run['pay_period_month'], 1, (int)$run['pay_period_year']))) ?> - GPTPayroll</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
</head>
|
|
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
|
|
<div class="flex md:flex-row-reverse flex-wrap">
|
|
|
|
<!-- Main Content -->
|
|
<div class="w-full md:w-4/5 bg-gray-100">
|
|
<div class="container bg-gray-100 pt-16 px-6 mx-auto">
|
|
<div class="bg-white shadow-md rounded p-8">
|
|
<h1 class="text-2xl font-bold text-gray-800 mb-6">Payslips for <?= htmlspecialchars(date('F Y', mktime(0,0,0, (int)$run['pay_period_month'], 1, (int)$run['pay_period_year']))) ?></h1>
|
|
<div class="overflow-x-auto">
|
|
<table class="min-w-full divide-y divide-gray-200">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Employee</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase">Net Pay</th>
|
|
<th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y divide-gray-200">
|
|
<?php if (empty($payslips)): ?>
|
|
<tr>
|
|
<td colspan="3" class="px-6 py-4 text-center text-sm text-gray-500">No payslips found for this run.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($payslips as $payslip): ?>
|
|
<tr>
|
|
<td class="px-6 py-4 text-sm font-medium text-gray-900"><?= htmlspecialchars($payslip['first_name'] . ' ' . $payslip['last_name']) ?></td>
|
|
<td class="px-6 py-4 text-sm text-gray-500 text-right">ZMW <?= htmlspecialchars(number_format((float)$payslip['net_pay'], 2)) ?></td>
|
|
<td class="px-6 py-4 text-right text-sm font-medium">
|
|
<a href="/download_payslip.php?payslip_id=<?= $payslip['id'] ?>" class="text-indigo-600 hover:text-indigo-900" target="_blank">Download PDF</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="mt-6">
|
|
<a href="/payroll_history.php" class="text-blue-500 hover:text-blue-700">← Back to Payroll History</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Sidebar -->
|
|
<div class="w-full md:w-1/5 bg-gray-800 md:min-h-screen">
|
|
<div class="md:relative mx-auto lg:float-right lg:px-6">
|
|
<ul class="list-reset flex flex-row md:flex-col text-center md:text-left">
|
|
<li class="mr-3 flex-1"><a href="/dashboard.php" class="block py-4 px-4 text-gray-400 hover:text-white no-underline">Dashboard</a></li>
|
|
<li class="mr-3 flex-1"><a href="/employees.php" class="block py-4 px-4 text-gray-400 hover:text-white no-underline">Employees</a></li>
|
|
<li class="mr-3 flex-1"><a href="/payroll.php" class="block py-4 px-4 text-gray-400 hover:text-white no-underline">Payroll</a></li>
|
|
<li class="mr-3 flex-1"><a href="/payroll_history.php" class="block py-4 px-4 text-white font-bold no-underline">Payroll History</a></li>
|
|
<li class="mr-3 flex-1"><a href="/settings.php" class="block py-4 px-4 text-gray-400 hover:text-white no-underline">Settings</a></li>
|
|
<li class="mr-3 flex-1"><a href="/logout.php" class="block py-4 px-4 text-gray-400 hover:text-white no-underline">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|