complete transaction flow
This commit is contained in:
@@ -60,7 +60,6 @@ class Transaction extends Model
|
|||||||
// if sale, move cost basis to sale price
|
// if sale, move cost basis to sale price
|
||||||
if ($transaction->transaction_type == 'SELL') {
|
if ($transaction->transaction_type == 'SELL') {
|
||||||
|
|
||||||
$transaction->sale_price = $transaction->cost_basis;
|
|
||||||
$transaction->cost_basis = $transaction->holding->average_cost_basis ?? $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;
|
public String $date;
|
||||||
|
|
||||||
#[Rule('required|numeric')]
|
#[Rule('required|numeric')]
|
||||||
public String $quantity;
|
public Float $quantity;
|
||||||
|
|
||||||
#[Rule('required|numeric')]
|
#[Rule('exclude_if:transaction_type,SELL|numeric')]
|
||||||
public String $cost_basis;
|
public ?Float $cost_basis;
|
||||||
|
|
||||||
|
#[Rule('exclude_if:transaction_type,BUY|numeric')]
|
||||||
|
public ?Float $sale_price;
|
||||||
|
|
||||||
public Bool $confirmingTransactionDeletion = false;
|
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
|
// methods
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
@@ -51,9 +44,8 @@ new class extends Component {
|
|||||||
$this->transaction_type = $this->transaction->transaction_type;
|
$this->transaction_type = $this->transaction->transaction_type;
|
||||||
$this->date = $this->transaction->date->format('Y-m-d');
|
$this->date = $this->transaction->date->format('Y-m-d');
|
||||||
$this->quantity = $this->transaction->quantity;
|
$this->quantity = $this->transaction->quantity;
|
||||||
$this->cost_basis = $this->transaction_type == 'SELL'
|
$this->cost_basis = $this->transaction->cost_basis;
|
||||||
? $this->transaction->sale_price
|
$this->sale_price = $this->transaction->sale_price;
|
||||||
: $this->transaction->cost_basis;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->transaction_type = 'BUY';
|
$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-form wire:submit="{{ $transaction ? 'update' : 'save' }}" class="">
|
||||||
|
|
||||||
<x-input label="{{ __('Symbol') }}" wire:model="symbol" required />
|
<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 />
|
<x-input label="{{ __('Quantity') }}" type="number" step="any" wire:model="quantity" required />
|
||||||
|
|
||||||
<x-input
|
@if($transaction_type == 'SELL')
|
||||||
label="{{ $this->cost_basis_label }}"
|
<x-input
|
||||||
wire:model="cost_basis"
|
label="Sale Price"
|
||||||
required
|
wire:model.number="sale_price"
|
||||||
prefix="USD"
|
required
|
||||||
money
|
prefix="USD"
|
||||||
type="number"
|
money
|
||||||
step="any"
|
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>
|
<x-slot:actions>
|
||||||
@if ($transaction)
|
@if ($transaction)
|
||||||
|
|||||||
@@ -40,12 +40,16 @@ new class extends Component {
|
|||||||
<x-slot:value class="flex items-center">
|
<x-slot:value class="flex items-center">
|
||||||
<x-badge
|
<x-badge
|
||||||
:value="$transaction->transaction_type"
|
: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->date->format('M j, Y') }}
|
||||||
{{ $transaction->symbol }}
|
{{ $transaction->symbol }}
|
||||||
({{ $transaction->quantity }}
|
({{ $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-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
|
||||||
</x-slot:value>
|
</x-slot:value>
|
||||||
|
|||||||
Reference in New Issue
Block a user