['required', 'string', new SymbolValidationRule], 'transaction_type' => 'required|string|in:BUY,SELL', 'portfolio_id' => 'required|exists:portfolios,id', 'date' => ['required', 'date_format:Y-m-d', 'before_or_equal:' . now()->format('Y-m-d')], 'quantity' => [ 'required', 'numeric', 'min:0', new QuantityValidationRule($this->portfolio, $this->symbol, $this->transaction_type, $this->date) ], 'cost_basis' => 'exclude_if:transaction_type,SELL|min:0|numeric', 'sale_price' => 'exclude_if:transaction_type,BUY|min:0|numeric', ]; } public function mount() { if (isset($this->transaction)) { $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; $this->sale_price = $this->transaction->sale_price; } else { $this->transaction_type = 'BUY'; $this->portfolio_id = isset($this->portfolio) ? $this->portfolio->id : ''; $this->date = now()->format('Y-m-d'); } } public function update() { $this->authorize('fullAccess', $this->portfolio); $this->transaction->update($this->validate()); // $this->transaction->owner_id = auth()->user()->id; $this->transaction->save(); $this->success(__('Transaction updated')); $this->dispatch('toggle-manage-transaction'); $this->dispatch('transaction-updated'); } public function save() { if (!isset($this->portfolio)) { $this->portfolio = Portfolio::find($this->portfolio_id); } $this->authorize('fullAccess', $this->portfolio); $validated = $this->validate(); $transaction = $this->portfolio->transactions()->create($validated); $transaction->save(); $this->dispatch('transaction-saved'); $this->success(__('Transaction created'), redirectTo: route('holding.show', ['portfolio' => $this->portfolio->id, 'symbol' => $this->symbol])); } public function delete() { $this->authorize('fullAccess', $this->portfolio); $this->transaction->delete(); $this->success(__('Transaction deleted'), redirectTo: route('holding.show', ['portfolio' => $this->portfolio->id, 'symbol' => $this->symbol])); } }; ?>
@if(empty($portfolio)) @endif @if($transaction_type == 'SELL') {{-- money --}} @else {{-- money --}} @endif @if ($transaction) @endif {{ __('Delete Transaction') }} {{ __('Are you sure you want to delete this transaction?') }} {{ __('Cancel') }} {{ __('Delete Transaction') }}