# Pricing Flow Quick Reference

## Current Configuration

```
SIMULATE_PACKAGE_PRICING = false (Reality Mode)
```

## Package Pricing Models

| Pricing Model | Portal Behavior | Odoo Required | Example |
|---------------|----------------|---------------|---------|
| **fixed** | Shows fixed price immediately | No | Satellite packages |
| **distance_based** | Calculates based on feasibility | No (uses feasibility data) | Fibre with extension |
| **bandwidth_based** | Calculates based on bandwidth | No (uses package rates) | Business variable bandwidth |
| **custom** | Shows "Request Quote", $0 pricing | Yes (manual pricing) | Enterprise, complex setups |

## Complete Flow by Pricing Model

### Fixed Pricing (e.g., Satellite)

```
1. Customer views package → Sees fixed price
2. Customer requests quotation → Quotation created with fixed price
3. Quotation sent to Odoo → Draft sale.order created
4. Customer accepts → Odoo confirms to sales order
5. Odoo generates invoice → Portal syncs invoice
6. Customer pays → Payment recorded in both systems
```

**Timeline:** Minutes to hours

### Distance-Based Pricing (e.g., Fibre)

```
1. Customer does feasibility check → Gets coverage status + extension cost
2. Customer views package → Sees base price + extension cost
3. Customer requests quotation → Quotation created with calculated price
4. Quotation sent to Odoo → Draft sale.order created
5. Customer accepts → Odoo confirms to sales order
6. Odoo generates invoice → Portal syncs invoice
7. Customer pays → Payment recorded in both systems
```

**Timeline:** Minutes to hours (after feasibility check)

### Bandwidth-Based Pricing (e.g., Business)

```
1. Customer selects bandwidth → Portal calculates price
2. Customer requests quotation → Quotation created with calculated price
3. Quotation sent to Odoo → Draft sale.order created
4. Customer accepts → Odoo confirms to sales order
5. Odoo generates invoice → Portal syncs invoice
6. Customer pays → Payment recorded in both systems
```

**Timeline:** Minutes to hours

### Custom Pricing (e.g., Enterprise) ⚠️ REQUIRES ODOO

```
1. Customer requests quotation → Quotation created with $0
   Status: pending_review
   
2. Portal sends to Odoo → Draft sale.order (no order lines)
   
3. Sales team in Odoo:
   - Reviews requirements
   - Adds products/services
   - Sets pricing
   - Sends quotation (state: 'sent')
   
4. Odoo webhook → Portal syncs pricing
   Status: sent
   Portal emails customer: "Your quotation is ready"
   
5. Customer views quotation → Sees real pricing from Odoo
   
6. Customer accepts quotation → Portal sends to Odoo
   
7. Odoo confirms → Sales order (state: 'sale')
   
8. Odoo webhook → Portal syncs sales order
   Status: accepted
   Portal updates quotation pricing (if changed)
   
9. Odoo generates invoice → Portal syncs invoice
   
10. Customer pays → Payment recorded in both systems
```

**Timeline:** 1-48 hours (depends on sales team response)

## Webhook Events

| Event | Trigger | Portal Action |
|-------|---------|---------------|
| `quotation.created` | Quotation created in Odoo | Create quotation in portal |
| `quotation.updated` | Quotation priced/updated in Odoo | Update pricing, send notification |
| `sale.order.confirmed` | Quotation confirmed to order | Create sales order, update quotation |
| `invoice.created` | Invoice generated in Odoo | Create invoice in portal |
| `invoice.paid` | Invoice marked paid in Odoo | Update invoice status |

## Pricing Sync Points

### Point 1: Quotation Created (Portal → Odoo)
- **Fixed/Calculated:** Portal sends pricing to Odoo
- **Custom:** Portal sends $0, notes with requirements

### Point 2: Quotation Updated (Odoo → Portal)
- **Custom:** Odoo sends real pricing to portal
- Portal updates quotation
- Portal emails customer

### Point 3: Sales Order Confirmed (Odoo → Portal)
- Portal creates sales order with Odoo pricing
- Portal updates quotation pricing (if changed)
- Ensures quotation and order have same price

### Point 4: Invoice Created (Odoo → Portal)
- Portal creates invoice with Odoo pricing
- Invoice price matches sales order price

## Customer Experience by Pricing Model

### Fixed/Calculated Pricing
```
View Package → See Price → Request Quote → Accept → Pay Invoice
Timeline: Same day
```

### Custom Pricing
```
Request Quote → Wait for Pricing → Review Quote → Accept → Pay Invoice
Timeline: 1-2 days
```

## Key Differences: Simulation vs Reality

| Aspect | Simulation Mode | Reality Mode (Current) |
|--------|----------------|------------------------|
| Custom pricing | Estimated prices | $0, wait for Odoo |
| Quotation approval | Immediate | After Odoo pricing |
| Invoice generation | Portal creates | Odoo creates, portal syncs |
| Payment flow | Works standalone | Requires Odoo sync |
| Use case | Demo/testing | Production |

## Troubleshooting

### Quotation stuck at $0
- **Expected:** For custom pricing in reality mode
- **Action:** Check Odoo for quotation, ensure sales team has priced it

### Quotation not updating with Odoo pricing
- **Check:** Webhook logs
- **Action:** `php artisan sync:data quotations`

### Customer not notified of pricing
- **Check:** Email logs
- **Action:** Verify email configuration, check QuotationStatusChanged mail

### Invoice price doesn't match quotation
- **Check:** Sales order pricing in Odoo
- **Action:** Verify sales order webhook fired and synced correctly

## Commands

```bash
# Clear config cache after changing SIMULATE_PACKAGE_PRICING
php artisan config:clear

# Manually sync quotations from Odoo
php artisan sync:data quotations

# Manually sync specific quotation
php artisan sync:data quotations --id=123

# Test email notifications
php artisan email:test your@email.com

# Check webhook logs
tail -f storage/logs/laravel.log | grep -i webhook
```

## Summary

**Reality Mode (Current):**
- Fixed/calculated pricing: Instant quotations with real prices
- Custom pricing: Quotation → Odoo pricing → Customer approval → Invoice
- All invoices come from Odoo
- All payments synced to Odoo
- Full audit trail across both systems

**The system enforces the real-world business process where custom pricing requires sales team review and approval before customers can proceed.**
