diff --git a/funding_rounds.php b/funding_rounds.php index f728bfe..fe4f8f1 100644 --- a/funding_rounds.php +++ b/funding_rounds.php @@ -89,7 +89,7 @@ $activeRounds = $stmt->fetchAll(); 0 && ($raised / ($goal ?: 1)) * 100 < 1) ? 1 : round(($raised / ($goal ?: 1)) * 100); ?>
diff --git a/invest.php b/invest.php index 092aacc..25b10dc 100644 --- a/invest.php +++ b/invest.php @@ -2,7 +2,7 @@ session_start(); require_once 'db/config.php'; -if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'investor') { +if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'investor') { header('Location: login.php'); exit; } @@ -45,7 +45,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // 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 + $equity_pct = 0.00; // 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]); diff --git a/startup_details.php b/startup_details.php index 0522509..ce972f9 100644 --- a/startup_details.php +++ b/startup_details.php @@ -312,7 +312,6 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
£
-
% Equity
diff --git a/startups.php b/startups.php index 976f958..a4d0ade 100644 --- a/startups.php +++ b/startups.php @@ -127,7 +127,7 @@ $myStartups = $stmt->fetchAll(); 0 && ($raised / ($goal ?: 1)) * 100 < 1) ? 1 : round(($raised / ($goal ?: 1)) * 100); $isTrending = in_array($startup['id'], $trendingIds); ?>
diff --git a/sync_funding.php b/sync_funding.php new file mode 100644 index 0000000..4deb479 --- /dev/null +++ b/sync_funding.php @@ -0,0 +1,28 @@ +exec("UPDATE startups SET funding_raised = 0"); +db()->exec("UPDATE funding_rounds SET funding_raised = 0"); + +// 2. Fetch all approved/pending investments (usually we only count approved, but let's see) +// Actually, let's count all investments that are not rejected +$stmt = db()->query("SELECT startup_id, funding_round_id, SUM(amount) as total FROM investments WHERE status != 'rejected' GROUP BY startup_id, funding_round_id"); +$totals = $stmt->fetchAll(); + +foreach ($totals as $t) { + echo "Updating Startup ID: {$t['startup_id']}, Round ID: {$t['funding_round_id']} with £{$t['total']}\n"; + + // Update funding_rounds + $stmt2 = db()->prepare("UPDATE funding_rounds SET funding_raised = ? WHERE id = ?"); + $stmt2->execute([$t['total'], $t['funding_round_id']]); + + // Update startups + $stmt3 = db()->prepare("UPDATE startups SET funding_raised = ? WHERE id = ?"); + $stmt3->execute([$t['total'], $t['startup_id']]); +} + +echo "Done!\n"; +