diff --git a/app/Models/Holding.php b/app/Models/Holding.php
index 085848a..b87d6d9 100644
--- a/app/Models/Holding.php
+++ b/app/Models/Holding.php
@@ -55,7 +55,7 @@ class Holding extends Model
*/
public function transactions()
{
- return $this->hasManyThrough(Transaction::class, Portfolio::class, 'id', 'portfolio_id', 'portfolio_id', 'id');
+ return $this->hasManyThrough(Transaction::class, Portfolio::class, 'id', 'portfolio_id', 'portfolio_id', 'id')->orderBy('date', 'DESC');
}
/**
diff --git a/app/Models/MarketData.php b/app/Models/MarketData.php
index 4eb6fa1..84a6070 100644
--- a/app/Models/MarketData.php
+++ b/app/Models/MarketData.php
@@ -57,7 +57,7 @@ class MarketData extends Model
// check if new or stale
if (
- !$market_data->exists
+ !$market_data->exists
|| is_null($market_data->updated_at)
|| $market_data->updated_at->diffInMinutes(now()) >= config('market_data.refresh')
) {
@@ -67,10 +67,10 @@ class MarketData extends Model
// fill data
$market_data->fill($quote->toArray());
- }
- // save with timestamps updated
- $market_data->touch();
+ // save with timestamps updated
+ $market_data->touch();
+ }
return $market_data;
}
diff --git a/resources/views/holding/show.blade.php b/resources/views/holding/show.blade.php
index ee28cb8..da5c2f6 100644
--- a/resources/views/holding/show.blade.php
+++ b/resources/views/holding/show.blade.php
@@ -39,44 +39,7 @@
{{ $holding->market_data->name }}
-
- {{ Number::currency($holding->market_data->market_value ?? 0) }}
-
-
-
-
-
- {{ __('Quantity Owned') }}:
- {{ $holding->quantity }}
-
-
-
- {{ __('Average Cost Basis') }}:
- {{ Number::currency($holding->average_cost_basis ?? 0) }}
-
-
-
- {{ __('Total Cost Basis') }}:
- {{ Number::currency($holding->total_cost_basis ?? 0) }}
-
-
-
- {{ __('Realized Gain/Loss') }}:
- {{ Number::currency($holding->realized_gain_dollars ?? 0) }}
-
-
-
- {{ __('Dividends Earned') }}:
- {{ Number::currency($holding->dividends_earned ?? 0) }}
-
-
-
- {{ __('Market Data Age') }}:
- {{ \Carbon\Carbon::parse($holding->market_data->updated_at)->diffForHumans() }}
-
+ @livewire('holding-market-data', ['holding' => $holding])
@@ -122,26 +85,7 @@
- @foreach ($holding->dividends->take(5) as $dividend)
-
-
-
-
- @php
- $owned = ($dividend->purchased - $dividend->sold);
- @endphp
-
- {{ Number::currency($dividend->dividend_amount) }}
- x {{ $owned }}
- = {{ Number::currency($owned * $dividend->dividend_amount) }}
-
-
-
- {{ $dividend->date->format('F d, Y') }}
-
-
-
- @endforeach
+ @livewire('holding-dividends-list', ['holding' => $holding])
diff --git a/resources/views/livewire/holding-dividends-list.blade.php b/resources/views/livewire/holding-dividends-list.blade.php
new file mode 100644
index 0000000..3cc6ad7
--- /dev/null
+++ b/resources/views/livewire/holding-dividends-list.blade.php
@@ -0,0 +1,41 @@
+ '$refresh',
+ 'transaction-saved' => '$refresh'
+ ];
+
+ // methods
+
+}; ?>
+
+
+ @foreach ($holding->dividends->take(5) as $dividend)
+
+
+
+
+ @php
+ $owned = ($dividend->purchased - $dividend->sold);
+ @endphp
+
+ {{ Number::currency($dividend->dividend_amount) }}
+ x {{ $owned }}
+ = {{ Number::currency($owned * $dividend->dividend_amount) }}
+
+
+
+ {{ $dividend->date->format('F d, Y') }}
+
+
+
+ @endforeach
+
\ No newline at end of file
diff --git a/resources/views/livewire/holding-market-data.blade.php b/resources/views/livewire/holding-market-data.blade.php
new file mode 100644
index 0000000..3ce1686
--- /dev/null
+++ b/resources/views/livewire/holding-market-data.blade.php
@@ -0,0 +1,59 @@
+ '$refresh',
+ 'transaction-saved' => '$refresh'
+ ];
+
+ // methods
+
+}; ?>
+
+
+
+ {{ Number::currency($holding->market_data->market_value ?? 0) }}
+
+
+
+
+
+ {{ __('Quantity Owned') }}:
+ {{ $holding->quantity }}
+
+
+
+ {{ __('Average Cost Basis') }}:
+ {{ Number::currency($holding->average_cost_basis ?? 0) }}
+
+
+
+ {{ __('Total Cost Basis') }}:
+ {{ Number::currency($holding->total_cost_basis ?? 0) }}
+
+
+
+ {{ __('Realized Gain/Loss') }}:
+ {{ Number::currency($holding->realized_gain_dollars ?? 0) }}
+
+
+
+ {{ __('Dividends Earned') }}:
+ {{ Number::currency($holding->dividends_earned ?? 0) }}
+
+
+
+ {{ __('Market Data Age') }}:
+ {{ \Carbon\Carbon::parse($holding->market_data->updated_at)->diffForHumans() }}
+
+
\ No newline at end of file
diff --git a/resources/views/livewire/holdings-table.blade.php b/resources/views/livewire/holdings-table.blade.php
index 7a11a3d..c67a008 100644
--- a/resources/views/livewire/holdings-table.blade.php
+++ b/resources/views/livewire/holdings-table.blade.php
@@ -17,7 +17,6 @@ new class extends Component {
public function mount()
{
-
$this->headers = [
['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''],
['key' => 'market_data_name', 'label' => __('Name'), 'sortable' => true],
diff --git a/resources/views/livewire/manage-transaction-form.blade.php b/resources/views/livewire/manage-transaction-form.blade.php
index 97bebcb..f160304 100644
--- a/resources/views/livewire/manage-transaction-form.blade.php
+++ b/resources/views/livewire/manage-transaction-form.blade.php
@@ -85,7 +85,7 @@ new class extends Component {
$this->dispatch('transaction-saved');
- $this->success(__('Transaction created'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
+ $this->success(__('Transaction created'), redirectTo: route('holding.show', ['portfolio' => $this->portfolio->id, 'symbol' => $this->symbol]));
}
public function delete()
@@ -93,7 +93,7 @@ new class extends Component {
$this->transaction->delete();
- $this->success(__('Transaction deleted'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
+ $this->success(__('Transaction deleted'), redirectTo: route('holding.show', ['portfolio' => $this->portfolio->id, 'symbol' => $this->symbol]));
}
}; ?>