From 52adc55c9cb26be122daa2af0900b41ca0db67c2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 24 Sep 2024 14:49:19 +1000 Subject: [PATCH] Fixes for static analysis --- app/PaymentDrivers/CBAPowerBoard/Settings.php | 5 ++- .../Quickbooks/Jobs/QuickbooksImport.php | 43 ++----------------- app/Services/Quickbooks/Models/QbClient.php | 3 +- app/Services/Quickbooks/Models/QbInvoice.php | 11 +++-- app/Services/Quickbooks/Models/QbProduct.php | 3 +- app/Services/Quickbooks/QuickbooksService.php | 2 +- 6 files changed, 16 insertions(+), 51 deletions(-) diff --git a/app/PaymentDrivers/CBAPowerBoard/Settings.php b/app/PaymentDrivers/CBAPowerBoard/Settings.php index 36cf300a0f97..a005ccdf363f 100644 --- a/app/PaymentDrivers/CBAPowerBoard/Settings.php +++ b/app/PaymentDrivers/CBAPowerBoard/Settings.php @@ -13,10 +13,11 @@ namespace App\PaymentDrivers\CBAPowerBoard; -use App\PaymentDrivers\CBAPowerBoard\Models\Gateways; +use App\Models\GatewayType; -use App\PaymentDrivers\CBAPowerBoard\Models\Gateway; use App\PaymentDrivers\CBAPowerBoardPaymentDriver; +use App\PaymentDrivers\CBAPowerBoard\Models\Gateway; +use App\PaymentDrivers\CBAPowerBoard\Models\Gateways; class Settings { diff --git a/app/Services/Quickbooks/Jobs/QuickbooksImport.php b/app/Services/Quickbooks/Jobs/QuickbooksImport.php index 16506102a3fa..3bafdbd046eb 100644 --- a/app/Services/Quickbooks/Jobs/QuickbooksImport.php +++ b/app/Services/Quickbooks/Jobs/QuickbooksImport.php @@ -153,7 +153,7 @@ class QuickbooksImport implements ShouldQueue $contact->fill($ninja_data[1]); $contact->saveQuietly(); } - elseif($this->qbs->syncable('vendor', (\App\Enum\SyncDirection::PULL)->value)){ + elseif($this->qbs->syncable('vendor', \App\Enum\SyncDirection::PULL)){ $contact->fill($ninja_data[1]); $contact->saveQuietly(); } @@ -194,7 +194,7 @@ class QuickbooksImport implements ShouldQueue return ExpenseFactory::create($this->company->id, $this->company->owner()->id); } elseif($search->count() == 1) { - return $this->service->syncable('expense', \App\Enum\SyncDirection::PULL) ? $search->first() : null; + return $this->qbs->syncable('expense', \App\Enum\SyncDirection::PULL) ? $search->first() : null; } return null; @@ -225,49 +225,12 @@ class QuickbooksImport implements ShouldQueue } elseif($search->count() == 1) { - return $this->service->syncable('vendor', \App\Enum\SyncDirection::PULL) ? $search->first() : null; + return $this->qbs->syncable('vendor', \App\Enum\SyncDirection::PULL) ? $search->first() : null; } return null; } - private function findClient(array $qb_data) :?Client - { - $client = $qb_data[0]; - $contact = $qb_data[1]; - $client_meta = $qb_data[2]; - - $search = Client::query() - ->withTrashed() - ->where('company_id', $this->company->id) - ->where(function ($q) use ($client, $client_meta, $contact){ - - $q->where('client_hash', $client_meta['client_hash']) - ->orWhere('number', $client['number']) - ->orWhereHas('contacts', function ($q) use ($contact){ - $q->where('email', $contact['email']); - }); - - }); - - if($search->count() == 0) { - //new client - $client = ClientFactory::create($this->company->id, $this->company->owner()->id); - $client->client_hash = $client_meta['client_hash']; - $client->settings = $client_meta['settings']; - - return $client; - } - elseif($search->count() == 1) { - -return $this->service->syncable('client', \App\Enum\SyncDirection::PULL) ? $search->first() : null; - } - - return null; - } - - - public function middleware() { return [new WithoutOverlapping("qbs-{$this->company_id}-{$this->db}")]; diff --git a/app/Services/Quickbooks/Models/QbClient.php b/app/Services/Quickbooks/Models/QbClient.php index c7c896150e3d..b40a71c7eb85 100644 --- a/app/Services/Quickbooks/Models/QbClient.php +++ b/app/Services/Quickbooks/Models/QbClient.php @@ -101,8 +101,7 @@ class QbClient implements SyncInterface return $client; } elseif ($search->count() == 1) { - -return $this->service->syncable('client', \App\Enum\SyncDirection::PULL) ? $search->first() : null; + return $this->service->syncable('client', \App\Enum\SyncDirection::PULL) ? $search->first() : null; } return null; diff --git a/app/Services/Quickbooks/Models/QbInvoice.php b/app/Services/Quickbooks/Models/QbInvoice.php index e1181f86824a..dc9dcc8aebde 100644 --- a/app/Services/Quickbooks/Models/QbInvoice.php +++ b/app/Services/Quickbooks/Models/QbInvoice.php @@ -81,7 +81,7 @@ class QbInvoice implements SyncInterface if($search->count() == 0) { $invoice = InvoiceFactory::create($this->service->company->id, $this->service->company->owner()->id); - $invoice->client_id = $client_id; + $invoice->client_id = (int)$client_id; $sync = new InvoiceSync(); $sync->qb_id = $id; @@ -89,8 +89,7 @@ class QbInvoice implements SyncInterface return $invoice; } elseif($search->count() == 1) { - -return $this->service->syncable('invoice', \App\Enum\SyncDirection::PULL) ? $search->first() : null; + return $this->service->syncable('invoice', \App\Enum\SyncDirection::PULL) ? $search->first() : null; } return null; @@ -102,6 +101,8 @@ return $this->service->syncable('invoice', \App\Enum\SyncDirection::PULL) ? $sea $qb_record = $this->find($id); + nlog($qb_record); + if($this->service->syncable('invoice', \App\Enum\SyncDirection::PULL)) { @@ -119,6 +120,8 @@ return $this->service->syncable('invoice', \App\Enum\SyncDirection::PULL) ? $sea elseif(Carbon::parse($last_updated)->gt(Carbon::parse($invoice->updated_at))) { $ninja_invoice_data = $this->invoice_transformer->qbToNinja($qb_record); + nlog($ninja_invoice_data); + $this->invoice_repository->save($ninja_invoice_data, $invoice); } @@ -182,7 +185,7 @@ return $this->service->syncable('invoice', \App\Enum\SyncDirection::PULL) ? $sea } - if ($record instanceof IPPSalesReceipt) { + if ($record instanceof \QuickBooksOnline\API\Data\IPPSalesReceipt) { $invoice->service()->markPaid()->save(); } diff --git a/app/Services/Quickbooks/Models/QbProduct.php b/app/Services/Quickbooks/Models/QbProduct.php index 6a9da37f5457..085718546231 100644 --- a/app/Services/Quickbooks/Models/QbProduct.php +++ b/app/Services/Quickbooks/Models/QbProduct.php @@ -73,8 +73,7 @@ class QbProduct implements SyncInterface return $product; } elseif($search->count() == 1) { - -return $this->service->syncable('product', \App\Enum\SyncDirection::PULL) ? $search->first() : null; + return $this->service->syncable('product', \App\Enum\SyncDirection::PULL) ? $search->first() : null; } return null; diff --git a/app/Services/Quickbooks/QuickbooksService.php b/app/Services/Quickbooks/QuickbooksService.php index 87a100ac1807..9c5c6580e42d 100644 --- a/app/Services/Quickbooks/QuickbooksService.php +++ b/app/Services/Quickbooks/QuickbooksService.php @@ -144,7 +144,7 @@ class QuickbooksService * Flag to determine if a sync is allowed in either direction * * @param string $entity - * @param mixed $direction + * @param \App\Enum\SyncDirection $direction * @return bool */ public function syncable(string $entity, \App\Enum\SyncDirection $direction): bool