From bddae3caa1778de8cfcc5db3287ca5e021018d70 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 15 Aug 2024 22:10:43 -0500 Subject: [PATCH] complete transaction flow --- app/Models/Transaction.php | 1 - .../manage-transaction-form.blade.php | 57 ++++++++++--------- .../livewire/transactions-list.blade.php | 8 ++- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index f40d4ed..272303c 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -60,7 +60,6 @@ class Transaction extends Model // if sale, move cost basis to sale price if ($transaction->transaction_type == 'SELL') { - $transaction->sale_price = $transaction->cost_basis; $transaction->cost_basis = $transaction->holding->average_cost_basis ?? $transaction->cost_basis; } }); diff --git a/resources/views/livewire/manage-transaction-form.blade.php b/resources/views/livewire/manage-transaction-form.blade.php index 690e58f..927cc1b 100644 --- a/resources/views/livewire/manage-transaction-form.blade.php +++ b/resources/views/livewire/manage-transaction-form.blade.php @@ -25,23 +25,16 @@ new class extends Component { public String $date; #[Rule('required|numeric')] - public String $quantity; + public Float $quantity; - #[Rule('required|numeric')] - public String $cost_basis; + #[Rule('exclude_if:transaction_type,SELL|numeric')] + public ?Float $cost_basis; + + #[Rule('exclude_if:transaction_type,BUY|numeric')] + public ?Float $sale_price; public Bool $confirmingTransactionDeletion = false; - #[Computed] - public function cost_basis_label() - { - if (isset($this->transaction_type) && $this->transaction_type == 'SELL') { - return __('Sale Price'); - } - - return __('Cost Basis'); - } - // methods public function mount() { @@ -51,9 +44,8 @@ new class extends Component { $this->transaction_type = $this->transaction->transaction_type; $this->date = $this->transaction->date->format('Y-m-d'); $this->quantity = $this->transaction->quantity; - $this->cost_basis = $this->transaction_type == 'SELL' - ? $this->transaction->sale_price - : $this->transaction->cost_basis; + $this->cost_basis = $this->transaction->cost_basis; + $this->sale_price = $this->transaction->sale_price; } else { $this->transaction_type = 'BUY'; @@ -89,7 +81,7 @@ new class extends Component { } }; ?> -
+
@@ -103,15 +95,28 @@ new class extends Component { - + @if($transaction_type == 'SELL') + + @else + + @endif @if ($transaction) diff --git a/resources/views/livewire/transactions-list.blade.php b/resources/views/livewire/transactions-list.blade.php index d87dca9..6730430 100644 --- a/resources/views/livewire/transactions-list.blade.php +++ b/resources/views/livewire/transactions-list.blade.php @@ -40,12 +40,16 @@ new class extends Component { {{ $transaction->date->format('M j, Y') }} {{ $transaction->symbol }} ({{ $transaction->quantity }} - @ {{ Number::currency($transaction->cost_basis) }}) + @ {{ $transaction->transaction_type == 'BUY' + ? Number::currency($transaction->cost_basis) + : Number::currency($transaction->sale_price) }})