+
-
Ready to share your vision with the world?
-
Start Your First Round
+
No startups registered
+
Ready to change the world? Start by registering your venture.
+
Get Started
-
-
-
-
-
- = substr($startup['name'], 0, 1) ?>
-
-
-
- = htmlspecialchars($startup['name']) ?>
-
- Trending
-
-
-
-
- = strtoupper($startup['round_status'] ?? 'Draft') ?>
-
- Target: £= number_get_formatted($goal) ?>
-
-
-
-
-
-
£= number_get_formatted($raised) ?>
-
Funds Raised
-
-
-
-
-
-
-
+
+
+
+
+
+
+ = strtoupper($startup['status']) ?>
+
-
-
+
= htmlspecialchars($startup['name']) ?>
+
= htmlspecialchars($startup['description']) ?>
+
+ 0): ?>
+
+
+ Active Funding Round
+ = round(($startup['active_raised'] / $startup['active_goal']) * 100) ?>%
+
+
+
+ £= number_get_formatted($startup['active_raised']) ?>
+ Target: £= number_get_formatted($startup['active_goal']) ?>
+
+
+
+
Start Funding Round
+
+
+
@@ -313,6 +269,29 @@ function number_get_formatted($num) {
Withdraw
+
+
+
+
Recent Transactions
+
+
No transactions yet.
+
+
+
+
+
+
= htmlspecialchars($tx['description']) ?>
+
= date('M d, H:i', strtotime($tx['created_at'])) ?>
+
+
+ = in_array($tx['type'], ['add', 'investment_in']) ? '+' : '-' ?>£= number_format($tx['amount'], 2) ?>
+
+
+
+
+
+
+
Manage your startup capital and dividend funds.
@@ -330,11 +309,11 @@ function number_get_formatted($num) {
- = substr($user['full_name'], 0, 1) ?>
+ = substr($user['full_name'] ?? 'U', 0, 1) ?>
-
= htmlspecialchars($user['full_name']) ?>
-
= htmlspecialchars($user['university']) ?>
+
= htmlspecialchars($user['full_name'] ?? 'User') ?>
+
= htmlspecialchars($user['university'] ?? 'Student') ?>
@@ -423,8 +402,9 @@ document.getElementById('wallet-form').addEventListener('submit', function(e) {
.then(data => {
if (data.success) {
document.getElementById('wallet-balance').innerText = '£' + parseFloat(data.new_balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
+ document.getElementById('header-wallet-balance').innerText = '£' + parseFloat(data.new_balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
closeWalletModal();
- alert(formData.get('action') === 'add' ? 'Funds added successfully!' : 'Withdrawal successful!');
+ location.reload(); // Reload to show new transaction
} else {
alert('Error: ' + data.error);
}
diff --git a/db/migrations/20_wallet_transactions.sql b/db/migrations/20_wallet_transactions.sql
new file mode 100644
index 0000000..152d6c0
--- /dev/null
+++ b/db/migrations/20_wallet_transactions.sql
@@ -0,0 +1,9 @@
+CREATE TABLE IF NOT EXISTS wallet_transactions (
+ id INT AUTO_INCREMENT PRIMARY KEY,
+ user_id INT NOT NULL,
+ amount DECIMAL(15,2) NOT NULL,
+ type ENUM('add', 'withdraw', 'investment_out', 'investment_in') NOT NULL,
+ description VARCHAR(255),
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+);
diff --git a/invest.php b/invest.php
index 2168d9f..1e83e6f 100644
--- a/invest.php
+++ b/invest.php
@@ -30,6 +30,8 @@ if ($startup['round_status'] !== 'Active') {
die("This startup does not have an active funding round.");
}
+$remaining = (float)($startup['funding_goal'] - $startup['funding_raised']);
+
$error = '';
$success = '';
@@ -45,7 +47,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($amount <= 0) {
$error = "Please enter a valid investment amount.";
} elseif ($amount > $investor_balance) {
- $error = "Insufficient funds in your money pot. Please add funds first.";
+ $error = "Insufficient funds in your money pot. Please add funds first. You currently have £" . number_format($investor_balance, 2) . ".";
+ } elseif ($amount > $remaining && $remaining > 0) {
+ $error = "The investment amount (£" . number_format($amount) . ") exceeds the remaining funding goal of £" . number_format($remaining) . ".";
} else {
db()->beginTransaction();
try {
@@ -72,6 +76,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt = db()->prepare("UPDATE users SET balance = balance + ? WHERE id = ?");
$stmt->execute([$amount, $startup['founder_id']]);
+ // 5. Log transactions
+ $stmt = db()->prepare("INSERT INTO wallet_transactions (user_id, amount, type, description) VALUES (?, ?, 'investment_out', ?)");
+ $stmt->execute([$investor_id, $amount, "Investment in " . $startup['name']]);
+
+ $stmt = db()->prepare("INSERT INTO wallet_transactions (user_id, amount, type, description) VALUES (?, ?, 'investment_in', ?)");
+ $stmt->execute([$startup['founder_id'], $amount, "Investment received from investor for " . $startup['name']]);
+
db()->commit();
$success = "Investment of £" . number_format($amount) . " confirmed successfully! Funds moved to the founder's pot.";
header("refresh:3;url=portfolio.php");
@@ -130,9 +141,6 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
Already Raised
£= number_format($startup['funding_raised']) ?>
Remaining
£= number_format(max(0, $remaining)) ?>
diff --git a/startup_details.php b/startup_details.php
index 24c87a9..03f26e9 100644
--- a/startup_details.php
+++ b/startup_details.php
@@ -1,26 +1,29 @@
prepare("SELECT * FROM users WHERE id = ?");
-$stmt->execute([$user_id]);
-$user = $stmt->fetch();
+require_once __DIR__ . '/db/config.php';
$startupId = $_GET['id'] ?? null;
if (!$startupId) {
- header('Location: startups.php');
+ header("Location: startups.php");
exit;
}
+// Fetch user data
+$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
+$stmt->execute([$_SESSION['user_id']]);
+$user = $stmt->fetch();
+
+// Fetch startup data
$stmt = db()->prepare("
- SELECT s.*, fr.id as round_id, fr.funding_goal as active_goal, fr.funding_raised as active_raised, fr.status as round_status
- FROM startups s
+ SELECT s.*, u.full_name as founder_name, u.university as founder_university, u.bio as founder_bio, u.skills as founder_skills, u.profile_image as founder_image,
+ fr.funding_goal, fr.funding_raised as current_round_raised, fr.status as round_status, fr.id as round_id
+ FROM startups s
+ JOIN users u ON s.founder_id = u.id
LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active'
WHERE s.id = ?
");
@@ -31,341 +34,163 @@ if (!$startup) {
die("Startup not found.");
}
-// Check if user is the founder or an investor
-$isFounder = ($_SESSION['user_id'] == $startup['founder_id']);
-$isInvestor = ($user['role'] == 'investor');
+$isFounder = ($startup['founder_id'] == $_SESSION['user_id']);
-// Basic permissions check
-if (!$isFounder && $startup['status'] === 'private' && !$isInvestor) {
- die("You do not have permission to view this profile.");
-}
+// Fetch followers count
+$stmt = db()->prepare("SELECT COUNT(*) FROM startup_followers WHERE startup_id = ?");
+$stmt->execute([$startupId]);
+$followersCount = $stmt->fetchColumn();
-// Fetch funding history
-$canSeeHistory = $isFounder || $isInvestor;
-$fundingHistory = [];
-if ($canSeeHistory) {
- $stmt = db()->prepare("
- SELECT i.*, u.full_name as investor_name, u.id as investor_user_id
- FROM investments i
- LEFT JOIN users u ON i.investor_id = u.id
- WHERE i.startup_id = ? AND i.status != 'rejected'
- ORDER BY i.created_at DESC
- ");
- $stmt->execute([$startupId]);
- $fundingHistory = $stmt->fetchAll();
-}
+// Check if current user follows
+$isFollowing = false;
+$stmt = db()->prepare("SELECT 1 FROM startup_followers WHERE startup_id = ? AND follower_id = ?");
+$stmt->execute([$startupId, $_SESSION['user_id']]);
+$isFollowing = (bool)$stmt->fetchColumn();
-// Fetch approved investments for dividends calculation (Founder only)
+// Fetch recent updates
+$stmt = db()->prepare("SELECT * FROM startup_updates WHERE startup_id = ? ORDER BY created_at DESC LIMIT 5");
+$stmt->execute([$startupId]);
+$updates = $stmt->fetchAll();
+
+// Fetch approved investments for founder view
$approvedInvestments = [];
if ($isFounder) {
$stmt = db()->prepare("
- SELECT i.*, u.full_name as investor_name
- FROM investments i
- JOIN users u ON i.investor_id = u.id
+ SELECT i.*, u.full_name as investor_name, u.id as investor_user_id
+ FROM investments i
+ JOIN users u ON i.investor_id = u.id
WHERE i.startup_id = ? AND i.status = 'approved'
+ ORDER BY i.created_at DESC
");
$stmt->execute([$startupId]);
$approvedInvestments = $stmt->fetchAll();
+
+ // Fetch Wallet Transactions for Founder
+ $stmt = db()->prepare("SELECT * FROM wallet_transactions WHERE user_id = ? ORDER BY created_at DESC LIMIT 5");
+ $stmt->execute([$_SESSION['user_id']]);
+ $transactions = $stmt->fetchAll();
}
-// Fetch founders
-$stmt = db()->prepare("SELECT id, full_name FROM users WHERE id = ?");
-$stmt->execute([$startup['founder_id']]);
-$founder = $stmt->fetch();
+function getNextDividendInfo($investmentDate) {
+ $nextDate = date('M d, Y', strtotime($investmentDate . ' + 1 month'));
+ return $nextDate;
+}
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
-
-// Calculate progress
-$goal = $startup['active_goal'] ?: 0;
-$raised = $startup['active_raised'] ?: 0;
-$progress = ($goal > 0) ? round(($raised / $goal) * 100) : 0;
-
-/**
- * Helper to calculate time left for next dividend
- */
-function getNextDividendInfo($createdAt) {
- $created = new DateTime($createdAt);
- $day = $created->format('d');
-
- $now = new DateTime();
- $thisMonth = new DateTime($now->format('Y-m-') . $day);
-
- // If today is past the day, next is next month
- if ($thisMonth <= $now) {
- $next = clone $thisMonth;
- $next->modify('+1 month');
- } else {
- $next = $thisMonth;
- }
-
- $interval = $now->diff($next);
- $days = $interval->days;
-
- return [
- 'date' => $next->format('M d, Y'),
- 'days_left' => $days
- ];
-}
?>
-
+
-
-
= htmlspecialchars($startup['name']) ?> | Startup Details
+
+
+
= htmlspecialchars($startup['name']) ?> — = htmlspecialchars($platformName) ?>
-
+
-
+
-