portfolio) || is_null($this->symbol) || is_null($this->transactionType) || is_null($this->date)) { // $fail(__('The quantity must not be greater than the available quantity.')); } if ($this->transactionType == 'SELL') { $purchase_qty = (float) $this->portfolio->transactions() ->symbol($this->symbol) ->buy() ->whereDate('date', '<', $this->date) ->sum('quantity'); $sales_qty = (float) $this->portfolio->transactions() ->where('id', '!=', $this->transaction?->id) ->symbol($this->symbol) ->sell() ->whereDate('date', '<', $this->date) ->sum('quantity'); $maxQuantity = $purchase_qty - $sales_qty; if (round($value, 4) > round($maxQuantity, 4)) { $fail(__('The quantity must not be greater than the available quantity.')); } } } }