From 306361e5fb32b43a80805f454bdd0f3c3ff30f6b Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 28 Feb 2026 18:39:14 +0000 Subject: [PATCH] s23 --- start_funding.php | 96 +++++++++++++++++++++++++++++++-------------- startup_details.php | 85 ++++++++++++++++++++++++++++++++++----- 2 files changed, 142 insertions(+), 39 deletions(-) diff --git a/start_funding.php b/start_funding.php index fe23cae..047e26d 100644 --- a/start_funding.php +++ b/start_funding.php @@ -9,6 +9,27 @@ require_once __DIR__ . '/db/config.php'; $error = ''; $success = ''; +$existingStartup = null; + +$startup_id = (int)($_GET['id'] ?? 0); +if ($startup_id > 0) { + $stmt = db()->prepare("SELECT * FROM startups WHERE id = ? AND founder_id = ?"); + $stmt->execute([$startup_id, $_SESSION['user_id']]); + $existingStartup = $stmt->fetch(); + + if (!$existingStartup) { + header("Location: startups.php"); + exit; + } + + // Check if there is already an active round + $stmt = db()->prepare("SELECT id FROM funding_rounds WHERE startup_id = ? AND status = 'Active'"); + $stmt->execute([$startup_id]); + if ($stmt->fetch()) { + header("Location: startup_details.php?id=" . $startup_id); + exit; + } +} if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); @@ -16,23 +37,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $target = (float)($_POST['funding_target'] ?? 0); $status = $_POST['status'] ?? 'public'; - if (empty($name) || empty($description) || $target < 50) { + if ((!$existingStartup && empty($name)) || (!$existingStartup && empty($description)) || $target < 50) { $error = "Please fill in all required fields. Minimum target is £50."; } else { db()->beginTransaction(); try { - // 1. Insert startup (keep target/raised for compatibility/legacy but we'll use funding_rounds) - $stmt = db()->prepare("INSERT INTO startups (name, description, founder_id, funding_target, status) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$name, $description, $_SESSION['user_id'], $target, $status]); - $startup_id = db()->lastInsertId(); - - // 2. Insert initial funding round - $stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')"); - $stmt->execute([$startup_id, $target]); + if ($existingStartup) { + // Just create a new round for existing startup + $stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')"); + $stmt->execute([$existingStartup['id'], $target]); + $final_id = $existingStartup['id']; + } else { + // 1. Insert startup + $stmt = db()->prepare("INSERT INTO startups (name, description, founder_id, funding_target, status) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$name, $description, $_SESSION['user_id'], $target, $status]); + $new_startup_id = db()->lastInsertId(); + + // 2. Insert initial funding round + $stmt = db()->prepare("INSERT INTO funding_rounds (startup_id, funding_goal, status) VALUES (?, ?, 'Active')"); + $stmt->execute([$new_startup_id, $target]); + $final_id = $new_startup_id; + } db()->commit(); - $success = "Startup listed successfully! Your funding round is now active."; - header("refresh:2;url=dashboard.php"); + $success = "Funding round is now active!"; + header("refresh:2;url=startup_details.php?id=" . $final_id); } catch (PDOException $e) { db()->rollBack(); $error = "Database error: " . $e->getMessage(); @@ -47,7 +76,7 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby'; - Start Funding Round — <?= htmlspecialchars($platformName) ?> + <?= $existingStartup ? 'Start New Round' : 'Start Funding Round' ?> — <?= htmlspecialchars($platformName) ?> @@ -55,8 +84,10 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
-

List Your Startup

-

Kickstart your project with micro-investments from peers.

+

+

+ +

@@ -70,27 +101,32 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
-
- - -
-
- - -
+ +
+ + +
+
+ + +
+
+ + +
+ +
Min investment per user will be £50.
-
- - -
- + + + Cancel
diff --git a/startup_details.php b/startup_details.php index bc6b2d8..a174a5a 100644 --- a/startup_details.php +++ b/startup_details.php @@ -26,7 +26,7 @@ $stmt = db()->prepare("SELECT id FROM startup_followers WHERE user_id = ? AND st $stmt->execute([$user_id, $startup_id]); $isFollowing = $stmt->fetch(); -// Actions: follow/unfollow, invest, post_update +// Actions: follow/unfollow, invest, post_update, finish_round, cancel_round if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { if ($_POST['action'] === 'follow') { $stmt = db()->prepare("INSERT IGNORE INTO startup_followers (user_id, startup_id) VALUES (?, ?)"); @@ -43,8 +43,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $stmt->execute([$startup_id]); $round = $stmt->fetch(); if ($round) { - $stmt = db()->prepare("INSERT INTO investments (investor_id, startup_id, amount, status) VALUES (?, ?, ?, 'approved')"); - $stmt->execute([$user_id, $startup_id, $amount]); + $stmt = db()->prepare("INSERT INTO investments (investor_id, startup_id, funding_round_id, amount, status) VALUES (?, ?, ?, ?, 'approved')"); + $stmt->execute([$user_id, $startup_id, $round['id'], $amount]); $stmt = db()->prepare("UPDATE funding_rounds SET funding_raised = funding_raised + ? WHERE id = ?"); $stmt->execute([$amount, $round['id']]); @@ -83,6 +83,50 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { } $success = "Update posted successfully!"; } + } elseif ($_POST['action'] === 'finish_round' && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) { + $stmt = db()->prepare("UPDATE funding_rounds SET status = 'Closed' WHERE startup_id = ? AND status = 'Active'"); + $stmt->execute([$startup_id]); + $success = "Funding round successfully closed!"; + } elseif ($_POST['action'] === 'cancel_round' && $user['role'] === 'founder' && $startup['founder_id'] == $user_id) { + db()->beginTransaction(); + try { + // Find active round + $stmt = db()->prepare("SELECT id FROM funding_rounds WHERE startup_id = ? AND status = 'Active'"); + $stmt->execute([$startup_id]); + $round = $stmt->fetch(); + + if ($round) { + // Cancel round + $stmt = db()->prepare("UPDATE funding_rounds SET status = 'Cancelled' WHERE id = ?"); + $stmt->execute([$round['id']]); + + // Refund all investments in this round + $stmt = db()->prepare("UPDATE investments SET status = 'Refunded' WHERE funding_round_id = ?"); + $stmt->execute([$round['id']]); + + // Deduct from startup total raised + $stmt = db()->prepare("SELECT SUM(amount) as total FROM investments WHERE funding_round_id = ? AND status = 'Refunded'"); + $stmt->execute([$round['id']]); + $totalRefunded = $stmt->fetch()['total'] ?? 0; + + $stmt = db()->prepare("UPDATE startups SET funding_raised = GREATEST(0, funding_raised - ?) WHERE id = ?"); + $stmt->execute([$totalRefunded, $startup_id]); + + db()->commit(); + $success = "Funding round cancelled and all investments marked for refund."; + + // Refresh data + $stmt = db()->prepare("SELECT * FROM startups WHERE id = ?"); + $stmt->execute([$startup_id]); + $startup = $stmt->fetch(); + } else { + db()->rollBack(); + $error = "No active round found to cancel."; + } + } catch (Exception $e) { + db()->rollBack(); + $error = "Error: " . $e->getMessage(); + } } } @@ -100,7 +144,7 @@ if ($canSeeHistory) { SELECT i.*, u.full_name as investor_name, u.profile_photo as investor_photo FROM investments i JOIN users u ON i.investor_id = u.id - WHERE i.startup_id = ? AND i.status = 'approved' + WHERE i.startup_id = ? AND i.status != 'rejected' ORDER BY i.created_at DESC "); $stmt->execute([$startup_id]); @@ -222,8 +266,12 @@ if ($canSeeHistory) {
-
£
-
Investment
+
+ £ +
+
+ +
@@ -290,7 +338,7 @@ if ($canSeeHistory) {
-
Investors
+
Investments
@@ -327,11 +375,30 @@ if ($canSeeHistory) { -
+
This is your active funding round. Share the link with potential investors to reach your goal.
+
+
+ + +
+
+ + +
+
+ + +
+ +

No Active Round

+

Ready to raise more capital?

+ Start New Round +
+
@@ -368,4 +435,4 @@ if ($canSeeHistory) { - + \ No newline at end of file