diff --git a/api/wallet_transaction.php b/api/wallet_transaction.php new file mode 100644 index 0000000..d5fa388 --- /dev/null +++ b/api/wallet_transaction.php @@ -0,0 +1,63 @@ + false, 'error' => 'Unauthorized']); + exit; +} + +$user_id = $_SESSION['user_id']; +$action = $_POST['action'] ?? ''; +$amount = (float)($_POST['amount'] ?? 0); + +if ($amount <= 0) { + header('Content-Type: application/json'); + echo json_encode(['success' => false, 'error' => 'Invalid amount']); + exit; +} + +try { + db()->beginTransaction(); + + // Fetch current balance + $stmt = db()->prepare("SELECT balance FROM users WHERE id = ? FOR UPDATE"); + $stmt->execute([$user_id]); + $user = $stmt->fetch(); + + if (!$user) { + throw new Exception("User not found"); + } + + $current_balance = (float)$user['balance']; + + if ($action === 'add') { + $new_balance = $current_balance + $amount; + $stmt = db()->prepare("UPDATE users SET balance = ? WHERE id = ?"); + $stmt->execute([$new_balance, $user_id]); + + // Log transaction (optional but good practice, maybe later) + + db()->commit(); + echo json_encode(['success' => true, 'new_balance' => $new_balance]); + } elseif ($action === 'withdraw') { + if ($current_balance < $amount) { + throw new Exception("Insufficient funds"); + } + + $new_balance = $current_balance - $amount; + $stmt = db()->prepare("UPDATE users SET balance = ? WHERE id = ?"); + $stmt->execute([$new_balance, $user_id]); + + db()->commit(); + echo json_encode(['success' => true, 'new_balance' => $new_balance]); + } else { + throw new Exception("Invalid action"); + } + +} catch (Exception $e) { + db()->rollBack(); + header('Content-Type: application/json'); + echo json_encode(['success' => false, 'error' => $e->getMessage()]); +} diff --git a/dashboard.php b/dashboard.php index 30e21df..debbacc 100644 --- a/dashboard.php +++ b/dashboard.php @@ -65,10 +65,10 @@ $myInvestments = []; if ($user['role'] === 'founder') { $stmt = db()->prepare(" - SELECT s.*, fr.funding_goal as active_goal, fr.funding_raised as active_raised, fr.status as round_status + SELECT s.*, fr.funding_goal as active_goal, fr.funding_raised as active_raised, fr.status as round_status, fr.id as round_id FROM startups s LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active' - WHERE s.founder_id = ? + WHERE s.user_id = ? ORDER BY s.created_at DESC "); $stmt->execute([$_SESSION['user_id']]); @@ -118,6 +118,28 @@ function number_get_formatted($num) { .profile-link-card:hover { transform: translateY(-2px); } + + /* Modal Styles */ + .modal { + display: none; + position: fixed; + z-index: 1000; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: rgba(0,0,0,0.8); + backdrop-filter: blur(5px); + } + .modal-content { + background-color: #1a1a24; + margin: 10% auto; + padding: 40px; + border: 1px solid var(--border-color); + width: 400px; + border-radius: 32px; + box-shadow: 0 25px 50px rgba(0,0,0,0.5); + } @@ -172,7 +194,9 @@ function number_get_formatted($num) {

My Ventures

- + Launch Startup +
+ + Launch Startup +
@@ -208,9 +232,17 @@ function number_get_formatted($num) {
-
-
£
-
Funds Raised
+
+
+
£
+
Funds Raised
+
+ +
+ + +
+
@@ -263,6 +295,33 @@ function number_get_formatted($num) {
+ +
+
+

My Money Pot

+ +
+
+ Available Balance +
£
+
+
+ + +
+

+ + Manage your startup capital and dividend funds. + + Manage your investment capital and earnings. + +

+
+

My Profile

@@ -304,15 +363,107 @@ function number_get_formatted($num) {
- -
-

Gatsby Premium

-

Unlock direct access to institutional investors and exclusive demo days.

- -
+ + + + + - + \ No newline at end of file diff --git a/db/migrations/19_add_balance_to_users.sql b/db/migrations/19_add_balance_to_users.sql new file mode 100644 index 0000000..ac7e34b --- /dev/null +++ b/db/migrations/19_add_balance_to_users.sql @@ -0,0 +1,2 @@ +-- Add balance to users table +ALTER TABLE users ADD COLUMN balance DECIMAL(15, 2) DEFAULT 0.00; diff --git a/invest.php b/invest.php index ffea442..3f15168 100644 --- a/invest.php +++ b/invest.php @@ -14,7 +14,7 @@ if (!$startupId) { } $stmt = db()->prepare(" - SELECT s.*, fr.id as round_id, fr.funding_goal, fr.funding_raised, fr.status as round_status + SELECT s.*, fr.id as round_id, fr.funding_goal, fr.funding_raised, fr.status as round_status, s.user_id as founder_id FROM startups s LEFT JOIN funding_rounds fr ON s.id = fr.startup_id AND fr.status = 'Active' WHERE s.id = ? @@ -33,18 +33,23 @@ if ($startup['round_status'] !== 'Active') { $error = ''; $success = ''; +// Get investor's current balance +$stmt = db()->prepare("SELECT balance FROM users WHERE id = ?"); +$stmt->execute([$_SESSION['user_id']]); +$investor_balance = (float)$stmt->fetchColumn(); + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $amount = (float)($_POST['amount'] ?? 0); $investor_id = $_SESSION['user_id']; if ($amount <= 0) { $error = "Please enter a valid investment amount."; + } elseif ($amount > $investor_balance) { + $error = "Insufficient funds in your money pot. Please add funds first."; } else { db()->beginTransaction(); try { // 1. Create investment record - // Note: We'll assume 1% equity for every £1000 for simplicity or use a formula - // Actually let's look at the database schema for investments $equity_pct = 0.00; // Mock logic for equity $stmt = db()->prepare("INSERT INTO investments (startup_id, investor_id, funding_round_id, amount, equity_pct, status) VALUES (?, ?, ?, ?, ?, 'approved')"); @@ -58,8 +63,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $stmt = db()->prepare("UPDATE startups SET funding_raised = funding_raised + ? WHERE id = ?"); $stmt->execute([$amount, $startupId]); + // 4. TRANSFER MONEY: Investor pot -> Founder pot + // Deduct from investor + $stmt = db()->prepare("UPDATE users SET balance = balance - ? WHERE id = ?"); + $stmt->execute([$amount, $investor_id]); + + // Add to founder + $stmt = db()->prepare("UPDATE users SET balance = balance + ? WHERE id = ?"); + $stmt->execute([$amount, $startup['founder_id']]); + db()->commit(); - $success = "Investment of £" . number_format($amount) . " confirmed successfully!"; + $success = "Investment of £" . number_format($amount) . " confirmed successfully! Funds moved to the founder's pot."; header("refresh:3;url=portfolio.php"); } catch (Exception $e) { db()->rollBack(); @@ -87,6 +101,15 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby'; You are participating in the active funding round for this startup.

+ +
+
+ Your Wallet Balance +
£
+
+ Add Funds +
+
@@ -133,4 +156,4 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
- + \ No newline at end of file diff --git a/portfolio.php b/portfolio.php index d01ffca..25d4aeb 100644 --- a/portfolio.php +++ b/portfolio.php @@ -42,6 +42,29 @@ foreach ($myInvestments as $inv) { + @@ -63,6 +86,12 @@ foreach ($myInvestments as $inv) { Messages
+ +
+ + £ +
+ @@ -140,6 +169,25 @@ foreach ($myInvestments as $inv) {
+ + + - + + - \ No newline at end of file + diff --git a/startup_details.php b/startup_details.php index 2d5f832..8049270 100644 --- a/startup_details.php +++ b/startup_details.php @@ -32,7 +32,7 @@ if (!$startup) { } // Check if user is the founder or an investor -$isFounder = ($_SESSION['user_id'] == $startup['founder_id']); +$isFounder = ($_SESSION['user_id'] == $startup['user_id']); $isInvestor = ($user['role'] == 'investor'); // Basic permissions check @@ -70,7 +70,7 @@ if ($isFounder) { // Fetch founders $stmt = db()->prepare("SELECT id, full_name as name FROM users WHERE id = ?"); -$stmt->execute([$startup['founder_id']]); +$stmt->execute([$startup['user_id']]); $founder = $stmt->fetch(); $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby'; @@ -233,6 +233,28 @@ function getNextDividendInfo($createdAt) { .btn-finish-small:hover { background: rgba(48, 209, 88, 0.1); } + + /* Modal Styles */ + .modal { + display: none; + position: fixed; + z-index: 2000; + left: 0; + top: 0; + width: 100%; + height: 100%; + background-color: rgba(0,0,0,0.85); + backdrop-filter: blur(8px); + } + .modal-content { + background-color: #1a1a24; + margin: 10% auto; + padding: 40px; + border: 1px solid var(--border-color); + width: 420px; + border-radius: 32px; + box-shadow: 0 25px 60px rgba(0,0,0,0.7); + } @@ -255,6 +277,12 @@ function getNextDividendInfo($createdAt) { Messages
+ +
+ + £ +
+
@@ -296,7 +324,7 @@ function getNextDividendInfo($createdAt) {
- + Message Founder @@ -352,6 +380,32 @@ function getNextDividendInfo($createdAt) { + + +
+
+

Startup Money Pot

+
+ + +
+
+
+
+
Available Capital
+
£
+
+
+
Total Investments Received
+
£
+
+
+

+ This pot holds all investments received. You can withdraw funds for business operations or add funds to cover investor dividends. +

+
+ +
@@ -522,9 +576,90 @@ function getNextDividendInfo($createdAt) {
+ + +

© Gatsby Capitalist Platform. All rights reserved.

+ + - \ No newline at end of file +