# Task Report Filters

## Overview

The task report page (`/tasks/report`) now includes additional filters for better task management and reporting capabilities.

## New Filters Added

### Client Filter
- **Purpose**: Filter tasks by the client associated with the matter
- **Functionality**: When a client is selected, only tasks from matters belonging to that client are displayed
- **Access Control**: Respects role-based permissions (Senior lawyers only see clients from their departments)

### Proposal Filter
- **Purpose**: Filter tasks by the proposal associated with the matter
- **Functionality**: When a proposal is selected, only tasks from matters created from that proposal are displayed
- **Access Control**: Respects role-based permissions (Senior lawyers only see proposals from their departments)

## How It Works

### Filter Logic
1. **Client Filter**: Uses the relationship `Task -> Matter -> Client` to filter tasks
2. **Proposal Filter**: Uses the relationship `Task -> Matter -> Proposal` to filter tasks
3. **Combined Filters**: Multiple filters work together (AND logic)

### Database Relationships
- `Task` belongs to `Matter`
- `Matter` belongs to `Client`
- `Matter` belongs to `Proposal`
- `Client` has many `Matters`
- `Proposal` has one `Matter`

### Role-Based Access Control
- **Admin/Superadmin**: Can see all clients and proposals
- **Senior Lawyer**: Can only see clients and proposals from their assigned departments
- **Associate/Trainee**: Can only see their own tasks (filters are limited by their task access)

## Usage

### Filtering by Client
1. Navigate to `/tasks/report`
2. In the filters section, select a client from the "Client" dropdown
3. The task list will update to show only tasks from matters belonging to that client

### Filtering by Proposal
1. Navigate to `/tasks/report`
2. In the filters section, select a proposal from the "Proposal" dropdown
3. The task list will update to show only tasks from matters created from that proposal

### Combining Filters
- You can combine client and proposal filters with other existing filters
- All filters work together using AND logic
- Use the "Reset Filters" button to clear all filters

## Technical Implementation

### Component Changes
- Added `selectedClient` and `selectedProposal` properties to `TaskReportPreview`
- Added corresponding `updatedSelectedClient()` and `updatedSelectedProposal()` methods
- Updated `buildQuery()` method to include client and proposal filtering logic
- Added `getClientsProperty()` and `getProposalsProperty()` computed properties

### View Changes
- Added client and proposal filter dropdowns to the filter section
- Updated grid layout to accommodate additional filters
- Maintained consistent styling with existing filters

### Model Relationships
- Added `matters()` relationship to `Client` model
- Utilized existing `matter()` relationship in `Proposal` model

## Benefits

1. **Better Task Organization**: Users can quickly find tasks related to specific clients or proposals
2. **Improved Reporting**: Generate reports focused on specific clients or proposals
3. **Enhanced Workflow**: Streamline task management for client-specific or proposal-specific work
4. **Role-Based Security**: Maintains proper access control based on user roles and departments

## Future Enhancements

- Add export functionality that respects client/proposal filters
- Add summary statistics for filtered results
- Consider adding date range filters specific to client/proposal selection
- Add bulk operations for filtered task sets 