Files
investbrain/resources/views/transaction/transactions-list.blade.php
T

154 lines
4.6 KiB
PHP
Raw Normal View History

2024-08-15 21:35:43 -05:00
<?php
use App\Models\Portfolio;
use App\Models\Transaction;
use Illuminate\Support\Collection;
use Livewire\Volt\Component;
2024-10-21 22:23:20 -05:00
use Mary\Traits\Toast;
2024-08-15 21:35:43 -05:00
2025-04-09 19:25:15 -05:00
new class extends Component
{
use Toast;
2024-10-21 22:23:20 -05:00
2024-08-15 21:35:43 -05:00
// props
public Collection $transactions;
2025-04-09 19:25:15 -05:00
public ?Portfolio $portfolio;
2025-04-09 19:25:15 -05:00
2024-08-15 21:35:43 -05:00
public ?Transaction $editingTransaction;
2025-04-09 19:25:15 -05:00
public bool $shouldGoToHolding = true;
public bool $showPortfolio = false;
public bool $paginate = true;
public int $perPage = 5;
public int $offset = 0;
2024-08-15 21:35:43 -05:00
2024-08-27 18:12:51 -05:00
protected $listeners = [
'transaction-updated' => '$refresh',
2025-04-09 19:25:15 -05:00
'transaction-saved' => '$refresh',
2024-08-27 18:12:51 -05:00
];
2024-08-15 21:35:43 -05:00
// methods
public function showTransactionDialog($transactionId)
{
2025-04-09 19:25:15 -05:00
if (! auth()->user()->can('fullAccess', $this->portfolio)) {
2024-10-21 22:23:20 -05:00
$this->error(__('You do not have permission to manage transactions for this portfolio'));
2025-04-09 19:25:15 -05:00
2024-10-21 22:23:20 -05:00
return;
}
2024-08-15 21:35:43 -05:00
$this->editingTransaction = Transaction::findOrFail($transactionId);
$this->dispatch('toggle-manage-transaction');
}
2024-08-27 21:17:54 -05:00
public function goToHolding($holding)
{
return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']]));
}
public function updateOffset($amount = 0)
{
$this->offset = $this->offset + $amount;
}
2024-08-15 21:35:43 -05:00
}; ?>
<div class="">
@foreach($transactions->sortByDesc('date')->slice($offset)->take($perPage) as $transaction)
2024-08-17 21:33:09 -05:00
<x-list-item
no-separator
:item="$transaction"
class="cursor-pointer"
x-data="{ loading: false, timeout: null }"
:key="$transaction->id"
2024-08-17 21:33:09 -05:00
@click="
2024-08-27 21:17:54 -05:00
if ($wire.shouldGoToHolding) {
$wire.goToHolding({{ $transaction }})
return;
}
2024-08-17 21:33:09 -05:00
timeout = setTimeout(() => { loading = true }, 200);
$wire.showTransactionDialog('{{ $transaction->id }}').then(() => {
clearTimeout(timeout);
loading = false;
})
"
>
<x-slot:value class="flex items-center">
<x-badge
2024-09-09 17:21:19 -05:00
:value="$transaction->split
? 'SPLIT'
2024-10-18 22:18:25 -05:00
: ($transaction->reinvested_dividend
? 'REINVEST'
: $transaction->transaction_type)"
2024-08-17 21:33:09 -05:00
class="{{ $transaction->transaction_type == 'BUY'
? 'badge-success'
: 'badge-error' }} badge-sm mr-3"
/>
{{ $transaction->symbol }}
({{ $transaction->quantity }}
2025-04-09 19:25:15 -05:00
@ {{ Number::currency(
$transaction->transaction_type == 'BUY'
? $transaction->cost_basis
: $transaction->sale_price,
$transaction->market_data->currency
) }})
2024-08-17 21:33:09 -05:00
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
</x-slot:value>
2024-08-27 18:12:51 -05:00
<x-slot:sub-value>
@if($showPortfolio)
<span title="{{ __('Portfolio') }}">{{ $transaction->portfolio->title }} </span>
&middot;
@endif
2024-09-05 20:41:07 -05:00
<span title="{{ __('Transaction Date') }}">{{ $transaction->date->format('F j, Y') }} </span>
2024-08-27 18:12:51 -05:00
</x-slot:sub-value>
2024-08-17 21:33:09 -05:00
</x-list-item>
2024-08-15 21:35:43 -05:00
@endforeach
@if ($paginate && count($transactions) > $perPage)
<div class="flex justify-between">
<span>
@if($offset > 0)
<x-button
class="btn btn-sm btn-ghost text-secondary"
wire:click="updateOffset(-{{ $perPage }})"
>
{!! __('pagination.previous') !!}
</x-button>
@endif
</span>
<span>
@if(count($transactions) - $offset > $offset)
<x-button
class="btn btn-sm btn-ghost text-secondary"
wire:click="updateOffset({{ $perPage }})"
>
{!! __('pagination.next') !!}
</x-button>
@endif
</span>
</div>
@endif
2024-10-22 16:48:53 -05:00
<x-ib-alpine-modal
2024-08-15 21:35:43 -05:00
key="manage-transaction"
2024-10-22 12:41:18 -05:00
title="{{ __('Manage Transaction') }}"
2024-08-15 21:35:43 -05:00
>
@livewire('manage-transaction-form', [
'portfolio' => $portfolio,
'transaction' => $editingTransaction,
], key($editingTransaction?->id.rand()))
2024-08-15 21:35:43 -05:00
2024-10-22 16:48:53 -05:00
</x-ib-alpine-modal>
2024-08-15 21:35:43 -05:00
</div>