# PeopleCore HR – Mobile App (v2.0)
## Full Role-Based Attendance & Approval System

---

## Role Hierarchy

| Role        | Can Apply | Can Approve | Sees Reports | Approves All Org |
|-------------|-----------|-------------|--------------|------------------|
| employee    | ✅         | ❌           | ❌            | ❌                |
| manager     | ✅         | ✅ (team)   | ✅ (team)    | ❌                |
| hr          | ✅         | ✅ (all)    | ✅ (all)     | ❌                |
| admin       | ✅         | ✅ (all)    | ✅ (all)     | ✅                |
| superadmin  | ✅         | ✅ (all)    | ✅ (all)     | ✅                |

---

## What Each Role Sees in the App

### Employee
- ✅ Mark Check-In / Check-Out
- ✅ Apply Permission (with date + from/to time)
- ✅ Apply Late Regularization (with reason)
- ✅ Apply Leave (all leave types)
- ✅ View my attendance history (monthly)
- ✅ View my leave balance
- ✅ View my leave applications + status

### Manager (Head / Team Lead)
- Everything Employee has PLUS:
- ✅ **Approvals tab** → approve/reject Leave, Permission, Late for their team
- ✅ **Reports tab** → today's team attendance + monthly summary

### HR / Senior Head
- Everything Manager has PLUS:
- ✅ Sees ALL employees' pending items (not just their team)
- ✅ Org-wide attendance reports

### Admin / Superadmin (Management)
- Everything HR has PLUS:
- ✅ **Management Approve** endpoint — final sign-off on any request
- ✅ All-org pending dashboard showing counts

---

## Setup Steps

### Step 1 – Database Migration
Run the SQL file on your server:
```sql
-- File: migration_late_regularizations.sql
-- Creates late_regularizations table
```

### Step 2 – Add New API Endpoints
Copy the contents of `NEW_API_ENDPOINTS.php` and **append** them to:
```
hr_system/api/v1/index.php
```

Also update the existing `dashboard` action to return `pending_approvals_count`.
(See the comment at the bottom of NEW_API_ENDPOINTS.php.)

### Step 3 – Configure Base URL
In `ApiClient.kt`, change:
```kotlin
private const val BASE_URL = "https://your-domain.com/hr_system/api/v1/"
```

### Step 4 – Open in Android Studio
Open the `hr_mobile_app/` folder in Android Studio.
Build → Run on device or emulator.

---

## File Structure

```
hr_mobile_app/
├── app/
│   ├── build.gradle.kts
│   └── src/main/
│       ├── AndroidManifest.xml
│       ├── java/com/peoplecore/hr/
│       │   ├── api/
│       │   │   ├── ApiClient.kt          ← Retrofit singleton
│       │   │   └── ApiService.kt         ← All API endpoints
│       │   ├── models/
│       │   │   └── Models.kt             ← All data classes
│       │   ├── utils/
│       │   │   └── PrefsManager.kt       ← Login session + role helpers
│       │   └── ui/
│       │       ├── MainActivity.kt       ← Role-based bottom nav
│       │       ├── auth/LoginActivity.kt
│       │       ├── dashboard/DashboardFragment.kt
│       │       ├── attendance/AttendanceFragment.kt  ← Check-in/out + Permission + Late
│       │       ├── leave/LeaveFragment.kt            ← Apply + view leaves
│       │       ├── approvals/ApprovalsFragment.kt    ← All approval flows by role
│       │       └── reports/ReportsFragment.kt        ← Team reports
│       └── res/
│           ├── layout/  ← All XML layouts
│           └── menu/    ← Bottom navigation menu
├── NEW_API_ENDPOINTS.php         ← Add to existing index.php
└── migration_late_regularizations.sql
```

---

## Approval Flow (How It Works)

```
Employee applies (Leave / Permission / Late)
        ↓
Manager (reporting_manager_id) sees it in Approvals → Leave tab
        ↓
Manager approves → status = 'approved' → reflected in web app
        ↓
HR / Admin can also approve (org-wide view)
        ↓
Admin / Superadmin see ALL pending in Management view
        → Uses /management_approve endpoint for final sign-off
```

The web app reflects all changes immediately — same database tables.

---

## Testing Credentials
Default admin password: `Gmhpl_2025`
