MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/lohri/user/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/lohri/user/myimpact.php
<?php
// ========================================
// SESSION MANAGEMENT
// ========================================
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once "../config/db.php";
require_once "../config/config.php";

// ========================================
// AUTHENTICATION CHECK - Support both regular and vendor login
// ========================================
$user_id = null;

if (isset($_SESSION['user_id'])) {
    $user_id = $_SESSION['user_id'];
} elseif (isset($_SESSION['vendor_id'])) {
    $user_id = $_SESSION['vendor_id'];
} elseif (isset($_SESSION['vendor_logged_in']) && isset($_SESSION['user_data']['uid'])) {
    $user_id = $_SESSION['user_data']['uid'];
}

if (!$user_id) {
    header("Location: ../user/login.php");
    exit;
}

// ========================================
// FETCH USER DATA
// ========================================
$stmt = $con->prepare("SELECT u.* FROM tbl_user u WHERE u.uid = ?");

if (!$stmt) {
    die("Database error: " . $con->error);
}

$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
$stmt->close();

if (!$user) {
    session_destroy();
    header("Location: ../user/login.php");
    exit;
}

// Create full name
$user['name'] = trim(($user['fname'] ?? '') . ' ' . ($user['lname'] ?? ''));
if (empty($user['name'])) {
    $user['name'] = 'User';
}

// ========================================
// CALCULATE E-COMMERCE METRICS (From First File)
// ========================================

// 1. Total Earnings (Completed Orders Only)
$earnings_query = "
    SELECT COALESCE(SUM(oi.quantity * p.vendor_price), 0) as total_earnings
    FROM order_items oi
    INNER JOIN orders o ON oi.order_id = o.order_id
    INNER JOIN products p ON oi.product_id = p.pid
    WHERE p.user_id = ? AND o.payment_status = 'completed'
";

$earnings_stmt = $con->prepare($earnings_query);
if (!$earnings_stmt) {
    die("Database error: " . $con->error);
}

$earnings_stmt->bind_param("i", $user_id);
$earnings_stmt->execute();
$earnings_result = $earnings_stmt->get_result();
$earnings_data = $earnings_result->fetch_assoc();
$total_earnings = $earnings_data['total_earnings'];
$earnings_stmt->close();

// 2. Total Products Count
$total_products_query = "SELECT COUNT(*) as total_products FROM products WHERE user_id = ?";

$total_products_stmt = $con->prepare($total_products_query);
if (!$total_products_stmt) {
    die("Database error: " . $con->error);
}

$total_products_stmt->bind_param("i", $user_id);
$total_products_stmt->execute();
$total_products_result = $total_products_stmt->get_result();
$total_products_data = $total_products_result->fetch_assoc();
$total_products = $total_products_data['total_products'];
$total_products_stmt->close();

// 3. Ordered Products Count
$ordered_products_query = "
    SELECT COUNT(DISTINCT p.pid) as ordered_products
    FROM products p
    INNER JOIN order_items oi ON p.pid = oi.product_id
    WHERE p.user_id = ?
";

$ordered_products_stmt = $con->prepare($ordered_products_query);
if (!$ordered_products_stmt) {
    die("Database error: " . $con->error);
}

$ordered_products_stmt->bind_param("i", $user_id);
$ordered_products_stmt->execute();
$ordered_products_result = $ordered_products_stmt->get_result();
$ordered_products_data = $ordered_products_result->fetch_assoc();
$ordered_products = $ordered_products_data['ordered_products'];
$ordered_products_stmt->close();

// 4. Total Orders Count
$total_orders_query = "
    SELECT COUNT(DISTINCT o.order_id) as total_orders
    FROM orders o
    INNER JOIN order_items oi ON o.order_id = oi.order_id
    INNER JOIN products p ON oi.product_id = p.pid
    WHERE p.user_id = ?
";

$total_orders_stmt = $con->prepare($total_orders_query);
if (!$total_orders_stmt) {
    die("Database error: " . $con->error);
}

$total_orders_stmt->bind_param("i", $user_id);
$total_orders_stmt->execute();
$total_orders_result = $total_orders_stmt->get_result();
$total_orders_data = $total_orders_result->fetch_assoc();
$total_orders = $total_orders_data['total_orders'];
$total_orders_stmt->close();

