# Setting Up Sales Objectives - Quick Start Guide

## Automatic Setup (Recommended)

I've created an automated setup system that will analyze your current sales data and automatically create the "Objetivos" sheet with 2026 targets.

### Step 1: Login to Dashboard
1. Go to your dashboard
2. Login with your admin account: **de.globalerc@gmail.com**
3. You should see your dashboard with all filters and data

### Step 2: Create Objectives Sheet
1. Click the **⚙️ Setup Objectives** button on the dashboard
2. The system will:
   - Analyze all your current sales data (84,780 rows!)
   - Extract revenue by comercial and by client
   - Extract URNAS quantities by comercial and by client
   - Project 2026 targets with 5% growth
   - Create/update the "Objetivos" sheet

3. You'll see a confirmation page with details

### Step 3: Review the Sheet
1. Open your Google Sheets spreadsheet
2. Look for the new "Objetivos" tab at the bottom
3. You'll see data like this:

```
Comercial         | Cliente           | Target_Valor | Target_Urnas | Period
Jose Amor         | Total             | €52,500.00   | 1050         | Annual
Jose Amor         | Client A          | €15,750.00   | 315          | Annual
Jose Amor         | Client B          | €21,000.00   | 420          | Annual
...
Helder Oliveira   | Total             | €47,250.00   | 945          | Annual
...
```

### Step 4: Adjust if Needed
- The system uses **5% growth** as the default projection
- If you want different targets:
  - Edit the Google Sheet directly
  - Change the Target_Valor (€) and Target_Urnas numbers
  - Changes take effect immediately

### Step 5: View Performance
1. Go back to the dashboard
2. Click **📈 Performance Report**
3. You'll see:
   - Total achievement % for each comercial
   - Achievement % by client
   - Color-coded status (green=excellent, red=below target)

## What Gets Created

The script analyzes:

### Revenue by Comercial
- **Jose Amor**: Total revenue from all current sales
- **Helder Oliveira**: Total revenue from all current sales

### URNAS Quantities
- Tracks only items from the "Familia" column containing "urna"
- Counts total units by comercial and by client

### Clients
- Lists all unique clients for each comercial
- Sets individual targets per client
- Creates "Total" row for overall objectives

## 2026 Target Calculation

Formula: `Current Sales Value × 1.05 = 2026 Target`

Example:
- If Jose Amor's current revenue: €50,000
- 2026 Target: €50,000 × 1.05 = **€52,500**

## Performance Dashboard

Once objectives are set, visit `/performance` to see:

- **Total Revenue Target vs Actual** (with % achievement)
- **URNAS Target vs Actual** (with % achievement)
- **By-Client Performance** (revenue and URNAS metrics)
- **Color-coded Status**:
  - 🟢 ≥100% = Excellent (Target met!)
  - 🔵 80-99% = Good (On track)
  - 🟡 60-79% = Warning (Needs improvement)
  - 🔴 <60% = Below Target (Action needed)

## Performance Reports

For each comercial, generate detailed reports:
- Visit `/performance-report/Jose Amor`
- Includes printable format (Ctrl+P or Print button)
- Professional layout ready for PDF export

## Troubleshooting

### "Setup Objectives" button not showing?
- Make sure you're logged in as **de.globalerc@gmail.com** (admin account)
- Only admins can set up objectives

### Objectives created but not showing in Performance?
- Refresh the page (Ctrl+F5)
- Check that comercial names match exactly:
  - Data sheet: "Jose Amor", "Helder Oliveira"
  - Objetivos sheet: Must be spelled identically

### Wrong numbers in targets?
- The script analyzes ALL data in the BASE sheet
- If numbers seem off, check for:
  - Duplicate client names with different spellings
  - Test/sample data mixed in
  - Filter the data first if needed

### Want to change the growth factor?
- Default is 5% (1.05 multiplier)
- Edit the "Target_Valor" or "Target_Urnas" columns directly in Google Sheets
- No code changes needed

## Technical Details

The setup process:
1. Connects to your Google Sheets using OAuth
2. Reads the "BASE" sheet (usually index 1)
3. Parses numeric values from Faturaçao column
4. Groups by Comercial → Cliente
5. Filters URNAS data (Familia contains 'urna')
6. Applies 5% growth: `value * 1.05`
7. Writes to "Objetivos" sheet with proper formatting

The performance dashboard then:
1. Reads actual sales from BASE sheet
2. Reads targets from Objetivos sheet
3. Calculates: `(Actual / Target) × 100 = Achievement %`
4. Displays with color coding and visual progress bars

---

**Questions?** Check the dashboard logs or review the data in Google Sheets directly.
