# ═══════════════════════════════════════════════════════════════
# PHASE 4: SUBSCRIPTIONS & FREEZES MODULE
# Module directory: /modules/subscriptions/
# ═══════════════════════════════════════════════════════════════
# READ THE MASTER PROMPT FIRST.

## YOUR TABLES
subscription_periods, member_subscriptions, subscription_renewal_log,
freeze_policies, member_freezes, freeze_extensions

## REFERENCE TABLES (read only)
members, membership_types, invoices

## PAGES TO BUILD

### 1. Subscription Periods (`GET /subscriptions/periods`)
- CRUD for subscription periods
- Open/close periods

### 2. Member Subscriptions Listing (`GET /subscriptions`)
- DataTable: Member#, Name, Type, Period, Start, End, Amount, Paid, Status
- Filters: Status, Membership Type, Period, Expiring Soon toggle
- Use vw_subscription_renewal_status view

### 3. Create/Renew Subscription (`POST /subscriptions`)
- Member lookup, period selection, auto-calculate amount from membership_type_fees
- Handle renewal (link renewed_from_id)
- Late fee calculation if past grace period
- Dependent count and fees

### 4. Bulk Renewal (`GET /subscriptions/bulk-renew`)
- List eligible members for renewal
- Select all / individual selection
- Bulk create subscriptions and invoices

### 5. Expiring Subscriptions Report
- Members whose subscription ends within N days
- Notify button (queue notifications)

### 6. Freeze Management (`GET /freezes`)
- DataTable: Freeze#, Member, Reason, Start, End, Duration, Status, Fee
- Filters: Status, Date Range
- Use vw_active_freezes view

### 7. Create Freeze Request (`POST /freezes/create`)
- Member lookup, reason, category, dates
- Validate against freeze_policies (max days, max times, etc.)
- Call `sp_create_freeze`

### 8. Approve/Reject Freeze (`POST /api/freezes/{id}/approve`)
- Approval workflow
- On approve: activate freeze, change member status to 'frozen'

### 9. End Freeze Early (`POST /api/freezes/{id}/end`)
- End before scheduled date with reason

### 10. Freeze Extensions (`POST /freezes/{id}/extend`)
- Request extension with additional days
- Approval workflow

### 11. Freeze Policies (`GET /freezes/policies`)
- CRUD for freeze_policies
- Per membership type configuration

## BUSINESS LOGIC
- Subscription creates invoice for payment
- Freeze validated against policy limits
- Active freeze changes member status to 'frozen'
- Ended freeze restores member to 'active'
- Subscription extended by freeze duration if policy allows
- Late renewals trigger late_fee based on membership_type settings

## DASHBOARD WIDGETS
1. **Expiring Subscriptions** — Count expiring in 30 days
2. **Active Freezes** — Count and list

## PERMISSIONS
freezes.view, freezes.create, freezes.approve