T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/public_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/public_html/event_sales_earnings.php
<?php
session_start();
require_once 'config/database.php';
require_once 'includes/translations.php';

if (!isset($_SESSION['user_id'])) {
    header('Location: /auth/login.php');
    exit;
}

$event_id = isset($_GET['event_id']) ? (int)$_GET['event_id'] : 0;
if ($event_id <= 0) {
    header('Location: /events.php');
    exit;
}

$pdo = getDBConnection();
$user_id = $_SESSION['user_id'];

// Get event details and verify creator
$stmt = $pdo->prepare("
    SELECT 
        e.*,
        u.name as creator_name
    FROM events e
    JOIN users u ON e.creator_id = u.id
    WHERE e.id = ?
");
$stmt->execute([$event_id]);
$event = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$event) {
    header('Location: /events.php');
    exit;
}

// Verify user is the creator
if ($event['creator_id'] != $user_id) {
    header('Location: /events.php?event=' . $event_id . '&access=denied');
    exit;
}

// Get user's plan for pricing tier
$user_stmt = $pdo->prepare("SELECT plan FROM users WHERE id = ?");
$user_stmt->execute([$user_id]);
$user = $user_stmt->fetch(PDO::FETCH_ASSOC);
$user_plan = strtolower($user['plan'] ?? 'free');

// Load pricing configuration
require_once __DIR__ . '/config/event_pricing.php';
$pricing_tier = getEventPricingTier($user_plan);

// Get all ticket sales for this event
$sales_stmt = $pdo->prepare("
    SELECT 
        ets.*,
        et.ticket_code,
        et.status as ticket_status,
        et.purchase_date,
        et.price_paid,
        u.name as buyer_name,
        u.email as buyer_email
    FROM event_ticket_sales ets
    JOIN event_tickets et ON ets.ticket_id = et.id
    LEFT JOIN users u ON ets.buyer_id = u.id
    WHERE ets.event_id = ? AND ets.event_creator_id = ?
    ORDER BY ets.created_at DESC
");
$sales_stmt->execute([$event_id, $user_id]);
$all_sales = $sales_stmt->fetchAll(PDO::FETCH_ASSOC);

// Calculate totals using new pricing model
$total_tickets_sold = count($all_sales);
$total_revenue = 0;
$total_service_fees = 0;
$total_payment_processing_fees = 0;
$total_platform_fees = 0;
$total_creator_earnings = 0;
$is_free_event = ($event['ticket_price'] == 0 || $event['is_free'] == 1);

foreach ($all_sales as $sale) {
    $amount = (float)$sale['amount'];
    $total_revenue += $amount;
    
    // Calculate fees using new pricing model
    $fees = calculateEventTicketFees($amount, $user_plan, $is_free_event, false);
    
    $service_fee = $fees['service_fee'];
    $payment_processing_fee = $fees['payment_processing_fee'];
    $total_fee = $fees['total_fees'];
    $creator_earning = $fees['organizer_receives'];
    
    $total_service_fees += $service_fee;
    $total_payment_processing_fees += $payment_processing_fee;
    $total_platform_fees += $total_fee;
    $total_creator_earnings += $creator_earning;
}

// Get free tickets count
$free_tickets_stmt = $pdo->prepare("
    SELECT COUNT(*) as free_count
    FROM event_tickets
    WHERE event_id = ? AND (price_paid = 0 OR price_paid IS NULL)
");
$free_tickets_stmt->execute([$event_id]);
$free_tickets = $free_tickets_stmt->fetch(PDO::FETCH_ASSOC)['free_count'] ?? 0;

$page_title = t('events.sales_earnings.title') . ' - ' . htmlspecialchars($event['title']);
$current_page = 'events';

include 'includes/header.php';
?>

<style>
.sales-earnings-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
}

.sales-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 2rem;
    color: white;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.sales-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: white;
}

.sales-header .event-title {
    font-size: 1.2rem;
    opacity: 0.9;
    margin-bottom: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
}

.stat-card .stat-label {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: white;
}

.stat-card.earnings .stat-value {
    color: #48bb78;
}

