Add market data scope

This commit is contained in:
hackerESQ
2024-08-28 15:19:20 -05:00
parent 8a136fe1d7
commit e684c1f4a3
4 changed files with 27 additions and 27 deletions
+2 -7
View File
@@ -46,15 +46,10 @@ class Portfolio extends Model
->withCount(['transactions as num_transactions' => function ($query) {
$query->portfolio($this->id);
}])
->withAggregate('market_data', 'name')
->withAggregate('market_data', 'market_value')
->withAggregate('market_data', 'fifty_two_week_low')
->withAggregate('market_data', 'fifty_two_week_high')
->withAggregate('market_data', 'updated_at')
->withMarketData()
->selectRaw('COALESCE(market_data.market_value * holdings.quantity, 0) AS total_market_value')
->selectRaw('COALESCE((market_data.market_value - holdings.average_cost_basis) * holdings.quantity, 0) AS market_gain_dollars')
->selectRaw('COALESCE(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis), 0) AS market_gain_percent')
->join('market_data', 'holdings.symbol', 'market_data.symbol');
->selectRaw('COALESCE(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis), 0) AS market_gain_percent');
}
public function transactions()