WIP
This commit is contained in:
@@ -15,6 +15,7 @@ new class extends Component {
|
||||
public ?Portfolio $portfolio;
|
||||
public ?Transaction $transaction;
|
||||
|
||||
public ?String $portfolio_id;
|
||||
public String $symbol;
|
||||
public String $transaction_type;
|
||||
public String $date;
|
||||
@@ -31,6 +32,7 @@ new class extends Component {
|
||||
return [
|
||||
'symbol' => ['required', 'string', new SymbolValidationRule],
|
||||
'transaction_type' => 'required|string|in:BUY,SELL',
|
||||
'portfolio_id' => 'required|exists:portfolios,id',
|
||||
'date' => 'required|date_format:Y-m-d',
|
||||
'quantity' => 'required|min:0|numeric',
|
||||
'cost_basis' => 'exclude_if:transaction_type,SELL|min:0|numeric',
|
||||
@@ -44,6 +46,7 @@ new class extends Component {
|
||||
|
||||
$this->symbol = $this->transaction->symbol;
|
||||
$this->transaction_type = $this->transaction->transaction_type;
|
||||
$this->portfolio_id = $this->transaction->portfolio_id;
|
||||
$this->date = $this->transaction->date->format('Y-m-d');
|
||||
$this->quantity = $this->transaction->quantity;
|
||||
$this->cost_basis = $this->transaction->cost_basis;
|
||||
@@ -51,6 +54,7 @@ new class extends Component {
|
||||
|
||||
} else {
|
||||
$this->transaction_type = 'BUY';
|
||||
$this->portfolio_id = isset($this->portfolio) ? $this->portfolio->id : '';
|
||||
$this->date = now()->format('Y-m-d');
|
||||
}
|
||||
}
|
||||
@@ -62,15 +66,25 @@ new class extends Component {
|
||||
// $this->transaction->owner_id = auth()->user()->id;
|
||||
$this->transaction->save();
|
||||
|
||||
$this->success(__('Transaction updated'), redirectTo: route('portfolio.show', ['portfolio' => $this->transaction->portfolio_id]));
|
||||
$this->success(__('Transaction updated'));
|
||||
|
||||
$this->dispatch('toggle-manage-transaction');
|
||||
$this->dispatch('transaction-updated');
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$validated = $this->validate();
|
||||
|
||||
$transaction = $this->portfolio->transactions()->create($this->validate());
|
||||
if (!isset($this->portfolio)) {
|
||||
$this->portfolio = Portfolio::find($this->portfolio_id);
|
||||
}
|
||||
|
||||
$transaction = $this->portfolio->transactions()->create($validated);
|
||||
$transaction->save();
|
||||
|
||||
$this->dispatch('transaction-saved');
|
||||
|
||||
$this->success(__('Transaction created'), redirectTo: route('portfolio.show', ['portfolio' => $this->portfolio->id]));
|
||||
}
|
||||
|
||||
@@ -86,6 +100,19 @@ new class extends Component {
|
||||
<div class="" x-data="{ transaction_type: @entangle('transaction_type') }">
|
||||
<x-form wire:submit="{{ $transaction ? 'update' : 'save' }}" class="">
|
||||
|
||||
@if(empty($portfolio))
|
||||
|
||||
<x-select
|
||||
label="{{ __('Portfolio') }}"
|
||||
wire:model="portfolio_id"
|
||||
required
|
||||
:options="auth()->user()->portfolios"
|
||||
option-label="title"
|
||||
placeholder="Select a portfolio"
|
||||
/>
|
||||
|
||||
@endif
|
||||
|
||||
<x-input label="{{ __('Symbol') }}" wire:model="symbol" required />
|
||||
|
||||
<x-select label="{{ __('Transaction Type') }}" :options="[
|
||||
@@ -99,7 +126,7 @@ new class extends Component {
|
||||
|
||||
@if($transaction_type == 'SELL')
|
||||
<x-input
|
||||
label="Sale Price"
|
||||
label="{{ __('Sale Price') }}"
|
||||
wire:model.number="sale_price"
|
||||
required
|
||||
prefix="USD"
|
||||
@@ -109,7 +136,7 @@ new class extends Component {
|
||||
{{-- money --}}
|
||||
@else
|
||||
<x-input
|
||||
label="Cost Basis"
|
||||
label="{{ __('Cost Basis') }}"
|
||||
wire:model.number="cost_basis"
|
||||
required
|
||||
prefix="USD"
|
||||
|
||||
Reference in New Issue
Block a user