|
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 ] |
|---|
<?php
session_start();
include "../config/config.php";
include "../config/db.php";
// Require login
if (empty($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$user_id = (int)$_SESSION['user_id'];
// Fetch user info
$user = null;
$stmt = $con->prepare("SELECT * FROM tbl_user WHERE uid = ?");
if ($stmt) {
$stmt->bind_param("i", $user_id);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
}
// ========================================
// CALCULATE VENDOR STATISTICS
// ========================================
// 1. Total Earnings (Completed Orders Only)
$total_earnings = 0;
$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) {
$earnings_stmt->bind_param("i", $user_id);
$earnings_stmt->execute();
$result = $earnings_stmt->get_result();
$data = $result->fetch_assoc();
$total_earnings = $data['total_earnings'];
$earnings_stmt->close();
}
// 2. Total Products Count
$total_products = 0;
$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) {
$total_products_stmt->bind_param("i", $user_id);
$total_products_stmt->execute();
$result = $total_products_stmt->get_result();
$data = $result->fetch_assoc();
$total_products = $data['total_products'];
$total_products_stmt->close();
}
// 3. Ordered Products Count
$ordered_products = 0;
$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) {
$ordered_products_stmt->bind_param("i", $user_id);
$ordered_products_stmt->execute();
$result = $ordered_products_stmt->get_result();
$data = $result->fetch_assoc();
$ordered_products = $data['ordered_products'];
$ordered_products_stmt->close();
}
// 4. Unordered Products Count
$unordered_products = $total_products - $ordered_products;
// 5. Total Orders Count
$total_orders = 0;
$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) {
$total_orders_stmt->bind_param("i", $user_id);
$total_orders_stmt->execute();
$result = $total_orders_stmt->get_result();
$data = $result->fetch_assoc();
$total_orders = $data['total_orders'];
$total_orders_stmt->close();
}
// 6. Pending Earnings (Orders not yet completed)
$pending_earnings = 0;
$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) {
$pending_earnings_stmt->bind_param("i", $user_id);
$pending_earnings_stmt->execute();
$result = $pending_earnings_stmt->get_result();
$data = $result->fetch_assoc();
$pending_earnings = $data['pending_earnings'];
$pending_earnings_stmt->close();
}
// 7. Withdrawal History
$withdrawal_history = [];
$history_query = "SELECT * FROM withdrawal_requests WHERE user_id = ? ORDER BY request_date DESC LIMIT 5";
$history_stmt = $con->prepare($history_query);
if ($history_stmt) {
$history_stmt->bind_param("i", $user_id);
$history_stmt->execute();
$withdrawal_history = $history_stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$history_stmt->close();
}
// 8. Calculate success rate
$success_rate = $total_products > 0 ? round(($ordered_products / $total_products) * 100, 1) : 0;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Statistics - TDS Marketplace</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="../css/style.css" rel="stylesheet"/>
<link href="css/style.css" rel="stylesheet"/>
<style>
@media (min-width: 1200px) and (max-width: 1599px) {
.insta-highlight-section{
padding: 40px 20px 150px !important;
}
}
body {
background: #ffffff;
color: #000;
}
.stat-boxes{
margin-bottom: 0px !important;
}
.page-header {
background: #ffffff;
border-bottom: 1px solid #e0e0e0;
padding: 40px 0;
margin-bottom: 40px;
}
.page-title {
font-size: 27px;
font-weight: 500;
color: #000;
}
.breadcrumb {
background: transparent;
padding: 0;
margin-bottom: 20px;
}
.breadcrumb-item a {
color: #6c757d;
text-decoration: none;
}
.breadcrumb-item.active {
color: #000;
}
.stats-section {
background: #ffffff;
border: 1px solid #e0e0e0;
border-radius: 12px;
padding: 40px;
margin-bottom: 40px;
}
.stats-section h3 {
font-size: 22px;
font-weight: 500;
margin-bottom: 30px;
color: #000;
}
.stat-boxes {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 40px;
}
.stat-box {
border: 1px solid #e0e0e0;
border-radius: 8px;
padding: 20px;
flex: 1;
min-width: 200px;
transition: all 0.3s;
}
.stat-box:hover {
border-color: #000;
transform: translateY(-2px);
}
.stat-box-value {
font-size: 28px;
font-weight: 600;
margin-bottom: 8px;
color: #000;
}
.stat-box-label {
font-size: 13px;
color: #6c757d;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.stat-box i {
font-size: 20px;
margin-right: 8px;
}
.badge {
/*padding: 6px 12px;*/
border-radius: 6px;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
}
.badge-success {
background: #d4edda;
color: #155724;
}
.badge-warning {
background: #fff3cd;
color: #856404;
}
.badge-danger {
background: #f8d7da;
color: #721c24;
}
/* Update the mobile media query section in your style tag */
@media (max-width: 768px) {
.stat-boxes {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
}
/* Withdrawal history section - full width boxes */
.stats-section:first-child .stat-boxes {
grid-template-columns: 1fr;
}
.stat-box {
min-width: unset;
padding: 15px;
}
.stats-section {
padding: 15px;
}
.d-sm-flexx{
display: flex;
flex-direction: column;
gap: 10px;
}
.btn {
padding: 13px 15px !important;
}
.stat-box-value{
font-size: 20px !important;
font-weight: 500 !important;
}
.stat-box-label {
font-size: 11px;
}
}
/* For very small screens (optional - if you want single column on very small devices) */
@media (max-width: 480px) {
.stat-boxes {
grid-template-columns: repeat(2, 1fr);
gap: 10px;
margin-bottom: 10px !important;
}
.stat-box {
padding: 12px;
}
.stat-box-value {
font-size: 18px !important;
}
.stat-box-label {
font-size: 10px;
}
.ml-sm-00{
margin-left:0px !important;
}
}
</style>
</head>
<body>
<?php include "../ui/nav.php"; ?>
<div class="page-header">
<div class="container">
<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">My Statistics</li>
</ol>
</nav>
<h1 class="page-title">My Statistics</h1>
</div>
</div>
<div class="container mb-5 pb-5">
<!-- Withdrawal History Section -->
<div class="stats-section">
<h3><i class="fas fa-history me-2"></i>Withdrawal History</h3>
<div class="stat-boxes">
<?php if (!empty($withdrawal_history)): ?>
<?php foreach ($withdrawal_history as $withdrawal): ?>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-rupee-sign"></i>
₹<?= number_format($withdrawal['amount'], 2) ?>
</div>
<div class="stat-box-label">
<?php
if ($withdrawal['status'] === 'pending') {
echo '<span class="badge badge-warning">Pending</span>';
} elseif ($withdrawal['status'] === 'paid') {
echo '<span class="badge badge-success">Paid on ' . date('M d, Y', strtotime($withdrawal['processed_date'])) . '</span>';
} else {
echo '<span class="badge badge-danger">Rejected</span>';
}
?>
</div>
<small class="text-muted d-block mt-2">
Requested: <?= date('M d, Y', strtotime($withdrawal['request_date'])) ?>
</small>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="stat-box">
<div class="stat-box-label">No withdrawal history yet</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Financial Metrics Section -->
<div class="stats-section">
<h3><i class="fas fa-chart-line me-2"></i>Financial Metrics</h3>
<div class="stat-boxes">
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-rupee-sign text-success"></i>
₹<?= number_format($total_earnings, 2) ?>
</div>
<div class="stat-box-label">Total Earnings (Paid)</div>
</div>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-shopping-cart text-primary"></i>
<?= $total_orders ?>
</div>
<div class="stat-box-label">Total Orders</div>
</div>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-box text-info"></i>
<?= $total_products ?>
</div>
<div class="stat-box-label">Total Products</div>
</div>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-clock text-warning"></i>
₹<?= number_format($pending_earnings, 2) ?>
</div>
<div class="stat-box-label">Pending Earnings</div>
</div>
</div>
</div>
<!-- Product Performance Section -->
<div class="stats-section">
<h3><i class="fas fa-chart-bar me-2"></i>Product Performance</h3>
<div class="stat-boxes">
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-check-circle text-success"></i>
<?= $ordered_products ?>
</div>
<div class="stat-box-label">Ordered Products</div>
</div>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-times-circle text-danger"></i>
<?= $unordered_products ?>
</div>
<div class="stat-box-label">Unordered Products</div>
</div>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-percentage text-primary"></i>
<?= $success_rate ?>%
</div>
<div class="stat-box-label">Product Order Rate</div>
</div>
<div class="stat-box">
<div class="stat-box-value">
<i class="fas fa-chart-pie text-info"></i>
<?php
$avg_order_value = $total_orders > 0 ? $total_earnings / $total_orders : 0;
echo '₹' . number_format($avg_order_value, 0);
?>
</div>
<div class="stat-box-label">Average Order Value</div>
</div>
</div>
</div>
<!-- Quick Actions -->
<div class="text-center mt-5 d-sm-flexx">
<a href="add-product.php" class="btn btn-dark btn-lg" >
<i class="fas fa-plus me-2"></i>Add New Product
</a>
<a href="my-products.php" class="btn btn-outline-dark btn-lg ml-sm-00" style="margin-left:20px">
<i class="fas fa-box me-2"></i>View All Products
</a>
</div>
</div>
<?php include "../ui/footer.php"; ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</body>
</html>