wip
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
<div role="status" class="flex w-full animate-pulse" wire:loading.delay>
|
||||
<div class="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
|
||||
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[360px] mb-2.5"></div>
|
||||
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
|
||||
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[330px] mb-2.5"></div>
|
||||
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[300px] mb-2.5"></div>
|
||||
<div class="h-2 bg-gray-200 rounded-full dark:bg-gray-700 max-w-[360px]"></div>
|
||||
<span class="sr-only">Loading...</span>
|
||||
</div>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Portfolio;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
||||
// props
|
||||
public Portfolio $portfolio;
|
||||
|
||||
public array $sortBy = ['column' => 'symbol', 'direction' => 'asc'];
|
||||
|
||||
public array $headers;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
|
||||
$this->headers = [
|
||||
['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''],
|
||||
['key' => 'market_data_name', 'label' => __('Name'), 'sortable' => true],
|
||||
['key' => 'quantity', 'label' => __('Quantity')],
|
||||
['key' => 'average_cost_basis', 'label' => __('Average Cost Basis')],
|
||||
['key' => 'total_cost_basis', 'label' => __('Total Cost Basis')],
|
||||
['key' => 'market_data_market_value', 'label' => __('Market Value')],
|
||||
['key' => 'total_market_value', 'label' => __('Total Market Value')],
|
||||
['key' => 'market_gain_loss_dollars', 'label' => __('Market Gain/Loss')],
|
||||
['key' => 'market_gain_loss_percent', 'label' => __('Market Gain/Loss')],
|
||||
['key' => 'realized_gain_loss_dollars', 'label' => __('Realized Gain/Loss')],
|
||||
['key' => 'dividends_earned', 'label' => __('Dividends Earned')],
|
||||
['key' => 'market_data_fifty_two_week_low', 'label' => __('52 week low')],
|
||||
['key' => 'market_data_fifty_two_week_high', 'label' => __('52 week high')],
|
||||
['key' => 'num_transactions', 'label' => __('Number of Transactions')],
|
||||
['key' => 'market_data_updated_at', 'label' => __('Market Data Age')],
|
||||
];
|
||||
}
|
||||
|
||||
public function holdings(): Collection
|
||||
{
|
||||
return $this->portfolio
|
||||
->holdings()
|
||||
->with(['transactions' => function ($query) {
|
||||
$query->portfolio($this->portfolio->id);
|
||||
}])
|
||||
->withCount(['transactions as num_transactions' => function ($query) {
|
||||
$query->portfolio($this->portfolio->id);
|
||||
}])
|
||||
->withAggregate('market_data', 'name')
|
||||
->withAggregate('market_data', 'market_value')
|
||||
->withAggregate('market_data', 'fifty_two_week_low')
|
||||
->withAggregate('market_data', 'fifty_two_week_high')
|
||||
->withAggregate('market_data', 'updated_at')
|
||||
->selectRaw('(market_data.market_value * holdings.quantity) AS total_market_value')
|
||||
->selectRaw('((market_data.market_value - holdings.average_cost_basis) * holdings.quantity) AS market_gain_loss_dollars')
|
||||
->selectRaw('(((market_data.market_value - holdings.average_cost_basis) / holdings.average_cost_basis) * 100) AS market_gain_loss_percent')
|
||||
->join('market_data', 'holdings.symbol', 'market_data.symbol')
|
||||
->orderBy(...array_values($this->sortBy))
|
||||
->where('quantity', '>', 0)
|
||||
->get();
|
||||
}
|
||||
|
||||
}; ?>
|
||||
|
||||
<div class="">
|
||||
|
||||
<x-table wire:loading.remove :headers="$headers" :rows="$this->holdings()" :sort-by="$sortBy" />
|
||||
</div>
|
||||
@@ -21,16 +21,16 @@ new class extends Component {
|
||||
#[Rule('required|string|in:BUY,SELL')]
|
||||
public String $transaction_type;
|
||||
|
||||
#[Rule('required|date')]
|
||||
#[Rule('required|date_format:Y-m-d')]
|
||||
public String $date;
|
||||
|
||||
#[Rule('required|numeric')]
|
||||
#[Rule('required|min:0|numeric')]
|
||||
public Float $quantity;
|
||||
|
||||
#[Rule('exclude_if:transaction_type,SELL|numeric')]
|
||||
#[Rule('exclude_if:transaction_type,SELL|min:0|numeric')]
|
||||
public ?Float $cost_basis;
|
||||
|
||||
#[Rule('exclude_if:transaction_type,BUY|numeric')]
|
||||
#[Rule('exclude_if:transaction_type,BUY|min:0|numeric')]
|
||||
public ?Float $sale_price;
|
||||
|
||||
public Bool $confirmingTransactionDeletion = false;
|
||||
|
||||
@@ -8,7 +8,6 @@ use Livewire\Volt\Component;
|
||||
new class extends Component {
|
||||
|
||||
// props
|
||||
public ?Collection $transactions;
|
||||
public Portfolio $portfolio;
|
||||
public ?Transaction $editingTransaction;
|
||||
|
||||
@@ -23,38 +22,39 @@ new class extends Component {
|
||||
|
||||
<div class="">
|
||||
|
||||
@foreach($transactions as $transaction)
|
||||
<div x-data="{ loading: false, timeout: null }">
|
||||
<x-list-item
|
||||
no-separator
|
||||
:item="$transaction"
|
||||
class="cursor-pointer"
|
||||
@click="
|
||||
timeout = setTimeout(() => { loading = true }, 200);
|
||||
$wire.showTransactionDialog('{{ $transaction->id }}').then(() => {
|
||||
clearTimeout(timeout);
|
||||
loading = false;
|
||||
})
|
||||
"
|
||||
>
|
||||
<x-slot:value class="flex items-center">
|
||||
<x-badge
|
||||
:value="$transaction->transaction_type"
|
||||
class="{{ $transaction->transaction_type == 'BUY'
|
||||
? 'badge-success'
|
||||
: 'badge-error' }} badge-sm mr-3"
|
||||
/>
|
||||
{{ $transaction->date->format('M j, Y') }}
|
||||
{{ $transaction->symbol }}
|
||||
({{ $transaction->quantity }}
|
||||
@ {{ $transaction->transaction_type == 'BUY'
|
||||
? Number::currency($transaction->cost_basis)
|
||||
: Number::currency($transaction->sale_price) }})
|
||||
@foreach($portfolio->transactions->take(10) as $transaction)
|
||||
|
||||
<x-list-item
|
||||
no-separator
|
||||
:item="$transaction"
|
||||
class="cursor-pointer"
|
||||
x-data="{ loading: false, timeout: null }"
|
||||
@click="
|
||||
timeout = setTimeout(() => { loading = true }, 200);
|
||||
$wire.showTransactionDialog('{{ $transaction->id }}').then(() => {
|
||||
clearTimeout(timeout);
|
||||
loading = false;
|
||||
})
|
||||
"
|
||||
>
|
||||
<x-slot:value class="flex items-center">
|
||||
<x-badge
|
||||
:value="$transaction->transaction_type"
|
||||
class="{{ $transaction->transaction_type == 'BUY'
|
||||
? 'badge-success'
|
||||
: 'badge-error' }} badge-sm mr-3"
|
||||
/>
|
||||
{{ $transaction->date->format('M j, Y') }}
|
||||
{{ $transaction->symbol }}
|
||||
({{ $transaction->quantity }}
|
||||
@ {{ $transaction->transaction_type == 'BUY'
|
||||
? Number::currency($transaction->cost_basis)
|
||||
: Number::currency($transaction->sale_price) }})
|
||||
|
||||
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
|
||||
</x-slot:value>
|
||||
</x-list-item>
|
||||
|
||||
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
|
||||
</x-slot:value>
|
||||
</x-list-item>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
<x-ib-modal
|
||||
|
||||
@@ -84,6 +84,15 @@
|
||||
<div class="mt-6 grid md:grid-cols-7 gap-5">
|
||||
|
||||
<x-ib-card title="{{ __('Holdings') }}" class="md:col-span-4">
|
||||
|
||||
|
||||
@livewire('holdings-table', [
|
||||
'portfolio' => $portfolio
|
||||
])
|
||||
|
||||
</x-ib-card>
|
||||
|
||||
{{-- <x-ib-card title="{{ __('Top performers') }}" class="md:col-span-3">
|
||||
|
||||
@php
|
||||
$users = App\Models\User::take(3)->get();
|
||||
@@ -93,19 +102,7 @@
|
||||
<x-list-item no-separator :item="$user" avatar="profile_photo_url" link="/docs/installation" />
|
||||
@endforeach
|
||||
|
||||
</x-ib-card>
|
||||
|
||||
<x-ib-card title="{{ __('Top performers') }}" class="md:col-span-3">
|
||||
|
||||
@php
|
||||
$users = App\Models\User::take(3)->get();
|
||||
@endphp
|
||||
|
||||
@foreach($users as $user)
|
||||
<x-list-item no-separator :item="$user" avatar="profile_photo_url" link="/docs/installation" />
|
||||
@endforeach
|
||||
|
||||
</x-ib-card>
|
||||
</x-ib-card> --}}
|
||||
|
||||
{{-- <x-ib-card title="{{ __('Top headlines') }}" class="md:col-span-3">
|
||||
|
||||
@@ -119,10 +116,9 @@
|
||||
|
||||
</x-ib-card> --}}
|
||||
|
||||
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-4">
|
||||
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-3">
|
||||
|
||||
@livewire('transactions-list', [
|
||||
'transactions' => $portfolio->transactions,
|
||||
'portfolio' => $portfolio
|
||||
])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user