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 { } }; ?> -