29 lines
1.1 KiB
PHP
29 lines
1.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
echo "Recalculating funding totals...\n";
|
|
|
|
// 1. Reset all funding_raised to 0
|
|
db()->exec("UPDATE startups SET funding_raised = 0");
|
|
db()->exec("UPDATE funding_rounds SET funding_raised = 0");
|
|
|
|
// 2. Fetch all approved/pending investments (usually we only count approved, but let's see)
|
|
// Actually, let's count all investments that are not rejected
|
|
$stmt = db()->query("SELECT startup_id, funding_round_id, SUM(amount) as total FROM investments WHERE status != 'rejected' GROUP BY startup_id, funding_round_id");
|
|
$totals = $stmt->fetchAll();
|
|
|
|
foreach ($totals as $t) {
|
|
echo "Updating Startup ID: {$t['startup_id']}, Round ID: {$t['funding_round_id']} with £{$t['total']}\n";
|
|
|
|
// Update funding_rounds
|
|
$stmt2 = db()->prepare("UPDATE funding_rounds SET funding_raised = ? WHERE id = ?");
|
|
$stmt2->execute([$t['total'], $t['funding_round_id']]);
|
|
|
|
// Update startups
|
|
$stmt3 = db()->prepare("UPDATE startups SET funding_raised = ? WHERE id = ?");
|
|
$stmt3->execute([$t['total'], $t['startup_id']]);
|
|
}
|
|
|
|
echo "Done!\n";
|
|
|