# Sunbase CRM Integration

## Overview
This integration connects Sunbright's Sunbase CRM to the FP&A platform, providing client data, sales pipeline, installation tracking, and operational metrics.

## Implementation Guide

### 1. Authentication
Sunbase uses API key authentication (not OAuth). Store the API key in `.env`:
```
SUNBASE_API_KEY=your-api-key
SUNBASE_BASE_URL=https://api.sunbase.com/v1
```

Update `SunbaseIntegration::isImplemented()` to return `true` when ready.

### 2. Data to sync
| Report ID | Sunbase Endpoint | Description | DB Table |
|-----------|-----------------|-------------|----------|
| clients | GET /clients | Client list with status, contact | `crm_clients` |
| pipeline | GET /deals | Deals by stage | `crm_pipeline` |
| installations | GET /projects | Installations with kW, status | `crm_installations` |
| operations | GET /metrics | Operational KPIs | `crm_metrics` |

### 3. Database tables needed
Create migrations for:
- `crm_clients` (id, company_id, name, email, phone, status, stage, created_at)
- `crm_pipeline` (id, company_id, deal_name, client_id, stage, value, probability, expected_close)
- `crm_installations` (id, company_id, project_name, client_id, kw_installed, status, installer_name, started_at, completed_at)

### 4. Integration steps
1. Edit `SunbaseIntegration.php`:
   - Implement `isConnected()` — check if API key is set and valid
   - Implement `getConnectionStatus()` — test API key with a ping endpoint
   - Implement `sync()` — fetch data from Sunbase API, store in DB tables
2. Create `SunbaseSyncService.php` following the pattern of `QboSyncService.php`
3. Update `migrations/` with new table definitions
4. The dashboard, reports hub, and sidebar will automatically pick up the new data

### 5. Cross-source features (after both QBO + Sunbase are connected)
- ROI per project: match CRM project → QBO transactions by client name
- Installation cost analysis: CRM project details + QBO invoice/expense data
- Pipeline value vs. actual revenue
