327 lines
16 KiB
PHP
327 lines
16 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once __DIR__ . "/sync_funding.php";
|
|
syncRepayments();
|
|
session_start();
|
|
|
|
$user_id = $_SESSION['user_id'] ?? null;
|
|
if (!$user_id) { header('Location: login.php'); exit; }
|
|
|
|
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$user = $stmt->fetch();
|
|
if (!$user) { header('Location: login.php'); exit; }
|
|
|
|
if ($user['role'] !== 'investor') { header('Location: dashboard.php'); exit; }
|
|
|
|
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
|
|
|
$stmt = db()->prepare("
|
|
SELECT i.*, s.name as startup_name, s.description as startup_desc
|
|
FROM investments i
|
|
JOIN startups s ON i.startup_id = s.id
|
|
WHERE i.investor_id = ?
|
|
ORDER BY i.created_at DESC
|
|
");
|
|
$stmt->execute([$user_id]);
|
|
$myInvestments = $stmt->fetchAll();
|
|
|
|
$totalInvested = 0;
|
|
foreach ($myInvestments as $inv) {
|
|
if ($inv['status'] === 'approved' || $inv['status'] === 'completed') {
|
|
$totalInvested += $inv['amount'];
|
|
}
|
|
}
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Investment Portfolio — <?= htmlspecialchars($platformName) ?></title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
.repayment-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, 1fr);
|
|
gap: 15px;
|
|
margin-top: 20px;
|
|
padding-top: 20px;
|
|
border-top: 1px solid rgba(255,255,255,0.05);
|
|
}
|
|
.repayment-item {
|
|
text-align: left;
|
|
}
|
|
.repayment-label {
|
|
font-size: 10px;
|
|
text-transform: uppercase;
|
|
color: var(--text-secondary);
|
|
font-weight: 700;
|
|
letter-spacing: 1px;
|
|
margin-bottom: 5px;
|
|
}
|
|
.repayment-value {
|
|
font-size: 14px;
|
|
font-weight: 800;
|
|
color: #fff;
|
|
}
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
z-index: 2000;
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0,0,0,0.85);
|
|
backdrop-filter: blur(8px);
|
|
}
|
|
.modal-content {
|
|
background-color: #1a1a24;
|
|
margin: 10% auto;
|
|
padding: 40px;
|
|
border: 1px solid var(--border-color);
|
|
width: 420px;
|
|
border-radius: 32px;
|
|
box-shadow: 0 25px 60px rgba(0,0,0,0.7);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<div class="container" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
|
|
<a href="dashboard.php" class="logo-container">
|
|
<img src="assets/images/logo.svg?v=<?php echo time(); ?>" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img">
|
|
<span class="logo-text"><?= htmlspecialchars($platformName) ?></span>
|
|
</a>
|
|
<nav class="nav-links">
|
|
<a href="funding_rounds.php">Founding Rounds</a>
|
|
<a href="portfolio.php" class="active">Portfolio</a>
|
|
<a href="discover.php">Discovery Hub</a>
|
|
<a href="messages.php">Messages</a>
|
|
</nav>
|
|
<div style="display: flex; align-items: center; gap: 15px;">
|
|
<div onclick="openWalletModal('add')" style="cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 5px 12px; background: rgba(0, 242, 255, 0.1); border-radius: 50px; border: 1px solid rgba(0, 242, 255, 0.2);">
|
|
<i class="fas fa-wallet" style="color: var(--accent-blue); font-size: 12px;"></i>
|
|
<span id="header-wallet-balance" style="font-size: 13px; font-weight: 800; color: #fff;">£<?= number_format($user['balance'], 2) ?></span>
|
|
</div>
|
|
<a href="notifications.php" style="color: var(--text-secondary); position: relative; font-size: 18px;">
|
|
<i class="fas fa-bell"></i>
|
|
</a>
|
|
<div style="display: flex; align-items: center; gap: 10px; padding: 5px 12px; background: rgba(255,255,255,0.05); border-radius: 50px; border: 1px solid var(--border-color);">
|
|
<div style="width: 24px; height: 24px; background: var(--gradient-primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; color: #fff; font-weight: 800;">
|
|
<?= substr($user['full_name'], 0, 1) ?>
|
|
</div>
|
|
<span style="font-size: 13px; font-weight: 600;"><?= htmlspecialchars(explode(' ', $user['full_name'])[0]) ?></span>
|
|
</div>
|
|
<a href="logout.php" class="btn btn-secondary" style="padding: 8px 16px; font-size: 12px; border-radius: 10px;">Log Out</a>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container" style="padding-top: 50px; padding-bottom: 50px;">
|
|
<div class="hero-bg">
|
|
<div class="hero-blob" style="top: 10%; right: -10%;"></div>
|
|
</div>
|
|
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;">
|
|
<div>
|
|
<h1>Investment Portfolio</h1>
|
|
<p style="color: var(--text-secondary);">Manage your stakes and track your repayments.</p>
|
|
</div>
|
|
<div class="card" style="padding: 20px 30px; display: flex; align-items: center; gap: 30px; border: 1px solid var(--border-color); background: var(--card-bg);">
|
|
<div>
|
|
<div style="font-size: 10px; text-transform: uppercase; color: var(--text-secondary); font-weight: 700; letter-spacing: 1px; margin-bottom: 5px;">Total Principal</div>
|
|
<div style="font-size: 28px; font-weight: 900; color: var(--accent-blue);">£<?= number_format($totalInvested, 0) ?></div>
|
|
</div>
|
|
<div style="width: 1px; height: 40px; background: var(--border-color);"></div>
|
|
<div>
|
|
<div style="font-size: 10px; text-transform: uppercase; color: var(--text-secondary); font-weight: 700; letter-spacing: 1px; margin-bottom: 5px;">Startups</div>
|
|
<div style="font-size: 28px; font-weight: 900; color: #fff;"><?= count($myInvestments) ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: 1fr; gap: 25px;">
|
|
<?php if (empty($myInvestments)): ?>
|
|
<div class="card" style="text-align: center; padding: 80px 20px; border: 1px dashed var(--border-color);">
|
|
<i class="fas fa-chart-line" style="font-size: 64px; color: var(--accent-blue); opacity: 0.2; margin-bottom: 30px;"></i>
|
|
<h3>No investments yet</h3>
|
|
<p style="color: var(--text-secondary);">Start your journey by backing the next generation of founders.</p>
|
|
<a href="discover.php" class="btn btn-primary" style="margin-top: 25px;">Go to Discovery Hub</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($myInvestments as $inv):
|
|
$interest = $inv['interest_rate'] ?? 0;
|
|
$totalReturn = $inv['total_return'] ?? ($inv['amount'] * (1 + $interest / 100));
|
|
$monthlyDiv = $inv['monthly_dividend'] ?? ($totalReturn / ($inv['repayment_term'] ?: 12));
|
|
$paid = $inv['paid_amount'] ?? 0;
|
|
$remainingAmount = $totalReturn - $paid;
|
|
$paymentsRemaining = $monthlyDiv > 0 ? ceil($remainingAmount / $monthlyDiv) : 0;
|
|
$status = ($inv['status'] === 'completed') ? 'Completed' : 'Active';
|
|
$statusColor = ($inv['status'] === 'completed') ? '#4cd964' : '#00f2ff';
|
|
if ($inv['status'] === 'pending') {
|
|
$status = 'Pending';
|
|
$statusColor = '#ffcc00';
|
|
} elseif ($inv['status'] === 'rejected') {
|
|
$status = 'Rejected';
|
|
$statusColor = '#ff3b30';
|
|
}
|
|
?>
|
|
<div class="card" style="padding: 30px; transition: all 0.3s; position: relative; overflow: hidden;">
|
|
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 25px;">
|
|
<div style="display: flex; align-items: center; gap: 20px;">
|
|
<div style="width: 50px; height: 50px; background: var(--gradient-primary); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: #fff; font-weight: 800;">
|
|
<?= substr($inv['startup_name'], 0, 1) ?>
|
|
</div>
|
|
<div>
|
|
<h3 style="margin: 0; font-size: 20px; font-weight: 800;"><?= htmlspecialchars($inv['startup_name']) ?></h3>
|
|
<div style="font-size: 12px; color: var(--text-secondary); margin-top: 4px;">
|
|
Invested on <?= date('M d, Y', strtotime($inv['created_at'])) ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div style="text-align: right;">
|
|
<div style="font-size: 10px; text-transform: uppercase; color: var(--text-secondary); font-weight: 700; letter-spacing: 1px; margin-bottom: 5px;">Status</div>
|
|
<div style="font-size: 12px; font-weight: 900; color: <?= $statusColor ?>; background: rgba(255,255,255,0.05); padding: 4px 12px; border-radius: 20px; border: 1px solid <?= $statusColor ?>33;">
|
|
<?= strtoupper($status) ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; background: rgba(255,255,255,0.02); padding: 20px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.05);">
|
|
<div>
|
|
<div class="repayment-label">Invested</div>
|
|
<div class="repayment-value">£<?= number_format($inv['amount'], 2) ?></div>
|
|
</div>
|
|
<div>
|
|
<div class="repayment-label">Interest Rate</div>
|
|
<div class="repayment-value"><?= number_format($interest, 1) ?>%</div>
|
|
</div>
|
|
<div>
|
|
<div class="repayment-label">Total Return</div>
|
|
<div class="repayment-value" style="color: var(--accent-blue);">£<?= number_format($totalReturn, 2) ?></div>
|
|
</div>
|
|
<div>
|
|
<div class="repayment-label">Monthly Div</div>
|
|
<div class="repayment-value" style="color: #4cd964;">£<?= number_format($monthlyDiv, 2) ?></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="repayment-grid">
|
|
<div class="repayment-item">
|
|
<div class="repayment-label">Term</div>
|
|
<div class="repayment-value"><?= $inv['repayment_term'] ?? 12 ?> Months</div>
|
|
</div>
|
|
<div class="repayment-item">
|
|
<div class="repayment-label">Remaining Payouts</div>
|
|
<div class="repayment-value"><?= $paymentsRemaining ?></div>
|
|
</div>
|
|
<div class="repayment-item">
|
|
<div class="repayment-label">Next Payment</div>
|
|
<div class="repayment-value"><?= $inv['next_payment_date'] ? date('M d, Y', strtotime($inv['next_payment_date'])) : 'N/A' ?></div>
|
|
</div>
|
|
<div class="repayment-item" style="text-align: right;">
|
|
<a href="startup_details.php?id=<?= $inv['startup_id'] ?>" style="color: var(--accent-blue); text-decoration: none; font-size: 13px; font-weight: 700;">View Profile <i class="fas fa-chevron-right" style="font-size: 10px; margin-left: 5px;"></i></a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Wallet Modal -->
|
|
<div id="wallet-modal" class="modal">
|
|
<div class="modal-content">
|
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px;">
|
|
<h2 id="modal-title" style="margin: 0; font-size: 24px; font-weight: 900; color: #fff;">Add Funds</h2>
|
|
<button onclick="closeWalletModal()" style="background: none; border: none; color: #999; cursor: pointer; font-size: 20px;"><i class="fas fa-times"></i></button>
|
|
</div>
|
|
<form id="wallet-form">
|
|
<input type="hidden" id="wallet-action" name="action" value="add">
|
|
<div style="margin-bottom: 25px;">
|
|
<label style="display: block; margin-bottom: 10px; font-size: 12px; color: #999; text-transform: uppercase; letter-spacing: 1px; font-weight: 700;">Amount (£)</label>
|
|
<input type="number" id="wallet-amount" name="amount" min="1" step="0.01" required placeholder="0.00"
|
|
style="width: 100%; padding: 18px; background: #000; border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; color: #fff; font-size: 24px; font-weight: 800;">
|
|
</div>
|
|
<button type="submit" id="wallet-submit-btn" class="btn btn-primary" style="width: 100%; padding: 18px; font-size: 16px; font-weight: 800; border-radius: 16px; background: var(--accent-blue); color: #000;">Confirm</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<footer style="margin-top: 80px; padding: 60px 0; border-top: 1px solid var(--border-color); background: rgba(0,0,0,0.2);">
|
|
<div class="container" style="text-align: center;">
|
|
<div class="logo-container" style="justify-content: center; margin-bottom: 25px;">
|
|
<img src="assets/images/logo.svg?v=<?php echo time(); ?>" alt="<?= htmlspecialchars($platformName) ?> Logo" class="logo-img" style="width: 30px; height: 30px;">
|
|
<span class="logo-text" style="font-size: 20px;"><?= htmlspecialchars($platformName) ?></span>
|
|
</div>
|
|
<p style="color: var(--text-secondary); font-size: 14px;">© <?= date('Y') ?> <?= htmlspecialchars($platformName) ?>. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script>
|
|
function openWalletModal(action) {
|
|
const modal = document.getElementById('wallet-modal');
|
|
const title = document.getElementById('modal-title');
|
|
const actionInput = document.getElementById('wallet-action');
|
|
const submitBtn = document.getElementById('wallet-submit-btn');
|
|
|
|
actionInput.value = action;
|
|
if (action === 'add') {
|
|
title.innerText = 'Add Funds';
|
|
submitBtn.innerText = 'Confirm Deposit';
|
|
submitBtn.style.background = 'var(--accent-blue)';
|
|
} else {
|
|
title.innerText = 'Withdraw Funds';
|
|
submitBtn.innerText = 'Confirm Withdrawal';
|
|
submitBtn.style.background = '#fff';
|
|
}
|
|
|
|
modal.style.display = 'block';
|
|
}
|
|
|
|
function closeWalletModal() {
|
|
document.getElementById('wallet-modal').style.display = 'none';
|
|
}
|
|
|
|
document.getElementById('wallet-form').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
const formData = new FormData(this);
|
|
|
|
fetch('api/wallet_transaction.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
const formattedBalance = '£' + parseFloat(data.new_balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
|
|
document.getElementById('header-wallet-balance').innerText = formattedBalance;
|
|
closeWalletModal();
|
|
alert(formData.get('action') === 'add' ? 'Funds added successfully!' : 'Withdrawal successful!');
|
|
} else {
|
|
alert('Error: ' + data.error);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
alert('An unexpected error occurred.');
|
|
});
|
|
});
|
|
|
|
window.onclick = function(event) {
|
|
const modal = document.getElementById('wallet-modal');
|
|
if (event.target == modal) {
|
|
closeWalletModal();
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|