From 017ad41531da7d1c5212d860b1d4d92f727b86ac Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 28 Feb 2026 19:54:19 +0000 Subject: [PATCH] Edit create_startup.php via Editor --- create_startup.php | 294 +++++++----------- .../16_recommended_return_reasoning.sql | 3 + startup_details.php | 292 ++++++++--------- 3 files changed, 251 insertions(+), 338 deletions(-) create mode 100644 db/migrations/16_recommended_return_reasoning.sql diff --git a/create_startup.php b/create_startup.php index 42863e5..bad0c11 100644 --- a/create_startup.php +++ b/create_startup.php @@ -1,28 +1,19 @@ prepare("SELECT * FROM startups WHERE id = ? AND founder_id = ?"); - $stmt->execute([$startup_id, $_SESSION['user_id']]); - $existingStartup = $stmt->fetch(); - if (!$existingStartup) { - header('Location: dashboard.php'); - exit; - } -} +$stmt = db()->prepare("SELECT * FROM startups WHERE founder_id = ?"); +$stmt->execute([$_SESSION['user_id']]); +$existingStartup = $stmt->fetch(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name'] ?? ''; @@ -34,24 +25,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $product_service = $_POST['product_service'] ?? ''; $operational_stage = $_POST['operational_stage'] ?? ''; - // Co-founder matching fields - $cofounder_equity_pct = $_POST['cofounder_equity_pct'] ?? ''; + $cofounder_equity_pct = $_POST['cofounder_equity_pct'] ?? 0.0; $cofounder_equity_type = $_POST['cofounder_equity_type'] ?? ''; $cofounder_responsibilities = $_POST['cofounder_responsibilities'] ?? ''; $desired_cofounder_experience = $_POST['desired_cofounder_experience'] ?? ''; $cofounder_commitment = $_POST['cofounder_commitment'] ?? ''; $other_partnership_details = $_POST['other_partnership_details'] ?? ''; - - // Financial stats - $current_cash_balance = (float)($_POST['current_cash_balance'] ?? 0); - $burn_rate = (float)($_POST['burn_rate'] ?? 0); + + $current_cash_balance = $_POST['current_cash_balance'] ?? 0.0; $outstanding_debt = $_POST['outstanding_debt'] ?? ''; $accounts_receivable_payable = $_POST['accounts_receivable_payable'] ?? ''; - - $upload_dir = 'assets/docs/financials/'; - if (!is_dir($upload_dir)) { - mkdir($upload_dir, 0775, true); - } + $burn_rate = $_POST['burn_rate'] ?? 0.0; $doc_fields = [ 'doc_income_statements', @@ -63,21 +47,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $uploaded_paths = []; foreach ($doc_fields as $field) { + $uploaded_paths[$field] = $existingStartup[$field] ?? null; if (isset($_FILES[$field]) && $_FILES[$field]['error'] === UPLOAD_ERR_OK) { - $file_ext = pathinfo($_FILES[$field]['name'], PATHINFO_EXTENSION); - $file_name = uniqid($field . '_', true) . '.' . $file_ext; - $dest_path = $upload_dir . $file_name; - if (move_uploaded_file($_FILES[$field]['tmp_name'], $dest_path)) { - $uploaded_paths[$field] = $dest_path; - } else { - $error = "Failed to upload $field."; - break; + $ext = pathinfo($_FILES[$field]['name'], PATHINFO_EXTENSION); + $new_name = $field . '_' . time() . '.' . $ext; + $upload_dir = 'assets/docs/financials/'; + if (!is_dir($upload_dir)) mkdir($upload_dir, 0775, true); + $upload_path = $upload_dir . $new_name; + if (move_uploaded_file($_FILES[$field]['tmp_name'], $upload_path)) { + $uploaded_paths[$field] = $upload_path; } - } elseif ($existingStartup && !empty($existingStartup[$field])) { - $uploaded_paths[$field] = $existingStartup[$field]; - } else { - $error = "The financial document for $field is mandatory."; - break; } } @@ -92,7 +71,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { // Compute AI Recommended Return Rate $recommended_return_rate = $existingStartup['recommended_return_rate'] ?? 0.0; + $recommended_return_reasoning = $existingStartup['recommended_return_reasoning'] ?? ''; + $doc_list = []; + foreach ($uploaded_paths as $key => $path) { + if ($path) { + $label = str_replace(['doc_', '_'], ['', ' '], $key); + $doc_list[] = ucwords($label); + } + } + $docs_str = !empty($doc_list) ? implode(", ", $doc_list) : "None"; + // AI Prompt $prompt = "As a financial analyst, calculate a recommended annual dividend yield (interest percentage) based on this startup profile: Name: {$name} @@ -102,8 +91,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { Stage: {$operational_stage} Cash Balance: £{$current_cash_balance} Burn Rate: £{$burn_rate} + Documents provided: {$docs_str} - Respond ONLY with a JSON object: {\"recommended_rate\": X.X}"; + Based on the financial documents provided and the company's stage/industry, please provide: + 1. A recommended return rate (percentage). + 2. A brief reasoning (2-3 sentences) on how you arrived at this figure, explicitly mentioning how the provided documents influenced your decision. + + Respond ONLY with a JSON object: {\"recommended_rate\": X.X, \"reasoning\": \"...\"}"; $aiResponse = LocalAIApi::createResponse([ 'input' => [ @@ -115,6 +109,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($aiResponse['success'])) { $decoded = LocalAIApi::decodeJsonFromResponse($aiResponse); $recommended_return_rate = (float)($decoded['recommended_rate'] ?? 5.0); + $recommended_return_reasoning = (string)($decoded['reasoning'] ?? 'Based on industry standards and provided financials.'); } if ($existingStartup) { @@ -123,7 +118,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { cofounder_equity_pct = ?, cofounder_equity_type = ?, cofounder_responsibilities = ?, desired_cofounder_experience = ?, cofounder_commitment = ?, other_partnership_details = ?, current_cash_balance = ?, outstanding_debt = ?, accounts_receivable_payable = ?, burn_rate = ?, doc_income_statements = ?, doc_balance_sheets = ?, doc_cash_flow_statements = ?, doc_revenue_breakdown = ?, doc_gross_margin = ?, - recommended_return_rate = ? + recommended_return_rate = ?, recommended_return_reasoning = ? WHERE id = ? AND founder_id = ?"); $stmt->execute([ @@ -132,7 +127,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $current_cash_balance, $outstanding_debt, $accounts_receivable_payable, $burn_rate, $uploaded_paths['doc_income_statements'], $uploaded_paths['doc_balance_sheets'], $uploaded_paths['doc_cash_flow_statements'], $uploaded_paths['doc_revenue_breakdown'], $uploaded_paths['doc_gross_margin'], - $recommended_return_rate, $existingStartup['id'], $_SESSION['user_id'] + $recommended_return_rate, $recommended_return_reasoning, $existingStartup['id'], $_SESSION['user_id'] ]); $final_id = $existingStartup['id']; } else { @@ -141,8 +136,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { cofounder_equity_pct, cofounder_equity_type, cofounder_responsibilities, desired_cofounder_experience, cofounder_commitment, other_partnership_details, current_cash_balance, outstanding_debt, accounts_receivable_payable, burn_rate, doc_income_statements, doc_balance_sheets, doc_cash_flow_statements, doc_revenue_breakdown, doc_gross_margin, - founder_id, recommended_return_rate, status - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'private')"); + founder_id, recommended_return_rate, recommended_return_reasoning, status + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'private')"); $stmt->execute([ $name, $legal_name, $country, $industry, $sub_industry, $business_model, $product_service, $operational_stage, @@ -150,13 +145,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $current_cash_balance, $outstanding_debt, $accounts_receivable_payable, $burn_rate, $uploaded_paths['doc_income_statements'], $uploaded_paths['doc_balance_sheets'], $uploaded_paths['doc_cash_flow_statements'], $uploaded_paths['doc_revenue_breakdown'], $uploaded_paths['doc_gross_margin'], - $_SESSION['user_id'], $recommended_return_rate + $_SESSION['user_id'], $recommended_return_rate, $recommended_return_reasoning ]); $final_id = db()->lastInsertId(); } db()->commit(); - $success = "Startup profile saved successfully! Recommended return rate: " . number_format($recommended_return_rate, 2) . "%"; + $success = "Startup profile saved successfully! Recommended return rate: " . number_format($recommended_return_rate, 2) . "%" ; // Refresh local data $stmt = db()->prepare("SELECT * FROM startups WHERE id = ?"); @@ -191,167 +186,112 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { -
+
-
- View Live Profile -
- -
-

1. Basic Company Information

-
+ + +
+

Company Information

+ +
- - + +
- - -
-
-
-
- - + +
- - +
+
+ +
-
-
- - -
-
- - -
+ +
+ +
-
- - +
+ +
+ +
-
- - -
+
-

2. Co-founder Matching & Partnership

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

3. Mandatory Financials

+ +
+

Financial Overview

-
-
-
- - -
-
- - -
+
+
+ +
-
- - -
-
- - +
+ +
-

Historical Financial Documentation (PDF/Images)

-
- 'Income Statements', - 'doc_balance_sheets' => 'Balance Sheets', - 'doc_cash_flow_statements' => 'Cash Flow Statements', - 'doc_revenue_breakdown' => 'Revenue Breakdown', - 'doc_gross_margin' => 'Gross Margin Data' - ]; - foreach ($doc_labels as $f_name => $label): - ?> -
- - accept=".pdf,image/*"> - +

Upload Financial Documents (PDF/Images)

+
+ 'Income Statements', + 'doc_balance_sheets' => 'Balance Sheets', + 'doc_cash_flow_statements' => 'Cash Flow Statements', + 'doc_revenue_breakdown' => 'Revenue Breakdown', + 'doc_gross_margin' => 'Gross Margin Analysis' + ]; + foreach ($doc_labels as $field => $label): ?> - Already uploaded - +
+ + + +
+ Already uploaded +
+ +
+
-
+
- - Cancel - - + +
- - - \ No newline at end of file + diff --git a/db/migrations/16_recommended_return_reasoning.sql b/db/migrations/16_recommended_return_reasoning.sql new file mode 100644 index 0000000..012978a --- /dev/null +++ b/db/migrations/16_recommended_return_reasoning.sql @@ -0,0 +1,3 @@ +-- Migration: Add recommended return reasoning to startups +ALTER TABLE startups +ADD COLUMN recommended_return_reasoning TEXT AFTER recommended_return_rate; diff --git a/startup_details.php b/startup_details.php index 6361e2c..961a7a7 100644 --- a/startup_details.php +++ b/startup_details.php @@ -1,153 +1,166 @@ prepare("SELECT s.*, u.full_name as founder_name - FROM startups s - JOIN users u ON s.founder_id = u.id - WHERE s.id = ?"); -$stmt->execute([$startup_id]); +$stmt = db()->prepare("SELECT * FROM startups WHERE id = ?"); +$stmt->execute([$startupId]); $startup = $stmt->fetch(); if (!$startup) { - header('Location: startups.php'); - exit; + die("Startup not found."); } -// Fetch funding history -$stmt = db()->prepare("SELECT i.*, u.full_name as investor_name - FROM investments i - JOIN users u ON i.investor_id = u.id - WHERE i.startup_id = ? - ORDER BY i.created_at DESC"); -$stmt->execute([$startup_id]); -$fundingHistory = $stmt->fetchAll(); +// Check if user is the founder or an investor +$isFounder = ($_SESSION['user_id'] == $startup['founder_id']); +$isInvestor = ($_SESSION['user_role'] == 'investor'); -// Check if user is the founder -$isFounder = isset($_SESSION['user_id']) && $_SESSION['user_id'] == $startup['founder_id']; -$isInvestor = isset($_SESSION['user_id']) && $_SESSION['role'] === 'investor'; - -// For investors, check if they can see history (maybe only after some interaction?) -// For now, let everyone see. -$canSeeHistory = true; - -// Handle following -$isFollowing = false; -if (isset($_SESSION['user_id'])) { - $stmt = db()->prepare("SELECT 1 FROM startup_followers WHERE startup_id = ? AND user_id = ?"); - $stmt->execute([$startup_id, $_SESSION['user_id']]); - $isFollowing = (bool)$stmt->fetch(); +// Basic permissions check +if (!$isFounder && $startup['status'] === 'private' && !$isInvestor) { + die("You do not have permission to view this profile."); } -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { - if (!isset($_SESSION['user_id'])) { - header('Location: login.php'); - exit; - } - - if ($_POST['action'] === 'follow') { - if ($isFollowing) { - $stmt = db()->prepare("DELETE FROM startup_followers WHERE startup_id = ? AND user_id = ?"); - $stmt->execute([$startup_id, $_SESSION['user_id']]); - $stmt = db()->prepare("UPDATE startups SET followers_count = followers_count - 1 WHERE id = ?"); - $stmt->execute([$startup_id]); - } else { - $stmt = db()->prepare("INSERT INTO startup_followers (startup_id, user_id) VALUES (?, ?)"); - $stmt->execute([$startup_id, $_SESSION['user_id']]); - $stmt = db()->prepare("UPDATE startups SET followers_count = followers_count + 1 WHERE id = ?"); - $stmt->execute([$startup_id]); - } - header("Location: startup_details.php?id=$startup_id"); - exit; - } +// Fetch funding history if investor +$canSeeHistory = $isFounder || $isInvestor; +$fundingHistory = []; +if ($canSeeHistory) { + $stmt = db()->prepare("SELECT i.*, u.name as investor_name FROM investments i JOIN users u ON i.investor_id = u.id WHERE i.startup_id = ? ORDER BY i.created_at DESC"); + $stmt->execute([$startupId]); + $fundingHistory = $stmt->fetchAll(); } +// Fetch founders +$stmt = db()->prepare("SELECT name FROM users WHERE id = ?"); +$stmt->execute([$startup['founder_id']]); +$founder = $stmt->fetch(); + ?> - <?= htmlspecialchars($startup['name']) ?> | Venture Capitalist + <?= htmlspecialchars($startup['name']) ?> | Startup Details - + - + -
-
-
+
+
+ + +
- - Back to Discover - -
-
- -
-
-

-
- - - Followers -
-
+
+ + + + + +
+

+ +

+

+ Founded by +

- -
-
-
-
+
-

Executive Summary

+

Product & Vision

@@ -230,6 +243,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
Target annual dividend yield set by founder
+ +
+
Calculation Reasoning
+ +
+ @@ -249,12 +268,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
-
+
-
£
+
£
+
% Equity
@@ -263,61 +283,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
- -
- -
-

Venture Financials

-
-
£
-
Total Raised All-Time
-
-
-
-
-
-
Investors
-
-
-
£
-
Current Goal
-
-
- -
-
-
-
-
- % Funded - £ Left -
-
- - - - Invest Now - - -
- -
-

The Founder

-
-
- -
-
-
-
Founder & CEO
-
-
-
- Managed and verified by Venture Capitalist Platform. -
-
-
+ + - \ No newline at end of file +