# Proposal Status Simplification

## Overview

The proposal status system has been simplified to include only 5 essential statuses, removing the complex conflict review workflow and other unnecessary statuses.

## New Status System

### Available Statuses

1. **Draft** - Default status for new proposals
2. **Sent** - Proposal has been sent to the client
3. **Expired** - Automatically set after configured time period
4. **Approved** - Client has approved the proposal
5. **Rejected** - Client has rejected the proposal

### Removed Statuses

The following statuses have been removed:
- `pending_review`
- `conflict_detected`
- `ready_to_send`
- `pending`
- `no_conflict`
- `conflict`
- `conflict_analyse`

## Configuration

### Environment Variables

Add the following to your `.env` file:

```env
# Proposal expiration time in hours (default: 24)
PROPOSAL_EXPIRATION_HOURS=24
```

### Configuration File

The proposal configuration is stored in `config/proposals.php`:

```php
return [
    'expiration_hours' => env('PROPOSAL_EXPIRATION_HOURS', 24),
    'statuses' => [
        'draft' => 'Draft',
        'sent' => 'Sent',
        'expired' => 'Expired',
        'approved' => 'Approved',
        'rejected' => 'Rejected',
    ],
    'default_status' => 'draft',
    'editable_statuses' => [
        'draft' => 'Draft',
        'sent' => 'Sent',
        'approved' => 'Approved',
        'rejected' => 'Rejected',
    ],
    'automatic_statuses' => [
        'expired' => 'Expired',
    ],
];
```

## Automatic Expiration

### How It Works

1. When a proposal status is changed to "sent", the system records the timestamp
2. A scheduled command runs every hour to check for proposals that should be expired
3. Proposals are automatically expired based on the `PROPOSAL_EXPIRATION_HOURS` configuration
4. The command logs all expired proposals for audit purposes

### Manual Execution

You can manually run the expiration command:

```bash
php artisan proposals:expire
```

### Scheduling

The command is automatically scheduled to run every hour in `app/Console/Kernel.php`:

```php
$schedule->command('proposals:expire')
         ->hourly()
         ->withoutOverlapping()
         ->appendOutputTo(storage_path('logs/proposals-expire.log'));
```

## Migration

### Database Changes

Run the migration to update the database:

```bash
php artisan migrate
```

This will:
- Update the status enum to only include the 5 new statuses
- Convert existing proposals with old statuses to "draft"
- Maintain data integrity

### Code Changes

The following components have been updated:
- `Proposal` model
- `ProposalsManager` Livewire component
- `CreateProposal` Livewire component
- `EditProposal` Livewire component
- `ProposalsDashboard` Livewire component
- All related Blade views

## Benefits

1. **Simplified Workflow** - Clear, linear progression of proposal statuses
2. **Automatic Management** - Proposals automatically expire based on configuration
3. **Reduced Complexity** - No more complex conflict review workflows
4. **Better UX** - Users can focus on essential proposal management tasks
5. **Configurable** - Expiration time can be adjusted per environment

## Breaking Changes

1. **Removed Components**:
   - `ProposalsKanbanBoard` component and view
   - Conflict review system integration
   - Complex status validation rules

2. **Updated Methods**:
   - `markAsApproved()` now directly updates status
   - `isUnderAutomaticConflictReview()` method removed
   - Status color and icon methods simplified

3. **Route Changes**:
   - `/proposals/kanban` route removed

## Testing

After implementing these changes:

1. Test proposal creation with new statuses
2. Verify automatic expiration works correctly
3. Check that approval/rejection buttons function properly
4. Ensure all views display correctly with new status system
5. Test the expiration command manually

## Rollback

If you need to rollback these changes:

1. Revert the migration: `php artisan migrate:rollback`
2. Restore the old components and views
3. Update the configuration files
4. Restore the old route definitions
