First create the salary table.

### SQL

```sql
CREATE TABLE employee_salary (
    id INT AUTO_INCREMENT PRIMARY KEY,

    employee_id INT NOT NULL UNIQUE,

    salary_type ENUM('monthly','daily','hourly')
    DEFAULT 'monthly',

    basic_salary DECIMAL(12,2) DEFAULT 0,

    overtime_rate DECIMAL(12,2) DEFAULT 0,

    tax_percent DECIMAL(5,2) DEFAULT 0,

    pension_percent DECIMAL(5,2) DEFAULT 0,

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
```

---

# salary_settings_script.php

```php
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);

require 'config.php';
session_start();

if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit;
}

$userRole = strtolower(trim($_SESSION['role'] ?? ''));

if (!in_array($userRole,['superadmin','admin','hr'])) {
    die("Access Denied");
}

/*
|--------------------------------------------------------------------------
| SAVE
|--------------------------------------------------------------------------
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $stmt = $conn->prepare("
        INSERT INTO employee_salary
        (
            employee_id,
            salary_type,
            basic_salary,
            overtime_rate,
            tax_percent,
            pension_percent
        )
        VALUES (?,?,?,?,?,?)
        ON DUPLICATE KEY UPDATE
            salary_type = VALUES(salary_type),
            basic_salary = VALUES(basic_salary),
            overtime_rate = VALUES(overtime_rate),
            tax_percent = VALUES(tax_percent),
            pension_percent = VALUES(pension_percent)
    ");

    foreach ($_POST['employee_id'] as $empId) {

        $empId = intval($empId);

        $salaryType = $_POST['salary_type'][$empId] ?? 'monthly';

        $basicSalary = floatval(
            $_POST['basic_salary'][$empId] ?? 0
        );

        $overtimeRate = floatval(
            $_POST['overtime_rate'][$empId] ?? 0
        );

        $taxPercent = floatval(
            $_POST['tax_percent'][$empId] ?? 0
        );

        $pensionPercent = floatval(
            $_POST['pension_percent'][$empId] ?? 0
        );

        $stmt->bind_param(
            "issddd",
            $empId,
            $salaryType,
            $basicSalary,
            $overtimeRate,
            $taxPercent,
            $pensionPercent
        );

        $stmt->execute();
    }

    $stmt->close();

    header("Location: salary_settings.php?saved=1");
    exit;
}

/*
|--------------------------------------------------------------------------
| LOAD EMPLOYEES
|--------------------------------------------------------------------------
*/
$employees = [];

$res = $conn->query("
SELECT
e.id,
e.name,
d.name AS department
FROM employees e
LEFT JOIN departments d
ON d.id = e.department_id
ORDER BY e.name
");

while($row = $res->fetch_assoc()){

    $employees[$row['id']] = $row;
}

/*
|--------------------------------------------------------------------------
| LOAD SALARIES
|--------------------------------------------------------------------------
*/
$salaries = [];

$res = $conn->query("
SELECT *
FROM employee_salary
");

while($row = $res->fetch_assoc()){

    $salaries[$row['employee_id']] = $row;
}
?>
```

---

# salary_settings.php

```php
<?php
require 'salary_settings_script.php';
?>

<!DOCTYPE html>
<html>
<head>

<title>Salary Settings</title>

<script src="https://cdn.tailwindcss.com"></script>

</head>

<body class="flex h-screen bg-gray-100">

<?php include 'sidebar.php'; ?>

<div class="flex-1 p-8 overflow-y-auto">

<div class="flex justify-between items-center mb-6">

    <div>

        <h1 class="text-3xl font-bold">
            Salary Settings
        </h1>

        <p class="text-gray-500">
            Configure employee payroll information
        </p>

    </div>

</div>

<?php if(isset($_GET['saved'])): ?>

<div class="bg-green-100 text-green-700 p-4 rounded-lg mb-6">

    Salary settings saved successfully.

</div>

<?php endif; ?>

<form method="POST">

<div class="bg-white rounded-2xl shadow overflow-hidden">

<div class="p-4 border-b">

<input
type="text"
id="employeeSearch"
placeholder="Search employee..."
class="w-full border p-3 rounded-lg">

</div>

<div class="overflow-auto">

<table class="w-full text-sm">

<thead class="bg-gray-100">

<tr>

<th class="p-4 text-left">
Employee
</th>

<th class="p-4 text-left">
Department
</th>

<th class="p-4">
Salary Type
</th>

<th class="p-4">
Basic Salary
</th>

<th class="p-4">
OT Rate
</th>

<th class="p-4">
Tax %
</th>

<th class="p-4">
Pension %
</th>

</tr>

</thead>

<tbody id="employeeTable">

<?php foreach($employees as $emp): ?>

<?php

$salary = $salaries[$emp['id']] ?? [];

?>

<tr class="border-b employee-row">

<td class="p-4">

<input
type="hidden"
name="employee_id[]"
value="<?= $emp['id'] ?>">

<?= htmlspecialchars($emp['name']) ?>

</td>

<td class="p-4">

<?= htmlspecialchars($emp['department']) ?>

</td>

<td class="p-4">

<select
name="salary_type[<?= $emp['id'] ?>]"
class="border p-2 rounded">

<option value="monthly"
<?= (($salary['salary_type'] ?? '')=='monthly')
? 'selected':''
?>>

Monthly

</option>

<option value="daily"
<?= (($salary['salary_type'] ?? '')=='daily')
? 'selected':''
?>>

Daily

</option>

<option value="hourly"
<?= (($salary['salary_type'] ?? '')=='hourly')
? 'selected':''
?>>

Hourly

</option>

</select>

</td>

<td class="p-4">

<input
type="number"
step="0.01"
name="basic_salary[<?= $emp['id'] ?>]"
value="<?= $salary['basic_salary'] ?? 0 ?>"
class="border p-2 rounded w-32">

</td>

<td class="p-4">

<input
type="number"
step="0.01"
name="overtime_rate[<?= $emp['id'] ?>]"
value="<?= $salary['overtime_rate'] ?? 0 ?>"
class="border p-2 rounded w-24">

</td>

<td class="p-4">

<input
type="number"
step="0.01"
name="tax_percent[<?= $emp['id'] ?>]"
value="<?= $salary['tax_percent'] ?? 0 ?>"
class="border p-2 rounded w-20">

</td>

<td class="p-4">

<input
type="number"
step="0.01"
name="pension_percent[<?= $emp['id'] ?>]"
value="<?= $salary['pension_percent'] ?? 0 ?>"
class="border p-2 rounded w-20">

</td>

</tr>

<?php endforeach; ?>

</tbody>

</table>

</div>

</div>

<button
class="mt-6 bg-green-600 hover:bg-green-700 text-white px-8 py-3 rounded-xl font-semibold">

Save Salary Settings

</button>

</form>

</div>

<script>

document.getElementById("employeeSearch")
.addEventListener("keyup", function(){

    let value =
    this.value.toLowerCase();

    document
    .querySelectorAll(".employee-row")
    .forEach(row => {

        row.style.display =
        row.innerText
        .toLowerCase()
        .includes(value)
        ? ""
        : "none";

    });

});

</script>

</body>
</html>
```

### Add to Sidebar

```php
<li>
    <a href="salary_settings.php">
        💰 Salary Settings
    </a>
</li>

<li>
    <a href="payroll.php">
        🧾 Payroll
    </a>
</li>
```

After this is working, the next file should be `payroll.php`, which will automatically calculate salaries from your attendance records and department schedules and generate monthly payroll.
