> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Braian551/viax/llms.txt
> Use this file to discover all available pages before exploring further.

# Driver Management

> Approve drivers, verify documents, and manage driver status

## Overview

Driver Management provides comprehensive tools for reviewing driver applications, verifying required documents, and monitoring driver compliance with platform requirements.

<Warning>
  All drivers must have their documents verified and approved before they can accept ride requests on the platform.
</Warning>

## Driver Documents Screen

Access the driver documents management interface:

```dart admin/presentation/screens/conductores_documentos_screen.dart theme={null}
class ConductoresDocumentosScreen extends StatefulWidget {
  final int adminId;

  const ConductoresDocumentosScreen({
    super.key,
    required this.adminId,
  });
}
```

## Dashboard Statistics

The driver documents screen displays real-time statistics:

<CardGroup cols={4}>
  <Card title="Total Drivers" icon="users">
    All registered drivers in the system
  </Card>

  <Card title="Pending" icon="clock" color="#ffa726">
    Drivers awaiting document review
  </Card>

  <Card title="Approved" icon="check-circle" color="#11998e">
    Verified and active drivers
  </Card>

  <Card title="Expired Docs" icon="triangle-exclamation" color="#f5576c">
    Drivers with expired documents
  </Card>
</CardGroup>

## Verification Status Filters

Filter drivers by their verification status:

