feat: adds pgsql compatibility (#72)
This commit is contained in:
@@ -2,29 +2,31 @@
|
||||
|
||||
use App\Models\DailyChange;
|
||||
use App\Models\Portfolio;
|
||||
use Livewire\Attributes\{Title, Rule};
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
// props
|
||||
public ?Portfolio $portfolio;
|
||||
public String $name = 'portfolio';
|
||||
public String $scope = 'YTD';
|
||||
public Array $scopeOptions = [
|
||||
|
||||
public string $name = 'portfolio';
|
||||
|
||||
public string $scope = 'YTD';
|
||||
|
||||
public array $scopeOptions = [
|
||||
['id' => '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]
|
||||
['id' => 'ALL', 'name' => 'All time', 'method' => null],
|
||||
];
|
||||
|
||||
// data
|
||||
public Array $chartSeries;
|
||||
public array $chartSeries;
|
||||
|
||||
// methods
|
||||
public function mount()
|
||||
public function mount()
|
||||
{
|
||||
$this->chartSeries = $this->generatePerformanceData();
|
||||
}
|
||||
@@ -33,52 +35,53 @@ new class extends Component {
|
||||
{
|
||||
$filterMethod = collect($this->scopeOptions)->where('id', $this->scope)->first();
|
||||
|
||||
$dailyChangeQuery = DailyChange::myDailyChanges();
|
||||
$dailyChangeQuery = DailyChange::myDailyChanges()->selectRaw('
|
||||
date,
|
||||
SUM(total_market_value) as total_market_value,
|
||||
SUM(total_cost_basis) as total_cost_basis,
|
||||
SUM(total_gain) as total_gain
|
||||
/* ,
|
||||
SUM(realized_gains) as realized_gains,
|
||||
SUM(total_dividends_earned) as total_dividends_earned
|
||||
*/
|
||||
');
|
||||
|
||||
if (isset($this->portfolio)) {
|
||||
|
||||
|
||||
// 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,
|
||||
SUM(total_gain) as total_gain
|
||||
/* ,
|
||||
SUM(realized_gains) as realized_gains,
|
||||
SUM(total_dividends_earned) as total_dividends_earned
|
||||
*/
|
||||
')
|
||||
->withoutWishlists()
|
||||
->groupBy('date')
|
||||
->orderBy('date');
|
||||
|
||||
// dashboard
|
||||
$dailyChangeQuery->withoutWishlists();
|
||||
}
|
||||
|
||||
if ($filterMethod['method']) {
|
||||
|
||||
|
||||
$dailyChangeQuery->whereDate('date', '>=', now()->{$filterMethod['method']}(...$filterMethod['args']));
|
||||
}
|
||||
// dd($dailyChangeQuery->toSql());
|
||||
$dailyChange = $dailyChangeQuery->get();
|
||||
|
||||
$dailyChange = $dailyChangeQuery
|
||||
->orderBy('date')
|
||||
->groupBy('date')
|
||||
->get();
|
||||
|
||||
return [
|
||||
'series' => [
|
||||
[
|
||||
'name' => __('Market Value'),
|
||||
'data' => $dailyChange->map(fn($data) => [$data->date, $data->total_market_value])->toArray(),
|
||||
'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(),
|
||||
'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()
|
||||
'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()
|
||||
@@ -87,7 +90,7 @@ new class extends Component {
|
||||
// 'name' => __('Realized Gains'),
|
||||
// 'data' => $dailyChange->map(fn($data) => [$data->date, $data->realized_gains])->toArray()
|
||||
// ],
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -102,7 +105,6 @@ new class extends Component {
|
||||
{
|
||||
return collect($this->scopeOptions)->where('id', $scope)->first()['name'];
|
||||
}
|
||||
|
||||
}; ?>
|
||||
|
||||
<x-card class="bg-slate-100 dark:bg-base-200 rounded-lg mb-6">
|
||||
|
||||
Reference in New Issue
Block a user