prepare("SELECT type, amount, symbol, status, created_at, 'finance' as source, NULL as direction, NULL as pnl FROM transactions WHERE user_id = ? UNION ALL SELECT 'binary' as type, amount, symbol, status, created_at, 'trading' as source, direction, (CASE WHEN status='won' THEN (amount * profit_rate / 100) WHEN status='lost' THEN -amount ELSE 0 END) as pnl FROM binary_orders WHERE user_id = ? UNION ALL SELECT 'contract' as type, amount, symbol, status, created_at, 'trading' as source, direction, profit as pnl FROM contract_orders WHERE user_id = ? ORDER BY created_at DESC LIMIT 100"); $stmt->execute([$user['id'], $user['id'], $user['id']]); $records = $stmt->fetchAll(); } else { if ($tab === 'binary') { $stmt = $db->prepare("SELECT 'binary' as type, amount, symbol, status, created_at, 'trading' as source, direction, (CASE WHEN status='won' THEN (amount * profit_rate / 100) WHEN status='lost' THEN -amount ELSE 0 END) as pnl FROM binary_orders WHERE user_id = ? ORDER BY created_at DESC LIMIT 100"); $stmt->execute([$user['id']]); } elseif ($tab === 'contract') { $stmt = $db->prepare("SELECT 'contract' as type, amount, symbol, status, created_at, 'trading' as source, direction, profit as pnl FROM contract_orders WHERE user_id = ? ORDER BY created_at DESC LIMIT 100"); $stmt->execute([$user['id']]); } elseif ($tab === 'spot') { $stmt = $db->prepare("SELECT 'spot' as type, amount, symbol, status, created_at, 'trading' as source, side as direction, 0 as pnl FROM spot_orders WHERE user_id = ? ORDER BY created_at DESC LIMIT 100"); $stmt->execute([$user['id']]); } else { $stmt = $db->prepare("SELECT *, 'finance' as source, NULL as direction, NULL as pnl FROM transactions WHERE user_id = ? AND type LIKE ? ORDER BY created_at DESC LIMIT 100"); $stmt->execute([$user['id'], $tab . '%']); } $records = $stmt->fetchAll(); } $types_map = [ 'recharge' => ['name' => __('recharge'), 'color' => 'success'], 'withdrawal' => ['name' => __('withdrawal'), 'color' => 'danger'], 'binary' => ['name' => __('sec_contract'), 'color' => 'primary'], 'contract' => ['name' => __('contract'), 'color' => 'warning'], 'spot' => ['name' => __('spot'), 'color' => 'info'], 'binary_win' => ['name' => __('binary_win'), 'color' => 'success'], 'binary_loss' => ['name' => __('binary_loss'), 'color' => 'danger'], ]; ?>

__($typeKey), 'color' => 'secondary']; $pnl = (float)($r['pnl'] ?? 0); ?>
/
= 0 ? '+' : '' ?>
--