From 77199fc6972ebccc36f4ffe4c8ce0a5affeab2d9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 26 Jan 2022 23:01:54 +1100 Subject: [PATCH] Performance improvements for payment reponses --- .../ClientPortal/PaymentController.php | 2 +- app/Services/Payment/UpdateInvoicePayment.php | 35 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index d784ca416c..220276dd78 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -94,7 +94,7 @@ class PaymentController extends Controller $gateway = CompanyGateway::findOrFail($request->input('company_gateway_id')); $payment_hash = PaymentHash::where('hash', $request->payment_hash)->first(); $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id); - $client = $invoice->client->exists() ? $invoice->client : auth()->user()->client; + $client = $invoice ? $invoice->client : auth()->user()->client; return $gateway // ->driver(auth()->user()->client) diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 16c5d9738b..5a6a2a2392 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -55,6 +55,16 @@ class UpdateInvoicePayment if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance) $paid_amount = $invoice->balance; + /*Improve performance here - 26-01-2022 - also change the order of events for invoice first*/ + $invoice->service() //caution what if we amount paid was less than partial - we wipe it! + ->clearPartial() + ->updateBalance($paid_amount * -1) + ->updatePaidToDate($paid_amount) + ->updateStatus() + ->touchPdf() + ->workFlow() + ->save(); + /* Updates the company ledger */ $this->payment ->ledger() @@ -77,19 +87,22 @@ class UpdateInvoicePayment $this->payment->applied += $paid_amount; - $invoice->service() //caution what if we amount paid was less than partial - we wipe it! - ->clearPartial() - ->updateBalance($paid_amount * -1) - ->updatePaidToDate($paid_amount) - ->updateStatus() - ->save(); + // $invoice->service() //caution what if we amount paid was less than partial - we wipe it! + // ->clearPartial() + // ->updateBalance($paid_amount * -1) + // ->updatePaidToDate($paid_amount) + // ->updateStatus() + // ->save(); + + // $invoice->refresh(); + + // $invoice->service() + // ->touchPdf(true) + // ->workFlow() + // ->save(); + - $invoice->refresh(); - $invoice->service() - ->touchPdf(true) - ->workFlow() - ->save(); });