From 9141a82a5292e287f6f65cc3ea4fc40cb481de57 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 28 Feb 2026 16:56:33 +0000 Subject: [PATCH] v7 --- db/migrations/05_investment_refund_status.sql | 2 + startup_details.php | 328 ++++++++++-------- 2 files changed, 190 insertions(+), 140 deletions(-) create mode 100644 db/migrations/05_investment_refund_status.sql diff --git a/db/migrations/05_investment_refund_status.sql b/db/migrations/05_investment_refund_status.sql new file mode 100644 index 0000000..3652fd1 --- /dev/null +++ b/db/migrations/05_investment_refund_status.sql @@ -0,0 +1,2 @@ +-- Migration: Add Refunded status to investments +ALTER TABLE investments MODIFY COLUMN status ENUM('pending', 'approved', 'rejected', 'Refunded') DEFAULT 'pending'; diff --git a/startup_details.php b/startup_details.php index 8002fcd..145731c 100644 --- a/startup_details.php +++ b/startup_details.php @@ -1,51 +1,41 @@ prepare("SELECT * FROM users WHERE id = ?"); +$stmt->execute([$user_id]); +$user = $stmt->fetch(); -$startup_id = (int)($_GET['id'] ?? 0); -if (!$startup_id) { - header("Location: startups.php"); - exit; -} - -// Fetch startup details (handle missing founder due to account deletion) -$stmt = db()->prepare("SELECT s.*, u.full_name as founder_name, u.university as founder_uni, u.graduation_year FROM startups s LEFT JOIN users u ON s.founder_id = u.id WHERE s.id = ?"); +$startup_id = isset($_GET['id']) ? (int)$_GET['id'] : 0; +$stmt = db()->prepare("SELECT * FROM startups WHERE id = ?"); $stmt->execute([$startup_id]); $startup = $stmt->fetch(); if (!$startup) { - header("Location: startups.php"); + header('Location: startups.php'); exit; } -$stmt = db()->prepare("SELECT * FROM users WHERE id = ?"); -$stmt->execute([$_SESSION['user_id']]); -$user = $stmt->fetch(); - -// Fetch active funding round +// Check for active funding round $stmt = db()->prepare("SELECT * FROM funding_rounds WHERE startup_id = ? AND status = 'Active' LIMIT 1"); $stmt->execute([$startup_id]); $activeRound = $stmt->fetch(); -// Fetch round history -$stmt = db()->prepare("SELECT * FROM funding_rounds WHERE startup_id = ? ORDER BY created_at DESC"); -$stmt->execute([$startup_id]); -$rounds = $stmt->fetchAll(); - +// Handle Founder Actions $error = ''; $success = ''; -// Handle Round Controls (Founder Only) -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $startup['founder_id'] == $_SESSION['user_id']) { +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) { $action = $_POST['action']; - $round_id = (int)($_POST['round_id'] ?? 0); + $round_id = isset($_POST['round_id']) ? (int)$_POST['round_id'] : 0; - if ($action === 'finish_round_early' && $activeRound && $activeRound['id'] == $round_id) { + if ($action === 'finish_round' && $activeRound && $activeRound['id'] == $round_id) { $stmt = db()->prepare("UPDATE funding_rounds SET status = 'Closed' WHERE id = ?"); $stmt->execute([$round_id]); $success = "Funding round finished early. No new investments allowed."; @@ -125,6 +115,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $stmt = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)"); $stmt->execute([$startup['founder_id'], "New investment of £" . number_format($amount) . " in " . $startup['name'] . "!"]); + // Check if goal reached for automated notification system + $stmt = db()->prepare("SELECT * FROM funding_rounds WHERE id = ?"); + $stmt->execute([$activeRound['id']]); + $updatedRound = $stmt->fetch(); + + if ($updatedRound['funding_raised'] >= $updatedRound['funding_goal']) { + // Update status to 'Closed' + $stmt = db()->prepare("UPDATE funding_rounds SET status = 'Closed' WHERE id = ?"); + $stmt->execute([$updatedRound['id']]); + + // Notify Founder (DB) + $stmt = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)"); + $stmt->execute([$startup['founder_id'], "Congratulations! The funding round for " . $startup['name'] . " has reached its goal of £" . number_format($updatedRound['funding_goal']) . "!"]); + + // Notify All Investors for this round (DB + Email) + $stmt = db()->prepare("SELECT DISTINCT u.id, u.email, u.full_name FROM investments i JOIN users u ON i.investor_id = u.id WHERE i.funding_round_id = ? AND i.status = 'approved'"); + $stmt->execute([$updatedRound['id']]); + $investorsToNotify = $stmt->fetchAll(); + + foreach ($investorsToNotify as $invUser) { + // DB Notification + $stmt = db()->prepare("INSERT INTO notifications (user_id, content) VALUES (?, ?)"); + $stmt->execute([$invUser['id'], "Great news! The funding round for " . $startup['name'] . " that you invested in has reached its goal!"]); + + // Email Notification + $subject = "Funding Goal Reached for " . $startup['name']; + $html = "

