# Optiqo Admin Panel — Build Report

## URL
`/ponir` — login at `http://localhost:8000/ponir/login`

## Credentials
- Email: `admin@optiqo.com`
- Password: `admin123456`

## Files Created

### Middleware
- `app/Http/Middleware/AdminAuth.php` — session-based admin gate; redirects to `/ponir/login` if not authenticated

### Controllers (`app/Http/Controllers/Admin/`)
| File | Responsibility |
|---|---|
| `AdminAuthController.php` | Login / logout using session |
| `AdminDashboardController.php` | Stats aggregation (users, trades, volume, house profit, pending actions) |
| `AdminUserController.php` | List + search users, show detail, adjust balance (add/subtract/set), update status |
| `AdminTradeController.php` | List + filter trades, force-cancel open trades with refund |
| `AdminDepositController.php` | List deposits, approve (credits real_balance), reject |
| `AdminWithdrawalController.php` | List withdrawals, approve, reject (refunds real_balance) |
| `AdminReportController.php` | 30-day daily revenue, top users, asset win/loss ratios, registration counts |
| `AdminSettingsController.php` | Read/write settings from `settings` table |

### Views (`resources/views/admin/`)
- `layout.blade.php` — dark sidebar layout with active link highlighting
- `login.blade.php` — standalone login page
- `dashboard.blade.php` — 8 stat cards, win/loss bar, recent users, recent trades
- `users/index.blade.php` — paginated user list with search + status filter
- `users/show.blade.php` — user detail, balance adjust form, status form, trade history
- `trades/index.blade.php` — trade list with status/asset/date filters, cancel button for open trades
- `deposits/index.blade.php` — deposit list with approve/reject buttons for pending
- `withdrawals/index.blade.php` — withdrawal list with approve/reject buttons
- `reports/index.blade.php` — 4 tables: daily revenue, registrations, top users, asset stats
- `settings/index.blade.php` — form for min/max trade, payout %, expiry range, maintenance mode toggle

### Model + Migration
- `app/Models/Setting.php` — key-value settings with `get()`/`set()` helpers
- `database/migrations/2024_01_07_000001_create_settings_table.php` — creates `settings` table with defaults

### Route changes
- `routes/web.php` — 19 admin routes under `/ponir` prefix
- `bootstrap/app.php` — added `admin.auth` middleware alias

## Key Design Decisions
- Uses existing `Deposit` and `Withdrawal` models (not separate `DepositRequest` tables)
- Trade `actual_profit` column used (not `profit`)
- Trade "open" = `status IN ('active','pending')`
- Deposit approve credits `real_balance`; withdrawal reject refunds `real_balance`
- Trade cancel refunds to the `account_type` balance of that trade
