From 01cc61b586c4c34cdd002f8d57a03ed237b0fc3b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 7 Aug 2023 15:07:52 +1000 Subject: [PATCH] Updated static analysis --- .../Invoice/InvoiceItemSumInclusive.php | 4 +- app/Helpers/Mail/GmailTransport.php | 4 +- .../ClientPortal/NinjaPlanController.php | 4 +- app/Http/Livewire/BillingPortalPurchasev2.php | 2 +- app/Http/Middleware/ContactKeyLogin.php | 4 +- app/Http/Middleware/ContactRegister.php | 3 +- .../Requests/ClientPortal/RegisterRequest.php | 5 +- .../Payments/PaymentWebhookRequest.php | 1 - .../StoreRecurringInvoiceRequest.php | 7 ++- .../UpdateRecurringInvoiceRequest.php | 10 +++- .../StoreRecurringQuoteRequest.php | 13 ++++- .../Documents/ShowDocumentRequest.php | 3 ++ .../Ninja/CanStoreClientsRule.php | 2 +- .../ValidationRules/ValidUserForCompany.php | 5 +- app/Import/Providers/BaseImport.php | 2 +- app/Import/Providers/Wave.php | 4 +- app/Import/Transformer/BaseTransformer.php | 52 +++++++++---------- .../Transformer/Zoho/InvoiceTransformer.php | 4 +- app/Models/Company.php | 1 + 19 files changed, 81 insertions(+), 49 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index 9e792c0d71..238f486365 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -226,8 +226,10 @@ class InvoiceItemSumInclusive $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100)); + /** @var float $item_tax_rate1_total */ $item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount); - + + /** @var float $item_tax */ $item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision); if (strlen($this->item->tax_name1) > 1) { diff --git a/app/Helpers/Mail/GmailTransport.php b/app/Helpers/Mail/GmailTransport.php index 0a7f582445..1538edcfde 100644 --- a/app/Helpers/Mail/GmailTransport.php +++ b/app/Helpers/Mail/GmailTransport.php @@ -34,7 +34,7 @@ class GmailTransport extends AbstractTransport $message = MessageConverter::toEmail($message->getOriginalMessage()); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line **/ $token = $message->getHeaders()->get('gmailtoken')->getValue(); $message->getHeaders()->remove('gmailtoken'); @@ -55,7 +55,7 @@ class GmailTransport extends AbstractTransport $bcc_list = 'Bcc: '; - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore-next-line **/ foreach ($bccs->getAddresses() as $address) { $bcc_list .= $address->getAddress() .','; } diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index f0346d2371..b57b2f0524 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -157,6 +157,8 @@ class NinjaPlanController extends Controller //create recurring invoice $subscription_repo = new SubscriptionRepository(); + + /** @var \App\Models\Subscription $subscription **/ $subscription = Subscription::find(6); $recurring_invoice = RecurringInvoiceFactory::create($subscription->company_id, $subscription->user_id); @@ -215,7 +217,7 @@ class NinjaPlanController extends Controller $data['late_invoice'] = false; if (MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) { - $account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); + $account = Account::query()->where('key', Auth::guard('contact')->user()->client->custom_value2)->first(); if ($account) { //offer the option to have a free trial diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index b4fbbdd255..1a6c1a8ba1 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -53,7 +53,7 @@ class BillingPortalPurchasev2 extends Component /** * Instance of subscription. * - * @var Subscription + * @var \App\Models\Subscription */ public $subscription; diff --git a/app/Http/Middleware/ContactKeyLogin.php b/app/Http/Middleware/ContactKeyLogin.php index e49306665e..7867e572c7 100644 --- a/app/Http/Middleware/ContactKeyLogin.php +++ b/app/Http/Middleware/ContactKeyLogin.php @@ -121,7 +121,7 @@ class ContactKeyLogin } } } elseif ($request->has('client_hash')) { - if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) { + if ($client = Client::query()->where('client_hash', $request->input('client_hash'))->first()) { $primary_contact = $client->primary_contact()->first(); if (empty($primary_contact->email)) { @@ -134,7 +134,7 @@ class ContactKeyLogin return redirect($this->setRedirectPath()); } } elseif ($request->segment(3)) { - if ($client_contact = ClientContact::with('company')->where('contact_key', $request->segment(3))->first()) { + if ($client_contact = ClientContact::query()->with('company')->where('contact_key', $request->segment(3))->first()) { if ($client_contact->company->settings->enable_client_portal_password) { return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]); } diff --git a/app/Http/Middleware/ContactRegister.php b/app/Http/Middleware/ContactRegister.php index 3263f878ee..a0356d6bbf 100644 --- a/app/Http/Middleware/ContactRegister.php +++ b/app/Http/Middleware/ContactRegister.php @@ -65,7 +65,7 @@ class ContactRegister // For self-hosted platforms with multiple companies, resolving is done using company key // if it doesn't resolve using a domain. - if ($request->company_key && Ninja::isSelfHost() && $company = Company::where('company_key', $request->company_key)->first()) { + if ($request->company_key && Ninja::isSelfHost() && $company = Company::query()->where('company_key', $request->company_key)->first()) { if (! (bool) $company->client_can_register) { abort(400, 'Registration disabled'); } @@ -79,6 +79,7 @@ class ContactRegister // As a fallback for self-hosted, it will use default company in the system // if key isn't provided in the url. if (! $request->route()->parameter('company_key') && Ninja::isSelfHost()) { + /** @var \App\Models\Company $company */ $company = Account::first()->default_company; if (! $company->client_can_register) { diff --git a/app/Http/Requests/ClientPortal/RegisterRequest.php b/app/Http/Requests/ClientPortal/RegisterRequest.php index b1e4763075..b395d54f98 100644 --- a/app/Http/Requests/ClientPortal/RegisterRequest.php +++ b/app/Http/Requests/ClientPortal/RegisterRequest.php @@ -66,14 +66,15 @@ class RegisterRequest extends FormRequest { //this should be all we need, the rest SHOULD be redundant because of our Middleware if ($this->key) { - return Company::where('company_key', $this->key)->first(); + return Company::query()->where('company_key', $this->key)->first(); } if ($this->company_key) { - return Company::where('company_key', $this->company_key)->firstOrFail(); + return Company::query()->where('company_key', $this->company_key)->firstOrFail(); } if (! $this->route()->parameter('company_key') && Ninja::isSelfHost()) { + /** @var \App\Models\Company $company */ $company = Account::first()->default_company; if (! $company->client_can_register) { diff --git a/app/Http/Requests/Payments/PaymentWebhookRequest.php b/app/Http/Requests/Payments/PaymentWebhookRequest.php index 5255ef6f2a..8714f7ba80 100644 --- a/app/Http/Requests/Payments/PaymentWebhookRequest.php +++ b/app/Http/Requests/Payments/PaymentWebhookRequest.php @@ -39,7 +39,6 @@ class PaymentWebhookRequest extends Request /** * Resolve company gateway. * - * @param mixed $id * @return null|\App\Models\CompanyGateway */ public function getCompanyGateway() diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index 307ab9cffe..aa8c8f406d 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -31,7 +31,11 @@ class StoreRecurringInvoiceRequest extends Request */ public function authorize() : bool { - return auth()->user()->can('create', RecurringInvoice::class); + + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + + return $user->can('create', RecurringInvoice::class); } public function rules() @@ -137,6 +141,7 @@ class StoreRecurringInvoiceRequest extends Request if (isset($input['auto_bill'])) { $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); } else { + /** @var \App\Models\Client $client */ if (array_key_exists('client_id', $input) && $client = Client::find($input['client_id'])) { $input['auto_bill'] = $client->getSetting('auto_bill'); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); diff --git a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php index bbfa22bc0c..bbff843b22 100644 --- a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php @@ -31,11 +31,17 @@ class UpdateRecurringInvoiceRequest extends Request */ public function authorize() : bool { - return auth()->user()->can('edit', $this->recurring_invoice); + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + + return $user->can('edit', $this->recurring_invoice); } public function rules() { + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { @@ -51,7 +57,7 @@ class UpdateRecurringInvoiceRequest extends Request } if ($this->number) { - $rules['number'] = Rule::unique('recurring_invoices')->where('company_id', auth()->user()->company()->id)->ignore($this->recurring_invoice->id); + $rules['number'] = Rule::unique('recurring_invoices')->where('company_id', $user->company()->id)->ignore($this->recurring_invoice->id); } $rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())]; diff --git a/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php b/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php index 396341b9fc..75eec29655 100644 --- a/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php +++ b/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php @@ -30,11 +30,19 @@ class StoreRecurringQuoteRequest extends Request */ public function authorize() : bool { - return auth()->user()->can('create', RecurringQuote::class); + + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + + return $user->can('create', RecurringQuote::class); } public function rules() { + + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + $rules = []; if ($this->file('documents') && is_array($this->file('documents'))) { @@ -49,7 +57,7 @@ class StoreRecurringQuoteRequest extends Request $rules['file'] = $this->file_validation; } - $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; + $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id; $rules['invitations.*.client_contact_id'] = 'distinct'; @@ -71,6 +79,7 @@ class StoreRecurringQuoteRequest extends Request $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); } else { if ($client = Client::find($input['client_id'])) { + /** @var \App\Models\Client $client */ $input['auto_bill'] = $client->getSetting('auto_bill'); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); } diff --git a/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php b/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php index 83e3357e1d..691cfe1d05 100644 --- a/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php +++ b/app/Http/Requests/VendorPortal/Documents/ShowDocumentRequest.php @@ -26,6 +26,9 @@ class ShowDocumentRequest extends FormRequest */ public function authorize() { + + /** @var \App\Models\VendorContact auth()->guard('vendor')->user() */ + return auth()->guard('vendor')->user()->client_id == $this->document->documentable_id || $this->document->company_id == auth()->guard('vendor')->user()->company_id; } diff --git a/app/Http/ValidationRules/Ninja/CanStoreClientsRule.php b/app/Http/ValidationRules/Ninja/CanStoreClientsRule.php index 6c1f49afb6..8bd700fefe 100644 --- a/app/Http/ValidationRules/Ninja/CanStoreClientsRule.php +++ b/app/Http/ValidationRules/Ninja/CanStoreClientsRule.php @@ -21,7 +21,7 @@ class CanStoreClientsRule implements Rule { public $company_id; - public $company; + public \App\Models\Company $company; public function __construct($company_id) { diff --git a/app/Http/ValidationRules/ValidUserForCompany.php b/app/Http/ValidationRules/ValidUserForCompany.php index 3a724c78ec..8a60cd2751 100644 --- a/app/Http/ValidationRules/ValidUserForCompany.php +++ b/app/Http/ValidationRules/ValidUserForCompany.php @@ -26,7 +26,10 @@ class ValidUserForCompany implements Rule */ public function passes($attribute, $value) { - return MultiDB::checkUserAndCompanyCoExist($value, auth()->user()->company()->company_key, auth()->user()->company()->id); + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + + return MultiDB::checkUserAndCompanyCoExist($value, $user->company()->company_key); } /** diff --git a/app/Import/Providers/BaseImport.php b/app/Import/Providers/BaseImport.php index 988c85b520..04ace061da 100644 --- a/app/Import/Providers/BaseImport.php +++ b/app/Import/Providers/BaseImport.php @@ -95,7 +95,7 @@ class BaseImport ini_set('auto_detect_line_endings', '1'); } - /** @var strin $base64_encoded_csv */ + /** @var string $base64_encoded_csv */ $base64_encoded_csv = Cache::pull($this->hash.'-'.$entity_type); if (empty($base64_encoded_csv)) { diff --git a/app/Import/Providers/Wave.php b/app/Import/Providers/Wave.php index 9543c704a2..4b4c10adc1 100644 --- a/app/Import/Providers/Wave.php +++ b/app/Import/Providers/Wave.php @@ -189,7 +189,7 @@ class Wave extends BaseImport implements ImportInterface $this->transformer = new ExpenseTransformer($this->company); - $expense_count = $this->ingestExpenses($data, $entity_type); + $expense_count = $this->ingestExpenses($data); $this->entity_count['expenses'] = $expense_count; } @@ -200,7 +200,7 @@ class Wave extends BaseImport implements ImportInterface private function groupExpenses($csvData) { - $grouped_expense = []; + $grouped = []; $key = 'Transaction ID'; foreach ($csvData as $expense) { diff --git a/app/Import/Transformer/BaseTransformer.php b/app/Import/Transformer/BaseTransformer.php index ddc190b029..a979a85082 100644 --- a/app/Import/Transformer/BaseTransformer.php +++ b/app/Import/Transformer/BaseTransformer.php @@ -176,7 +176,7 @@ class BaseTransformer public function getClient($client_name, $client_email) { if (! empty($client_name)) { - $client_id_search = Client::where('company_id', $this->company->id) + $client_id_search = Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->where('id_number', $client_name); @@ -184,7 +184,7 @@ class BaseTransformer return $client_id_search->first()->id; } - $client_name_search = Client::where('company_id', $this->company->id) + $client_name_search = Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $client_name)), @@ -195,7 +195,7 @@ class BaseTransformer } } if (! empty($client_email)) { - $contacts = ClientContact::whereHas('client', function ($query) { + $contacts = ClientContact::query()->whereHas('client', function ($query) { $query->where('is_deleted', false); }) ->where('company_id', $this->company->id) @@ -238,7 +238,7 @@ class BaseTransformer */ public function hasClient($name) { - return Client::where('company_id', $this->company->id) + return Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -248,7 +248,7 @@ class BaseTransformer public function hasClientIdNumber($id_number) { - return Client::where('company_id', $this->company->id) + return Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->where('id_number', trim($id_number)) ->exists(); @@ -262,7 +262,7 @@ class BaseTransformer */ public function hasVendor($name) { - return Vendor::where('company_id', $this->company->id) + return Vendor::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -277,7 +277,7 @@ class BaseTransformer */ public function hasProject($name) { - return Project::where('company_id', $this->company->id) + return Project::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -292,7 +292,7 @@ class BaseTransformer */ public function hasProduct($key) { - return Product::where('company_id', $this->company->id) + return Product::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $key)), @@ -341,7 +341,7 @@ class BaseTransformer */ public function getClientId($name) { - $client = Client::where('company_id', $this->company->id) + $client = Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -358,7 +358,7 @@ class BaseTransformer */ public function getProduct($key) { - $product = Product::where('company_id', $this->company->id) + $product = Product::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $key)), @@ -375,7 +375,7 @@ class BaseTransformer */ public function getContact($email): ?ClientContact { - $contact = ClientContact::where('company_id', $this->company->id) + $contact = ClientContact::query()->where('company_id', $this->company->id) ->whereRaw("LOWER(REPLACE(`email`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $email)), ]) @@ -400,7 +400,7 @@ class BaseTransformer return $this->getCountryIdBy2($name); } - $country = Country::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ + $country = Country::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), ])->first(); @@ -414,8 +414,8 @@ class BaseTransformer */ public function getCountryIdBy2($name) { - return Country::where('iso_3166_2', $name)->exists() - ? Country::where('iso_3166_2', $name)->first()->id + return Country::query()->where('iso_3166_2', $name)->exists() + ? Country::query()->where('iso_3166_2', $name)->first()->id : null; } @@ -428,7 +428,7 @@ class BaseTransformer { $name = strtolower(trim($name)); - $tax_rate = TaxRate::where('company_id', $this->company->id) + $tax_rate = TaxRate::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -447,7 +447,7 @@ class BaseTransformer { $name = strtolower(trim($name)); - $tax_rate = TaxRate::where('company_id', $this->company->id) + $tax_rate = TaxRate::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -495,7 +495,7 @@ class BaseTransformer */ public function getInvoiceId($invoice_number) { - $invoice = Invoice::where('company_id', $this->company->id) + $invoice = Invoice::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $invoice_number)), @@ -512,7 +512,7 @@ class BaseTransformer */ public function hasInvoice($invoice_number) { - return Invoice::where('company_id', $this->company->id) + return Invoice::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $invoice_number)), @@ -528,7 +528,7 @@ class BaseTransformer */ public function hasRecurringInvoice($invoice_number) { - return RecurringInvoice::where('company_id', $this->company->id) + return RecurringInvoice::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $invoice_number)), @@ -541,7 +541,7 @@ class BaseTransformer */ public function hasExpense($expense_number) { - return Expense::where('company_id', $this->company->id) + return Expense::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $expense_number)), @@ -556,7 +556,7 @@ class BaseTransformer */ public function hasQuote($quote_number) { - return Quote::where('company_id', $this->company->id) + return Quote::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $quote_number)), @@ -571,7 +571,7 @@ class BaseTransformer */ public function getInvoiceClientId($invoice_number) { - $invoice = Invoice::where('company_id', $this->company->id) + $invoice = Invoice::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $invoice_number)), @@ -588,7 +588,7 @@ class BaseTransformer */ public function getVendorId($name) { - $vendor = Vendor::where('company_id', $this->company->id) + $vendor = Vendor::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -626,7 +626,7 @@ class BaseTransformer { /** @var \App\Models\ExpenseCategory $ec */ - $ec = ExpenseCategory::where('company_id', $this->company->id) + $ec = ExpenseCategory::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -669,7 +669,7 @@ class BaseTransformer */ public function getProjectId($name, $clientId = null) { - $project = Project::where('company_id', $this->company->id) + $project = Project::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), @@ -700,7 +700,7 @@ class BaseTransformer */ public function getPaymentTypeId($name) { - $pt = PaymentType::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ + $pt = PaymentType::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $name)), ])->first(); diff --git a/app/Import/Transformer/Zoho/InvoiceTransformer.php b/app/Import/Transformer/Zoho/InvoiceTransformer.php index 2c13bce53c..faae4fffa2 100644 --- a/app/Import/Transformer/Zoho/InvoiceTransformer.php +++ b/app/Import/Transformer/Zoho/InvoiceTransformer.php @@ -102,7 +102,7 @@ class InvoiceTransformer extends BaseTransformer $client_name = $this->getString($invoice_data, 'Customer Name'); if(strlen($client_name) >= 2) { - $client_name_search = \App\Models\Client::where('company_id', $this->company->id) + $client_name_search = \App\Models\Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [ strtolower(str_replace(' ', '', $client_name)), @@ -115,7 +115,7 @@ class InvoiceTransformer extends BaseTransformer $customer_id = $this->getString($invoice_data, 'Customer ID'); - $client_id_search = \App\Models\Client::where('company_id', $this->company->id) + $client_id_search = \App\Models\Client::query()->where('company_id', $this->company->id) ->where('is_deleted', false) ->where('id_number', trim($customer_id)); diff --git a/app/Models/Company.php b/app/Models/Company.php index f1fbea97fd..932a3899c9 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -200,6 +200,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property-read int|null $vendors_count * @property-read \Illuminate\Database\Eloquent\Collection $webhooks * @method static \Illuminate\Database\Eloquent\Builder|Company where($query) + * @method static \Illuminate\Database\Eloquent\Builder|Company find($query) * @property-read int|null $webhooks_count * @property int $calculate_taxes * @property mixed $tax_data