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') { -