# Workload Management System

## Overview

The workload management system allows tracking user capacity and utilization through monthly hours and hourly rates. This helps managers understand resource allocation and workload distribution across the team.

## Features

### User Workload Fields

- **Daily Hours**: Number of hours per day for workload calculation
- **Hourly Rate**: Hourly rate for workload calculation
- **Monthly Value**: Automatically calculated (daily hours × hourly rate × 22 working days)
- **Workload Status**: Visual indicator of utilization level

### Workload Status Levels

1. **Not Configured** (Gray): No monthly hours or hourly rate set
2. **Under Utilized** (Yellow): Less than 70% of capacity used
3. **Optimal** (Green): 70-100% of capacity used
4. **Over Utilized** (Red): More than 100% of capacity used

### User Interface

#### User Management
- **Create User**: Add daily hours and hourly rate during user creation
- **Edit User**: Modify workload settings with real-time status display
- **Users List**: View workload summary in the users table

#### Workload Display
- Daily capacity in hours
- Hourly rate
- Monthly value calculation (daily hours × hourly rate × 22 working days)
- Workload status with color-coded badges

## Database Schema

### Users Table Additions

```sql
ALTER TABLE users ADD COLUMN daily_hours INT NULL COMMENT 'Number of hours per day for workload calculation';
ALTER TABLE users ADD COLUMN hourly_rate DECIMAL(10,2) NULL COMMENT 'Hourly rate for workload calculation';
```

## Model Methods

### User Model

```php
// Get daily hours (with default 0)
public function getDailyHoursAttribute(): int

// Get hourly rate (with default 0.0)
public function getHourlyRateAttribute(): float

// Calculate monthly workload value
public function getMonthlyWorkloadValue(): float

// Get workload status
public function getWorkloadStatus(): string

// Get workload status color for UI
public function getWorkloadStatusColor(): string

// Get workload status label for UI
public function getWorkloadStatusLabel(): string
```

## Usage Examples

### Setting Workload for a User

```php
$user = User::find(1);
$user->update([
    'daily_hours' => 8,
    'hourly_rate' => 150.00,
]);
```

### Getting Workload Information

```php
$user = User::find(1);

// Get basic values
$dailyHours = $user->daily_hours; // 8
$hourlyRate = $user->hourly_rate; // 150.00

// Get calculated values
$monthlyValue = $user->getMonthlyWorkloadValue(); // 26400.00 (8 * 150 * 22)
$status = $user->getWorkloadStatus(); // 'under_utilized'
$statusLabel = $user->getWorkloadStatusLabel(); // 'Under Utilized'
$statusColor = $user->getWorkloadStatusColor(); // 'yellow'
```

## Future Enhancements

### Actual Hours Tracking
The current implementation includes a placeholder for actual hours worked. To implement real workload tracking:

1. **Task Hours**: Track time spent on tasks
2. **Matter Hours**: Track time spent on matters
3. **Time Tracking**: Implement time tracking functionality
4. **Reports**: Generate workload utilization reports

### Integration Points
- Connect with existing Task and Matter models
- Add time tracking to task completion
- Create workload utilization dashboards
- Generate capacity planning reports

## Validation Rules

### Create User
- `daily_hours`: nullable, integer, min:0, max:24
- `hourly_rate`: nullable, numeric, min:0, max:10000

### Edit User
- Same validation rules as create user
- Real-time change detection
- Visual indicators for modified fields

## CSS Classes

The system includes custom CSS classes for workload styling:

```css
.workload-status
.workload-status.under-utilized
.workload-status.optimal
.workload-status.over-utilized
.workload-status.not-configured
.workload-value
.workload-details
```

## Testing

Run the workload tests:

```bash
php artisan test --filter=UserWorkloadTest
```

## Migration

To add workload fields to existing installations:

```bash
php artisan migrate
```

This will add the `daily_hours` and `hourly_rate` columns to the users table. 