38873-vm/create_startup.php
Flatlogic Bot a7855afce8 v31
2026-02-28 19:47:28 +00:00

357 lines
21 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'ai/LocalAIApi.php';
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'founder') {
header('Location: login.php');
exit;
}
$error = '';
$success = '';
$startup_id = $_GET['id'] ?? null;
$existingStartup = null;
if ($startup_id) {
$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: dashboard.php');
exit;
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$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'] ?? '';
// Co-founder matching fields
$cofounder_equity_pct = $_POST['cofounder_equity_pct'] ?? '';
$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);
$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);
}
$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) {
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;
}
} elseif ($existingStartup && !empty($existingStartup[$field])) {
$uploaded_paths[$field] = $existingStartup[$field];
} else {
$error = "The financial document for $field is mandatory.";
break;
}
}
if (!$error) {
if (empty($name) || 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.";
}
}
if (!$error) {
db()->beginTransaction();
try {
// Compute AI Recommended Return Rate
$recommended_return_rate = $existingStartup['recommended_return_rate'] ?? 0.0;
// AI Prompt
$prompt = "As a financial analyst, calculate a recommended annual dividend yield (interest percentage) based on this startup profile:
Name: {$name}
Industry: {$industry}/{$sub_industry}
Business Model: {$business_model}
Product: {$product_service}
Stage: {$operational_stage}
Cash Balance: £{$current_cash_balance}
Burn Rate: £{$burn_rate}
Respond ONLY with a JSON object: {\"recommended_rate\": X.X}";
$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);
}
if ($existingStartup) {
$stmt = db()->prepare("UPDATE startups SET
name = ?, 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 = ?, 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 = ?
WHERE id = ? AND founder_id = ?");
$stmt->execute([
$name, $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, $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']
]);
$final_id = $existingStartup['id'];
} else {
$stmt = db()->prepare("INSERT INTO startups (
name, 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, 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')");
$stmt->execute([
$name, $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, $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
]);
$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">
<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>
<?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(76, 217, 100, 0.1); color: #4cd964; padding: 15px; border-radius: 12px; border: 1px solid #4cd964; margin-bottom: 25px;">
<i class="fas fa-check-circle"></i> <?= $success ?>
<div style="margin-top: 10px;">
<a href="startup_details.php?id=<?= $final_id ?>" class="btn btn-secondary" style="padding: 8px 15px; font-size: 13px;">View Live Profile</a>
</div>
</div>
<?php endif; ?>
<?php if (!$success || $existingStartup): ?>
<form method="POST" enctype="multipart/form-data" class="card" style="padding: 30px; border-radius: 24px;">
<h3 style="margin-top: 0; margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; font-size: 18px;"><i class="fas fa-info-circle"></i> 1. Basic Company Information</h3>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
<div>
<label>Public Name (Marketing) *</label>
<input type="text" name="name" required value="<?= htmlspecialchars($existingStartup['name'] ?? '') ?>">
</div>
<div>
<label>Legal Entity Name *</label>
<input type="text" name="legal_name" required value="<?= htmlspecialchars($existingStartup['legal_name'] ?? '') ?>">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
<div>
<label>Country of Incorporation *</label>
<input type="text" name="country" required value="<?= htmlspecialchars($existingStartup['country'] ?? '') ?>">
</div>
<div>
<label>Primary Industry *</label>
<select name="industry" required>
<option value="">Select...</option>
<option value="FinTech" <?= ($existingStartup['industry'] ?? '') === 'FinTech' ? 'selected' : '' ?>>FinTech</option>
<option value="HealthTech" <?= ($existingStartup['industry'] ?? '') === 'HealthTech' ? 'selected' : '' ?>>HealthTech</option>
<option value="SaaS" <?= ($existingStartup['industry'] ?? '') === 'SaaS' ? 'selected' : '' ?>>SaaS</option>
<option value="E-commerce" <?= ($existingStartup['industry'] ?? '') === 'E-commerce' ? 'selected' : '' ?>>E-commerce</option>
<option value="CleanTech" <?= ($existingStartup['industry'] ?? '') === 'CleanTech' ? 'selected' : '' ?>>CleanTech</option>
<option value="EdTech" <?= ($existingStartup['industry'] ?? '') === 'EdTech' ? 'selected' : '' ?>>EdTech</option>
<option value="Other" <?= ($existingStartup['industry'] ?? '') === 'Other' ? 'selected' : '' ?>>Other</option>
</select>
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
<div>
<label>Sub-Industry / Niche</label>
<input type="text" name="sub_industry" value="<?= htmlspecialchars($existingStartup['sub_industry'] ?? '') ?>" placeholder="e.g. AI-driven logistics">
</div>
<div>
<label>Business Model *</label>
<select name="business_model" required>
<option value="">Select...</option>
<option value="B2B" <?= ($existingStartup['business_model'] ?? '') === 'B2B' ? 'selected' : '' ?>>B2B</option>
<option value="B2C" <?= ($existingStartup['business_model'] ?? '') === 'B2C' ? 'selected' : '' ?>>B2C</option>
<option value="Marketplace" <?= ($existingStartup['business_model'] ?? '') === 'Marketplace' ? 'selected' : '' ?>>Marketplace</option>
<option value="SaaS" <?= ($existingStartup['business_model'] ?? '') === 'SaaS' ? 'selected' : '' ?>>SaaS Subscription</option>
</select>
</div>
</div>
<div style="margin-bottom: 20px;">
<label>Operational Stage *</label>
<select name="operational_stage" required>
<option value="">Select...</option>
<option value="Pre-revenue" <?= ($existingStartup['operational_stage'] ?? '') === 'Pre-revenue' ? 'selected' : '' ?>>Pre-revenue / Prototype</option>
<option value="Early-traction" <?= ($existingStartup['operational_stage'] ?? '') === 'Early-traction' ? 'selected' : '' ?>>Early Traction (Paying customers)</option>
<option value="Growth" <?= ($existingStartup['operational_stage'] ?? '') === 'Growth' ? 'selected' : '' ?>>Growth (Consistent MRR)</option>
<option value="Scale" <?= ($existingStartup['operational_stage'] ?? '') === 'Scale' ? 'selected' : '' ?>>Scaling (National/International)</option>
</select>
</div>
<div style="margin-bottom: 30px;">
<label>Briefly describe your Product/Service *</label>
<textarea name="product_service" required style="height: 80px;"><?= htmlspecialchars($existingStartup['product_service'] ?? '') ?></textarea>
</div>
<h3 style="margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; font-size: 18px;"><i class="fas fa-handshake"></i> 2. Co-founder Matching & Partnership</h3>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
<div>
<label>Equity Offered (%)</label>
<input type="text" name="cofounder_equity_pct" value="<?= htmlspecialchars($existingStartup['cofounder_equity_pct'] ?? '') ?>" placeholder="e.g. 10-15%">
</div>
<div>
<label>Commitment Level</label>
<input type="text" name="cofounder_commitment" value="<?= htmlspecialchars($existingStartup['cofounder_commitment'] ?? '') ?>" placeholder="e.g. Full-time">
</div>
</div>
<div style="margin-bottom: 20px;">
<label>Equity Type</label>
<input type="text" name="cofounder_equity_type" value="<?= htmlspecialchars($existingStartup['cofounder_equity_type'] ?? '') ?>" placeholder="e.g. Common Shares, Options">
</div>
<div style="margin-bottom: 20px;">
<label>Core Responsibilities for Co-founder</label>
<textarea name="cofounder_responsibilities" style="height: 60px;"><?= htmlspecialchars($existingStartup['cofounder_responsibilities'] ?? '') ?></textarea>
</div>
<div style="margin-bottom: 20px;">
<label>Desired Experience/Background</label>
<textarea name="desired_cofounder_experience" style="height: 60px;"><?= htmlspecialchars($existingStartup['desired_cofounder_experience'] ?? '') ?></textarea>
</div>
<div style="margin-bottom: 30px;">
<label>Other Partnership Details</label>
<textarea name="other_partnership_details" style="height: 60px;"><?= htmlspecialchars($existingStartup['other_partnership_details'] ?? '') ?></textarea>
</div>
<h3 style="margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; font-size: 18px;"><i class="fas fa-file-invoice-dollar"></i> 3. Mandatory Financials</h3>
<div style="background: rgba(255,255,255,0.03); padding: 20px; border-radius: 12px; margin-bottom: 25px;">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
<div>
<label>Current Cash Balance (£)</label>
<input type="number" step="0.01" name="current_cash_balance" value="<?= (float)($existingStartup['current_cash_balance'] ?? 0) ?>">
</div>
<div>
<label>Monthly Burn Rate (£)</label>
<input type="number" step="0.01" name="burn_rate" value="<?= (float)($existingStartup['burn_rate'] ?? 0) ?>">
</div>
</div>
<div style="margin-bottom: 20px;">
<label>Outstanding Debt</label>
<input type="text" name="outstanding_debt" value="<?= htmlspecialchars($existingStartup['outstanding_debt'] ?? '') ?>">
</div>
<div style="margin-bottom: 20px;">
<label>Accounts Receivable / Payable</label>
<input type="text" name="accounts_receivable_payable" value="<?= htmlspecialchars($existingStartup['accounts_receivable_payable'] ?? '') ?>">
</div>
</div>
<p style="font-size: 14px; font-weight: 700; color: var(--accent-blue); margin-bottom: 15px;">Historical Financial Documentation (PDF/Images)</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 30px;">
<?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 Data'
];
foreach ($doc_labels as $f_name => $label):
?>
<div class="file-input-group">
<label><?= $label ?> <?= $existingStartup ? '' : '*' ?></label>
<input type="file" name="<?= $f_name ?>" <?= $existingStartup ? '' : 'required' ?> accept=".pdf,image/*">
<?php if ($existingStartup && !empty($existingStartup[$f_name])):
?>
<span style="font-size: 10px; color: #4cd964;"><i class="fas fa-check"></i> Already uploaded</span>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%; padding: 18px; font-weight: 800; font-size: 18px; border-radius: 16px;">
<?= $existingStartup ? 'Update Profile' : 'Create Startup Profile' ?> <i class="fas fa-save" style="margin-left: 10px;"></i>
</button>
<a href="<?= $existingStartup ? 'startup_details.php?id=' . $startup_id : 'dashboard.php' ?>" style="display: block; text-align: center; margin-top: 15px; color: var(--text-secondary); text-decoration: none;">Cancel</a>
</form>
<?php endif; ?>
</div>
</div>
<style>
label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--text-secondary); }
input, select, textarea { width: 100%; padding: 12px 16px; background: var(--surface-color); border: 1px solid var(--border-color); border-radius: 12px; color: #fff; font-size: 14px; margin-bottom: 10px; }
textarea { resize: vertical; }
.file-input-group { background: rgba(255,255,255,0.02); padding: 15px; border-radius: 12px; border: 1px dashed var(--border-color); }
.file-input-group input { border: none; padding: 0; margin: 0; background: transparent; }
</style>
</body>
</html>