WIP
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user