# Simulation vs Reality Mode - Confirmed Behavior

## Current Setting

```env
SIMULATE_PACKAGE_PRICING=false  # Reality Mode
```

## SIMULATE_PACKAGE_PRICING = true (Simulation Mode)

### Purpose
Development, testing, demos - **NOT for production**

### Complete Flow

```
1. Customer Requests Quotation
   ↓
   Portal calculates mock/estimated pricing
   Status: 'pending' (ready to accept)
   ↓
2. Customer Can Accept Immediately
   ↓
   Portal creates sales order locally
   Portal sends to Odoo (if connected)
   ↓
3. Portal Creates Invoice Locally (WRONG FOR PRODUCTION!)
   ↓
4. Customer Can Pay Immediately
```

### Key Points

✅ **Instant pricing** - No waiting for sales team
✅ **Instant acceptance** - Customer can accept right away
✅ **Auto-generated invoice** - Portal creates invoice (not Odoo)
✅ **Fast flow** - Complete process in minutes
❌ **NOT REAL** - Prices are estimates/mock data
❌ **NO SALES REVIEW** - No human verification
❌ **WRONG FOR PRODUCTION** - Bypasses business process

### When to Use

- Frontend development
- UI/UX testing
- Demo presentations
- Development without Odoo access
- Testing payment flows

## SIMULATE_PACKAGE_PRICING = false (Reality Mode) ✓ CURRENT

### Purpose
Production - **Real business operations**

### Complete Flow

#### For Starlink (Only Package with Fixed Pricing)

```
1. Customer Requests Quotation
   ↓
   Portal retrieves pricing from Odoo product catalog
   Portal creates quotation with Odoo pricing
   Status: 'pending_review' (awaiting sales approval)
   Portal sends to Odoo
   ↓
2. Sales Team Reviews in Odoo
   ↓
   Verifies pricing is correct
   Sends quotation to customer (state: 'sent')
   ↓
3. Scheduler Syncs (within 5 minutes)
   ↓
   Portal updates quotation status to 'sent'
   Customer receives email: "Your quotation is ready"
   ↓
4. Customer Reviews and Accepts
   ↓
   Portal confirms quotation in Odoo
   Odoo creates sales order (state: 'sale')
   ↓
5. Scheduler Syncs (within 5 minutes)
   ↓
   Portal creates sales order record
   ↓
6. Sales Team Generates Invoice in Odoo
   ↓
   Manual or automatic (Odoo configuration)
   ↓
7. Scheduler Syncs (within 5 minutes)
   ↓
   Portal creates invoice record
   Customer receives email: "Your invoice is ready"
   ↓
8. Customer Pays
```

**Timeline:** 1-2 days (depends on sales team response)

#### For All Other Packages (Custom Pricing)

```
1. Customer Requests Quotation
   ↓
   Portal calculates estimate (if feasibility data available) OR $0
   Portal creates quotation with estimate/$0
   Status: 'pending_review' (awaiting sales pricing)
   Portal sends to Odoo
   ↓
2. Sales Team Prices in Odoo
   ↓
   Reviews requirements
   Adds products/services
   Sets final pricing
   Sends quotation to customer (state: 'sent')
   ↓
3. Scheduler Syncs (within 5 minutes)
   ↓
   Portal updates quotation with REAL pricing from Odoo
   Portal updates status to 'sent'
   Customer receives email: "Your quotation is ready"
   ↓
4. Customer Reviews Real Pricing and Accepts
   ↓
   Portal confirms quotation in Odoo
   Odoo creates sales order (state: 'sale')
   ↓
5. Scheduler Syncs (within 5 minutes)
   ↓
   Portal creates sales order record
   Portal updates quotation pricing (if changed)
   ↓
6. Sales Team Generates Invoice in Odoo
   ↓
   Manual or automatic (Odoo configuration)
   ↓
7. Scheduler Syncs (within 5 minutes)
   ↓
   Portal creates invoice record
   Customer receives email: "Your invoice is ready"
   ↓
8. Customer Pays
```

**Timeline:** 1-3 days (depends on sales team response)

### Key Points

✅ **Real pricing** - From Odoo or sales team
✅ **Sales review** - Human verification required
✅ **Odoo invoices** - All invoices from Odoo (never portal)
✅ **Proper flow** - Follows business process
✅ **Audit trail** - Everything recorded in Odoo
✅ **Customer transparency** - Sees approved pricing before committing
❌ **Slower** - Requires sales team actions
❌ **Wait times** - 1-3 days for complete process