<Tabs>
  <Tab title="All">
    Display all drivers regardless of status
  </Tab>

  <Tab title="Pending">
    **Status:** `pendiente`

    **Color:** Yellow (#ffa726)

    New driver applications awaiting review
  </Tab>

  <Tab title="In Review">
    **Status:** `en_revision`

    **Color:** Blue (#667eea)

    Documents currently being verified
  </Tab>

  <Tab title="Approved">
    **Status:** `aprobado`

    **Color:** Green (#11998e)

    Fully verified and active drivers
  </Tab>

  <Tab title="Rejected">
    **Status:** `rechazado`

    **Color:** Red (#f5576c)

    Applications rejected due to invalid documents
  </Tab>
</Tabs>

## Driver Information Fields

The system tracks comprehensive driver information:

### Personal Information

```dart theme={null}
{
  "nombre": "Juan",
  "apellido": "Pérez",
  "email": "juan.perez@example.com",
  "telefono": "+57 300 123 4567",
  "es_activo": 1,
  "estado_verificacion": "pendiente"
}
```

### Driver's License

```dart theme={null}
{
  "licencia_conduccion": "12345678",
  "licencia_categoria": "C2",
  "licencia_expedicion": "2020-01-15",
  "licencia_vencimiento": "2030-01-15"
}
```

<Info>
  The system automatically alerts when a driver's license is within 30 days of expiration.
</Info>

### Vehicle Information

```dart theme={null}
{
  "vehiculo_tipo": "carro",      // motocicleta, carro, furgoneta, camión
  "vehiculo_placa": "ABC123",
  "vehiculo_marca": "Toyota",
  "vehiculo_modelo": "Corolla",
  "vehiculo_anio": 2020,
  "vehiculo_color": "Blanco"
}
```

### SOAT (Mandatory Insurance)

```dart theme={null}
{
  "soat_numero": "SOAT-2024-001",
  "soat_vencimiento": "2024-12-31"
}
```

### Technomechanical Inspection

```dart theme={null}
{
  "tecnomecanica_numero": "TEC-2024-001",
  "tecnomecanica_vencimiento": "2024-10-15"
}
```

### Vehicle Insurance

```dart theme={null}
{
  "aseguradora": "Seguros Bolivar",
  "numero_poliza_seguro": "POL-2024-001",
  "vencimiento_seguro": "2024-12-31"
}
```

### Other Documents

```dart theme={null}
{
  "tarjeta_propiedad_numero": "TP-2020-001"
}
```

## Document Completeness Calculation

The system automatically calculates document completeness percentage:

```dart theme={null}
int _calculateCompleteness(Map<String, dynamic> conductor) {
  int count = 0;
  int total = 8;

  if (conductor['licencia_conduccion'] != null && 
      conductor['licencia_conduccion'].toString().isNotEmpty) count++;
  if (conductor['licencia_vencimiento'] != null) count++;
  if (conductor['vehiculo_placa'] != null && 
      conductor['vehiculo_placa'].toString().isNotEmpty) count++;
  if (conductor['soat_numero'] != null && 
      conductor['soat_numero'].toString().isNotEmpty) count++;
  if (conductor['tecnomecanica_numero'] != null && 
      conductor['tecnomecanica_numero'].toString().isNotEmpty) count++;
  if (conductor['aseguradora'] != null && 
      conductor['aseguradora'].toString().isNotEmpty) count++;
  if (conductor['vehiculo_marca'] != null) count++;
  if (conductor['vehiculo_modelo'] != null) count++;

  return ((count / total) * 100).round();
}
```

## Expired Documents Detection

Automatic detection of expired or soon-to-expire documents:

```dart theme={null}
bool _hasExpiredDocuments(Map<String, dynamic> conductor) {
  final now = DateTime.now();
  
  // Check license expiration
  if (conductor['licencia_vencimiento'] != null) {
    final licenciaExp = DateTime.parse(conductor['licencia_vencimiento']);
    if (licenciaExp.isBefore(now)) return true;
  }
  
  // Check SOAT expiration
  if (conductor['soat_vencimiento'] != null) {
    final soatExp = DateTime.parse(conductor['soat_vencimiento']);
    if (soatExp.isBefore(now)) return true;
  }
  
  // Check technomechanical expiration
  if (conductor['tecnomecanica_vencimiento'] != null) {
    final tecExp = DateTime.parse(conductor['tecnomecanica_vencimiento']);
    if (tecExp.isBefore(now)) return true;
  }
  
  return false;
}
```

## Driver Details Modal

View comprehensive driver information in a detailed modal:

```dart theme={null}
void _showDriverDetails(Map<String, dynamic> conductor) {
  showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    backgroundColor: Colors.transparent,
    builder: (context) => DraggableScrollableSheet(
      initialChildSize: 0.9,
      minChildSize: 0.5,
      maxChildSize: 0.95,
      builder: (context, scrollController) {
        return Container(
          decoration: BoxDecoration(
            color: Colors.black,
            borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
          ),
          child: SingleChildScrollView(
            controller: scrollController,
            child: Column(
              children: [
                _buildHeader(conductor),
                _buildPersonalInfo(conductor),
                _buildLicenseInfo(conductor),
                _buildVehicleInfo(conductor),
                _buildSOATInfo(conductor),
                _buildTechnomechanicalInfo(conductor),
                _buildInsuranceInfo(conductor),
                _buildVerificationStatus(conductor),
                _buildActionButtons(conductor),
              ],
            ),
          ),
        );
      },
    ),
  );
}
```

## Approve Driver Use Case

```dart admin/domain/usecases/approve_driver.dart theme={null}
class ApproveDriver {
  final AdminRepository repository;

  ApproveDriver(this.repository);

  Future<Result<void>> call(int conductorId) async {
    if (conductorId <= 0) {
      return Error(ValidationFailure('ID de conductor inválido'));
    }

    return await repository.approveDriver(conductorId);
  }
}
```

## Approve Driver Action

<Steps>
  <Step title="Review Documents">
    Open driver details modal and review all provided documents
  </Step>

  <Step title="Verify Information">
    Check that license, vehicle, insurance, and SOAT are valid
  </Step>

  <Step title="Tap Approve">
    Press the green "Aprobar" button at the bottom of the modal
  </Step>

  <Step title="Confirm Action">
    Confirm the approval in the dialog that appears
  </Step>

  <Step title="Driver Activated">
    Driver status changes to "aprobado" and they can now accept rides
  </Step>
</Steps>

### Approval Backend Endpoint

```php backend/admin/aprobar_conductor.php theme={null}
// POST /admin/aprobar_conductor.php
{
  "conductor_id": 123
}

// Updates:
// - estado_verificacion = "aprobado"
// - es_verificado = 1
// - Logs action in audit_logs
```

## Reject Driver Use Case

```dart admin/domain/usecases/reject_driver.dart theme={null}
class RejectDriver {
  final AdminRepository repository;

  RejectDriver(this.repository);

  Future<Result<void>> call(int conductorId, String motivo) async {
    if (conductorId <= 0) {
      return Error(ValidationFailure('ID de conductor inválido'));
    }
    if (motivo.isEmpty) {
      return Error(ValidationFailure('Debe proporcionar un motivo'));
    }

    return await repository.rejectDriver(conductorId, motivo);
  }
}
```

## Reject Driver Action

<Steps>
  <Step title="Review Documents">
    Identify issues or missing information in driver documents
  </Step>

  <Step title="Tap Reject">
    Press the red "Rechazar" button
  </Step>

  <Step title="Enter Reason">
    **Required:** Provide a clear explanation for rejection

    Example: "Licencia de conducción vencida"
  </Step>

  <Step title="Confirm Rejection">
    Confirm the rejection with the provided reason
  </Step>

  <Step title="Driver Notified">
    Driver status changes to "rechazado" and reason is logged
  </Step>
</Steps>

### Rejection Backend Endpoint

```php backend/admin/rechazar_conductor.php theme={null}
// POST /admin/rechazar_conductor.php
{
  "conductor_id": 123,
  "motivo": "Licencia de conducción vencida"
}

// Updates:
// - estado_verificacion = "rechazado"
// - Logs action with motivo in audit_logs
```

## Document Expiration Alerts

Visual indicators for document expiration:

<CardGroup cols={3}>
  <Card title="Expired" icon="circle-xmark" color="#f5576c">
    Document is past expiration date
  </Card>

  <Card title="Expiring Soon" icon="triangle-exclamation" color="#ffa726">
    Document expires within 30 days
  </Card>

  <Card title="Valid" icon="circle-check" color="#11998e">
    Document is valid and current
  </Card>
</CardGroup>

## Status Color Coding

| Status          | Color  | Hex Code  | Icon         |
| --------------- | ------ | --------- | ------------ |
| **Pendiente**   | Yellow | `#ffa726` | Clock        |
| **En Revisión** | Blue   | `#667eea` | Eye          |
| **Aprobado**    | Green  | `#11998e` | Check Circle |
| **Rechazado**   | Red    | `#f5576c` | X Circle     |

## Audit Logging

All driver approval/rejection actions are logged:

```sql theme={null}
INSERT INTO audit_logs (
  admin_id,
  usuario_afectado_id,
  accion,
  descripcion,
  ip_address,
  user_agent
) VALUES (
  1,
  123,
  'aprobar_conductor',
  'Conductor aprobado: Juan Pérez (ID: 123)',
  '192.168.1.100',
  'Mozilla/5.0...'
);
```

<Note>
  All approvals and rejections are tracked in the audit logs with timestamps, admin IDs, and reasons (for rejections).
</Note>

## Document Types by Vehicle Category

### Motorcycle (motocicleta)

* Driver's license (Category A2 or higher)
* SOAT
* Technomechanical inspection
* Vehicle registration

### Car (carro)

* Driver's license (Category C1 or higher)
* SOAT
* Technomechanical inspection
* Vehicle insurance
* Vehicle registration

### Cargo Motorcycle (moto\_carga)

* Driver's license (Category C1 or higher)
* SOAT
* Technomechanical inspection
* Cargo permit
* Vehicle registration

### Cargo Van (carro\_carga)

* Driver's license (Category C2 or higher)
* SOAT
* Technomechanical inspection
* Commercial insurance
* Cargo permit
* Vehicle registration

## Best Practices

<Accordion title="Review Thoroughly">
  Always review all documents before approving. Check expiration dates, license categories, and vehicle information.
</Accordion>

<Accordion title="Provide Clear Rejection Reasons">
  When rejecting a driver, provide specific, actionable feedback so they know what to correct.
</Accordion>

<Accordion title="Monitor Expirations">
  Regularly check the "Expired Docs" count and proactively notify drivers to renew documents.
</Accordion>

<Accordion title="Track Pending Applications">
  Process pending driver applications promptly to maintain good driver onboarding experience.
</Accordion>

## Related Features

<CardGroup cols={3}>
  <Card title="User Management" icon="users" href="/admin/user-management">
    Manage all platform users
  </Card>

  <Card title="Company Management" icon="building" href="/admin/company-management">
    Assign drivers to companies
  </Card>

  <Card title="Audit Logs" icon="clipboard-list" href="/admin/audit-logs">
    View driver approval history
  </Card>
</CardGroup>
