complete transaction flow

This commit is contained in:
hackerESQ
2024-08-15 22:10:43 -05:00
parent 0f22e2c33e
commit bddae3caa1
3 changed files with 37 additions and 29 deletions
-1
View File
@@ -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;
}
});
@@ -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 {
}
}; ?>
<div class="">
<div class="" x-data="{ transaction_type: @entangle('transaction_type') }">
<x-form wire:submit="{{ $transaction ? 'update' : 'save' }}" class="">
<x-input label="{{ __('Symbol') }}" wire:model="symbol" required />
@@ -103,15 +95,28 @@ new class extends Component {
<x-input label="{{ __('Quantity') }}" type="number" step="any" wire:model="quantity" required />
@if($transaction_type == 'SELL')
<x-input
label="{{ $this->cost_basis_label }}"
wire:model="cost_basis"
label="Sale Price"
wire:model.number="sale_price"
required
prefix="USD"
money
type="number"
step="any"
/>
@else
<x-input
label="Cost Basis"
wire:model.number="cost_basis"
required
prefix="USD"
money
type="number"
step="any"
/>
@endif
<x-slot:actions>
@if ($transaction)
@@ -40,12 +40,16 @@ new class extends Component {
<x-slot:value class="flex items-center">
<x-badge
:value="$transaction->transaction_type"
class="{{ $transaction->transaction_type == 'BUY' ? 'badge-success' : 'badge-error' }} badge-sm mr-3"
class="{{ $transaction->transaction_type == 'BUY'
? 'badge-success'
: 'badge-error' }} badge-sm mr-3"
/>
{{ $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) }})
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
</x-slot:value>