347 lines
21 KiB
PHP
347 lines
21 KiB
PHP
<?php
|
|
session_start();
|
|
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'founder') {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
require_once __DIR__ . '/ai/LocalAIApi.php';
|
|
|
|
$error = '';
|
|
$success = '';
|
|
$existingStartup = null;
|
|
|
|
$startup_id = (int)($_GET['id'] ?? 0);
|
|
if ($startup_id > 0) {
|
|
$stmt = db()->prepare("SELECT * FROM startups WHERE id = ? AND founder_id = ?");
|
|
$stmt->execute([$startup_id, $_SESSION['user_id']]);
|
|
$existingStartup = $stmt->fetch();
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// Basic Info
|
|
$name = trim($_POST['name'] ?? '');
|
|
$legal_name = trim($_POST['legal_name'] ?? '');
|
|
$country = trim($_POST['country'] ?? '');
|
|
$industry = trim($_POST['industry'] ?? '');
|
|
$sub_industry = trim($_POST['sub_industry'] ?? '');
|
|
$business_model = trim($_POST['business_model'] ?? '');
|
|
$product_service = trim($_POST['product_service'] ?? '');
|
|
$operational_stage = trim($_POST['operational_stage'] ?? '');
|
|
|
|
// Co-founder Matching
|
|
$cofounder_equity_pct = trim($_POST['cofounder_equity_pct'] ?? '');
|
|
$cofounder_equity_type = trim($_POST['cofounder_equity_type'] ?? '');
|
|
$cofounder_responsibilities = trim($_POST['cofounder_responsibilities'] ?? '');
|
|
$desired_cofounder_experience = trim($_POST['desired_cofounder_experience'] ?? '');
|
|
$cofounder_commitment = trim($_POST['cofounder_commitment'] ?? '');
|
|
$other_partnership_details = trim($_POST['other_partnership_details'] ?? '');
|
|
|
|
// Current Financials
|
|
$current_cash_balance = (float)($_POST['current_cash_balance'] ?? 0);
|
|
$outstanding_debt = trim($_POST['outstanding_debt'] ?? '');
|
|
$accounts_receivable_payable = trim($_POST['accounts_receivable_payable'] ?? '');
|
|
$burn_rate = (float)($_POST['burn_rate'] ?? 0);
|
|
|
|
// File Uploads
|
|
$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',
|
|
'doc_opex_breakdown'
|
|
];
|
|
|
|
$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 = ?, doc_opex_breakdown = ?,
|
|
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'], $uploaded_paths['doc_opex_breakdown'],
|
|
$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, doc_opex_breakdown,
|
|
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'], $uploaded_paths['doc_opex_breakdown'],
|
|
$_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) . "%";
|
|
header("refresh:2;url=startup_details.php?id=" . $final_id);
|
|
} catch (Exception $e) {
|
|
db()->rollBack();
|
|
$error = "Error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
$platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title><?= $existingStartup ? 'Edit Profile' : 'Step 1: Setup Startup Profile' ?> — <?= htmlspecialchars($platformName) ?></title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<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.4.0/css/all.min.css">
|
|
</head>
|
|
<body style="padding: 60px 20px; background: #0f0f13;">
|
|
|
|
<div class="container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="card" style="padding: 40px;">
|
|
<h1 style="font-size: 32px; font-weight: 800; margin-bottom: 10px;"><?= $existingStartup ? 'Edit Startup Profile' : 'Step 1: Company Profile Setup' ?></h1>
|
|
<p style="color: var(--text-secondary); margin-bottom: 30px;">
|
|
<?= $existingStartup ? 'Update your venture details below.' : 'This information is required to establish your startup entity and calculate investor return projections.' ?>
|
|
</p>
|
|
|
|
<?php if ($error): ?>
|
|
<div style="background: rgba(255, 0, 0, 0.1); border: 1px solid rgba(255, 0, 0, 0.3); color: #ff5555; padding: 15px; border-radius: 12px; margin-bottom: 25px;">
|
|
<i class="fas fa-exclamation-circle" style="margin-right: 8px;"></i> <?= htmlspecialchars($error) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($success): ?>
|
|
<div style="background: rgba(0, 255, 0, 0.1); border: 1px solid rgba(0, 255, 0, 0.3); color: #55ff55; padding: 15px; border-radius: 12px; margin-bottom: 25px;">
|
|
<i class="fas fa-check-circle" style="margin-right: 8px;"></i> <?= htmlspecialchars($success) ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<form method="POST" enctype="multipart/form-data">
|
|
|
|
<h3 style="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>Startup Name *</label>
|
|
<input type="text" name="name" required value="<?= htmlspecialchars($existingStartup['name'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label>Registered Legal Name *</label>
|
|
<input type="text" name="legal_name" required value="<?= htmlspecialchars($existingStartup['legal_name'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label>Country of Incorporation *</label>
|
|
<input type="text" name="country" required value="<?= htmlspecialchars($existingStartup['country'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label>Industry *</label>
|
|
<select name="industry" required>
|
|
<?php $ind = $existingStartup['industry'] ?? ''; ?>
|
|
<option value="">Select Industry</option>
|
|
<option value="Fintech" <?= $ind == 'Fintech' ? 'selected' : '' ?>>Fintech</option>
|
|
<option value="Healthtech" <?= $ind == 'Healthtech' ? 'selected' : '' ?>>Healthtech</option>
|
|
<option value="Edtech" <?= $ind == 'Edtech' ? 'selected' : '' ?>>Edtech</option>
|
|
<option value="SaaS" <?= $ind == 'SaaS' ? 'selected' : '' ?>>SaaS</option>
|
|
<option value="AI & Robotics" <?= $ind == 'AI & Robotics' ? 'selected' : '' ?>>AI & Robotics</option>
|
|
<option value="Clean Energy" <?= $ind == 'Clean Energy' ? 'selected' : '' ?>>Clean Energy</option>
|
|
<option value="Other" <?= $ind == 'Other' ? 'selected' : '' ?>>Other</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label>Sub-Industry *</label>
|
|
<input type="text" name="sub_industry" required value="<?= htmlspecialchars($existingStartup['sub_industry'] ?? '') ?>">
|
|
</div>
|
|
<div>
|
|
<label>Operational Stage *</label>
|
|
<select name="operational_stage" required>
|
|
<?php $stage = $existingStartup['operational_stage'] ?? ''; ?>
|
|
<option value="">Select Stage</option>
|
|
<option value="Idea" <?= $stage == 'Idea' ? 'selected' : '' ?>>Idea / Concept</option>
|
|
<option value="MVP" <?= $stage == 'MVP' ? 'selected' : '' ?>>MVP (Minimum Viable Product)</option>
|
|
<option value="Pre-revenue" <?= $stage == 'Pre-revenue' ? 'selected' : '' ?>>Pre-revenue (Early Traction)</option>
|
|
<option value="Revenue-generating" <?= $stage == 'Revenue-generating' ? 'selected' : '' ?>>Revenue-generating</option>
|
|
<option value="Scaling" <?= $stage == 'Scaling' ? 'selected' : '' ?>>Scaling / Growth</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div style="margin-bottom: 20px;">
|
|
<label>Business Model Description *</label>
|
|
<textarea name="business_model" required style="height: 80px;"><?= htmlspecialchars($existingStartup['business_model'] ?? '') ?></textarea>
|
|
</div>
|
|
<div style="margin-bottom: 30px;">
|
|
<label>Product/Service Description *</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',
|
|
'doc_opex_breakdown' => 'OpEx Breakdown'
|
|
];
|
|
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>
|