# Green Zone Automation - Quick Start

## 🚀 5-Minute Setup

### 1. Create Generic Product in Odoo
```bash
cd afinet-portal-backend
php setup-generic-product.php
```
**Copy the product ID from output**

### 2. Update .env
```env
ODOO_GENERIC_PRODUCT_ID=123  # Use ID from step 1
AUTO_APPROVE_HIGH_FEASIBILITY=true
AUTO_CREATE_ORDER_LINES=true
```

### 3. Clear Cache
```bash
php artisan config:clear
```

### 4. Test
- Create order with high feasibility
- Check email for auto-approval
- Verify order in Odoo has pricing

## ✅ What's Automated

| Feature | Status | What It Does |
|---------|--------|--------------|
| Auto-Approval | ✅ Active | Instantly approves high feasibility orders |
| Order Lines | ✅ Active | Creates order lines in Odoo with pricing |
| Email Notification | ✅ Active | Sends auto-approval email to customer |
| Installation Scheduling | ⏳ Phase 3 | Not yet implemented |
| Service Activation | ⏳ Phase 4 | Not yet implemented |

## 🎯 Auto-Approval Criteria

Order is auto-approved if **ALL** are true:
- ✅ Feasibility = HIGH (green zone)
- ✅ Customer account = active
- ✅ Outstanding balance < 80% of credit limit
- ✅ Package doesn't require custom quote
- ✅ Feature flag enabled

## 📊 Quick Check

```bash
# Check if automation is enabled
php artisan tinker
>>> config('services.automation.auto_approve_high_feasibility')

# Check auto-approval rate
>>> \App\Models\SalesOrder::where('auto_approved', true)->count()

# View recent auto-approved orders
>>> \App\Models\SalesOrder::where('auto_approved', true)->latest()->take(5)->get(['order_number', 'created_at'])
```

## 🔧 Toggle Features

```env
# Disable auto-approval (emergency)
AUTO_APPROVE_HIGH_FEASIBILITY=false

# Disable order line creation
AUTO_CREATE_ORDER_LINES=false
```

Then: `php artisan config:clear`

## 📝 Logs

```bash
# Watch auto-approvals
tail -f storage/logs/laravel.log | grep "auto-approved"

# Watch Odoo sync
tail -f storage/logs/laravel.log | grep "Order created in Odoo"
```

## 🆘 Troubleshooting

| Problem | Solution |
|---------|----------|
| Orders not auto-approving | Check feasibility is "high" and customer account is "active" |
| No order lines in Odoo | Run `php setup-generic-product.php` and update ODOO_GENERIC_PRODUCT_ID |
| Email not sent | Check MAIL_* settings in .env |
| $0.00 in Odoo | Verify ODOO_GENERIC_PRODUCT_ID is set correctly |

## 📞 Support

**Logs:** `storage/logs/laravel.log`
**Config:** `php artisan config:show services.automation`
**Test:** `php setup-generic-product.php`

---

**Status:** ✅ Ready to Use
**Last Updated:** {{ date('Y-m-d') }}
