38873-vm/invest.php
Flatlogic Bot 93e195d19b v31
2026-02-28 20:00:36 +00:00

137 lines
6.4 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'investor') {
header('Location: login.php');
exit;
}
$startupId = $_GET['id'] ?? null;
if (!$startupId) {
header('Location: startups.php');
exit;
}
$stmt = db()->prepare("
SELECT s.*, fr.id as round_id, fr.funding_goal, fr.funding_raised, fr.status as round_status
FROM startups s
LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active'
WHERE s.id = ?
");
$stmt->execute([$startupId]);
$startup = $stmt->fetch();
if (!$startup) {
die("Startup not found.");
}
if ($startup['round_status'] !== 'Active') {
die("This startup does not have an active funding round.");
}
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$amount = (float)($_POST['amount'] ?? 0);
$investor_id = $_SESSION['user_id'];
if ($amount <= 0) {
$error = "Please enter a valid investment amount.";
} else {
db()->beginTransaction();
try {
// 1. Create investment record
// Note: We'll assume 1% equity for every £1000 for simplicity or use a formula
// Actually let's look at the database schema for investments
$equity_pct = round(($amount / $startup['funding_goal']) * 10, 2); // Mock logic for equity
$stmt = db()->prepare("INSERT INTO investments (startup_id, investor_id, funding_round_id, amount, equity_pct, status) VALUES (?, ?, ?, ?, ?, 'pending')");
$stmt->execute([$startupId, $investor_id, $startup['round_id'], $amount, $equity_pct]);
// 2. Update funding_rounds raised amount
$stmt = db()->prepare("UPDATE funding_rounds SET funding_raised = funding_raised + ? WHERE id = ?");
$stmt->execute([$amount, $startup['round_id']]);
// 3. Update startup total raised
$stmt = db()->prepare("UPDATE startups SET funding_raised = funding_raised + ? WHERE id = ?");
$stmt->execute([$amount, $startupId]);
db()->commit();
$success = "Investment of £" . number_format($amount) . " submitted successfully! The founder will be notified.";
header("refresh:3;url=portfolio.php");
} catch (Exception $e) {
db()->rollBack();
$error = "Error: " . $e->getMessage();
}
}
}
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Invest in <?= htmlspecialchars($startup['name']) ?> | <?= htmlspecialchars($platformName) ?></title>
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body style="background: #000; color: #fff; padding: 60px 20px;">
<div class="container" style="max-width: 600px; margin: 0 auto;">
<div class="card" style="padding: 40px; background: #1a1a1a; border-radius: 24px; border: 1px solid rgba(255,255,255,0.1);">
<h1 style="font-size: 32px; font-weight: 900; margin-bottom: 10px;">Back <?= htmlspecialchars($startup['name']) ?></h1>
<p style="color: #999; margin-bottom: 30px;">
You are participating in the active funding round for this startup.
</p>
<?php if ($error): ?>
<div style="background: rgba(255, 0, 0, 0.1); border: 1px solid rgba(255, 0, 0, 0.3); color: #ff5555; padding: 15px; border-radius: 12px; margin-bottom: 25px;">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div style="background: rgba(0, 242, 255, 0.1); border: 1px solid var(--accent-blue); color: var(--accent-blue); padding: 15px; border-radius: 12px; margin-bottom: 25px;">
<?= htmlspecialchars($success) ?>
</div>
<?php else: ?>
<div style="background: rgba(255,255,255,0.03); padding: 25px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.05); margin-bottom: 30px;">
<div style="display: flex; justify-content: space-between; margin-bottom: 15px;">
<span style="color: #999;">Funding Goal</span>
<span style="font-weight: 700;">£<?= number_format($startup['funding_goal']) ?></span>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 15px;">
<span style="color: #999;">Already Raised</span>
<span style="font-weight: 700;">£<?= number_format($startup['funding_raised']) ?></span>
</div>
<?php
$remaining = $startup['funding_goal'] - $startup['funding_raised'];
?>
<div style="display: flex; justify-content: space-between; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.05);">
<span style="color: #999;">Remaining</span>
<span style="font-weight: 900; color: var(--accent-blue);">£<?= number_format(max(0, $remaining)) ?></span>
</div>
</div>
<form method="POST">
<div style="margin-bottom: 30px;">
<label style="display: block; margin-bottom: 10px; font-weight: 600; color: #999; text-transform: uppercase; font-size: 12px; letter-spacing: 1px;">Investment Amount (£)</label>
<input type="number" name="amount" min="1" step="1" required placeholder="Enter amount..."
style="width: 100%; padding: 20px; background: #000; border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; color: #fff; font-size: 24px; font-weight: 900;">
</div>
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 20px; font-size: 18px; font-weight: 800; border-radius: 16px; background: var(--accent-blue); color: #000; border: none; cursor: pointer;">
Confirm Investment <i class="fas fa-rocket" style="margin-left: 10px;"></i>
</button>
<a href="startup_details.php?id=<?= $startupId ?>" style="display: block; text-align: center; margin-top: 20px; color: #999; text-decoration: none; font-size: 14px;">Back to Startup Profile</a>
</form>
<?php endif; ?>
</div>
</div>
</body>
</html>