.stat-card.fees .stat-value {
    color: #f56565;
}

.earnings-breakdown {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.breakdown-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: #1a202c;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.breakdown-item:last-child {
    border-bottom: none;
    font-weight: 700;
    font-size: 1.1rem;
    padding-top: 1.5rem;
    border-top: 2px solid #667eea;
    margin-top: 0.5rem;
}

.breakdown-label {
    color: #4a5568;
}

.breakdown-value {
    font-weight: 600;
    color: #1a202c;
}

.breakdown-item:last-child .breakdown-value {
    color: #48bb78;
    font-size: 1.3rem;
}

.sales-table-container {
    background: white;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.sales-table-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: #1a202c;
}

.sales-table {
    width: 100%;
    border-collapse: collapse;
}

.sales-table thead {
    background: #f7fafc;
    border-radius: 12px;
}

.sales-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: #4a5568;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.sales-table td {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    color: #2d3748;
}

.sales-table tbody tr:hover {
    background: #f7fafc;
}

.sales-table tbody tr:last-child td {
    border-bottom: none;
}

.ticket-code {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: #667eea;
    font-weight: 600;
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.status-confirmed {
    background: #c6f6d5;
    color: #22543d;
}

.status-used {
    background: #bee3f8;
    color: #2c5282;
}

.status-pending {
    background: #feebc8;
    color: #7c2d12;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #718096;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: #cbd5e0;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: #4a5568;
}

@media (max-width: 768px) {
    .sales-earnings-container {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .sales-table {
        font-size: 0.85rem;
    }
    
    .sales-table th,
    .sales-table td {
        padding: 0.75rem 0.5rem;
    }
}
</style>

<div class="sales-earnings-container">
    <div class="sales-header">
        <h1><i class="fas fa-chart-line"></i> <?= t('events.sales_earnings.title') ?></h1>
        <div class="event-title"><?= htmlspecialchars($event['title']) ?></div>
        
        <div class="stats-grid">
            <div class="stat-card">
                <div class="stat-label"><?= t('events.sales_earnings.tickets_sold') ?></div>
                <div class="stat-value"><?= number_format($total_tickets_sold) ?></div>
                <?php if ($free_tickets > 0): ?>
                    <div style="font-size: 0.85rem; opacity: 0.7; margin-top: 0.5rem;">
                        <?= $free_tickets ?> <?= t('events.sales_earnings.free_tickets') ?>
                    </div>
                <?php endif; ?>
            </div>
            
            <div class="stat-card">
                <div class="stat-label"><?= t('events.sales_earnings.total_revenue') ?></div>
                <div class="stat-value">$<?= number_format($total_revenue, 2) ?></div>
            </div>
            
                    <div class="stat-card fees">
                        <div class="stat-label"><?= t('events.sales_earnings.platform_fees') ?></div>
                        <div class="stat-value">$<?= number_format($total_platform_fees, 2) ?></div>
                        <div style="font-size: 0.85rem; opacity: 0.7; margin-top: 0.5rem;">
                            <?= $pricing_tier['service_fee_percentage'] ?>% + $<?= number_format($pricing_tier['fixed_fee_per_ticket'], 2) ?>
                        </div>
                        <div style="font-size: 0.75rem; opacity: 0.6; margin-top: 0.25rem;">
                            <?= $pricing_tier['name'] ?>
                        </div>
                    </div>
                    
                    <div class="stat-card earnings">
                        <div class="stat-label"><?= t('events.sales_earnings.your_earnings') ?></div>
                        <div class="stat-value">$<?= number_format($total_creator_earnings, 2) ?></div>
                        <div style="font-size: 0.85rem; opacity: 0.7; margin-top: 0.5rem;">
                            <?= $total_revenue > 0 ? number_format(($total_creator_earnings / $total_revenue) * 100, 1) : 0 ?>% <?= t('events.sales_earnings.of_revenue') ?>
                        </div>
                    </div>
        </div>
    </div>
    
    <div class="earnings-breakdown">
        <h2 class="breakdown-title"><?= t('events.sales_earnings.breakdown') ?></h2>
        <div class="breakdown-item">
            <span class="breakdown-label"><?= t('events.sales_earnings.total_sales') ?></span>
            <span class="breakdown-value">$<?= number_format($total_revenue, 2) ?></span>
        </div>
            <div class="breakdown-item">
                <span class="breakdown-label"><?= t('events.sales_earnings.service_fee') ?> (<?= $pricing_tier['service_fee_percentage'] ?>% + $<?= number_format($pricing_tier['fixed_fee_per_ticket'], 2) ?>)</span>
                <span class="breakdown-value">-$<?= number_format($total_service_fees, 2) ?></span>
            </div>
            <div class="breakdown-item">
                <span class="breakdown-label"><?= t('events.sales_earnings.payment_processing') ?> (<?= $pricing_tier['payment_processing_percentage'] ?>%)</span>
                <span class="breakdown-value">-$<?= number_format($total_payment_processing_fees, 2) ?></span>
            </div>
            <div class="breakdown-item" style="border-top: 1px solid #e2e8f0; padding-top: 1rem; margin-top: 0.5rem;">
                <span class="breakdown-label" style="font-weight: 600;"><?= t('events.sales_earnings.total_fees') ?></span>
                <span class="breakdown-value" style="font-weight: 700; color: #f56565;">-$<?= number_format($total_platform_fees, 2) ?></span>
            </div>
        <div class="breakdown-item">
            <span class="breakdown-label"><?= t('events.sales_earnings.net_earnings') ?></span>
            <span class="breakdown-value">$<?= number_format($total_creator_earnings, 2) ?></span>
        </div>
    </div>
    
    <div class="sales-table-container">
        <h2 class="sales-table-title"><?= t('events.sales_earnings.sales_details') ?></h2>
        
        <?php if (empty($all_sales)): ?>
            <div class="empty-state">
                <i class="fas fa-receipt"></i>
                <h3><?= t('events.sales_earnings.no_sales') ?></h3>
                <p><?= t('events.sales_earnings.no_sales_message') ?></p>
            </div>
        <?php else: ?>
            <table class="sales-table">
                <thead>
                    <tr>
                        <th><?= t('events.sales_earnings.date') ?></th>
                        <th><?= t('events.sales_earnings.ticket_code') ?></th>
                        <th><?= t('events.sales_earnings.buyer') ?></th>
                        <th><?= t('events.sales_earnings.amount') ?></th>
                        <th><?= t('events.sales_earnings.total_fees') ?></th>
                        <th><?= t('events.sales_earnings.earning') ?></th>
                        <th><?= t('events.sales_earnings.status') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($all_sales as $sale): 
                        $amount = (float)$sale['amount'];
                        $fees = calculateEventTicketFees($amount, $user_plan, $is_free_event, false);
                        $total_fee = $fees['total_fees'];
                        $creator_earning = $fees['organizer_receives'];
                        $purchase_date = $sale['purchase_date'] ?? $sale['created_at'];
                        $status = $sale['ticket_status'] ?? 'confirmed';
                    ?>
                    <tr>
                        <td><?= date('M j, Y g:i A', strtotime($purchase_date)) ?></td>
                        <td><span class="ticket-code"><?= htmlspecialchars($sale['ticket_code']) ?></span></td>
                        <td>
                            <?php if ($sale['buyer_name']): ?>
                                <?= htmlspecialchars($sale['buyer_name']) ?>
                            <?php else: ?>
                                <span style="color: #a0aec0;"><?= t('events.sales_earnings.anonymous') ?></span>
                            <?php endif; ?>
                        </td>
                        <td><strong>$<?= number_format($amount, 2) ?></strong></td>
                        <td style="color: #f56565;">-$<?= number_format($total_fee, 2) ?></td>
                        <td style="color: #48bb78;"><strong>$<?= number_format($creator_earning, 2) ?></strong></td>
                        <td>
                            <span class="status-badge status-<?= $status ?>">
                                <?= ucfirst($status) ?>
                            </span>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php endif; ?>
    </div>
</div>

<?php include 'includes/footer.php'; ?>


CasperSecurity Mini