# Quick Update Instructions

## For Updating Existing cPanel Installation

### Step 1: Backup Everything
```bash
# Backup database
mysqldump -u username -p database_name > backup.sql

# Backup .env file
cp .env .env.backup

# Backup uploaded files
tar -czf uploads_backup.tar.gz storage/app/public
```

### Step 2: Upload New Files
Upload all files from `laracom` directory EXCEPT:
- `.env` (keep your existing one)
- `storage/app/public/*` (your uploaded images)
- `vendor/` (will regenerate)
- `node_modules/` (will regenerate)

### Step 3: Install Dependencies
```bash
composer install --optimize-autoloader --no-dev
```

### Step 4: Run New Migrations
```bash
php artisan migrate --force
```

This will add:
- `incomplete_orders` table enhancements
- `courier_error_logs` table
- Courier fields to `orders` table
- Admin logs table

### Step 5: Clear All Caches
```bash
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
```

### Step 6: Rebuild Caches
```bash
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

### Step 7: Rebuild Frontend Assets (if CSS/JS changed)
```bash
npm install
npm run build
```

### Step 8: Test New Features
1. Login to admin panel
2. Go to Settings → Couriers
3. Configure courier services (Steadfast, Pathao, RedX)
4. Test incomplete orders tracking
5. Verify order creation works

## New Database Tables
- `incomplete_orders` - Tracks abandoned checkouts
- `courier_error_logs` - Logs courier API errors
- `admin_logs` - Tracks admin actions

## New Settings to Configure
Navigate to Admin Panel → Settings:

### Courier Settings
- Steadfast API credentials
- Pathao API credentials and store selection
- RedX API token and store selection

### Fraud Detection
- Enable/disable fraud checking
- Max orders per phone number
- Time window for duplicate detection

## Files Modified in This Update

### Controllers
- `app/Http/Controllers/Admin/CourierController.php` - Enhanced courier management
- `app/Http/Controllers/Admin/IncompleteOrderController.php` - New incomplete orders
- `app/Http/Controllers/Admin/OrderController.php` - Courier integration
- `app/Http/Controllers/Frontend/CheckoutController.php` - Incomplete order tracking

### Services
- `app/Services/Courier/SteadfastService.php` - New balance checking
- `app/Services/Courier/PathaoService.php` - Store management
- `app/Services/Courier/RedXService.php` - Store management
- `app/Services/IncompleteOrderService.php` - New service
- `app/Services/FraudCheckService.php` - Enhanced fraud detection

### Views
- `resources/views/admin/couriers/index.blade.php` - New courier settings UI
- `resources/views/admin/couriers/errors.blade.php` - Courier error logs
- `resources/views/admin/incomplete-orders/index.blade.php` - Incomplete orders dashboard
- `resources/views/admin/orders/show.blade.php` - Enhanced order details

### JavaScript
- `public/js/courier.js` - Courier integration
- `public/js/incomplete-orders-admin.js` - Incomplete orders management
- `resources/js/app.js` - Lucide icons fix

### Migrations
- `2025_01_18_000001_add_order_key_and_status_to_incomplete_orders.php`
- `2025_01_18_000002_enhance_incomplete_orders_table.php`
- `2025_01_18_000003_create_courier_error_logs_table.php`
- `2025_01_18_000004_add_courier_fields_to_orders.php`
- `2026_01_18_075846_add_missing_columns_to_incomplete_orders_table.php`

## Rollback Instructions (If Needed)

### Restore Database
```bash
mysql -u username -p database_name < backup.sql
```

### Restore Files
```bash
# Restore .env
cp .env.backup .env

# Restore uploads
tar -xzf uploads_backup.tar.gz
```

### Clear Caches
```bash
php artisan config:clear
php artisan route:clear
php artisan view:clear
php artisan cache:clear
```

## Common Issues After Update

### Issue: Courier settings not saving
**Solution**: Check database connection and run migrations

### Issue: Incomplete orders not showing
**Solution**: Ensure middleware is registered in `bootstrap/app.php`

### Issue: Icons not displaying
**Solution**: Clear browser cache and rebuild assets with `npm run build`

### Issue: 500 Error after update
**Solution**: 
1. Check `storage/logs/laravel.log`
2. Verify file permissions: `chmod -R 755 storage bootstrap/cache`
3. Clear all caches
4. Regenerate autoload: `composer dump-autoload`

## Support

Check these files for detailed implementation notes:
- `COURIER_SETTINGS_IMPLEMENTATION.md`
- `INCOMPLETE_ORDERS_COURIER_IMPLEMENTATION.md`
- `DEPLOYMENT_GUIDE.md`
