From 1e2f7259a312455b0f083178df8b954c7f92da64 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 5 Sep 2023 11:54:05 +1000 Subject: [PATCH] Static Analysis Cleanup --- .../Controllers/PurchaseOrderController.php | 12 ++++++++--- app/Http/Controllers/QuoteController.php | 4 ++-- .../RecurringInvoiceController.php | 21 +++++++++++++------ app/PaymentDrivers/BaseDriver.php | 12 +++++------ app/Services/Credit/ApplyPayment.php | 4 ++-- app/Services/Credit/CreditService.php | 2 +- app/Services/Credit/MarkSent.php | 2 +- app/Services/Invoice/ApplyPayment.php | 7 ++++++- app/Services/Invoice/InvoiceService.php | 4 ++-- app/Services/Invoice/MarkPaid.php | 2 +- app/Services/Payment/UpdateInvoicePayment.php | 2 +- .../PurchaseOrder/TriggeredActions.php | 13 ++++++++++-- app/Services/Quote/MarkSent.php | 2 +- app/Services/Quote/QuoteService.php | 2 +- .../Subscription/SubscriptionService.php | 2 +- 15 files changed, 60 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/PurchaseOrderController.php b/app/Http/Controllers/PurchaseOrderController.php index 44470dfa23bb..4ed383f30870 100644 --- a/app/Http/Controllers/PurchaseOrderController.php +++ b/app/Http/Controllers/PurchaseOrderController.php @@ -139,7 +139,10 @@ class PurchaseOrderController extends BaseController */ public function create(CreatePurchaseOrderRequest $request) { - $purchase_order = PurchaseOrderFactory::create(auth()->user()->company()->id, auth()->user()->id); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $purchase_order = PurchaseOrderFactory::create($user->company()->id, $user->id); return $this->itemResponse($purchase_order); } @@ -183,7 +186,10 @@ class PurchaseOrderController extends BaseController */ public function store(StorePurchaseOrderRequest $request) { - $purchase_order = $this->purchase_order_repository->save($request->all(), PurchaseOrderFactory::create(auth()->user()->company()->id, auth()->user()->id)); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $purchase_order = $this->purchase_order_repository->save($request->all(), PurchaseOrderFactory::create($user->company()->id, $user->id)); $purchase_order = $purchase_order->service() ->fillDefaults() @@ -361,7 +367,7 @@ class PurchaseOrderController extends BaseController $purchase_order = $purchase_order->service() ->triggeredActions($request) - ->touchPdf() + // ->touchPdf() ->save(); event(new PurchaseOrderWasUpdated($purchase_order, $purchase_order->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index 22eb75249cfc..4d06e8bc5ca6 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -395,8 +395,8 @@ class QuoteController extends BaseController $quote = $this->quote_repo->save($request->all(), $quote); $quote->service() - ->triggeredActions($request) - ->deletePdf(); + ->triggeredActions($request); + // ->deletePdf(); event(new QuoteWasUpdated($quote, $quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Http/Controllers/RecurringInvoiceController.php b/app/Http/Controllers/RecurringInvoiceController.php index 271c6e57df30..d09d31e80220 100644 --- a/app/Http/Controllers/RecurringInvoiceController.php +++ b/app/Http/Controllers/RecurringInvoiceController.php @@ -153,7 +153,10 @@ class RecurringInvoiceController extends BaseController */ public function create(CreateRecurringInvoiceRequest $request) { - $recurring_invoice = RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $recurring_invoice = RecurringInvoiceFactory::create($user->company()->id, $user->id); return $this->itemResponse($recurring_invoice); } @@ -199,7 +202,10 @@ class RecurringInvoiceController extends BaseController */ public function store(StoreRecurringInvoiceRequest $request) { - $recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id)); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $recurring_invoice = $this->recurring_invoice_repo->save($request->all(), RecurringInvoiceFactory::create($user->company()->id, $user->id)); $recurring_invoice->service() ->triggeredActions($request) @@ -380,7 +386,7 @@ class RecurringInvoiceController extends BaseController $recurring_invoice->service() ->triggeredActions($request) - ->deletePdf() + // ->deletePdf() ->save(); event(new RecurringInvoiceWasUpdated($recurring_invoice, $recurring_invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); @@ -405,18 +411,21 @@ class RecurringInvoiceController extends BaseController */ public function bulk(BulkRecurringInvoiceRequest $request) { + /** @var \App\Models\User $user */ + $user = auth()->user(); + $percentage_increase = request()->has('percentage_increase') ? request()->input('percentage_increase') : 0; if (in_array($request->action, ['increase_prices', 'update_prices'])) { - UpdateRecurring::dispatch($request->ids, auth()->user()->company(), auth()->user(), $request->action, $percentage_increase); + UpdateRecurring::dispatch($request->ids, $user->company(), $user, $request->action, $percentage_increase); return response()->json(['message' => 'Update in progress.'], 200); } $recurring_invoices = RecurringInvoice::withTrashed()->find($request->ids); - $recurring_invoices->each(function ($recurring_invoice, $key) use ($request) { - if (auth()->user()->can('edit', $recurring_invoice)) { + $recurring_invoices->each(function ($recurring_invoice, $key) use ($request, $user) { + if ($user->can('edit', $recurring_invoice)) { $this->performAction($recurring_invoice, $request->action, true); } }); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 940727d9f917..183578d89342 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -530,9 +530,9 @@ class BaseDriver extends AbstractPaymentDriver $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); - $invoices->each(function ($invoice) { - $invoice->service()->deletePdf(); - }); + // $invoices->each(function ($invoice) { + // $invoice->service()->deletePdf(); + // }); $invoices->first()->invitations->each(function ($invitation) use ($nmo) { if ((bool) $invitation->contact->send_email !== false && $invitation->contact->email) { @@ -575,9 +575,9 @@ class BaseDriver extends AbstractPaymentDriver $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); - $invoices->each(function ($invoice) { - $invoice->service()->deletePdf(); - }); + // $invoices->each(function ($invoice) { + // $invoice->service()->deletePdf(); + // }); $invoices->first()->invitations->each(function ($invitation) use ($nmo) { if (! $invitation->contact->trashed()) { diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index 70639ce02001..99a3d9f28729 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -137,7 +137,7 @@ class ApplyPayment ->updateBalance($this->amount_applied * -1) ->updatePaidToDate($this->amount_applied) ->updateStatus() - ->deletePdf() + // ->deletePdf() ->save(); $this->credit @@ -147,7 +147,7 @@ class ApplyPayment event(new InvoiceWasUpdated($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); if ((int) $this->invoice->balance == 0) { - $this->invoice->service()->deletePdf(); + // $this->invoice->service()->deletePdf(); $this->invoice = $this->invoice->fresh(); event(new InvoiceWasPaid($this->invoice, $this->payment, $this->payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); } diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index 648bed322e1c..7b00f0ead97d 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -154,7 +154,7 @@ class CreditService { $this->credit = (new ApplyPayment($this->credit, $invoice, $amount, $payment))->run(); - $this->deletePdf(); + // $this->deletePdf(); return $this; } diff --git a/app/Services/Credit/MarkSent.php b/app/Services/Credit/MarkSent.php index 890f6887c741..ea38f9c43dc9 100644 --- a/app/Services/Credit/MarkSent.php +++ b/app/Services/Credit/MarkSent.php @@ -42,7 +42,7 @@ class MarkSent ->setStatus(Credit::STATUS_SENT) ->applyNumber() ->adjustBalance($this->credit->amount) - ->deletePdf() + // ->deletePdf() ->save(); $this->client diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index a0a2fb5f83fd..de4e5791b594 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -92,7 +92,12 @@ class ApplyPayment extends AbstractService } }); - $this->invoice->service()->applyNumber()->workFlow()->deletePdf()->save(); + $this->invoice + ->service() + ->applyNumber() + ->workFlow() + // ->deletePdf() + ->save(); return $this->invoice; } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 148f0cae88d5..1122683a7735 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -346,7 +346,7 @@ class InvoiceService return $item; })->toArray(); - $this->deletePdf(); + // $this->deletePdf(); $this->deleteEInvoice(); return $this; @@ -414,7 +414,7 @@ class InvoiceService })->toArray(); $this->invoice = $this->invoice->calc()->getInvoice(); - $this->deletePdf(); + // $this->deletePdf(); $this->deleteEInvoice(); /* 24-03-2022 */ diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 6b2c515a97cb..dd9ef12b552c 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -102,7 +102,7 @@ class MarkPaid extends AbstractService $this->invoice ->service() ->applyNumber() - ->deletePdf() + // ->deletePdf() ->save(); $payment->ledger() diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index e0e793bd6e2b..10243007fc70 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -79,7 +79,7 @@ class UpdateInvoicePayment $invoice = $invoice->service() ->clearPartial() ->updateStatus() - ->deletePdf() + // ->deletePdf() ->workFlow() ->save(); diff --git a/app/Services/PurchaseOrder/TriggeredActions.php b/app/Services/PurchaseOrder/TriggeredActions.php index 38510fc70962..624efc3ac4fd 100644 --- a/app/Services/PurchaseOrder/TriggeredActions.php +++ b/app/Services/PurchaseOrder/TriggeredActions.php @@ -35,12 +35,21 @@ class TriggeredActions extends AbstractService public function run() { if ($this->request->has('send_email') && $this->request->input('send_email') == 'true') { - $this->purchase_order->service()->markSent()->touchPdf()->save(); + $this->purchase_order + ->service() + ->markSent() + // ->touchPdf() + ->save(); + $this->sendEmail(); } if ($this->request->has('mark_sent') && $this->request->input('mark_sent') == 'true') { - $this->purchase_order = $this->purchase_order->service()->markSent()->touchPdf()->save(); + $this->purchase_order = $this->purchase_order + ->service() + ->markSent() + // ->touchPdf() + ->save(); } if ($this->request->has('save_default_footer') && $this->request->input('save_default_footer') == 'true') { diff --git a/app/Services/Quote/MarkSent.php b/app/Services/Quote/MarkSent.php index c6a615efd9a5..263ce043ce20 100644 --- a/app/Services/Quote/MarkSent.php +++ b/app/Services/Quote/MarkSent.php @@ -42,7 +42,7 @@ class MarkSent ->service() ->setStatus(Quote::STATUS_SENT) ->applyNumber() - ->deletePdf() + // ->deletePdf() ->save(); event(new QuoteWasMarkedSent($this->quote, $this->quote->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 45b38cc0b52b..908cb257c151 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -116,7 +116,7 @@ class QuoteService $this->invoice ->service() ->markSent() - ->deletePdf() + // ->deletePdf() ->save(); } diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index ad3bae0cfa37..64b13fa38db3 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -188,7 +188,7 @@ class SubscriptionService //update the invoice and attach to the recurring invoice!!!!! $invoice->recurring_id = $recurring_invoice->id; $invoice->is_proforma = false; - $invoice->service()->deletePdf(); + // $invoice->service()->deletePdf(); $invoice->save(); $contact = $invoice->client->contacts()->whereNotNull('email')->first();