wip
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Portfolio;
|
||||
use App\Rules\SymbolValidationRule;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Attributes\Rule;
|
||||
use Livewire\Attributes\{Computed};
|
||||
use Livewire\Volt\Component;
|
||||
use Mary\Traits\Toast;
|
||||
use Livewire\Attributes\Computed;
|
||||
|
||||
new class extends Component {
|
||||
use Toast;
|
||||
@@ -15,27 +15,29 @@ new class extends Component {
|
||||
public ?Portfolio $portfolio;
|
||||
public ?Transaction $transaction;
|
||||
|
||||
#[Rule('required|string|max:15')]
|
||||
public String $symbol;
|
||||
|
||||
#[Rule('required|string|in:BUY,SELL')]
|
||||
public String $transaction_type;
|
||||
|
||||
#[Rule('required|date_format:Y-m-d')]
|
||||
public String $date;
|
||||
|
||||
#[Rule('required|min:0|numeric')]
|
||||
public Float $quantity;
|
||||
|
||||
#[Rule('exclude_if:transaction_type,SELL|min:0|numeric')]
|
||||
public ?Float $cost_basis;
|
||||
|
||||
#[Rule('exclude_if:transaction_type,BUY|min:0|numeric')]
|
||||
public ?Float $sale_price;
|
||||
|
||||
public Bool $confirmingTransactionDeletion = false;
|
||||
|
||||
// methods
|
||||
public function rules()
|
||||
{
|
||||
|
||||
return [
|
||||
'symbol' => ['required', 'string', new SymbolValidationRule],
|
||||
'transaction_type' => 'required|string|in:BUY,SELL',
|
||||
'date' => 'required|date_format:Y-m-d',
|
||||
'quantity' => 'required|min:0|numeric',
|
||||
'cost_basis' => 'exclude_if:transaction_type,SELL|min:0|numeric',
|
||||
'sale_price' => 'exclude_if:transaction_type,BUY|min:0|numeric',
|
||||
];
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
if (isset($this->transaction)) {
|
||||
@@ -128,7 +130,13 @@ new class extends Component {
|
||||
/>
|
||||
@endif
|
||||
|
||||
<x-button label="{{ $transaction ? 'Update' : 'Create' }}" type="submit" icon="o-paper-airplane" class="btn-primary" spinner="save" />
|
||||
<x-button
|
||||
label="{{ $transaction ? 'Update' : 'Create' }}"
|
||||
type="submit"
|
||||
icon="o-paper-airplane"
|
||||
class="btn-primary"
|
||||
spinner="{{ $transaction ? 'update' : 'save' }}"
|
||||
/>
|
||||
</x-slot:actions>
|
||||
</x-form>
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ new class extends Component {
|
||||
<div class="">
|
||||
|
||||
@foreach(
|
||||
$holdings->sortBy('market_gain_percent')
|
||||
$holdings->sortByDesc('market_gain_percent')
|
||||
->where('quantity', '>', 0)
|
||||
->where('market_data.market_value', '>', 0)
|
||||
->take(5)
|
||||
@@ -29,17 +29,13 @@ new class extends Component {
|
||||
link="{{ route('portfolio.show', ['portfolio' => $holding->portfolio_id]) }}"
|
||||
>
|
||||
|
||||
@php
|
||||
$gainPercent = (($holding->market_data->market_value - $holding->average_cost_basis) / $holding->average_cost_basis) * 100;
|
||||
@endphp
|
||||
|
||||
<x-slot:value class="flex items-center">
|
||||
|
||||
{{ $holding->market_data?->name }} ({{ $holding->symbol }})
|
||||
|
||||
<x-badge class="{{ $gainPercent > 0 ? 'badge-success' : 'badge-error' }} ml-2 badge-sm" >
|
||||
<x-badge class="{{ $holding->market_gain_percent > 0 ? 'badge-success' : 'badge-error' }} ml-2 badge-sm" >
|
||||
<x-slot:value>
|
||||
{{ Number::percentage($gainPercent) }}
|
||||
{{ Number::percentage($holding->market_gain_percent) }}
|
||||
</x-slot:value>
|
||||
</x-badge>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user