fix: export daily change dates transposition

reference #148
This commit is contained in:
hackerESQ
2025-11-04 19:59:33 -06:00
parent bb0a0ef928
commit 5f583de857
3 changed files with 20 additions and 3 deletions
+18 -1
View File
@@ -33,7 +33,24 @@ class DailyChangesSheet implements FromCollection, WithHeadings, WithTitle
*/ */
public function collection() 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 public function title(): string
+1 -1
View File
@@ -58,7 +58,7 @@ class TransactionsSheet implements FromCollection, WithHeadings, WithTitle
'currency' => $transaction->market_data_currency, 'currency' => $transaction->market_data_currency,
'split' => $transaction->split, 'split' => $transaction->split,
'reinvested_dividend' => $transaction->reinvested_dividend, 'reinvested_dividend' => $transaction->reinvested_dividend,
'date' => $transaction->date, 'date' => date_format($transaction->date, 'Y-m-d'),
'created_at' => $transaction->created_at, 'created_at' => $transaction->created_at,
'updated_at' => $transaction->updated_at, 'updated_at' => $transaction->updated_at,
]; ];
+1 -1
View File
@@ -121,7 +121,7 @@ class DailyChange extends Model
->groupBy('portfolio_id', 'date'); ->groupBy('portfolio_id', 'date');
return $query 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('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('SUM(COALESCE(ccb.cumulative_cost_basis, 0)) AS total_cost_basis')
->selectRaw('daily_change.total_market_value * COALESCE(cr.rate, 1) ->selectRaw('daily_change.total_market_value * COALESCE(cr.rate, 1)