This commit is contained in:
hackerESQ
2024-08-27 18:12:51 -05:00
parent 10b6c7cda2
commit db01c27113
12 changed files with 202 additions and 67 deletions
@@ -1,8 +1,15 @@
<span
class=""
style="width:90em;overflow: hidden; white-space: nowrap;"
title="{{ Number::currency($low) }} - {{ Number::currency($high) }}"
title="{{ Number::currency($low ?? 0) }} - {{ Number::currency($high ?? 0) }}"
>
@php
// 52-week low must be a non-zero
if (empty($low)) {
$low = 1;
}
@endphp
@for ($x = 0; $x < 10; $x++)
@if ((($current - $low) * 100) / ($high - $low) > ($x * 10))
@@ -0,0 +1,27 @@
@php
if (isset($percent)) {
$isUp = $percent > 0;
} else {
$isUp = $costBasis <= $marketValue;
$percent = ($marketValue - $costBasis) / $costBasis;
}
@endphp
@if(!empty($percent))
<x-badge class="badge-sm {{ $isUp ? 'badge-success' : 'badge-error' }} badge-outline ml-2">
<x-slot:value>
{!! $isUp ? '&#9650;' :'&#9660;' !!}
{{ Number::percentage(
$percent,
$percent < 1 ? 2 : 0
) }}
</x-slot:value>
</x-badge>
@endif
@@ -12,7 +12,7 @@
</div>
</div>
<div class="flex flex-grow gap-4 w-50">
<div class="flex flex-grow gap-4 w-50" x-data>
<x-spotlight
shortcut="slash"
@@ -22,11 +22,11 @@
<x-button
icon="o-magnifying-glass"
@click="$dispatch('mary-search-open')"
@click.stop="$dispatch('mary-search-open')"
class="btn-sm"
>
<x-slot:label>
@lang('Press :key to search', ['key' => '<kbd class="kbd kbd-sm">/</kbd>'])
@lang('Click or press :key to search', ['key' => '<kbd class="kbd kbd-sm">/</kbd>'])
</x-slot:label>
</x-button>
+64 -26
View File
@@ -18,26 +18,14 @@
<span class="text-sm"> {{ $market_data->name }} </span>
</x-slot:title>
<p class="font-bold text-2xl pb-2">
{{ Number::currency($market_data->market_value) }}
<div class="font-bold text-2xl py-1 flex items-center">
{{ Number::currency($market_data->market_value ?? 0) }}
@if ($holding->average_cost_basis)
@php
$isUp = $holding->average_cost_basis <= $market_data->market_value;
$percent = ($market_data->market_value - $holding->average_cost_basis) / $holding->average_cost_basis
@endphp
<span class="text-base font-normal" style="color: {{ $isUp ? 'rgb(0, 200, 0)' : 'rgb(255, 20, 0)' }};">
{!! $isUp ? '&#9650;' :'&#9660;' !!}
{{ Number::percentage(
$percent,
$percent < 1 ? 2 : 1
) }}
</span>
@endif
</p>
<x-gain-loss-arrow-badge
:cost-basis="$holding->average_cost_basis"
:market-value="$market_data->market_value"
/>
</div>
<p>
<span class="font-bold">{{ __('Quantity Owned') }}: </span>
@@ -46,22 +34,22 @@
<p>
<span class="font-bold">{{ __('Average Cost Basis') }}: </span>
{{ Number::currency($holding->average_cost_basis) }}
{{ Number::currency($holding->average_cost_basis ?? 0) }}
</p>
<p>
<span class="font-bold">{{ __('Total Cost Basis') }}: </span>
{{ Number::currency($holding->total_cost_basis) }}
{{ Number::currency($holding->total_cost_basis ?? 0) }}
</p>
<p>
<span class="font-bold">{{ __('Realized Gain/Loss') }}: </span>
{{ Number::currency($holding->realized_gain_dollars) }}
{{ Number::currency($holding->realized_gain_dollars ?? 0) }}
</p>
<p>
<span class="font-bold">{{ __('Dividends Earned') }}: </span>
{{ Number::currency($holding->dividends_earned) }}
{{ Number::currency($holding->dividends_earned ?? 0) }}
</p>
<p>
@@ -84,25 +72,75 @@
<x-ib-card title="{{ __('Fundamentals') }}" class="md:col-span-4">
<p>
<span class="font-bold">{{ __('Forward PE') }}: </span>
{{ $market_data->forward_pe }}
</p>
<p>
<span class="font-bold">{{ __('Trailing PE') }}: </span>
{{ $market_data->trailing_pe }}
</p>
<p>
<span class="font-bold">{{ __('Market Cap') }}: </span>
${{ Number::forHumans($market_data->market_cap ?? 0) }}
</p>
</x-ib-card>
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-3">
@livewire('transactions-list', [
'portfolio' => $holding->portfolio,
'transactions' => $holding->transactions
])
</x-ib-card>
<x-ib-card title="{{ __('Dividends') }}" class="md:col-span-3">
@foreach ($holding->dividends->take(5) as $dividend)
<x-list-item :item="$dividend">
<x-slot:value>
Purchased {{$dividend->purchased}}<br>
Sold {{$dividend->sold}}<br>
@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 title="{{ __('Splits') }}" class="md:col-span-3">
@foreach ($holding->splits->take(5) as $split)
<x-list-item :item="$split">
<x-slot:value>
1:{{ $split->split_amount }}
</x-slot:value>
<x-slot:sub-value>
{{ $split->date->format('F d, Y') }}
</x-slot:sub-value>
</x-list-item>
@endforeach
</x-ib-card>
@@ -45,11 +45,21 @@ new class extends Component {
->get();
}
public function goToHolding($holding)
{
return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']]));
}
}; ?>
<div class="">
<x-table wire:loading.remove :headers="$headers" :rows="$this->holdings()" :sort-by="$sortBy">
<x-table
:headers="$headers"
:rows="$this->holdings()"
:sort-by="$sortBy"
@row-click="$wire.goToHolding($event.detail)"
>
@scope('cell_average_cost_basis', $row)
{{ Number::currency($row->average_cost_basis ?? 0) }}
@endscope
@@ -63,7 +73,7 @@ new class extends Component {
{{ Number::currency($row->market_gain_dollars ?? 0) }}
@endscope
@scope('cell_market_gain_percent', $row)
{{ Number::percentage($row->market_gain_percent ?? 0) }}
<x-gain-loss-arrow-badge :percent="$row->market_gain_percent" />
@endscope
@scope('cell_market_data_market_value', $row)
{{ Number::currency($row->market_data_market_value ?? 0) }}
@@ -15,6 +15,7 @@ new class extends Component {
public ?Portfolio $portfolio;
public ?Transaction $transaction;
public ?String $portfolio_id;
public String $symbol;
public String $transaction_type;
public String $date;
@@ -31,6 +32,7 @@ new class extends Component {
return [
'symbol' => ['required', 'string', new SymbolValidationRule],
'transaction_type' => 'required|string|in:BUY,SELL',
'portfolio_id' => 'required|exists:portfolios,id',
'date' => 'required|date_format:Y-m-d',
'quantity' => 'required|min:0|numeric',
'cost_basis' => 'exclude_if:transaction_type,SELL|min:0|numeric',
@@ -44,6 +46,7 @@ new class extends Component {
$this->symbol = $this->transaction->symbol;
$this->transaction_type = $this->transaction->transaction_type;
$this->portfolio_id = $this->transaction->portfolio_id;
$this->date = $this->transaction->date->format('Y-m-d');
$this->quantity = $this->transaction->quantity;
$this->cost_basis = $this->transaction->cost_basis;
@@ -51,6 +54,7 @@ new class extends Component {
} else {
$this->transaction_type = 'BUY';
$this->portfolio_id = isset($this->portfolio) ? $this->portfolio->id : '';
$this->date = now()->format('Y-m-d');
}
}
@@ -62,15 +66,25 @@ new class extends Component {
// $this->transaction->owner_id = auth()->user()->id;
$this->transaction->save();
$this->success(__('Transaction updated'), redirectTo: route('portfolio.show', ['portfolio' => $this->transaction->portfolio_id]));
$this->success(__('Transaction updated'));
$this->dispatch('toggle-manage-transaction');
$this->dispatch('transaction-updated');
}
public function save()
{
$validated = $this->validate();
$transaction = $this->portfolio->transactions()->create($this->validate());
if (!isset($this->portfolio)) {
$this->portfolio = Portfolio::find($this->portfolio_id);
}
$transaction = $this->portfolio->transactions()->create($validated);
$transaction->save();
$this->dispatch('transaction-saved');
$this->success(__('Transaction created'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
}
@@ -86,6 +100,19 @@ new class extends Component {
<div class="" x-data="{ transaction_type: @entangle('transaction_type') }">
<x-form wire:submit="{{ $transaction ? 'update' : 'save' }}" class="">
@if(empty($portfolio))
<x-select
label="{{ __('Portfolio') }}"
wire:model="portfolio_id"
required
:options="auth()->user()->portfolios"
option-label="title"
placeholder="Select a portfolio"
/>
@endif
<x-input label="{{ __('Symbol') }}" wire:model="symbol" required />
<x-select label="{{ __('Transaction Type') }}" :options="[
@@ -99,7 +126,7 @@ new class extends Component {
@if($transaction_type == 'SELL')
<x-input
label="Sale Price"
label="{{ __('Sale Price') }}"
wire:model.number="sale_price"
required
prefix="USD"
@@ -109,7 +136,7 @@ new class extends Component {
{{-- money --}}
@else
<x-input
label="Cost Basis"
label="{{ __('Cost Basis') }}"
wire:model.number="cost_basis"
required
prefix="USD"
@@ -35,12 +35,8 @@ new class extends Component {
<x-slot:value class="flex items-center">
{{ $holding->market_data?->name }} ({{ $holding->symbol }})
<x-badge class="{{ $holding->market_gain_percent > 0 ? 'badge-success' : 'badge-error' }} ml-2 badge-sm" >
<x-slot:value>
{{ Number::percentage($holding->market_gain_percent) }}
</x-slot:value>
</x-badge>
<x-gain-loss-arrow-badge :percent="$holding->market_gain_percent" />
</x-slot:value>
<x-slot:sub-value>
@@ -12,6 +12,11 @@ new class extends Component {
public ?Portfolio $portfolio;
public ?Transaction $editingTransaction;
protected $listeners = [
'transaction-updated' => '$refresh',
'transaction-saved' => '$refresh'
];
// methods
public function showTransactionDialog($transactionId)
{
@@ -45,7 +50,6 @@ new class extends Component {
? 'badge-success'
: 'badge-error' }} badge-sm mr-3"
/>
{{ $transaction->date->format('M j, Y') }}
{{ $transaction->symbol }}
({{ $transaction->quantity }}
@ {{ $transaction->transaction_type == 'BUY'
@@ -54,6 +58,9 @@ new class extends Component {
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
</x-slot:value>
<x-slot:sub-value>
{{ $transaction->date->format('F j, Y') }}
</x-slot:sub-value>
</x-list-item>
@endforeach
@@ -14,6 +14,11 @@ new class extends Component {
public User $user;
public ?Transaction $editingTransaction;
protected $listeners = [
'transaction-updated' => '$refresh',
'transaction-saved' => '$refresh'
];
public array $sortBy = ['column' => 'date', 'direction' => 'desc'];
public array $headers;
@@ -33,16 +38,10 @@ new class extends Component {
['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''],
['key' => 'market_data_name', 'label' => __('Name')],
['key' => 'transaction_type', 'label' => __('Type')],
['key' => 'split', 'label' => __('Split')],
['key' => 'quantity', 'label' => __('Quantity')],
['key' => 'cost_basis', 'label' => __('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_dollars', 'label' => __('Market Gain/Loss')],
// ['key' => 'market_gain_percent', 'label' => __('Market Gain/Loss')],
// ['key' => 'realized_gain_dollars', 'label' => __('Realized Gain/Loss')],
// ['key' => 'dividends_earned', 'label' => __('Dividends Earned')],
// ['key' => 'market_data_updated_at', 'label' => __('Market Data Age')],
['key' => 'gain_dollars', 'label' => __('Gain/Loss')],
];
}
@@ -82,6 +81,9 @@ new class extends Component {
@scope('cell_date', $row)
{{ $row->date->format('M d, Y') }}
@endscope
@scope('cell_split', $row)
{{ $row->split ? 'Yes' : '' }}
@endscope
@scope('cell_transaction_type', $row)
<x-badge
:value="$row->transaction_type"
@@ -96,14 +98,8 @@ new class extends Component {
@scope('cell_total_cost_basis', $row)
{{ Number::currency($row->total_cost_basis ?? 0) }}
@endscope
@scope('cell_realized_gain_dollars', $row)
{{ Number::currency($row->realized_gain_dollars ?? 0) }}
@endscope
@scope('cell_market_gain_dollars', $row)
{{ Number::currency($row->market_gain_dollars ?? 0) }}
@endscope
@scope('cell_market_gain_percent', $row)
{{ Number::percentage($row->market_gain_percent ?? 0) }}
@scope('cell_gain_dollars', $row)
{{ Number::currency($row->gain_dollars ?? 0) }}
@endscope
@scope('cell_market_data_market_value', $row)
{{ Number::currency($row->market_data_market_value ?? 0) }}
@@ -111,12 +107,6 @@ new class extends Component {
@scope('cell_total_market_value', $row)
{{ Number::currency($row->total_market_value ?? 0) }}
@endscope
@scope('cell_dividends_earned', $row)
{{ Number::currency($row->dividends_earned ?? 0) }}
@endscope
@scope('cell_market_data_updated_at', $row)
{{ \Carbon\Carbon::parse($row->market_data_updated_at)->diffForHumans() }}
@endscope
</x-table>
<x-ib-modal
+21 -2
View File
@@ -1,7 +1,26 @@
<x-app-layout>
<div>
<div x-data>
<x-ib-toolbar title="{{ __('All Transactions') }}" />
<x-ib-modal
key="new-transaction"
title="New Transaction"
>
@livewire('manage-transaction-form')
</x-ib-modal>
<x-ib-toolbar title="{{ __('All Transactions') }}">
<x-ib-flex-spacer />
<div>
<x-button
label="{{ __('Create Transaction') }}"
class="btn-sm btn-primary"
@click="$dispatch('toggle-new-transaction')"
/>
</div>
</x-ib-toolbar>
@livewire('transactions-table')