fix delete transaction flow
This commit is contained in:
@@ -55,7 +55,7 @@ class Holding extends Model
|
|||||||
*/
|
*/
|
||||||
public function transactions()
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class MarketData extends Model
|
|||||||
|
|
||||||
// check if new or stale
|
// check if new or stale
|
||||||
if (
|
if (
|
||||||
!$market_data->exists
|
!$market_data->exists
|
||||||
|| is_null($market_data->updated_at)
|
|| is_null($market_data->updated_at)
|
||||||
|| $market_data->updated_at->diffInMinutes(now()) >= config('market_data.refresh')
|
|| $market_data->updated_at->diffInMinutes(now()) >= config('market_data.refresh')
|
||||||
) {
|
) {
|
||||||
@@ -67,10 +67,10 @@ class MarketData extends Model
|
|||||||
|
|
||||||
// fill data
|
// fill data
|
||||||
$market_data->fill($quote->toArray());
|
$market_data->fill($quote->toArray());
|
||||||
}
|
|
||||||
|
|
||||||
// save with timestamps updated
|
// save with timestamps updated
|
||||||
$market_data->touch();
|
$market_data->touch();
|
||||||
|
}
|
||||||
|
|
||||||
return $market_data;
|
return $market_data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,44 +39,7 @@
|
|||||||
<span class="text-sm"> {{ $holding->market_data->name }} </span>
|
<span class="text-sm"> {{ $holding->market_data->name }} </span>
|
||||||
</x-slot:title>
|
</x-slot:title>
|
||||||
|
|
||||||
<div class="font-bold text-2xl py-1 flex items-center">
|
@livewire('holding-market-data', ['holding' => $holding])
|
||||||
{{ Number::currency($holding->market_data->market_value ?? 0) }}
|
|
||||||
|
|
||||||
<x-gain-loss-arrow-badge
|
|
||||||
:cost-basis="$holding->average_cost_basis"
|
|
||||||
:market-value="$holding->market_data->market_value"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span class="font-bold">{{ __('Quantity Owned') }}: </span>
|
|
||||||
{{ $holding->quantity }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span class="font-bold">{{ __('Average Cost Basis') }}: </span>
|
|
||||||
{{ Number::currency($holding->average_cost_basis ?? 0) }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span class="font-bold">{{ __('Total Cost Basis') }}: </span>
|
|
||||||
{{ Number::currency($holding->total_cost_basis ?? 0) }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span class="font-bold">{{ __('Realized Gain/Loss') }}: </span>
|
|
||||||
{{ Number::currency($holding->realized_gain_dollars ?? 0) }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
<span class="font-bold">{{ __('Dividends Earned') }}: </span>
|
|
||||||
{{ Number::currency($holding->dividends_earned ?? 0) }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="pt-2 text-sm">
|
|
||||||
{{ __('Market Data Age') }}:
|
|
||||||
{{ \Carbon\Carbon::parse($holding->market_data->updated_at)->diffForHumans() }}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
|
|
||||||
@@ -122,26 +85,7 @@
|
|||||||
|
|
||||||
<x-ib-card title="{{ __('Dividends') }}" class="md:col-span-3">
|
<x-ib-card title="{{ __('Dividends') }}" class="md:col-span-3">
|
||||||
|
|
||||||
@foreach ($holding->dividends->take(5) as $dividend)
|
@livewire('holding-dividends-list', ['holding' => $holding])
|
||||||
|
|
||||||
<x-list-item :item="$dividend">
|
|
||||||
<x-slot:value>
|
|
||||||
|
|
||||||
@php
|
|
||||||
$owned = ($dividend->purchased - $dividend->sold);
|
|
||||||
@endphp
|
|
||||||
|
|
||||||
{{ Number::currency($dividend->dividend_amount) }}
|
|
||||||
x {{ $owned }}
|
|
||||||
= {{ Number::currency($owned * $dividend->dividend_amount) }}
|
|
||||||
|
|
||||||
</x-slot:value>
|
|
||||||
<x-slot:sub-value>
|
|
||||||
{{ $dividend->date->format('F d, Y') }}
|
|
||||||
</x-slot:sub-value>
|
|
||||||
</x-list-item>
|
|
||||||
|
|
||||||
@endforeach
|
|
||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Holding;
|
||||||
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
|
new class extends Component {
|
||||||
|
|
||||||
|
// props
|
||||||
|
public Holding $holding;
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
'transaction-updated' => '$refresh',
|
||||||
|
'transaction-saved' => '$refresh'
|
||||||
|
];
|
||||||
|
|
||||||
|
// methods
|
||||||
|
|
||||||
|
}; ?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
@foreach ($holding->dividends->take(5) as $dividend)
|
||||||
|
|
||||||
|
<x-list-item :item="$dividend">
|
||||||
|
<x-slot:value>
|
||||||
|
|
||||||
|
@php
|
||||||
|
$owned = ($dividend->purchased - $dividend->sold);
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
{{ Number::currency($dividend->dividend_amount) }}
|
||||||
|
x {{ $owned }}
|
||||||
|
= {{ Number::currency($owned * $dividend->dividend_amount) }}
|
||||||
|
|
||||||
|
</x-slot:value>
|
||||||
|
<x-slot:sub-value>
|
||||||
|
{{ $dividend->date->format('F d, Y') }}
|
||||||
|
</x-slot:sub-value>
|
||||||
|
</x-list-item>
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Holding;
|
||||||
|
use Livewire\Volt\Component;
|
||||||
|
|
||||||
|
new class extends Component {
|
||||||
|
|
||||||
|
// props
|
||||||
|
public Holding $holding;
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
'transaction-updated' => '$refresh',
|
||||||
|
'transaction-saved' => '$refresh'
|
||||||
|
];
|
||||||
|
|
||||||
|
// methods
|
||||||
|
|
||||||
|
}; ?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="font-bold text-2xl py-1 flex items-center">
|
||||||
|
{{ Number::currency($holding->market_data->market_value ?? 0) }}
|
||||||
|
|
||||||
|
<x-gain-loss-arrow-badge
|
||||||
|
:cost-basis="$holding->average_cost_basis"
|
||||||
|
:market-value="$holding->market_data->market_value"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">{{ __('Quantity Owned') }}: </span>
|
||||||
|
{{ $holding->quantity }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">{{ __('Average Cost Basis') }}: </span>
|
||||||
|
{{ Number::currency($holding->average_cost_basis ?? 0) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">{{ __('Total Cost Basis') }}: </span>
|
||||||
|
{{ Number::currency($holding->total_cost_basis ?? 0) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">{{ __('Realized Gain/Loss') }}: </span>
|
||||||
|
{{ Number::currency($holding->realized_gain_dollars ?? 0) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<span class="font-bold">{{ __('Dividends Earned') }}: </span>
|
||||||
|
{{ Number::currency($holding->dividends_earned ?? 0) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p class="pt-2 text-sm">
|
||||||
|
{{ __('Market Data Age') }}:
|
||||||
|
{{ \Carbon\Carbon::parse($holding->market_data->updated_at)->diffForHumans() }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
@@ -17,7 +17,6 @@ new class extends Component {
|
|||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->headers = [
|
$this->headers = [
|
||||||
['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''],
|
['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''],
|
||||||
['key' => 'market_data_name', 'label' => __('Name'), 'sortable' => true],
|
['key' => 'market_data_name', 'label' => __('Name'), 'sortable' => true],
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ new class extends Component {
|
|||||||
|
|
||||||
$this->dispatch('transaction-saved');
|
$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()
|
public function delete()
|
||||||
@@ -93,7 +93,7 @@ new class extends Component {
|
|||||||
|
|
||||||
$this->transaction->delete();
|
$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]));
|
||||||
}
|
}
|
||||||
}; ?>
|
}; ?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user