# TurboFi WiFi Billing System - Development Task Checklist

## Day 1: Core Platform & Infrastructure Setup

### 1. Laravel Installation & Configuration
- [x] Install Laravel 12 & PHP 8.3 environment
- [x] Configure `.env` file (Database, App URL, Timezone to Africa/Juba)
- [x] Install required dependencies:
  - [x] Laravel Breeze (Auth scaffolding)
  - [x] DomPDF (`barryvdh/laravel-dompdf`)
  - [x] RouterOS API Client (`mivodev/mikrotik-api-ros7`)
  - [x] ApexCharts (via CDN/npm)
  - [x] Heroicons (via Blade components or CDN)
- [x] Setup folder structure (Services, Actions, Repositories, Traits, Enums)
- [x] Create `HasUuid` trait for UUID support on public-facing models

### 2. Database Schema: Models & Migrations
- [x] Create migration & model for `sites`
- [x] Create migration & model for `routers` (encrypt password field)
- [x] Create migration & model for `packages`
- [x] Create migration & model for `vouchers`
- [x] Create migration & model for `voucher_batches`
- [x] Create migration & model for `customers`
- [x] Create migration & model for `payments`
- [x] Create migration & model for `hotspot_users`
- [x] Create migration & model for `currencies`
- [x] Create migration & model for `exchange_rates`
- [x] Create migration & model for `settings`
- [x] Create migration & model for `activity_logs`
- [x] Create migration & model for `router_logs`
- [x] Update `users` migration to include role_id, site_id, etc.

### 3. Authentication & Role Management
- [x] Run Laravel Breeze installation
- [x] Create `Role` and `Permission` models & migrations
- [x] Create middleware for `Admin`, `Operator`, `Manager`, `Viewer`
- [x] Register middleware aliases in bootstrap/app.php
- [ ] Setup database seeders (Super Admin, Default Currencies, Settings)

### 4. Layout & Landing Page
- [x] Create `layouts/app.blade.php` for the authenticated dashboard (Sidebar + Topbar)
- [x] Create `layouts/landing.blade.php` for the public site
- [x] Implement Vanilla CSS design system (Colors, Typography, Spacing, Cards)
- [x] Build Landing Page (`LandingController`):
- [x] Hero section
- [x] Features section
- [x] Pricing section
- [x] Contact section
- [x] Footer
- [x] Setup Dark Mode toggle script (Vanilla JS)

### 5. Core Modules Controllers & Views
- [x] **Dashboard Shell**:
- [x] `DashboardController` (DashboardService for stats)
- [x] `DashboardService` with stats aggregation methods
- [x] `dashboard/index.blade.php` with live stats cards, ApexCharts, and recent activity
- [x] **Site Management**:
- [x] `SiteController` (CRUD)
- [x] Form Requests (`StoreSiteRequest`, `UpdateSiteRequest`) for validation
- [x] `sites/index.blade.php`, `create.blade.php`, `edit.blade.php`
- [x] **Router Management**:
- [x] `RouterController` (CRUD)
- [x] Form Requests (`StoreRouterRequest`, `UpdateRouterRequest`) for validation
- [x] `routers/index.blade.php`, `create.blade.php`, `edit.blade.php`, `show.blade.php`
- [x] **Settings Module**:
- [x] `SettingController` (index, update)
- [x] `settings/index.blade.php` (Company Info, SMTP, PDF Branding)
- [x] **Routes** updated with all resource routes
- [x] **Sidebar links** updated with named routes for Dashboard, Routers, Sites, Settings

---

## Day 2: Billing & Voucher Engine

### 6. Currency Management
- [x] Create `CurrencyController`
- [x] Create `CurrencyService` (Centralized conversion logic with `convert()`, `format()`, `getBaseCurrency()`)
- [x] `currencies/index.blade.php` (Manage SSP, USD, Exchange Rates with inline rate editing, add/edit modals, converter tool)
- [x] Form Requests (`StoreCurrencyRequest`, `UpdateCurrencyRequest`)
- [x] Routes and sidebar navigation updated

### 7. Package Management
- [x] Create `PackageController` (CRUD)
- [x] Form Requests (`StorePackageRequest`, `UpdatePackageRequest`)
- [x] `packages/index.blade.php`, `create.blade.php`, `edit.blade.php`
- [x] Migration added for SSP/USD pricing, bandwidth limits, burst, profile fields
- [x] Routes and sidebar navigation updated

