# Subscriptions Management Feature

## Overview
Complete subscriptions management system for customers to view, manage, and renew their active services.

## Features Implemented

### Backend (Laravel)
- **SubscriptionController** with full CRUD operations
- Subscription listing with enhanced data from Odoo
- Subscription details with billing history
- Renewal functionality
- Suspend/reactivate functionality
- Alerts system for upcoming renewals and overdue payments
- Integration with Odoo services API

### Frontend (Next.js)
- **Subscriptions Page** (`/subscriptions`)
  - Summary dashboard with key metrics
  - Active subscriptions count
  - Total monthly cost
  - Upcoming renewals
  - Suspended services count
- **Alerts & Notifications**
  - Critical alerts for overdue payments
  - Warning alerts for upcoming renewals
  - Info alerts for general notifications
- **Subscription Cards**
  - Service details and status
  - Installation status
  - Quick actions (renew, suspend, manage)
  - Pricing and billing information

## API Endpoints

### GET /api/subscriptions
Get all customer subscriptions with summary
- Returns: subscriptions list + summary statistics

### GET /api/subscriptions/alerts
Get all subscription alerts and notifications
- Returns: sorted alerts by urgency

### GET /api/subscriptions/{id}
Get detailed subscription information
- Returns: subscription details, installation info, billing history, metrics

### POST /api/subscriptions/{id}/renew
Initiate subscription renewal
- Creates renewal order in Odoo

### POST /api/subscriptions/{id}/suspend
Suspend a subscription
- Updates status locally and in Odoo

## Data Structure

### Subscription Object
```javascript
{
  id: number,
  service_name: string,
  service_type: string, // 'fibre', 'wireless', 'starlink'
  monthly_price: number,
  status: string, // 'active', 'suspended', 'cancelled', 'pending'
  start_date: date,
  next_bill_date: date,
  speed_mbps: number,
  installation: {
    is_installed: boolean,
    installation_date: date,
    status: string
  },
  alerts: array,
  renewal_info: {
    next_bill_date: date,
    days_until_renewal: number,
    amount_due: number,
    can_renew_early: boolean,
    is_overdue: boolean
  }
}
```

### Alert Object
```javascript
{
  type: string, // 'renewal_due', 'overdue', 'suspended'
  urgency: string, // 'critical', 'warning', 'info'
  title: string,
  message: string,
  action_url: string,
  action_text: string
}
```

## Features

### 1. Subscription Listing
- View all active and suspended subscriptions
- See service details, pricing, and status
- Quick access to installation information
- Visual indicators for alerts and status

### 2. Alerts System
- Automatic alerts for renewals due within 3 days
- Critical alerts for overdue payments
- Warning alerts for suspended services
- Actionable buttons for quick resolution

### 3. Renewal Management
- Early renewal option (up to 30 days before due date)
- One-click renewal initiation
- Automatic order creation in Odoo
- Payment integration

### 4. Service Management
- Suspend active subscriptions
- Reactivate suspended services
- View installation status
- Access service details

### 5. Summary Dashboard
- Total subscriptions count
- Active services count
- Monthly cost calculation
- Upcoming renewals count
- Suspended services count

## Integration Points

### Odoo Integration
- Fetches subscription data from Odoo services API
- Syncs with local database for performance
- Creates renewal orders in Odoo
- Updates subscription status in Odoo

### Installation Tracking
- Links subscriptions to installation records
- Shows installation status and dates
- Enables reordering for uninstalled services

### Billing Integration
- Fetches billing history from Odoo invoices
- Calculates total paid and metrics
- Tracks payment due dates

## Usage

### Customer Flow
1. Navigate to `/subscriptions`
2. View all active subscriptions and summary
3. Check alerts for any action items
4. Click on subscription for details
5. Use quick actions to renew or manage services

### Renewal Flow
1. System generates alert 3 days before renewal
2. Customer clicks "Renew Now" button
3. System creates renewal order in Odoo
4. Customer is redirected to payment
5. Subscription is updated upon payment

### Suspension Flow
1. Customer clicks "Suspend" on active subscription
2. Confirmation dialog appears
3. System updates status locally and in Odoo
4. Service is marked as suspended
5. Customer can reactivate anytime

## Future Enhancements
- Upgrade/downgrade subscription plans
- Add-on services management
- Usage tracking and analytics
- Automated payment methods
- Subscription bundling
- Loyalty rewards integration
