From 5f583de857db5560b5a66858375987d2e53d7ed5 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Tue, 4 Nov 2025 19:59:33 -0600 Subject: [PATCH] fix: export daily change dates transposition reference #148 --- app/Exports/Sheets/DailyChangesSheet.php | 19 ++++++++++++++++++- app/Exports/Sheets/TransactionsSheet.php | 2 +- app/Models/DailyChange.php | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/Exports/Sheets/DailyChangesSheet.php b/app/Exports/Sheets/DailyChangesSheet.php index 909e0c4..4366750 100644 --- a/app/Exports/Sheets/DailyChangesSheet.php +++ b/app/Exports/Sheets/DailyChangesSheet.php @@ -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 diff --git a/app/Exports/Sheets/TransactionsSheet.php b/app/Exports/Sheets/TransactionsSheet.php index f8426ba..7c3f3ad 100644 --- a/app/Exports/Sheets/TransactionsSheet.php +++ b/app/Exports/Sheets/TransactionsSheet.php @@ -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, ]; diff --git a/app/Models/DailyChange.php b/app/Models/DailyChange.php index fe82cbe..003021e 100644 --- a/app/Models/DailyChange.php +++ b/app/Models/DailyChange.php @@ -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)