diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index aa310479d812..b6440543eeb6 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -28,8 +28,6 @@ class ClientService public function updateBalance(float $amount) { - // $this->client->balance += $amount; - $this->client->increment('balance', $amount); return $this; @@ -37,8 +35,6 @@ class ClientService public function updatePaidToDate(float $amount) { - // $this->client->paid_to_date += $amount; - $this->client->increment('paid_to_date', $amount); return $this; @@ -46,8 +42,6 @@ class ClientService public function adjustCreditBalance(float $amount) { - // $this->client->credit_balance += $amount; - $this->client->increment('credit_balance', $amount); return $this; diff --git a/app/Services/Payment/RefundPayment.php b/app/Services/Payment/RefundPayment.php index ac1d0fdf420a..6786edde00cb 100644 --- a/app/Services/Payment/RefundPayment.php +++ b/app/Services/Payment/RefundPayment.php @@ -263,7 +263,8 @@ class RefundPayment foreach ($this->refund_data['invoices'] as $refunded_invoice) { $invoice = Invoice::withTrashed()->find($refunded_invoice['invoice_id']); - $invoice->restore(); + if($invoice->trashed()) + $invoice->restore(); $invoice->service()->updateBalance($refunded_invoice['amount'])->save(); $invoice->ledger()->updateInvoiceBalance($refunded_invoice['amount'], "Refund of payment # {$this->payment->number}")->save(); @@ -300,6 +301,10 @@ class RefundPayment } $client = $this->payment->client->fresh(); + + if($client->trashed()) + $client->restore(); + $client->service()->updatePaidToDate(-1 * $refunded_invoice['amount'])->save(); @@ -318,6 +323,10 @@ class RefundPayment //if we are refunding and no payments have been tagged, then we need to decrement the client->paid_to_date by the total refund amount. $client = $this->payment->client->fresh(); + + if($client->trashed()) + $client->restore(); + $client->service()->updatePaidToDate(-1 * $this->total_refund)->save(); $transaction = [ diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 3a34b2e80310..5054c9b87a3e 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -43,12 +43,19 @@ class UpdateInvoicePayment collect($paid_invoices)->each(function ($paid_invoice) use ($invoices) { - $client = $this->payment->client->fresh(); + $client = $this->payment->client; + + if($client->trashed()) + $client->restore(); $invoice = $invoices->first(function ($inv) use ($paid_invoice) { return $paid_invoice->invoice_id == $inv->hashed_id; }); + + if($invoice->trashed()) + $invoice->restore(); + if ($invoice->id == $this->payment_hash->fee_invoice_id) { $paid_amount = $paid_invoice->amount + $this->payment_hash->fee_total; } else { @@ -116,7 +123,6 @@ class UpdateInvoicePayment $invoices->each(function ($invoice) { - $invoice = $invoice->fresh(); event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); });