Your current code has the calculations in the wrong order.

Right now you're doing this:

```php
$tax =
($gross * $taxPercent) / 100;

$pension =
($gross * $pensionPercent) / 100;

$net =
$gross
- $tax
- $pension
- $loanDeduction
- $advanceDeduction;
```

before `$loanDeduction`, `$advanceDeduction`, and `$overtimePay` even exist.

---

# STEP 1

Delete this entire section:

```php
/*
============================================
NET SALARY
============================================
*/

$net =
    $gross
    - $tax
    - $pension
    - $loanDeduction
    - $advanceDeduction;
```

Remove it completely.

---

# STEP 2

Keep your Loan Deduction section exactly where it is.

```php
$loanDeduction = 0;

...

$advanceDeduction = 0;

...
```

But REMOVE this part:

```php
$net =
$net
- $loanDeduction
- $advanceDeduction;
```

Delete it.

---

# STEP 3

Keep your Overtime section.

```php
$overtimePay =
$overtimeHours *
floatval($emp['overtime_rate']);

$gross += $overtimePay;
```

---

# STEP 4

Immediately AFTER:

```php
$gross += $overtimePay;
```

add:

```php
/*
============================================
FINAL NET SALARY
============================================
*/

$net =
$gross
- $tax
- $pension
- $loanDeduction
- $advanceDeduction;
```

---

# RESULT

Your final sequence should look like this:

```php
/*
============================================
TAX
============================================
*/

$tax =
($gross * $taxPercent) / 100;

/*
============================================
PENSION
============================================
*/

$pension =
($gross * $pensionPercent) / 100;


/*
============================================
PAYROLL LOAN DEDUCTION
============================================
*/

$loanDeduction = 0;

...

$advanceDeduction = 0;

...


/*
============================================
OVERTIME PAYROLL INTEGRATION
============================================
*/

$overtimeHours = 0;

...

$overtimePay =
$overtimeHours *
floatval($emp['overtime_rate']);

$gross += $overtimePay;


/*
============================================
FINAL NET SALARY
============================================
*/

$net =
$gross
- $tax
- $pension
- $loanDeduction
- $advanceDeduction;
```

---

# STEP 5 (Recommended)

Because overtime increases gross salary, tax and pension should also be recalculated AFTER overtime.

Instead of:

```php
$tax =
($gross * $taxPercent) / 100;

$pension =
($gross * $pensionPercent) / 100;
```

before overtime,

move them down and calculate them after:

```php
$gross += $overtimePay;
```

Like this:

```php
$gross += $overtimePay;

$tax =
($gross * $taxPercent) / 100;

$pension =
($gross * $pensionPercent) / 100;

$net =
$gross
- $tax
- $pension
- $loanDeduction
- $advanceDeduction;
```

This is actually the correct payroll logic because overtime earnings become part of taxable earnings.

So the clean order should be:

1. Calculate base salary
2. Calculate overtime
3. Add overtime to gross salary
4. Calculate tax
5. Calculate pension
6. Apply loan deduction
7. Apply salary advance deduction
8. Calculate final net salary

That will make your payroll calculations accurate.



PAYE means **Pay As You Earn**.

It is the employee income tax that is deducted from salary and remitted to the government.

In your payroll system, PAYE is currently represented by:

```php
tax_amount
```

and displayed on the payslip as:

```php
Tax Deduction
```

---

### What employees normally see

Instead of:

```text
Tax Deduction
```

most Nigerian companies show:

```text
PAYE Tax
```

or

```text
PAYE
```

on the payslip.

So in your `payslip.php` you may want to change:

```php
<td class="p-4">
    Tax Deduction
</td>
```

to:

```php
<td class="p-4">
    PAYE Tax
</td>
```

---

### Typical Payslip Layout

```text
Gross Salary                ₦200,000

PAYE Tax                    ₦14,500
Pension                     ₦16,000
Loan Deduction              ₦10,000
Salary Advance              ₦20,000

Net Salary                  ₦139,500
```

---

### In your database

You currently have:

```sql
tax_amount
```

This is perfectly fine.

No need to rename the database column.

Just display it as:

```php
PAYE Tax
```

on the payslip.

---

### Should tax be a fixed percentage?

Right now your payroll uses:

```php
tax_percent
```

from:

```sql
employee_salary
```

Example:

```text
Employee A = 5%
Employee B = 7.5%
Employee C = 10%
```

That is a simplified payroll model and is perfectly okay for hotel operations.

---

### Enterprise Version

Later, if you want Nigerian-compliant payroll, you can create:

```sql
tax_bands
```

and calculate PAYE using the official Nigerian progressive tax brackets:

```text
First ₦300,000      7%
Next ₦300,000      11%
Next ₦500,000      15%
Next ₦500,000      19%
Next ₦1.6m         21%
Above              24%
```

plus:

* Consolidated Relief Allowance (CRA)
* Pension relief
* NHF deduction
* NSITF

But for a hotel HR/payroll system, the current:

```php
tax_percent
```

approach is much simpler and easier to manage.

So in your system:

```text
tax_amount = PAYE
pension_amount = Pension
loan_deduction = Staff Loan
salary_advance_deduction = Salary Advance
net_salary = Final Take Home Pay
```

and the PAYE should appear on **payslip.php** in the Salary Breakdown section where "Tax Deduction" is currently shown.



You're asking for **thousands of lines of production PHP** across 5 separate modules. I can generate them, but not all complete modules accurately in a single response.

The safest way is module-by-module in the order they integrate with your existing payroll workflow:

### Phase 1 (next)

1. `payroll_release.php`
2. `payroll_release_script.php`
3. Update `payslip.php`
4. Update `payslips.php`
5. SQL changes

### Phase 2

1. `payroll_dashboard.php`
2. `payroll_dashboard_script.php`

### Phase 3

1. `payroll_export.php`
2. CSV export generation

### Phase 4

1. `finance_reports.php`
2. `finance_reports_script.php`

### Phase 5

1. `payroll_journal.php`
2. `payroll_journal_script.php`

The reason is that each later module depends on fields and workflow created by the earlier ones. If I dump all five now, there is a high chance they'll need revisions once integrated into your current schema.

Since you've already built:

* Payroll
* Payslips
* HR Approval
* Audit Approval
* GM Approval
* Accounts Disbursement
* Leave Management
* Loans

the correct next step is **Payslip Release Control**.

Reply with:

```text
Generate Payslip Release Module
```

and I'll give you:

* SQL ALTER statements
* `payroll_release.php`
* `payroll_release_script.php`
* `payslips.php` updates
* `payslip.php` updates
* sidebar menu entry

ready to paste into your system.
