feat: show complete metrics on dashboard

This commit is contained in:
hackerESQ
2024-08-21 20:47:06 -05:00
parent 58533a454d
commit 406665217f
3 changed files with 23 additions and 14 deletions
+14 -8
View File
@@ -2,8 +2,9 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use stdClass;
use App\Models\Holding;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
@@ -14,13 +15,18 @@ class DashboardController extends Controller
{
$user = $request->user()->load('portfolios');
$dashboard = new stdClass;
$dashboard->marketGainLoss = rand(-200, 3999);
$dashboard->totalCostBasis = rand(-200, 3999);
$dashboard->totalMarketValue = rand(-200, 3999);
$dashboard->realizedGainLoss = rand(-200, 3999);
$dashboard->dividendsEarned = rand(-200, 3999);
// get portfolio metrics
$metrics = cache()->remember(
'dashboard-metrics-' . $user->id,
10,
function () {
return
Holding::query()
->getPortfolioMetrics()
->first();
}
);
return view('dashboard', compact('user', 'dashboard'));
return view('dashboard', compact('user', 'metrics'));
}
}
+5 -5
View File
@@ -7,27 +7,27 @@
<div class="grid sm:grid-cols-5 gap-5">
<x-card class="col-span-5 sm:col-span-1 bg-slate-100 dark:bg-base-200 rounded-lg">
<div class="text-sm text-gray-400 whitespace-nowrap">{{ __('Market Gain/Loss') }}</div>
<div class="font-black text-xl"> {{ Number::currency($dashboard->marketGainLoss) }} </div>
<div class="font-black text-xl"> {{ Number::currency($metrics->total_gain_dollars) }} </div>
</x-card>
<x-card class="col-span-5 sm:col-span-1 bg-slate-100 dark:bg-base-200 rounded-lg">
<div class="text-sm text-gray-400 whitespace-nowrap">{{ __('Total Cost Basis') }}</div>
<div class="font-black text-xl"> {{ Number::currency($dashboard->totalCostBasis) }} </div>
<div class="font-black text-xl"> {{ Number::currency($metrics->total_cost_basis) }} </div>
</x-card>
<x-card class="col-span-5 sm:col-span-1 bg-slate-100 dark:bg-base-200 rounded-lg">
<div class="text-sm text-gray-400 whitespace-nowrap">{{ __('Total Market Value') }}</div>
<div class="font-black text-xl"> {{ Number::currency($dashboard->totalMarketValue) }} </div>
<div class="font-black text-xl"> {{ Number::currency($metrics->total_market_value) }} </div>
</x-card>
<x-card class="col-span-5 sm:col-span-1 bg-slate-100 dark:bg-base-200 rounded-lg">
<div class="text-sm text-gray-400 whitespace-nowrap">{{ __('Realized Gain/Loss') }}</div>
<div class="font-black text-xl"> {{ Number::currency($dashboard->realizedGainLoss) }} </div>
<div class="font-black text-xl"> {{ Number::currency($metrics->realized_gain_dollars) }} </div>
</x-card>
<x-card class="col-span-5 sm:col-span-1 bg-slate-100 dark:bg-base-200 rounded-lg">
<div class="text-sm text-gray-400 whitespace-nowrap">{{ __('Dividends Earned') }}</div>
<div class="font-black text-xl"> {{ Number::currency($dashboard->dividendsEarned) }} </div>
<div class="font-black text-xl"> {{ Number::currency($metrics->total_dividends_earned) }} </div>
</x-card>
</div>
@@ -37,7 +37,9 @@ new class extends Component {
if (isset($this->portfolio)) {
$dailyChangeQuery->portfolio($this->portfolio->id);
} else {
$dailyChangeQuery->selectRaw('date,
SUM(total_market_value) as total_market_value,
SUM(total_cost_basis) as total_cost_basis,
@@ -48,11 +50,12 @@ new class extends Component {
}
if ($filterMethod['method']) {
$dailyChangeQuery->whereDate('date', '>=', now()->{$filterMethod['method']}(...$filterMethod['args']));
}
$dailyChange = $dailyChangeQuery->get();
return [
'series' => [
[