### When to Use

- Production environment
- Real customer transactions
- Actual business operations
- When sales team review is required
- When proper audit trail is needed

## Comparison Table

| Aspect | Simulation (true) | Reality (false) ✓ |
|--------|------------------|-------------------|
| **Pricing Source** | Mock/Estimated | Odoo/Sales Team |
| **Sales Review** | ❌ No | ✅ Yes |
| **Customer Wait** | None | 1-3 days |
| **Invoice Source** | Portal (wrong!) | Odoo (correct!) |
| **Can Accept Immediately** | ✅ Yes | ❌ No (must wait for 'sent' status) |
| **Timeline** | Minutes | Days |
| **Use Case** | Development/Testing | Production |
| **Audit Trail** | Incomplete | Complete in Odoo |

## Critical Differences

### Quotation Status

**Simulation Mode:**
- Status: `'pending'` (can accept immediately)
- No sales team review needed

**Reality Mode:**
- Status: `'pending_review'` (cannot accept yet)
- Must wait for sales team to change to `'sent'`
- Customer can only accept when status is `'sent'` or `'pending'`

### Invoice Generation

**Simulation Mode:**
```php
// WRONG - Portal auto-generates invoice
$invoice = Invoice::create([...]);
```

**Reality Mode:**
```php
// CORRECT - No auto-generation
// Invoice comes from Odoo via scheduler sync
// Sales team generates in Odoo
```

### Acceptance Flow

**Simulation Mode:**
```
Customer → Accept → Sales Order Created → Invoice Created → Pay
(All instant, no waiting)
```

**Reality Mode:**
```
Customer → Wait (Sales Review) → Accept → Wait (Invoice Generation) → Pay
(Multiple wait points for sales team actions)
```

## Code Behavior

### PricingService

```php
// When SIMULATE_PACKAGE_PRICING=true
if (PricingSimulationService::isEnabled()) {
    // Returns mock pricing for all packages
    return [
        'monthly_price' => 150,  // Estimated
        'installation_fee' => 300,  // Estimated
        'requires_custom_quote' => false,  // Can accept immediately
    ];
}

// When SIMULATE_PACKAGE_PRICING=false
if ($package->pricing_model === 'custom') {
    return [
        'monthly_price' => 0,
        'installation_fee' => 0,
        'requires_custom_quote' => true,  // Must wait for sales team
    ];
}
```

### QuotationController

```php
// When requires_custom_quote = true (Reality Mode)
if ($pricing['requires_custom_quote']) {
    $quotation = Quotation::create([
        'status' => 'pending_review',  // Cannot accept yet
        'total_amount' => 0,  // No pricing yet
    ]);
    return 'Quotation request submitted for review';
}

// When requires_custom_quote = false (Simulation Mode)
$quotation = Quotation::create([
    'status' => 'pending',  // Can accept immediately
    'total_amount' => $pricing['total_amount'],  // Has pricing
]);
```

### Accept Method

```php
// Check if quotation can be accepted
if (!in_array($quotation->status, ['sent', 'pending'])) {
    return 'Quotation cannot be accepted in current status';
}

// Reality Mode: Status is 'pending_review' → Cannot accept
// Simulation Mode: Status is 'pending' → Can accept
// After sales review: Status is 'sent' → Can accept
```

## Confirmation

### SIMULATE_PACKAGE_PRICING = true

✅ **YES** - You can do the whole process immediately
- Request quotation → Accept → Pay
- No waiting for sales team
- Portal generates everything
- **BUT** - Not real pricing, not for production

### SIMULATE_PACKAGE_PRICING = false ✓ CURRENT

✅ **YES** - You must wait for sales team
- Request quotation → **WAIT** (sales team prices) → Accept → **WAIT** (invoice generated) → Pay
- Sales team reviews and prices in Odoo
- Sales team generates invoice in Odoo
- Scheduler syncs every 5 minutes
- **AND** - Real pricing, proper business process, production-ready

## Summary

**Simulation Mode (true):**
- Fast, automated, no waiting
- For development/testing only
- Portal does everything (wrong for production)

**Reality Mode (false):** ✓ CURRENT
- Slower, requires sales team actions
- For production use
- Odoo controls everything (correct for production)
- Customer waits for:
  1. Sales team to price quotation (1-48 hours)
  2. Sales team to generate invoice (within 5 minutes of sync)

**Your understanding is 100% correct!**
