@@ -33,7 +33,24 @@ class DailyChangesSheet implements FromCollection, WithHeadings, WithTitle
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return $this->empty ? collect() : DailyChange::myDailyChanges()->withDailyPerformance()->get();
|
||||
if ($this->empty) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
return DailyChange::myDailyChanges()
|
||||
->withDailyPerformance()
|
||||
->get()
|
||||
->map(function ($daily_change) {
|
||||
return [
|
||||
'date' => date_format($daily_change->date, 'Y-m-d'),
|
||||
'portfolio_id' => $daily_change->portfolio_id,
|
||||
'total_market_value' => $daily_change->total_market_value,
|
||||
'total_cost_basis' => $daily_change->total_cost_basis,
|
||||
'realized_gains' => $daily_change->realized_gain_dollars,
|
||||
'total_dividends_earned' => $daily_change->total_dividends_earned,
|
||||
'annotation' => $daily_change->annotation,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function title(): string
|
||||
|
||||
@@ -58,7 +58,7 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
|
||||
'currency' => $transaction->market_data_currency,
|
||||
'split' => $transaction->split,
|
||||
'reinvested_dividend' => $transaction->reinvested_dividend,
|
||||
'date' => $transaction->date,
|
||||
'date' => date_format($transaction->date, 'Y-m-d'),
|
||||
'created_at' => $transaction->created_at,
|
||||
'updated_at' => $transaction->updated_at,
|
||||
];
|
||||
|
||||
@@ -121,7 +121,7 @@ class DailyChange extends Model
|
||||
->groupBy('portfolio_id', 'date');
|
||||
|
||||
return $query
|
||||
->select(['daily_change.portfolio_id', 'daily_change.date'])
|
||||
->select(['daily_change.date', 'daily_change.portfolio_id'])
|
||||
->selectRaw('daily_change.total_market_value * COALESCE(cr.rate, 1) AS total_market_value')
|
||||
->selectRaw('SUM(COALESCE(ccb.cumulative_cost_basis, 0)) AS total_cost_basis')
|
||||
->selectRaw('daily_change.total_market_value * COALESCE(cr.rate, 1)
|
||||
|
||||
Reference in New Issue
Block a user