38873-vm/create_startup.php
Flatlogic Bot 7642b9a18a v77
2026-03-01 10:04:21 +00:00

388 lines
27 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
require_once 'ai/LocalAIApi.php';
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'founder') {
header('Location: login.php');
exit;
}
$countries = require_once 'includes/countries.php';
$success = '';
$error = '';
$startupId = $_GET['id'] ?? null;
$existingStartup = null;
if ($startupId) {
$stmt = db()->prepare("SELECT * FROM startups WHERE id = ? AND founder_id = ?");
$stmt->execute([$startupId, $_SESSION['user_id']]);
$existingStartup = $stmt->fetch();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$description = $_POST['description'] ?? '';
$legal_name = $_POST['legal_name'] ?? '';
$country = $_POST['country'] ?? '';
$industry = $_POST['industry'] ?? '';
$sub_industry = $_POST['sub_industry'] ?? '';
$business_model = $_POST['business_model'] ?? '';
$product_service = $_POST['product_service'] ?? '';
$operational_stage = $_POST['operational_stage'] ?? '';
$cofounder_equity_pct = $_POST['cofounder_equity_pct'] ?? 0.0;
$cofounder_equity_type = $_POST['cofounder_equity_type'] ?? '';
$cofounder_responsibilities = $_POST['cofounder_responsibilities'] ?? '';
$repayment_term = (int)($_POST["repayment_term"] ?? 12);
$desired_cofounder_experience = $_POST['desired_cofounder_experience'] ?? '';
$cofounder_commitment = $_POST['cofounder_commitment'] ?? '';
$other_partnership_details = $_POST['other_partnership_details'] ?? '';
$current_cash_balance = $_POST['current_cash_balance'] ?? 0.0;
$burn_rate = $_POST['burn_rate'] ?? 0.0;
$founder_return_rate = isset($_POST['founder_return_rate']) && $_POST['founder_return_rate'] !== '' ? (float)$_POST['founder_return_rate'] : null;
$doc_fields = [
'doc_income_statements',
'doc_balance_sheets',
'doc_cash_flow_statements',
'doc_revenue_breakdown',
'doc_gross_margin'
];
$uploaded_paths = [];
foreach ($doc_fields as $field) {
$uploaded_paths[$field] = $existingStartup[$field] ?? null;
if (isset($_FILES[$field]) && $_FILES[$field]['error'] === UPLOAD_ERR_OK) {
$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;
}
}
}
if (!$error) {
if (empty($name) || empty($description) || empty($legal_name) || empty($country) || empty($industry) || empty($business_model) || empty($product_service) || empty($operational_stage)) {
$error = "Please fill in all mandatory company information fields, including the short pitch.";
}
}
if (!$error) {
db()->beginTransaction();
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}
Short Pitch: {$description}
Industry: {$industry}/{$sub_industry}
Business Model: {$business_model}
Product: {$product_service}
Stage: {$operational_stage}
Cash Balance: £{$current_cash_balance}
Burn Rate: £{$burn_rate}
Documents provided: {$docs_str}
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' => [
['role' => 'system', 'content' => 'You are a financial analyst. Return JSON only.'],
['role' => 'user', 'content' => $prompt],
],
]);
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) {
$stmt = db()->prepare("UPDATE startups SET
name = ?, description = ?, legal_name = ?, country = ?, industry = ?, sub_industry = ?, business_model = ?, product_service = ?, operational_stage = ?,
cofounder_equity_pct = ?, cofounder_equity_type = ?, cofounder_responsibilities = ?, desired_cofounder_experience = ?, cofounder_commitment = ?, other_partnership_details = ?,
current_cash_balance = ?, burn_rate = ?,
doc_income_statements = ?, doc_balance_sheets = ?, doc_cash_flow_statements = ?, doc_revenue_breakdown = ?, doc_gross_margin = ?,
recommended_return_rate = ?, recommended_return_reasoning = ?, founder_return_rate = ?, repayment_term = ?
WHERE id = ? AND founder_id = ?");
$stmt->execute([
$name, $description, $legal_name, $country, $industry, $sub_industry, $business_model, $product_service, $operational_stage,
$cofounder_equity_pct, $cofounder_equity_type, $cofounder_responsibilities, $desired_cofounder_experience, $cofounder_commitment, $other_partnership_details,
$current_cash_balance, $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, $recommended_return_reasoning, $founder_return_rate, $repayment_term,
$existingStartup['id'], $_SESSION['user_id']
]);
$final_id = $existingStartup['id'];
} else {
$stmt = db()->prepare("INSERT INTO startups (
name, description, legal_name, country, industry, sub_industry, business_model, product_service, operational_stage,
cofounder_equity_pct, cofounder_equity_type, cofounder_responsibilities, desired_cofounder_experience, cofounder_commitment, other_partnership_details,
current_cash_balance, burn_rate,
doc_income_statements, doc_balance_sheets, doc_cash_flow_statements, doc_revenue_breakdown, doc_gross_margin,
founder_id, recommended_return_rate, recommended_return_reasoning, founder_return_rate, repayment_term, status
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'private')");
$stmt->execute([
$name, $description, $legal_name, $country, $industry, $sub_industry, $business_model, $product_service, $operational_stage,
$cofounder_equity_pct, $cofounder_equity_type, $cofounder_responsibilities, $desired_cofounder_experience, $cofounder_commitment, $other_partnership_details,
$current_cash_balance, $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, $recommended_return_reasoning, $founder_return_rate, $repayment_term
]);
$final_id = db()->lastInsertId();
}
db()->commit();
$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 = ?");
$stmt->execute([$final_id]);
$existingStartup = $stmt->fetch();
} catch (Exception $e) {
db()->rollBack();
$error = "Database error: " . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><?= $existingStartup ? 'Edit' : 'Create' ?> Startup Profile | Venture Capitalist</title>
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
</head>
<body style="background: var(--bg-color); color: #fff;">
<div class="container" style="padding: 40px 20px;">
<div style="max-width: 800px; margin: 0 auto;">
<h1 style="font-weight: 900; font-size: 32px; margin-bottom: 30px;"><?= $existingStartup ? 'Edit' : 'Create' ?> Startup Profile</h1>
<a href="startups.php" style="display: inline-block; margin-bottom: 20px; color: #aaa; text-decoration: none; font-size: 14px;"><i class="fas fa-arrow-left"></i> Back to Startups</a>
<?php if ($error): ?>
<div style="background: rgba(255, 59, 48, 0.1); color: #ff3b30; padding: 15px; border-radius: 12px; border: 1px solid #ff3b30; margin-bottom: 25px;">
<i class="fas fa-exclamation-circle"></i> <?= $error ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div style="background: rgba(48, 209, 88, 0.1); color: #30d158; padding: 15px; border-radius: 12px; border: 1px solid #30d158; margin-bottom: 25px;">
<i class="fas fa-check-circle"></i> <?= $success ?>
<?php if (!$startupId): ?>
<div style="margin-top: 15px;">
<a href="start_funding_round.php?id=<?= $final_id ?>" class="btn btn-primary" style="display: inline-block;">Launch Funding Round Now</a>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<form method="POST" enctype="multipart/form-data">
<!-- Basic Info -->
<section style="background: var(--card-bg); padding: 30px; border-radius: 20px; border: 1px solid var(--border-color); margin-bottom: 30px;">
<h2 style="font-size: 20px; margin-bottom: 20px;"><i class="fas fa-info-circle" style="color: var(--accent-color);"></i> Company Information</h2>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Startup Name *</label>
<input type="text" name="name" value="<?= htmlspecialchars($existingStartup['name'] ?? '') ?>" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Legal Entity Name *</label>
<input type="text" name="legal_name" value="<?= htmlspecialchars($existingStartup['legal_name'] ?? '') ?>" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Country of Incorporation *</label>
<select name="country" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
<option value="">Select Country</option>
<?php foreach ($countries as $c): ?>
<option value="<?= $c ?>" <?= ($existingStartup['country'] ?? '') === $c ? 'selected' : '' ?>><?= $c ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Industry *</label>
<select name="industry" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
<option value="FinTech" <?= ($existingStartup['industry'] ?? '') === 'FinTech' ? 'selected' : '' ?>>FinTech</option>
<option value="SaaS" <?= ($existingStartup['industry'] ?? '') === 'SaaS' ? 'selected' : '' ?>>SaaS</option>
<option value="HealthTech" <?= ($existingStartup['industry'] ?? '') === 'HealthTech' ? 'selected' : '' ?>>HealthTech</option>
<option value="E-commerce" <?= ($existingStartup['industry'] ?? '') === 'E-commerce' ? 'selected' : '' ?>>E-commerce</option>
<option value="AI/ML" <?= ($existingStartup['industry'] ?? '') === 'AI/ML' ? 'selected' : '' ?>>AI/ML</option>
<option value="CleanTech" <?= ($existingStartup['industry'] ?? '') === 'CleanTech' ? 'selected' : '' ?>>CleanTech</option>
<option value="EdTech" <?= ($existingStartup['industry'] ?? '') === 'EdTech' ? 'selected' : '' ?>>EdTech</option>
<option value="PropTech" <?= ($existingStartup['industry'] ?? '') === 'PropTech' ? 'selected' : '' ?>>PropTech</option>
<option value="Other" <?= ($existingStartup['industry'] ?? '') === 'Other' ? 'selected' : '' ?>>Other</option>
</select>
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Sub-Industry</label>
<input type="text" name="sub_industry" value="<?= htmlspecialchars($existingStartup['sub_industry'] ?? '') ?>" placeholder="e.g. Payments, CRM, Bioinformatics" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Operational Stage *</label>
<select name="operational_stage" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
<option value="Idea/Prototype" <?= ($existingStartup['operational_stage'] ?? '') === 'Idea/Prototype' ? 'selected' : '' ?>>Idea/Prototype</option>
<option value="MVP/Early Traction" <?= ($existingStartup['operational_stage'] ?? '') === 'MVP/Early Traction' ? 'selected' : '' ?>>MVP/Early Traction</option>
<option value="Growth/Scaling" <?= ($existingStartup['operational_stage'] ?? '') === 'Growth/Scaling' ? 'selected' : '' ?>>Growth/Scaling</option>
<option value="Mature" <?= ($existingStartup['operational_stage'] ?? '') === 'Mature' ? 'selected' : '' ?>>Mature</option>
</select>
</div>
</div>
<div style="margin-top: 20px;">
<label style="display: block; margin-bottom: 8px; color: #aaa;">Short Description / Elevator Pitch *</label>
<input type="text" name="description" value="<?= htmlspecialchars($existingStartup['description'] ?? '') ?>" required placeholder="A catchy one-sentence pitch (max 150 chars)" maxlength="255" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
<div style="margin-top: 20px;">
<label style="display: block; margin-bottom: 8px; color: #aaa;">Business Model *</label>
<textarea name="business_model" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff; height: 100px;" placeholder="e.g. B2B Subscription, Marketplace, Freemium..."><?= htmlspecialchars($existingStartup['business_model'] ?? '') ?></textarea>
</div>
<div style="margin-top: 20px;">
<label style="display: block; margin-bottom: 8px; color: #aaa;">Product/Service Overview *</label>
<textarea name="product_service" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff; height: 100px;" placeholder="Describe what your startup actually does..."><?= htmlspecialchars($existingStartup['product_service'] ?? '') ?></textarea>
</div>
</section>
<!-- Financials -->
<section style="background: var(--card-bg); padding: 30px; border-radius: 20px; border: 1px solid var(--border-color); margin-bottom: 30px;">
<h2 style="font-size: 20px; margin-bottom: 20px;"><i class="fas fa-chart-line" style="color: var(--accent-color);"></i> Financial Overview</h2>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Current Cash Balance (£)</label>
<input type="number" step="0.01" name="current_cash_balance" value="<?= htmlspecialchars($existingStartup['current_cash_balance'] ?? 0) ?>" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Monthly Burn Rate (£)</label>
<input type="number" step="0.01" name="burn_rate" value="<?= htmlspecialchars($existingStartup['burn_rate'] ?? 0) ?>" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
</div>
<div style="margin-top: 20px; border-top: 1px solid #333; padding-top: 20px;">
<div style="margin-bottom: 20px;">
<label style="display: block; margin-bottom: 8px; font-weight: 700;">Repayment Term (Months)</label>
<input type="number" name="repayment_term" value="<?= htmlspecialchars($existingStartup["repayment_term"] ?? "12") ?>" min="1" max="60" required style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid var(--accent-color); color: #fff; font-size: 16px; font-weight: 700;">
<small style="color: #aaa; display: block; margin-top: 8px;">The duration over which you will repay the investment plus interest.</small>
</div>
<label style="display: block; margin-bottom: 8px; font-weight: 700;">Proposed Investor Return (%)</label>
<input type="number" step="0.1" name="founder_return_rate" value="<?= htmlspecialchars($existingStartup['founder_return_rate'] ?? '') ?>" placeholder="e.g. 8.5" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid var(--accent-color); color: #fff; font-size: 16px; font-weight: 700;">
<small style="color: #aaa; display: block; margin-top: 8px;">Your proposed annual dividend yield. The platform also computes a recommendation based on your financials.</small>
</div>
<div style="margin-top: 30px;">
<h3 style="font-size: 16px; margin-bottom: 15px; color: #fff;">Upload Financial Documents (PDF/Images)</h3>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px;">
<?php
$doc_labels = [
'doc_income_statements' => '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):
?>
<div style="background: #222; padding: 15px; border-radius: 12px; border: 1px solid #333;">
<label style="display: block; margin-bottom: 8px; font-size: 14px; color: #aaa;"><?= $label ?></label>
<input type="file" name="<?= $field ?>" style="width: 100%; color: #888; font-size: 12px;">
<?php if (!empty($existingStartup[$field])):
?>
<div style="margin-top: 8px; font-size: 12px; color: var(--accent-color);">
<i class="fas fa-file-alt"></i> Already uploaded
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
</section>
<!-- Partnership & Co-founder Info -->
<section style="background: var(--card-bg); padding: 30px; border-radius: 20px; border: 1px solid var(--border-color); margin-bottom: 30px;">
<h2 style="font-size: 20px; margin-bottom: 20px;"><i class="fas fa-handshake" style="color: var(--accent-color);"></i> Partnership & Co-founder Info</h2>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Co-founder Equity (%)</label>
<input type="number" step="0.1" name="cofounder_equity_pct" value="<?= htmlspecialchars($existingStartup['cofounder_equity_pct'] ?? 0) ?>" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Equity Type</label>
<select name="cofounder_equity_type" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
<option value="Ordinary" <?= ($existingStartup['cofounder_equity_type'] ?? '') === 'Ordinary' ? 'selected' : '' ?>>Ordinary Shares</option>
<option value="Restricted" <?= ($existingStartup['cofounder_equity_type'] ?? '') === 'Restricted' ? 'selected' : '' ?>>Restricted Stock</option>
<option value="Phantom" <?= ($existingStartup['cofounder_equity_type'] ?? '') === 'Phantom' ? 'selected' : '' ?>>Phantom Equity</option>
<option value="Options" <?= ($existingStartup['cofounder_equity_type'] ?? '') === 'Options' ? 'selected' : '' ?>>Stock Options</option>
<option value="Other" <?= ($existingStartup['cofounder_equity_type'] ?? '') === 'Other' ? 'selected' : '' ?>>Other</option>
</select>
</div>
</div>
<div style="margin-top: 20px;">
<label style="display: block; margin-bottom: 8px; color: #aaa;">Co-founder Responsibilities</label>
<textarea name="cofounder_responsibilities" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff; height: 80px;" placeholder="What will the co-founder be responsible for?"><?= htmlspecialchars($existingStartup['cofounder_responsibilities'] ?? '') ?></textarea>
</div>
<div style="margin-top: 20px;">
<label style="display: block; margin-bottom: 8px; color: #aaa;">Desired Co-founder Experience</label>
<textarea name="desired_cofounder_experience" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff; height: 80px;" placeholder="What background should they have?"><?= htmlspecialchars($existingStartup['desired_cofounder_experience'] ?? '') ?></textarea>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px;">
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Commitment Required</label>
<select name="cofounder_commitment" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
<option value="Full-time" <?= ($existingStartup['cofounder_commitment'] ?? '') === 'Full-time' ? 'selected' : '' ?>>Full-time</option>
<option value="Part-time" <?= ($existingStartup['cofounder_commitment'] ?? '') === 'Part-time' ? 'selected' : '' ?>>Part-time</option>
<option value="Flexible" <?= ($existingStartup['cofounder_commitment'] ?? '') === 'Flexible' ? 'selected' : '' ?>>Flexible</option>
</select>
</div>
<div>
<label style="display: block; margin-bottom: 8px; color: #aaa;">Other Partnership Details</label>
<input type="text" name="other_partnership_details" value="<?= htmlspecialchars($existingStartup['other_partnership_details'] ?? '') ?>" style="width: 100%; padding: 12px; border-radius: 8px; background: #222; border: 1px solid #333; color: #fff;">
</div>
</div>
</section>
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 16px; border-radius: 12px; font-weight: 700; font-size: 18px;">
Save & Compute AI Recommendation
</button>
</form>
</div>
</div>
</body>
</html>