Goal Reached!

Hi " . htmlspecialchars($invUser['full_name']) . ", the funding round for " . htmlspecialchars($startup['name']) . " has successfully reached its goal. Thank you for being a part of this journey!

"; + $text = "Goal Reached! Hi " . $invUser['full_name'] . ", the funding round for " . $startup['name'] . " has successfully reached its goal. Thank you for being a part of this journey!"; + MailService::sendMail($invUser['email'], $subject, $html, $text); + } + + // Email Founder + $stmt = db()->prepare("SELECT email, full_name FROM users WHERE id = ?"); + $stmt->execute([$startup['founder_id']]); + $founderUser = $stmt->fetch(); + if ($founderUser) { + $subject = "Funding Goal Reached: " . $startup['name']; + $html = "

Congratulations!

Your funding round for " . htmlspecialchars($startup['name']) . " has reached its goal of £" . number_format($updatedRound['funding_goal']) . ".

"; + $text = "Congratulations! Your funding round for " . $startup['name'] . " has reached its goal of £" . number_format($updatedRound['funding_goal']) . "."; + MailService::sendMail($founderUser['email'], $subject, $html, $text); + } + } + db()->commit(); $success = "Investment successful! You've backed the current round."; // Refresh active round data @@ -175,145 +208,160 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
+ +
+ + +
+ +
-
+
-

-
- Founded by Account Deleted' ?> - () +

+
+ Founded +
-
-

About Startup

-

- -

-
+
+

About the Venture

+

+
-
-

Investment Terms (Dividend-Only Returns)

-
-

How it works:

-
    -
  • Investors are entitled to a share of future profits as **dividends**.
  • -
  • No voting rights or equity control are granted to investors.
  • -
  • Returns are primarily distributed through profit-sharing mechanisms.
  • -
  • Each funding round is independent and maintains its own investment pot.
  • -
-
-
+ +
+

Active Funding Round

+
+ 0) ? min(100, ($activeRound['funding_raised'] / $activeRound['funding_goal']) * 100) : 0; + ?> +
+
+
+ £ raised + Target: £ +
-
-

Funding Round History

-
- -
-
-
Round
-
Target: £
-
-
-
£ Raised
- - - -
+ +
+
+ + + +
+
+ + + +
- -
-
+ +
+ + +
+ + +
+

Minimum investment is £50. Your support helps students grow.

+
+ +
+ +
+
+

No Active Funding Round

+

This startup is not currently raising funds, or the previous round has closed.

+ + + + + + +
+
- -
-

Current Funding Round

- -
-
- £ - of £ +
+

Venture Stats

+
+
+
Total Rounds
+ prepare("SELECT COUNT(*) FROM funding_rounds WHERE startup_id = ?"); + $stmt->execute([$startup_id]); + $roundCount = $stmt->fetchColumn(); + ?> +
-
-
-
-
- % Raised +
+
Backers
+ prepare("SELECT COUNT(DISTINCT investor_id) FROM investments WHERE startup_id = ? AND status = 'approved'"); + $stmt->execute([$startup_id]); + $backerCount = $stmt->fetchColumn(); + ?> +
+
- -
- -
- -
- -
- - - -
- -
- - +
+

Founder

+ prepare("SELECT * FROM users WHERE id = ?"); + $stmt->execute([$startup['founder_id']]); + $founder = $stmt->fetch(); + ?> + +
+
+ + + +
+ +
+ +
+
+
+
- - - -
-
- - - -
-
- - - -
+ Send Message + +
Founder account deleted. Venture is community-managed.
-
- -
- -

No Active Round

-

This startup is not currently seeking investment.

- - -
-

Start a New Round

-
- -
- - -
- -
-
- -
- - -
-

Risk Disclosure

-

- Student startups carry high risk. Dividends are not guaranteed and depend on the profitability of the venture. Each round is independent. -

-
+
+ + - + \ No newline at end of file