2024-08-26 19:49:43 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Transaction;
|
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
|
use Livewire\Volt\Component;
|
|
|
|
|
use Livewire\WithPagination;
|
|
|
|
|
|
|
|
|
|
new class extends Component {
|
|
|
|
|
|
|
|
|
|
use WithPagination;
|
|
|
|
|
|
|
|
|
|
// props
|
|
|
|
|
public User $user;
|
|
|
|
|
public ?Transaction $editingTransaction;
|
|
|
|
|
|
2024-08-27 18:12:51 -05:00
|
|
|
protected $listeners = [
|
|
|
|
|
'transaction-updated' => '$refresh',
|
|
|
|
|
'transaction-saved' => '$refresh'
|
|
|
|
|
];
|
|
|
|
|
|
2024-08-26 19:49:43 -05:00
|
|
|
public array $sortBy = ['column' => 'date', 'direction' => 'desc'];
|
|
|
|
|
|
|
|
|
|
public array $headers;
|
|
|
|
|
|
|
|
|
|
// methods
|
2024-08-27 21:17:54 -05:00
|
|
|
public function goToHolding($holding)
|
2024-08-26 19:49:43 -05:00
|
|
|
{
|
2024-08-27 21:17:54 -05:00
|
|
|
return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']]));
|
2024-08-26 19:49:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
|
{
|
|
|
|
|
$this->headers = [
|
|
|
|
|
['key' => 'date', 'label' => __('Date'), 'sortable' => true],
|
|
|
|
|
['key' => 'portfolio_title', 'label' => __('Portfolio')],
|
|
|
|
|
['key' => 'symbol', 'label' => __('Symbol'), 'class' => ''],
|
|
|
|
|
['key' => 'market_data_name', 'label' => __('Name')],
|
|
|
|
|
['key' => 'transaction_type', 'label' => __('Type')],
|
2024-08-27 18:12:51 -05:00
|
|
|
['key' => 'split', 'label' => __('Split')],
|
2024-08-26 19:49:43 -05:00
|
|
|
['key' => 'quantity', 'label' => __('Quantity')],
|
|
|
|
|
['key' => 'cost_basis', 'label' => __('Cost Basis')],
|
2024-08-27 18:12:51 -05:00
|
|
|
['key' => 'gain_dollars', 'label' => __('Gain/Loss')],
|
2024-08-26 19:49:43 -05:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function transactions()
|
|
|
|
|
{
|
|
|
|
|
return auth()
|
|
|
|
|
->user()
|
|
|
|
|
->transactions()
|
|
|
|
|
->orderBy(...array_values($this->sortBy))
|
|
|
|
|
->paginate(10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}; ?>
|
|
|
|
|
|
|
|
|
|
<div class="">
|
|
|
|
|
|
|
|
|
|
<x-table
|
|
|
|
|
:headers="$headers"
|
|
|
|
|
:rows="$this->transactions()"
|
2024-08-26 20:26:15 -05:00
|
|
|
x-data="{ loadingId: null, timeout: null }"
|
2024-08-26 19:49:43 -05:00
|
|
|
@row-click="
|
2024-08-26 20:26:15 -05:00
|
|
|
timeout = setTimeout(() => { loadingId = $event.detail.id }, 200);
|
2024-08-27 21:17:54 -05:00
|
|
|
$wire.goToHolding($event.detail).then(() => {
|
2024-08-26 19:49:43 -05:00
|
|
|
clearTimeout(timeout);
|
2024-08-26 20:26:15 -05:00
|
|
|
loadingId = null;
|
2024-08-26 19:49:43 -05:00
|
|
|
})
|
|
|
|
|
"
|
|
|
|
|
:sort-by="$sortBy"
|
|
|
|
|
with-pagination
|
|
|
|
|
>
|
|
|
|
|
@scope('cell_symbol', $row)
|
2024-08-26 20:26:15 -05:00
|
|
|
<span class="flex">
|
|
|
|
|
{{ $row->symbol }}
|
|
|
|
|
<x-loading x-show="loadingId === '{{ $row->id }}'" x-cloak class="text-gray-400 ml-2" />
|
|
|
|
|
</span>
|
2024-08-26 19:49:43 -05:00
|
|
|
@endscope
|
|
|
|
|
@scope('cell_date', $row)
|
|
|
|
|
{{ $row->date->format('M d, Y') }}
|
|
|
|
|
@endscope
|
2024-08-27 18:12:51 -05:00
|
|
|
@scope('cell_split', $row)
|
2024-10-18 20:46:22 -05:00
|
|
|
{{ $row->split ? __('Yes') : '' }}
|
2024-08-27 18:12:51 -05:00
|
|
|
@endscope
|
2024-08-26 19:49:43 -05:00
|
|
|
@scope('cell_transaction_type', $row)
|
|
|
|
|
<x-badge
|
2024-09-09 19:39:38 -05:00
|
|
|
:value="$row->split
|
2024-10-18 22:18:25 -05:00
|
|
|
? 'SPLIT'
|
|
|
|
|
: ($row->reinvested_dividend
|
|
|
|
|
? 'REINVEST'
|
|
|
|
|
: $row->transaction_type)"
|
2024-08-26 19:49:43 -05:00
|
|
|
class="{{ $row->transaction_type == 'BUY'
|
|
|
|
|
? 'badge-success'
|
|
|
|
|
: 'badge-error' }} badge-sm mr-3"
|
|
|
|
|
/>
|
|
|
|
|
@endscope
|
|
|
|
|
@scope('cell_cost_basis', $row)
|
|
|
|
|
{{ Number::currency($row->cost_basis ?? 0) }}
|
|
|
|
|
@endscope
|
|
|
|
|
@scope('cell_total_cost_basis', $row)
|
|
|
|
|
{{ Number::currency($row->total_cost_basis ?? 0) }}
|
|
|
|
|
@endscope
|
2024-08-27 18:12:51 -05:00
|
|
|
@scope('cell_gain_dollars', $row)
|
|
|
|
|
{{ Number::currency($row->gain_dollars ?? 0) }}
|
2024-08-26 19:49:43 -05:00
|
|
|
@endscope
|
|
|
|
|
@scope('cell_market_data_market_value', $row)
|
|
|
|
|
{{ Number::currency($row->market_data_market_value ?? 0) }}
|
|
|
|
|
@endscope
|
|
|
|
|
@scope('cell_total_market_value', $row)
|
|
|
|
|
{{ Number::currency($row->total_market_value ?? 0) }}
|
|
|
|
|
@endscope
|
|
|
|
|
</x-table>
|
|
|
|
|
|
2024-10-22 16:48:53 -05:00
|
|
|
<x-ib-alpine-modal
|
2024-08-26 19:49:43 -05:00
|
|
|
key="manage-transaction"
|
|
|
|
|
title="Manage Transaction"
|
|
|
|
|
>
|
|
|
|
|
@livewire('manage-transaction-form', [
|
|
|
|
|
'transaction' => $editingTransaction,
|
|
|
|
|
], key($editingTransaction->id ?? 'new'))
|
|
|
|
|
|
2024-10-22 16:48:53 -05:00
|
|
|
</x-ib-alpine-modal>
|
2024-08-26 19:49:43 -05:00
|
|
|
</div>
|