# Attendance Module Fix Guide

## Problem: Attendance Module Not Working

### Possible Causes:

1. **Database tables missing** - Attendance table doesn't exist
2. **Employees table missing** - Can't mark attendance without employees
3. **Database connection issue**
4. **PHP errors**

## Solution Steps:

### Step 1: Check Database

Open this URL to check:
```
http://localhost/hrm/modules/attendance/debug.php
```

This will show:
- ✅ If attendance table exists
- ✅ If employees table exists
- ✅ Current site_id
- ✅ Any errors

### Step 2: Import Complete Schema

If tables are missing, import the complete schema:

1. Open phpMyAdmin: `http://localhost/phpmyadmin`
2. Select database: `hrm2`
3. Click **Import** tab
4. Choose file: `c:\xampp\htdocs\hrm2\database\schema.sql`
5. Click **Go**

**Important:** Use `database/schema.sql` (NOT `hrm/database/schema.sql`)

### Step 3: Verify Tables

After import, check these tables exist:
- ✅ `attendance`
- ✅ `employees`
- ✅ `sites`
- ✅ `users`
- ✅ `roles`

### Step 4: Add Employees First

Before marking attendance, you need employees:

1. Go to: `http://localhost/hrm/modules/employee/create.php`
2. Add at least one employee
3. Then try marking attendance

### Step 5: Test Attendance

1. Go to: `http://localhost/hrm/modules/attendance/list.php`
2. Click "Mark Attendance"
3. Select employee and date
4. Submit

## Quick Fix Commands:

### Check if tables exist:
```sql
SHOW TABLES LIKE 'attendance';
SHOW TABLES LIKE 'employees';
```

### If missing, import:
```bash
mysql -u root -p hrm2 < c:\xampp\htdocs\hrm2\database\schema.sql
```

## Common Errors:

### Error: "Table 'attendance' doesn't exist"
**Fix:** Import complete schema.sql

### Error: "No employees found"
**Fix:** Add employees first via Employee Management module

### Error: "site_id is null"
**Fix:** Check user_sites table and assign user to a site

## Still Not Working?

1. Check debug page: `http://localhost/hrm/modules/attendance/debug.php`
2. Check PHP error logs
3. Check browser console (F12)
4. Verify database connection in `config/db.php`