### 8. Voucher Management
- [x] Create `VoucherState` enum (Unused, Used, Expired, Cancelled with labels and colors)
- [x] Create `VoucherService` (Business logic for generating codes, passwords, batch generation, cancel/expire)
- [x] Create `VoucherController` (index with search/filter, create, store, show, cancel, expire, destroy)
- [x] Create `StoreVoucherRequest` (Validation for single & batch generation)
- [x] `vouchers/index.blade.php` (Search, Filter by State, Package, Router, Date range)
- [x] `vouchers/create.blade.php` (Single & Batch generation form with dynamic field toggling)
- [x] `vouchers/show.blade.php` (Voucher detail view with package info and actions)
- [x] Implement Voucher States (Unused, Used, Expired, Cancelled) with color-coded badges
- [x] Create `VoucherPdfService` (Generate single/batch PDFs with company branding)
- [x] Create `VoucherPdfController` (Export single PDF, batch PDF, preview)
- [x] `vouchers/pdf.blade.php` (Single voucher PDF template)
- [x] `vouchers/pdf-batch.blade.php` (Batch voucher PDF template)
- [x] Create `GenerateVoucherPdfJob` (Queue batch PDF generation)
- [x] Register routes (resource + custom cancel/expire/pdf routes)
- [x] Update sidebar navigation with active route detection

### 9. Customer & Payment Management
- [x] Create `CustomerController` (CRUD)
- [x] `customers/index.blade.php`, `create.blade.php`, `edit.blade.php`
- [x] Create `PaymentService` (Calculate SSP/USD, attach to voucher)
- [x] Create `PaymentController`
- [x] `payments/index.blade.php`, `create.blade.php` (Cash collection form)
- [x] `payments/show.blade.php` (Payment detail view with voucher info)
- [x] Form Requests: `StoreCustomerRequest`, `UpdateCustomerRequest`, `StorePaymentRequest`
- [x] Routes registered (resource + custom), sidebar links updated

---

## Day 3: MikroTik Integration & Monitoring

### 10. RouterOS API Integration
- [x] Create `RouterApiService` (Wrap all MikroTik communication)
  - [x] Connect/Authenticate to Router
  - [x] Fetch System Resources (CPU, Memory, Uptime, Version)
  - [x] Fetch Interfaces (Bandwidth)
  - [x] Fetch Active Hotspot Users
- [x] Create `RouterSyncController` & `RouterSyncService`
- [x] Implement `SyncRouterJob` and `CheckRouterStatusJob`
- [x] Update Router Details view (`routers/show.blade.php`) to show live data via AJAX/Vanilla JS
- [x] Register sync/test/live routes for AJAX endpoints
- [x] Add sync buttons to routers index with spinner feedback
- [x] Add scheduled commands in `routes/console.php` for periodic status checks and syncing

### 11. Hotspot Users Monitoring
- [x] Create `HotspotUserController`
- [x] Create `hotspot_users/index.blade.php` (Table with MAC, IP, Login Time, Data usage, filters, stats cards)
- [x] Create `SyncHotspotUsers` artisan command (`php artisan hotspot-users:sync`)
- [x] Register route and sidebar navigation link
- [x] Setup scheduled command to sync active hotspot users every 5 minutes

