loan_management/

because staff salary advances and staff loans affect payroll directly and can be automatically deducted on payslips every month. This usually comes immediately after Leave Management in HR systems.

go ahead

The next module should be:

loan_management/
│
├── loan_settings.php
├── loan_settings_script.php
│
├── loan_request.php
├── loan_request_script.php
│
├── loan_approval.php
├── loan_approval_script.php
│
├── loan_schedule.php
├── loan_schedule_script.php
│
├── salary_advance.php
├── salary_advance_script.php
│
└── loan_reports.php

This integrates directly into:

Attendance
     ↓
Payroll
     ↓
Payslip
     ↓
Loans & Salary Advance
STEP 1

Create Loan Tables

CREATE TABLE employee_loans (

    id INT AUTO_INCREMENT PRIMARY KEY,

    employee_id INT NOT NULL,

    loan_type VARCHAR(100) DEFAULT 'Staff Loan',

    amount DECIMAL(12,2) NOT NULL,

    monthly_deduction DECIMAL(12,2) NOT NULL,

    total_months INT NOT NULL,

    balance DECIMAL(12,2) NOT NULL,

    reason TEXT,

    request_date DATE,

    manager_status ENUM(
        'Pending',
        'Approved',
        'Rejected'
    ) DEFAULT 'Pending',

    hr_status ENUM(
        'Pending',
        'Approved',
        'Rejected'
    ) DEFAULT 'Pending',

    status ENUM(
        'Active',
        'Completed'
    ) DEFAULT 'Active',

    created_at TIMESTAMP
    DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE loan_deductions (

    id INT AUTO_INCREMENT PRIMARY KEY,

    loan_id INT NOT NULL,

    payroll_month INT NOT NULL,

    payroll_year INT NOT NULL,

    deduction_amount DECIMAL(12,2) NOT NULL,

    created_at TIMESTAMP
    DEFAULT CURRENT_TIMESTAMP
);
Salary Advance Table
CREATE TABLE salary_advances (

    id INT AUTO_INCREMENT PRIMARY KEY,

    employee_id INT NOT NULL,

    amount DECIMAL(12,2) NOT NULL,

    reason TEXT,

    request_date DATE,

    manager_status ENUM(
        'Pending',
        'Approved',
        'Rejected'
    ) DEFAULT 'Pending',

    hr_status ENUM(
        'Pending',
        'Approved',
        'Rejected'
    ) DEFAULT 'Pending',

    payroll_deducted TINYINT(1)
    DEFAULT 0,

    created_at TIMESTAMP
    DEFAULT CURRENT_TIMESTAMP
);
STEP 2

Create menu

Add to sidebar:

<li>
<a href="loan_management/loan_request.php">
💰 Staff Loans
</a>
</li>

<li>
<a href="loan_management/salary_advance.php">
💵 Salary Advance
</a>
</li>

<li>
<a href="loan_management/loan_approval.php">
✅ Loan Approval
</a>
</li>

<li>
<a href="loan_management/loan_reports.php">
📊 Loan Reports
</a>
</li>
STEP 3

loan_request_script.php

Staff applies for a loan.

<?php

error_reporting(E_ALL);
ini_set('display_errors',1);

require '../config.php';
session_start();

$userId =
intval($_SESSION['user_id']);

if($_SERVER['REQUEST_METHOD']=='POST'){

    $amount =
    floatval($_POST['amount']);

    $months =
    intval($_POST['months']);

    $monthly =
    $amount / $months;

    $reason =
    trim($_POST['reason']);

    $stmt = $conn->prepare("
        INSERT INTO employee_loans
        (
            employee_id,
            amount,
            monthly_deduction,
            total_months,
            balance,
            reason,
            request_date
        )
        VALUES
        (
            ?,?,?,?,?,?,CURDATE()
        )
    ");

    $stmt->bind_param(
        "idddds",
        $userId,
        $amount,
        $monthly,
        $months,
        $amount,
        $reason
    );

    $stmt->execute();

    header(
        "Location: loan_request.php?saved=1"
    );
    exit;
}
loan_request.php
<?php require 'loan_request_script.php'; ?>

<!DOCTYPE html>
<html>
<head>

<title>Loan Request</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">

<h1 class="text-3xl font-bold mb-6">

Staff Loan Request

</h1>

<?php if(isset($_GET['saved'])): ?>

<div class="bg-green-100 p-4 rounded-lg mb-4">

Loan request submitted.

</div>

<?php endif; ?>

<div class="bg-white p-6 rounded-xl shadow">

<form method="POST">

<div class="grid md:grid-cols-2 gap-5">

<div>

<label class="block mb-2">
Amount
</label>

<input
type="number"
step="0.01"
name="amount"
required
class="w-full border p-3 rounded-lg">

</div>

<div>

<label class="block mb-2">
Repayment Months
</label>

<input
type="number"
name="months"
required
class="w-full border p-3 rounded-lg">

</div>

</div>

<div class="mt-5">

<label class="block mb-2">
Reason
</label>

<textarea
name="reason"
rows="4"
required
class="w-full border p-3 rounded-lg"></textarea>

</div>

<button
class="mt-6 bg-blue-600 text-white px-8 py-3 rounded-lg">

Submit Request

</button>

</form>

</div>

</div>

</body>
</html>
STEP 4

Loan Approval Workflow

Exactly like leave:

Staff submits loan
       ↓
Manager approves
       ↓
HR approves
       ↓
Loan becomes Active
       ↓
Payroll deducts monthly
       ↓
Balance reaches zero
       ↓
Loan Completed
STEP 5

Payroll Integration

Add inside payroll_script.php

after:

$net =
$gross
- $tax
- $pension;

Add:

$loanDeduction = 0;

$loanQuery = $conn->query("
SELECT *
FROM employee_loans
WHERE employee_id = $empId
AND manager_status='Approved'
AND hr_status='Approved'
AND status='Active'
");

while($loan = $loanQuery->fetch_assoc()){

    $loanDeduction +=
    $loan['monthly_deduction'];
}

$advanceDeduction = 0;

$advQuery = $conn->query("
SELECT *
FROM salary_advances
WHERE employee_id = $empId
AND payroll_deducted = 0
AND manager_status='Approved'
AND hr_status='Approved'
");

while($adv = $advQuery->fetch_assoc()){

    $advanceDeduction +=
    $adv['amount'];

    $conn->query("
    UPDATE salary_advances
    SET payroll_deducted = 1
    WHERE id = {$adv['id']}
    ");
}

$net =
$net
- $loanDeduction
- $advanceDeduction;
STEP 6

Add columns to payroll_details

ALTER TABLE payroll_details
ADD loan_deduction DECIMAL(12,2) DEFAULT 0;

ALTER TABLE payroll_details
ADD salary_advance_deduction DECIMAL(12,2) DEFAULT 0;
STEP 7

Payslip Enhancement

Add:

LOAN DEDUCTION
SALARY ADVANCE
TOTAL DEDUCTIONS
LOAN BALANCE

to your payslip.php.

That gives you a fully integrated Loan & Salary Advance module that automatically recovers money through payroll every month. After this, the next strongest module is Overtime Approval, because you already capture attendance hours and overtime rates in salary settings.