v56
This commit is contained in:
parent
173d4d77a5
commit
cab62424f8
@ -14,7 +14,7 @@ $amount = (float)($_POST['amount'] ?? 0);
|
||||
|
||||
if ($amount <= 0) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['success' => false, 'error' => 'Invalid amount']);
|
||||
echo json_encode(['success' => false, 'error' => 'Please enter a valid amount greater than zero.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ try {
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (!$user) {
|
||||
throw new Exception("User not found");
|
||||
throw new Exception("User account not found.");
|
||||
}
|
||||
|
||||
$current_balance = (float)$user['balance'];
|
||||
@ -37,13 +37,11 @@ try {
|
||||
$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");
|
||||
throw new Exception("Insufficient funds. Your current balance is £" . number_format($current_balance, 2) . ".");
|
||||
}
|
||||
|
||||
$new_balance = $current_balance - $amount;
|
||||
@ -53,11 +51,11 @@ try {
|
||||
db()->commit();
|
||||
echo json_encode(['success' => true, 'new_balance' => $new_balance]);
|
||||
} else {
|
||||
throw new Exception("Invalid action");
|
||||
throw new Exception("Invalid wallet action requested.");
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
db()->rollBack();
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
@ -123,22 +123,22 @@ function number_get_formatted($num) {
|
||||
.modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
z-index: 2000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0,0,0,0.8);
|
||||
backdrop-filter: blur(5px);
|
||||
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: 400px;
|
||||
width: 420px;
|
||||
border-radius: 32px;
|
||||
box-shadow: 0 25px 50px rgba(0,0,0,0.5);
|
||||
box-shadow: 0 25px 60px rgba(0,0,0,0.7);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
@ -162,6 +162,12 @@ function number_get_formatted($num) {
|
||||
<a href="messages.php">Messages</a>
|
||||
</nav>
|
||||
<div style="display: flex; align-items: center; gap: 15px;">
|
||||
<!-- Money Pot Widget in Header -->
|
||||
<div onclick="openWalletModal('add')" style="cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 5px 12px; background: rgba(0, 242, 255, 0.1); border-radius: 50px; border: 1px solid rgba(0, 242, 255, 0.2);">
|
||||
<i class="fas fa-wallet" style="color: var(--accent-blue); font-size: 12px;"></i>
|
||||
<span id="header-wallet-balance" style="font-size: 13px; font-weight: 800; color: #fff;">£<?= number_format($user['balance'], 2) ?></span>
|
||||
</div>
|
||||
|
||||
<a href="notifications.php" style="color: var(--text-secondary); position: relative; font-size: 18px;">
|
||||
<i class="fas fa-bell"></i>
|
||||
</a>
|
||||
@ -422,7 +428,13 @@ document.getElementById('wallet-form').addEventListener('submit', function(e) {
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
document.getElementById('wallet-balance').innerText = '£' + parseFloat(data.new_balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
|
||||
const formattedBalance = '£' + parseFloat(data.new_balance).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
|
||||
if (document.getElementById('wallet-balance')) {
|
||||
document.getElementById('wallet-balance').innerText = formattedBalance;
|
||||
}
|
||||
if (document.getElementById('header-wallet-balance')) {
|
||||
document.getElementById('header-wallet-balance').innerText = formattedBalance;
|
||||
}
|
||||
closeWalletModal();
|
||||
alert(formData.get('action') === 'add' ? 'Funds added successfully!' : 'Withdrawal successful!');
|
||||
} else {
|
||||
@ -466,4 +478,4 @@ window.onclick = function(event) {
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
18
invest.php
18
invest.php
@ -41,11 +41,14 @@ $investor_balance = (float)$stmt->fetchColumn();
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$amount = (float)($_POST['amount'] ?? 0);
|
||||
$investor_id = $_SESSION['user_id'];
|
||||
$remaining = $startup['funding_goal'] - $startup['funding_raised'];
|
||||
|
||||
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.";
|
||||
} elseif ($amount > $remaining) {
|
||||
$error = "You cannot invest more than the remaining goal (£" . number_format($remaining, 2) . ").";
|
||||
} else {
|
||||
db()->beginTransaction();
|
||||
try {
|
||||
@ -73,7 +76,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$stmt->execute([$amount, $startup['founder_id']]);
|
||||
|
||||
db()->commit();
|
||||
$success = "Investment of £" . number_format($amount) . " confirmed successfully! Funds moved to the founder's pot.";
|
||||
$success = "Investment of £" . number_format($amount, 2) . " confirmed successfully! Funds moved to the founder's pot.";
|
||||
header("refresh:3;url=portfolio.php");
|
||||
} catch (Exception $e) {
|
||||
db()->rollBack();
|
||||
@ -89,6 +92,9 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Invest in <?= htmlspecialchars($startup['name']) ?> | <?= htmlspecialchars($platformName) ?></title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?= time() ?>">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
||||
</head>
|
||||
@ -124,25 +130,25 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
||||
<div style="background: rgba(255,255,255,0.03); padding: 25px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.05); margin-bottom: 30px;">
|
||||
<div style="display: flex; justify-content: space-between; margin-bottom: 15px;">
|
||||
<span style="color: #999;">Funding Goal</span>
|
||||
<span style="font-weight: 700;">£<?= number_format($startup['funding_goal']) ?></span>
|
||||
<span style="font-weight: 700;">£<?= number_format($startup['funding_goal'], 2) ?></span>
|
||||
</div>
|
||||
<div style="display: flex; justify-content: space-between; margin-bottom: 15px;">
|
||||
<span style="color: #999;">Already Raised</span>
|
||||
<span style="font-weight: 700;">£<?= number_format($startup['funding_raised']) ?></span>
|
||||
<span style="font-weight: 700;">£<?= number_format($startup['funding_raised'], 2) ?></span>
|
||||
</div>
|
||||
<?php
|
||||
$remaining = $startup['funding_goal'] - $startup['funding_raised'];
|
||||
?>
|
||||
<div style="display: flex; justify-content: space-between; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.05);">
|
||||
<span style="color: #999;">Remaining</span>
|
||||
<span style="font-weight: 900; color: var(--accent-blue);">£<?= number_format(max(0, $remaining)) ?></span>
|
||||
<span style="font-weight: 900; color: var(--accent-blue);">£<?= number_format(max(0, $remaining), 2) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="POST">
|
||||
<div style="margin-bottom: 30px;">
|
||||
<label style="display: block; margin-bottom: 10px; font-weight: 600; color: #999; text-transform: uppercase; font-size: 12px; letter-spacing: 1px;">Investment Amount (£)</label>
|
||||
<input type="number" name="amount" min="1" step="1" required placeholder="Enter amount..."
|
||||
<input type="number" name="amount" min="1" step="0.01" required placeholder="Enter amount..."
|
||||
style="width: 100%; padding: 20px; background: #000; border: 1px solid rgba(255,255,255,0.1); border-radius: 16px; color: #fff; font-size: 24px; font-weight: 900;">
|
||||
</div>
|
||||
|
||||
@ -156,4 +162,4 @@ $platformName = defined('PLATFORM_NAME') ? PLATFORM_NAME : 'Gatsby';
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user