### 12. Basic Analytics & Dashboard Stats
- [x] Implement `DashboardService` to aggregate data
- [x] Populate Dashboard Cards (Today's Sales, Online Users, Connected Routers, Vouchers)
- [x] Integrate ApexCharts for:
- [x] Sales Chart (Daily/Monthly)
- [x] Top Packages Chart
- [x] Daily Active Users Chart

---

## Day 4: Polish, QA & Deployment

### 13. Advanced Analytics & Reports
- [x] Create `AnalyticsController` & `AnalyticsService` (Revenue Daily/Monthly, Package Sales, Router Usage, Peak Hours, Online Users Timeline, Bandwidth, Top Packages, Router Health, Voucher Usage)
- [x] `analytics/index.blade.php` (10 ApexCharts: Daily Revenue, Monthly Revenue, Package Sales Donut, Router Usage Bar, Peak Hours Heatmap, Online Users Area, Bandwidth Bar, Top Packages Bar, Router Health List, Voucher Pie)
- [x] Create `ReportController` & `ReportService` (Sales, Users, Routers, Packages, Voucher Usage reports with date filtering)
- [x] `reports/index.blade.php` (Tabbed interface with 5 report types, summary cards, and data tables)
- [x] Implement PDF Export using DomPDF (5 PDF templates)
- [x] Implement CSV Export with BOM for Excel compatibility
- [x] Registered routes: `/analytics`, `/reports`, `/reports/export-pdf`, `/reports/export-csv`

### 14. Notifications & Activity Logging
- [x] Setup Laravel Notifications (Database & Email channels)
- [x] Create `notifications` table migration
- [x] Create `NotificationController` (index, show, markAsRead, markAllAsRead, destroy, unreadCount, poll)
- [x] Create notification classes: `RouterOfflineNotification`, `VoucherLowStockNotification`, `DailySummaryNotification`
- [x] Create `NotificationService` (checkRouterStatus, checkVoucherStock, sendDailySummary, notifyAdmins)
- [x] Implement Triggers: Router Offline (via RouterSyncService), Voucher Low (hourly command), Daily Summary (daily at 8 AM)
- [x] Create `ActivityLogger` service (`log`, `created`, `updated`, `deleted`, `custom` static methods)
- [x] Create `ActivityLogController` (index with filters, show with detail view)
- [x] Create `notifications/index.blade.php` view (with type-based icons, mark as read, delete)
- [x] Create `activity-logs/index.blade.php` view (with action/user/date filters, action badges)
- [x] Create `activity-logs/show.blade.php` view (detailed activity info)
- [x] Create artisan commands: `vouchers:check-stock`, `notifications:daily-summary`
- [x] Create `DailySummaryJob` queued job
- [x] Update sidebar with Notifications (with unread count badge) and Activity Logs links
- [x] Add notification bell icon in topbar with live unread count badge
- [x] Add notification polling (every 30 seconds) via JavaScript
- [x] Register scheduled commands in `routes/console.php`
- [x] Register all notification and activity log routes in `routes/web.php`

### 15. UI/UX Polish & Mobile Responsiveness
- [x] Test and fix all views on mobile devices (Mobile-first adjustments)
- [x] Ensure modals, dropdowns, and tables work perfectly on small screens
- [x] Polish Vanilla CSS for premium look (Shadows, border radius, transitions)
- [x] Add loading spinners for long-running operations (Router sync, PDF gen)

### 16. Security & Deployment Prep
- [x] Implement Form Request validation across all POST/PUT routes (Created `UpdateSettingRequest`, verified all controllers use Form Requests or inline validation)
- [x] Setup Policies for Role-based authorization (9 Policies: Site, Router, Package, Voucher, Customer, Payment, Currency, Setting, User)
- [x] Apply Rate Limiting to auth routes (`throttle:auth` on login, register, forgot-password, reset-password; `throttle:global` generic limiter)
- [x] Verify CSRF tokens and XSS protection in Blade views (41 `@csrf` usages confirmed, no unescaped `{!! !!}` output found)
- [x] Configure `supervisor` config for Laravel Queues (`deploy/supervisor/laravel-worker.conf`)
- [x] Setup `nginx` config and PHP-FPM optimization (`deploy/nginx/turbofi.conf` + SSL variant with security headers, gzip, caching)
- [x] Applied role middleware to route groups (`admin` on Sites/Routers/Settings/Currencies, `manager` on Analytics/Reports, `operator` on Vouchers/Packages/Customers/Payments)
- [x] Registered policies and rate limiters in `AppServiceProvider::boot()`
- [ ] Final end-to-end testing with multiple MikroTik routers
- [ ] Push to Production VPS

```

### Architectural Notes Applied to this Checklist:
1. **Thin Controllers, Fat Services:** I've explicitly added `Services` to handle the complex logic (e.g., `VoucherService`, `RouterApiService`).
2. **UUIDs & Security:** I included a `HasUuid` trait task and ensuring router passwords are encrypted.
3. **Queues:** Batch PDF generations and Router syncing are scheduled to run via Queues/Jobs so the UI doesn't freeze.
4. **Validation & Authorization:** Added Form Requests and Policies to ensure robust security before deployment.