set_charset('utf8mb4'); function h($value): string { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } function money($value): string { return number_format((float)$value, 2, '.', ','); } function tableExists(mysqli $db, string $table): bool { $safe = $db->real_escape_string($table); $res = $db->query("SHOW TABLES LIKE '{$safe}'"); return $res && $res->num_rows > 0; } if (!tableExists($conn, 'saas_pending_commissions')) { http_response_code(500); exit('Table saas_pending_commissions does not exist. Run the updated bootstrap/schema first.'); } $status = isset($_GET['status']) ? strtolower(trim((string)$_GET['status'])) : 'pending'; if (!in_array($status, ['pending', 'credited', 'all'], true)) $status = 'pending'; $agentId = isset($_GET['agent_id']) ? (int)$_GET['agent_id'] : 0; $from = isset($_GET['from']) ? trim((string)$_GET['from']) : ''; $to = isset($_GET['to']) ? trim((string)$_GET['to']) : ''; $where = []; $params = []; $types = ''; if ($status !== 'all') { $where[] = 'p.status = ?'; $params[] = $status; $types .= 's'; } if ($agentId > 0) { $where[] = 'p.sponsor_id = ?'; $params[] = $agentId; $types .= 'i'; } if ($from !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $from)) { $where[] = 'DATE(p.created_at) >= ?'; $params[] = $from; $types .= 's'; } if ($to !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $to)) { $where[] = 'DATE(p.created_at) <= ?'; $params[] = $to; $types .= 's'; } $whereSql = $where ? ('WHERE ' . implode(' AND ', $where)) : ''; function fetchRows(mysqli $db, string $sql, string $types, array $params): array { $stmt = $db->prepare($sql); if (!$stmt) throw new RuntimeException('SQL prepare failed: ' . $db->error); if ($types !== '') $stmt->bind_param($types, ...$params); if (!$stmt->execute()) throw new RuntimeException('SQL execute failed: ' . $stmt->error); $result = $stmt->get_result(); $rows = $result ? $result->fetch_all(MYSQLI_ASSOC) : []; $stmt->close(); return $rows; } $error = ''; $rows = []; $summary = ['amount' => 0, 'entries' => 0, 'agents' => 0]; try { $rows = fetchRows( $conn, "SELECT p.id, p.sponsor_id, p.bettor_id, p.level_no, p.commission_amount, p.turnover, p.due_at, p.status, p.created_at, p.credited_at FROM saas_pending_commissions p {$whereSql} ORDER BY CASE WHEN p.status='pending' THEN 0 ELSE 1 END, p.due_at ASC, p.id DESC LIMIT 2000", $types, $params ); $agentSet = []; foreach ($rows as $r) { $summary['amount'] += (float)$r['commission_amount']; $summary['entries']++; $agentSet[(string)$r['sponsor_id']] = true; } $summary['agents'] = count($agentSet); } catch (Throwable $e) { $error = $e->getMessage(); } $pendingTotals = ['amount' => 0.0, 'entries' => 0, 'agents' => 0]; try { $totals = fetchRows( $conn, "SELECT COUNT(*) AS entries, COALESCE(SUM(commission_amount),0) AS amount, COUNT(DISTINCT sponsor_id) AS agents FROM saas_pending_commissions WHERE status='pending'", '', [] ); if ($totals) { $pendingTotals['amount'] = (float)$totals[0]['amount']; $pendingTotals['entries'] = (int)$totals[0]['entries']; $pendingTotals['agents'] = (int)$totals[0]['agents']; } } catch (Throwable $e) { if ($error === '') $error = $e->getMessage(); } $now = time(); ?>
| Agent ID | Bettor ID | Level | Bet Turnover | Commission | Created At | Credit Due (IST) | Time Left | Status | Credited At |
|---|---|---|---|---|---|---|---|---|---|
| No commission records found for this filter. | |||||||||
| = h($r['sponsor_id']) ?> | = h($r['bettor_id']) ?> | L= h($r['level_no']) ?> | ₹= money($r['turnover']) ?> | ₹= money($r['commission_amount']) ?> | = h($r['created_at']) ?> | = h($r['due_at']) ?> | Calculating… Credited Due time unavailable | = h(ucfirst((string)$r['status'])) ?> | = $r['credited_at'] ? h($r['credited_at']) : '—' ?> |
Showing up to 2,000 records. Countdown updates every second; data refreshes when you reload the page. Wallet credit is handled only by the settlement cron, not from this dashboard.