// 5. Pending Earnings
$pending_earnings_query = "
    SELECT COALESCE(SUM(oi.quantity * p.vendor_price), 0) as pending_earnings
    FROM order_items oi
    INNER JOIN orders o ON oi.order_id = o.order_id
    INNER JOIN products p ON oi.product_id = p.pid
    WHERE p.user_id = ? AND o.payment_status = 'pending'
";

$pending_earnings_stmt = $con->prepare($pending_earnings_query);
if (!$pending_earnings_stmt) {
    die("Database error: " . $con->error);
}

$pending_earnings_stmt->bind_param("i", $user_id);
$pending_earnings_stmt->execute();
$pending_earnings_result = $pending_earnings_stmt->get_result();
$pending_earnings_data = $pending_earnings_result->fetch_assoc();
$pending_earnings = $pending_earnings_data['pending_earnings'];
$pending_earnings_stmt->close();

// 6. Days as Vendor
$days_as_vendor = 0;
if ($user) {
    $created_date = $user['created_at'] ?? $user['registration_date'] ?? $user['created'] ?? date('Y-m-d');
    $created_timestamp = strtotime($created_date);
    $current_timestamp = time();
    $days_as_vendor = floor(($current_timestamp - $created_timestamp) / (60 * 60 * 24));
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Impact - Vendor Dashboard</title>

    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <style>
    .breadcrumb-item.active{
        color:black;
        font-size: 16px;
    }
        :root {
            --primary-color: #000;
            --text-dark: #000000;
            --text-light: #666666;
            --border-color: #e0e0e0;
            --bg-light: #f8f9fa;
        }

        body {
            background-color: #ffffff;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            color: var(--text-dark);
        }

        .page-content {
            margin-bottom: 80px;
            padding: 60px 0 0px 40px;
        }

        /* Breadcrumb */
        .breadcrumb {
            background: transparent;
            padding: 0;
            margin: 0 0 30px 0;
        }

        .breadcrumb-item + .breadcrumb-item::before {
            content: "/";
            color: #6c757d;
        }

        .breadcrumb-item a {
            color: #6c757d;
            font-size: 12px;
            text-decoration: none;
        }

        .breadcrumb-item a:hover {
            color: #000;
        }

        /* Page Header */
        .impact-header {
            margin-bottom: 50px;
        }

        .impact-title {
           font-size: 27px;
    color: #000;
    font-weight: 500;
            margin-bottom: 10px;
        }

        .impact-subtitle {
            font-size: 16px;
            color: #666;
            margin-bottom: 0;
        }

        /* Impact Grid */
        .impact-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 50px;
            margin-bottom: 60px;
        }

        .impact-card {
            text-align: center;
            padding: 20px;
            transition: transform 0.3s ease;
        }

        .impact-card:hover {
            transform: translateY(-5px);
        }

        .impact-icon {
            width:50px;
 
            margin: 0 auto 30px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .impact-icon svg {
            width: 100%;
            height: 100%;
            stroke: #000;
            stroke-width: 1;
            fill: none;
            stroke-linecap: round;
            stroke-linejoin: round;
        }

        .impact-value {
            font-size: 36px;
            font-weight: 500;
            color: #000;
            margin-bottom: 8px;
            line-height: 1;
        }

        .impact-label {
            font-size: 16px;
            color: #000;
            font-weight: 400;
            margin-bottom: 4px;
        }

        .impact-sublabel {
            font-size: 14px;
            color: #666;
        }

        /* Responsive */
        @media (max-width: 768px) {
            
            .page-content {
                padding: 40px 0;
                margin-bottom: 0px;
            }

            .impact-title {
                font-size: 24px;
            }

            .impact-subtitle {
                font-size: 14px;
            }

            .impact-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 40px;
            }

            .impact-icon {
            width: 39px;
        height: 48px;
        margin-bottom: 11px;
    }
    .impact-value {
    font-size: 30px !important;
}
.impact-label {
    font-size: 16px !important;
}
.impact-grid{
    margin-bottom: 30px !important;
}

            }

            .impact-value {
                font-size: 36px;
            }

            .impact-label {
                font-size: 14px;
            }

            .impact-sublabel {
                font-size: 12px;
            }
        }

        @media (max-width: 400px) {
            .impact-grid {
                grid-template-columns: 1fr;
                gap: 30px;
            }

            .impact-title {
                font-size: 24px !important;
            }

            .impact-value {
                font-size: 32px;
            }
        }
        @media(max-width:768px){
    .impact-grid{
        display:flex !important;
        flex-wrap:wrap !important;
        gap:20px !important;
        grid-template-columns:unset !important;
    }
    .impact-card{
        width:calc(50% - 10px);
    }
}

    </style>
