decodePrimaryKey(request()->input('id')))->first(); if($request->has('refunded') && ($request->input('refunded') > $payment->amount)){ $this->error_msg = "Attempting to refunded more than payment amount, enter a value equal to or lower than the payment amount of ". $payment->amount; return false; } /*If no invoices has been sent, then we apply the payment to the client account*/ $invoices = []; if (is_array($value)) { $invoices = Invoice::whereIn('id', array_column($value, 'invoice_id'))->company()->get(); } else return true; foreach ($invoices as $invoice) { if (! $invoice->isRefundable()) { $this->error_msg = "One or more of these invoices have been paid"; return false; } foreach ($value as $val) { if ($val['invoice_id'] == $invoice->id) { if($val['refunded'] > ($invoice->amount - $invoice->balance)) $this->error_msg = "Attempting to refund more than is possible for an invoice"; return false; } } } return true; } /** * @return string */ public function message() { return $this->error_msg; } }