'1M', 'name' => '1 month', 'method' => 'subMonths', 'args' => [1]], ['id' => '3M', 'name' => '3 months', 'method' => 'subMonths', 'args' => [3]], ['id' => 'YTD', 'name' => 'Year to date', 'method' => 'startOfYear', 'args' => []], ['id' => '1Y', 'name' => '1 year', 'method' => 'subYears', 'args' => [1]], ['id' => '3Y', 'name' => '3 years', 'method' => 'subYears', 'args' => [3]], ['id' => 'ALL', 'name' => 'All time', 'method' => null], ]; // data public array $chartSeries; // methods public function mount() { $this->chartSeries = $this->generatePerformanceData(); } public function generatePerformanceData() { $filterMethod = collect($this->scopeOptions)->where('id', $this->scope)->first(); $dailyChangeQuery = DailyChange::withDailyPerformance(); if (isset($this->portfolio)) { // portfolio $dailyChangeQuery->portfolio($this->portfolio->id); } else { // dashboard $dailyChangeQuery->myDailyChanges()->withoutWishlists(); } if ($filterMethod['method']) { $dailyChangeQuery->whereDate('daily_change.date', '>=', now()->{$filterMethod['method']}(...$filterMethod['args'])); } $dailyChange = $dailyChangeQuery->get(); $dailyChange = $dailyChange ->sortBy('date') ->groupBy('date') ->map(function ($group) { return (object) [ 'date' => $group->first()->date->toDateString(), 'total_market_value' => $group->sum('total_market_value'), 'total_cost_basis' => $group->sum('total_cost_basis'), 'total_gain' => $group->sum('total_gain'), 'realized_gain_dollars' => $group->sum('realized_gain_dollars'), 'total_dividends_earned' => $group->sum('total_dividends_earned'), ]; }) ->values(); return [ 'series' => [ [ 'name' => __('Market Value'), 'data' => $dailyChange->map(fn ($data) => [$data->date, $data->total_market_value])->toArray(), ], [ 'name' => __('Cost Basis'), 'data' => $dailyChange->map(fn ($data) => [$data->date, $data->total_cost_basis])->toArray(), ], [ 'name' => __('Market Gain'), 'data' => $dailyChange->map(fn ($data) => [$data->date, $data->total_gain])->toArray(), ], // [ // 'name' => __('Dividends Earned'), // 'data' => $dailyChange->map(fn($data) => [$data->date, $data->total_dividends_earned])->toArray() // ], // [ // 'name' => __('Realized Gains'), // 'data' => $dailyChange->map(fn($data) => [$data->date, $data->realized_gains])->toArray() // ], ], ]; } public function changeScope($scope) { $this->scope = $scope; $this->chartSeries = $this->generatePerformanceData(); } public function getScopeName($scope) { return collect($this->scopeOptions)->where('id', $scope)->first()['name']; } }; ?>

{{ __('Performance') }}

{{-- --}} @foreach($scopeOptions as $option) @endforeach