</head>
<body>

<?php include "../ui/nav.php"; ?>

<div class="page-content">
    <div class="container">

        <!-- Breadcrumb -->
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                <li class="breadcrumb-item"><a href="account.php">Account</a></li>
                <li class="breadcrumb-item active" aria-current="page">My Impact</li>
            </ol>
        </nav>

        <!-- Page Header -->
        <div class="impact-header">
            <h1 class="impact-title">My impact</h1>
            <p class="impact-subtitle">Your selling performance overview</p>
        </div>

        <!-- Impact Grid - E-commerce Metrics -->
        <div class="impact-grid">
            
            <!-- Total Earnings -->
            <div class="impact-card">
                <div class="impact-icon">
                    <svg viewBox="0 0 24 24">
                        <circle cx="12" cy="12" r="10"></circle>
                        <path d="M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8"></path>
                        <path d="M12 18V6"></path>
                    </svg>
                </div>
                <div class="impact-value">₹<?= number_format($total_earnings, 0) ?></div>
                <div class="impact-label">Total Earnings</div>
                <div class="impact-sublabel">from completed orders</div>
            </div>

            <!-- Total Products -->
            <div class="impact-card">
                <div class="impact-icon">
                    <svg viewBox="0 0 24 24">
                        <path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path>
                        <polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
                        <line x1="12" y1="22.08" x2="12" y2="12"></line>
                    </svg>
                </div>
                <div class="impact-value"><?= $total_products ?></div>
                <div class="impact-label">Products Listed</div>
                <div class="impact-sublabel">total inventory</div>
            </div>

            <!-- Total Orders -->
            <div class="impact-card">
                <div class="impact-icon">
                    <svg viewBox="0 0 24 24">
                        <path d="M6 2L3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4z"></path>
                        <line x1="3" y1="6" x2="21" y2="6"></line>
                        <path d="M16 10a4 4 0 0 1-8 0"></path>
                    </svg>
                </div>
                <div class="impact-value"><?= $total_orders ?></div>
                <div class="impact-label">Orders Received</div>
                <div class="impact-sublabel">total orders</div>
            </div>

            <!-- Ordered Products -->
            <div class="impact-card">
                <div class="impact-icon">
                    <svg viewBox="0 0 24 24">
                        <polyline points="9 11 12 14 22 4"></polyline>
                        <path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"></path>
                    </svg>
                </div>
                <div class="impact-value"><?= $ordered_products ?></div>
                <div class="impact-label">Products Sold</div>
                <div class="impact-sublabel">unique items sold</div>
            </div>

            <!-- Pending Earnings -->
            <div class="impact-card">
                <div class="impact-icon">
                    <svg viewBox="0 0 24 24">
                        <circle cx="12" cy="12" r="10"></circle>
                        <polyline points="12 6 12 12 16 14"></polyline>
                    </svg>
                </div>
                <div class="impact-value">₹<?= number_format($pending_earnings, 0) ?></div>
                <div class="impact-label">Pending Earnings</div>
                <div class="impact-sublabel">awaiting completion</div>
            </div>

            <!-- Days as Vendor -->
            <div class="impact-card">
                <div class="impact-icon">
                    <svg viewBox="0 0 24 24">
                        <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
                        <line x1="16" y1="2" x2="16" y2="6"></line>
                        <line x1="8" y1="2" x2="8" y2="6"></line>
                        <line x1="3" y1="10" x2="21" y2="10"></line>
                    </svg>
                </div>
                <div class="impact-value"><?= $days_as_vendor ?></div>
                <div class="impact-label">Days</div>
                <div class="impact-sublabel">as vendor</div>
            </div>

        </div>

    </div>
</div>

<?php include "../ui/footer.php"; ?>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

</body>
</html>

MMCT - 2023