temp remove dividends

This commit is contained in:
hackerESQ
2025-08-20 18:31:15 -05:00
parent c799da58e1
commit 24aeb72549
+22 -23
View File
@@ -63,7 +63,6 @@ class DailyChange extends Model
$currency = auth()->user()?->getCurrency() ?? config('investbrain.base_currency'); $currency = auth()->user()?->getCurrency() ?? config('investbrain.base_currency');
return $query return $query
// Join currency rates to get the rate for each date
->leftJoin('currency_rates as cr', function ($join) use ($currency) { ->leftJoin('currency_rates as cr', function ($join) use ($currency) {
$join->on(DB::raw('DATE(cr.date)'), '=', DB::raw('DATE(daily_change.date)')) $join->on(DB::raw('DATE(cr.date)'), '=', DB::raw('DATE(daily_change.date)'))
->where('cr.currency', '=', $currency); ->where('cr.currency', '=', $currency);
@@ -100,27 +99,27 @@ class DailyChange extends Model
->whereColumn('transactions.portfolio_id', 'daily_change.portfolio_id') ->whereColumn('transactions.portfolio_id', 'daily_change.portfolio_id')
->whereColumn('transactions.date', '<=', 'daily_change.date'); ->whereColumn('transactions.date', '<=', 'daily_change.date');
}, },
'total_dividends_earned' => function ($query) use ($currency) { // 'total_dividends_earned' => function ($query) use ($currency) {
$query->from('holdings') // $query->from('holdings')
->join('dividends', 'dividends.symbol', '=', 'holdings.symbol') // ->join('dividends', 'dividends.symbol', '=', 'holdings.symbol')
->leftJoin('currency_rates as cr', function ($join) use ($currency) { // ->leftJoin('currency_rates as cr', function ($join) use ($currency) {
$join->on(DB::raw('DATE(cr.date)'), '=', DB::raw('DATE(dividends.date)')) // $join->on(DB::raw('DATE(cr.date)'), '=', DB::raw('DATE(dividends.date)'))
->where('cr.currency', '=', $currency); // ->where('cr.currency', '=', $currency);
}) // })
->join('transactions as tx', function ($join) { // ->join('transactions as tx', function ($join) {
$join->on('tx.symbol', '=', 'holdings.symbol') // $join->on('tx.symbol', '=', 'holdings.symbol')
->on('tx.portfolio_id', '=', 'holdings.portfolio_id') // ->on('tx.portfolio_id', '=', 'holdings.portfolio_id')
->whereColumn('tx.date', '<=', 'dividends.date'); // ->whereColumn('tx.date', '<=', 'dividends.date');
}) // })
->selectRaw('SUM( // ->selectRaw('SUM(
((CASE WHEN tx.transaction_type = \'BUY\' THEN tx.quantity ELSE 0 END) // ((CASE WHEN tx.transaction_type = \'BUY\' THEN tx.quantity ELSE 0 END)
- (CASE WHEN tx.transaction_type = \'SELL\' THEN tx.quantity ELSE 0 END)) // - (CASE WHEN tx.transaction_type = \'SELL\' THEN tx.quantity ELSE 0 END))
* dividends.dividend_amount_base // * dividends.dividend_amount_base
* COALESCE(cr.rate, 1) // * COALESCE(cr.rate, 1)
)') // )')
->whereColumn('holdings.portfolio_id', 'daily_change.portfolio_id') // ->whereColumn('holdings.portfolio_id', 'daily_change.portfolio_id')
->whereColumn('dividends.date', '<=', 'daily_change.date'); // ->whereColumn('dividends.date', '<=', 'daily_change.date');
}, // },
]) ])
->orderBy('daily_change.date'); ->orderBy('daily_change.date');
} }
@@ -141,7 +140,7 @@ class DailyChange extends Model
'total_cost_basis' => $total_cost_basis, 'total_cost_basis' => $total_cost_basis,
'total_gain' => $total_market_gain, 'total_gain' => $total_market_gain,
'realized_gain_dollars' => $group->sum('realized_gain_dollars'), 'realized_gain_dollars' => $group->sum('realized_gain_dollars'),
'total_dividends_earned' => $group->sum('total_dividends_earned'), // 'total_dividends_earned' => $group->sum('total_dividends_earned'),
]; ];
}) })
->values(); ->values();