From b13783d75bcab7b0d7d1f34e2b411f88271a015f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 6 Aug 2023 17:03:12 +1000 Subject: [PATCH] Migration for dashboard permissions --- .../Subscription/SubscriptionCalculator.php | 2 +- app/Http/Controllers/BaseController.php | 2 +- .../ClientPortal/ApplePayDomainController.php | 3 +- .../ClientPortal/DocumentController.php | 2 +- .../ClientPortal/InvoiceController.php | 16 +++++-- .../ClientPortal/NinjaPlanController.php | 6 +-- .../ClientPortal/PaymentController.php | 2 +- .../ClientPortal/QuoteController.php | 9 ++-- app/Http/Controllers/CreditController.php | 12 +++-- app/Http/Controllers/DocumentController.php | 2 +- .../PreviewPurchaseOrderController.php | 2 +- .../VendorPortal/DocumentController.php | 2 +- .../VendorPortal/PurchaseOrderController.php | 3 +- .../VendorContactHashLoginController.php | 2 +- .../ValidCreditsPresentRule.php | 2 +- .../ValidPayableInvoicesRule.php | 2 +- .../ValidRefundableInvoices.php | 2 +- app/Jobs/Bank/MatchBankTransactions.php | 2 +- app/Jobs/Document/ZipDocuments.php | 2 +- app/Jobs/Mail/PaymentFailedMailer.php | 2 +- app/Mail/Admin/AutoBillingFailureObject.php | 2 +- app/Mail/Engine/InvoiceEmailEngine.php | 4 +- app/Models/Account.php | 7 ++- app/Models/BankTransaction.php | 2 +- app/Models/BaseModel.php | 13 +++--- app/Models/Company.php | 5 ++- app/Models/CompanyGateway.php | 2 +- app/Models/Invoice.php | 4 +- app/Models/PurchaseOrder.php | 14 +----- app/Models/Quote.php | 2 + app/Models/Traits/Excludable.php | 6 +++ app/Models/User.php | 2 +- .../Authorize/AuthorizeTransaction.php | 2 +- .../Authorize/ChargePaymentProfile.php | 2 +- app/PaymentDrivers/BaseDriver.php | 10 ++--- app/PaymentDrivers/BraintreePaymentDriver.php | 2 +- .../CheckoutComPaymentDriver.php | 2 +- app/PaymentDrivers/GoCardless/ACH.php | 2 +- app/PaymentDrivers/GoCardless/DirectDebit.php | 2 +- app/PaymentDrivers/GoCardless/SEPA.php | 2 +- .../GoCardlessPaymentDriver.php | 2 +- app/PaymentDrivers/MolliePaymentDriver.php | 2 +- app/PaymentDrivers/SquarePaymentDriver.php | 2 +- .../BankTransactionRepository.php | 2 +- .../Migration/PaymentMigrationRepository.php | 4 +- app/Repositories/PaymentRepository.php | 2 +- app/Services/ClientPortal/InstantPayment.php | 2 +- app/Services/Credit/CreateInvitations.php | 3 +- app/Services/Email/EmailDefaults.php | 4 +- app/Services/Email/EmailMailable.php | 4 +- app/Services/Invoice/InvoiceService.php | 4 +- app/Services/Payment/UpdateInvoicePayment.php | 2 +- app/Services/Quote/CreateInvitations.php | 3 +- .../Subscription/SubscriptionService.php | 10 ++--- .../Traits/GeneratesConvertedQuoteCounter.php | 2 +- ...te_view_dashboard_permission_migration.php | 45 +++++++++++++++++++ phpstan.neon | 1 + 57 files changed, 161 insertions(+), 97 deletions(-) create mode 100644 database/migrations/2023_08_06_070205_create_view_dashboard_permission_migration.php diff --git a/app/Helpers/Subscription/SubscriptionCalculator.php b/app/Helpers/Subscription/SubscriptionCalculator.php index 99049bab3993..2c5cd39988ee 100644 --- a/app/Helpers/Subscription/SubscriptionCalculator.php +++ b/app/Helpers/Subscription/SubscriptionCalculator.php @@ -40,7 +40,7 @@ class SubscriptionCalculator */ public function isPaidUp() :bool { - $outstanding_invoices_exist = Invoice::whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) + $outstanding_invoices_exist = Invoice::query()->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('subscription_id', $this->invoice->subscription_id) ->where('client_id', $this->invoice->client_id) ->where('balance', '>', 0) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index b61390e34742..d320a8fad265 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -532,7 +532,7 @@ class BaseController extends Controller /** @phpstan-ignore-next-line */ $query = $paginator->getCollection(); /** @phpstan-ignore-line */ - + /** @phpstan-ignore-line */ $resource = new Collection($query, $transformer, $this->entity_type); diff --git a/app/Http/Controllers/ClientPortal/ApplePayDomainController.php b/app/Http/Controllers/ClientPortal/ApplePayDomainController.php index c4b016c647e5..ed1e174a9529 100644 --- a/app/Http/Controllers/ClientPortal/ApplePayDomainController.php +++ b/app/Http/Controllers/ClientPortal/ApplePayDomainController.php @@ -26,7 +26,8 @@ class ApplePayDomainController extends Controller /* Self Host */ if (Ninja::isSelfHost()) { - $cgs = CompanyGateway::whereIn('gateway_key', $this->stripe_keys) + $cgs = CompanyGateway::query() + ->whereIn('gateway_key', $this->stripe_keys) ->where('is_deleted', false) ->get(); diff --git a/app/Http/Controllers/ClientPortal/DocumentController.php b/app/Http/Controllers/ClientPortal/DocumentController.php index 1f4da5d02434..88024a39a3be 100644 --- a/app/Http/Controllers/ClientPortal/DocumentController.php +++ b/app/Http/Controllers/ClientPortal/DocumentController.php @@ -71,7 +71,7 @@ class DocumentController extends Controller public function downloadMultiple(DownloadMultipleDocumentsRequest $request) { /** @var \Illuminate\Database\Eloquent\Collection $documents **/ - $documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) + $documents = Document::query()->whereIn('id', $this->transformKeys($request->file_hash)) ->where('company_id', auth()->guard('contact')->user()->company_id) ->get(); diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index cb6764c6a84d..f67ae6042705 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -87,7 +87,8 @@ class InvoiceController extends Controller public function showBlob($hash) { $data = Cache::get($hash); - + $invitation = false; + match($data['entity_type']){ 'invoice' => $invitation = InvoiceInvitation::withTrashed()->find($data['invitation_id']), 'quote' => $invitation = QuoteInvitation::withTrashed()->find($data['invitation_id']), @@ -95,6 +96,10 @@ class InvoiceController extends Controller 'recurring_invoice' => $invitation = RecurringInvoiceInvitation::withTrashed()->find($data['invitation_id']), }; + if (! $invitation) { + return redirect('/'); + } + $file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $invitation->company->db))->handle(); $headers = ['Content-Type' => 'application/pdf']; @@ -128,7 +133,8 @@ class InvoiceController extends Controller public function downloadInvoices($ids) { - $data['invoices'] = Invoice::whereIn('id', $ids) + $data['invoices'] = Invoice::query() + ->whereIn('id', $ids) ->whereClientId(auth()->guard('contact')->user()->client->id) ->withTrashed() ->get(); @@ -153,7 +159,8 @@ class InvoiceController extends Controller */ private function makePayment(array $ids) { - $invoices = Invoice::whereIn('id', $ids) + $invoices = Invoice::query() + ->whereIn('id', $ids) ->whereClientId(auth()->guard('contact')->user()->client->id) ->withTrashed() ->get(); @@ -215,7 +222,8 @@ class InvoiceController extends Controller */ private function downloadInvoicePDF(array $ids) { - $invoices = Invoice::whereIn('id', $ids) + $invoices = Invoice::query() + ->whereIn('id', $ids) ->withTrashed() ->whereClientId(auth()->guard('contact')->user()->client->id) ->get(); diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index 996b8c2209c7..f0346d2371ae 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -40,13 +40,13 @@ class NinjaPlanController extends Controller public function index(string $contact_key, string $account_or_company_key) { MultiDB::findAndSetDbByCompanyKey($account_or_company_key); - $company = Company::where('company_key', $account_or_company_key)->first(); + $company = Company::query()->where('company_key', $account_or_company_key)->first(); if (! $company) { MultiDB::findAndSetDbByAccountKey($account_or_company_key); /** @var \App\Models\Account $account **/ - $account = Account::where('key', $account_or_company_key)->first(); + $account = Account::query()->where('key', $account_or_company_key)->first(); } else { $account = $company->account; } @@ -181,7 +181,7 @@ class NinjaPlanController extends Controller ->increment() ->queue(); - $old_recurring = RecurringInvoice::where('company_id', config('ninja.ninja_default_company_id')) + $old_recurring = RecurringInvoice::query()->where('company_id', config('ninja.ninja_default_company_id')) ->where('client_id', $client->id) ->where('id', '!=', $recurring_invoice->id) ->first(); diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index d696c083de43..841a61a105aa 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -169,7 +169,7 @@ class PaymentController extends Controller $payment = $payment->service()->applyCredits($payment_hash)->save(); /** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Invoice> $invoices */ - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id'))); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id'))); $invoices->each(function ($invoice) { /** @var \App\Models\Invoice $invoice **/ diff --git a/app/Http/Controllers/ClientPortal/QuoteController.php b/app/Http/Controllers/ClientPortal/QuoteController.php index d53d668ee2ef..6d3eb9c0335a 100644 --- a/app/Http/Controllers/ClientPortal/QuoteController.php +++ b/app/Http/Controllers/ClientPortal/QuoteController.php @@ -95,7 +95,8 @@ class QuoteController extends Controller /** @var \App\Models\ClientContact $client_contact **/ $client_contact = auth()->user(); - $data['quotes'] = Quote::whereIn('id', $ids) + $data['quotes'] = Quote::query() + ->whereIn('id', $ids) ->where('client_id', $client_contact->client_id) ->withTrashed() ->get(); @@ -120,7 +121,8 @@ class QuoteController extends Controller /** @var \App\Models\ClientContact $client_contact **/ $client_contact = auth()->user(); - $quotes = Quote::whereIn('id', $ids) + $quotes = Quote::query() + ->whereIn('id', $ids) ->whereClientId($client_contact->client_id) ->withTrashed() ->get(); @@ -168,7 +170,8 @@ class QuoteController extends Controller protected function approve(array $ids, $process = false) { - $quotes = Quote::whereIn('id', $ids) + $quotes = Quote::query() + ->whereIn('id', $ids) ->where('client_id', auth()->guard('contact')->user()->client->id) ->where('company_id', auth()->guard('contact')->user()->client->company_id) ->whereIn('status_id', [Quote::STATUS_DRAFT, Quote::STATUS_SENT]) diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index fb48ea46cbe8..e502f7ba2979 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -148,10 +148,10 @@ class CreditController extends BaseController */ public function create(CreateCreditRequest $request) { - /** @var \App\Models\User $user**/ + /** @var \App\Models\User $user **/ $user = auth()->user(); - $credit = CreditFactory::create($user->company()->id, auth()->user()->id); + $credit = CreditFactory::create($user->company()->id, $user->id); return $this->itemResponse($credit); } @@ -197,11 +197,9 @@ class CreditController extends BaseController public function store(StoreCreditRequest $request) { - /** @var \App\Models\User $user**/ + /** @var \App\Models\User $user **/ $user = auth()->user(); - // $client = Client::find($request->input('client_id')); - $credit = $this->credit_repository->save($request->all(), CreditFactory::create($user->company()->id, $user->id)); $credit = $credit->service() @@ -506,7 +504,7 @@ class CreditController extends BaseController public function bulk(BulkCreditRequest $request) { - /** @var \App\Models\User $user**/ + /** @var \App\Models\User $user **/ $user = auth()->user(); $action = $request->input('action'); @@ -725,7 +723,7 @@ class CreditController extends BaseController * Update the specified resource in storage. * * @param UploadCreditRequest $request - * @param Credit $client + * @param Credit $credit * @return Response * * diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index 0d65af5d84f1..70d4b1e8a1b4 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -128,7 +128,7 @@ class DocumentController extends BaseController /** * Show the form for editing the specified resource. * - * @param EditDocumentRegquest $request + * @param EditDocumentRequest $request * @param Document $document * @return Response */ diff --git a/app/Http/Controllers/PreviewPurchaseOrderController.php b/app/Http/Controllers/PreviewPurchaseOrderController.php index bdc90f3f8d28..6aac31cbac53 100644 --- a/app/Http/Controllers/PreviewPurchaseOrderController.php +++ b/app/Http/Controllers/PreviewPurchaseOrderController.php @@ -95,7 +95,7 @@ class PreviewPurchaseOrderController extends BaseController return response()->json(['message' => ctrans('texts.invalid_design_object')], 400); } - $entity_obj = PurchaseOrder::whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first(); + $entity_obj = PurchaseOrder::query()->whereId($this->decodePrimaryKey(request()->input('entity_id')))->company()->first(); if (! $entity_obj) { return $this->blankEntity(); diff --git a/app/Http/Controllers/VendorPortal/DocumentController.php b/app/Http/Controllers/VendorPortal/DocumentController.php index 537326b29c45..e622106904e4 100644 --- a/app/Http/Controllers/VendorPortal/DocumentController.php +++ b/app/Http/Controllers/VendorPortal/DocumentController.php @@ -96,7 +96,7 @@ class DocumentController extends Controller public function downloadMultiple(DownloadMultipleDocumentsRequest $request) { /** @var \Illuminate\Database\Eloquent\Collection $documents */ - $documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) + $documents = Document::query()->whereIn('id', $this->transformKeys($request->file_hash)) ->where('company_id', auth()->guard('vendor')->user()->company_id) ->get(); diff --git a/app/Http/Controllers/VendorPortal/PurchaseOrderController.php b/app/Http/Controllers/VendorPortal/PurchaseOrderController.php index 589c7d53dd58..775758dc893d 100644 --- a/app/Http/Controllers/VendorPortal/PurchaseOrderController.php +++ b/app/Http/Controllers/VendorPortal/PurchaseOrderController.php @@ -203,7 +203,8 @@ class PurchaseOrderController extends Controller public function downloadInvoices($ids) { - $purchase_orders = PurchaseOrder::whereIn('id', $ids) + $purchase_orders = PurchaseOrder::query() + ->whereIn('id', $ids) ->where('vendor_id', auth()->guard('vendor')->user()->vendor_id) ->withTrashed() ->get(); diff --git a/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php b/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php index 96190431d68c..102b3634a2b9 100644 --- a/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php +++ b/app/Http/Controllers/VendorPortal/VendorContactHashLoginController.php @@ -19,7 +19,7 @@ class VendorContactHashLoginController extends Controller /** * Logs a user into the client portal using their contact_key * @param string $contact_key The contact key - * @return Auth|Redirect + * @return Auth|\Illuminate\Support\Facades\Redirect */ public function login(string $contact_key) { diff --git a/app/Http/ValidationRules/ValidCreditsPresentRule.php b/app/Http/ValidationRules/ValidCreditsPresentRule.php index 5b662da16a45..00979435e38c 100644 --- a/app/Http/ValidationRules/ValidCreditsPresentRule.php +++ b/app/Http/ValidationRules/ValidCreditsPresentRule.php @@ -52,7 +52,7 @@ class ValidCreditsPresentRule implements Rule //todo need to ensure the clients credits are here not random ones! if (array_key_exists('credits', $this->input) && is_array($this->input['credits']) && count($this->input['credits']) > 0) { - $credit_collection = Credit::whereIn('id', array_column($this->input['credits'], 'credit_id'))->count(); + $credit_collection = Credit::query()->whereIn('id', array_column($this->input['credits'], 'credit_id'))->count(); return $credit_collection == count($this->input['credits']); } diff --git a/app/Http/ValidationRules/ValidPayableInvoicesRule.php b/app/Http/ValidationRules/ValidPayableInvoicesRule.php index a83eba85c61e..93503c7a36e5 100644 --- a/app/Http/ValidationRules/ValidPayableInvoicesRule.php +++ b/app/Http/ValidationRules/ValidPayableInvoicesRule.php @@ -35,7 +35,7 @@ class ValidPayableInvoicesRule implements Rule $invoices = []; if (is_array($value)) { - $invoices = Invoice::whereIn('id', array_column($value, 'invoice_id'))->company()->get(); + $invoices = Invoice::query()->whereIn('id', array_column($value, 'invoice_id'))->company()->get(); } foreach ($invoices as $invoice) { diff --git a/app/Http/ValidationRules/ValidRefundableInvoices.php b/app/Http/ValidationRules/ValidRefundableInvoices.php index 5c3d57334ad5..7b4abfce5e54 100644 --- a/app/Http/ValidationRules/ValidRefundableInvoices.php +++ b/app/Http/ValidationRules/ValidRefundableInvoices.php @@ -58,7 +58,7 @@ class ValidRefundableInvoices implements Rule $invoices = []; if (is_array($value)) { - $invoices = Invoice::whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get(); + $invoices = Invoice::query()->whereIn('id', array_column($this->input['invoices'], 'invoice_id'))->company()->get(); } else { return true; } diff --git a/app/Jobs/Bank/MatchBankTransactions.php b/app/Jobs/Bank/MatchBankTransactions.php index bc3c0fc3a2d1..c4084047dff0 100644 --- a/app/Jobs/Bank/MatchBankTransactions.php +++ b/app/Jobs/Bank/MatchBankTransactions.php @@ -113,7 +113,7 @@ class MatchBankTransactions implements ShouldQueue } } - return BankTransaction::whereIn('id', $this->bts); + return BankTransaction::query()->whereIn('id', $this->bts); } private function getInvoices(string $invoice_hashed_ids): array diff --git a/app/Jobs/Document/ZipDocuments.php b/app/Jobs/Document/ZipDocuments.php index c713e778e599..393aeec3bb80 100644 --- a/app/Jobs/Document/ZipDocuments.php +++ b/app/Jobs/Document/ZipDocuments.php @@ -85,7 +85,7 @@ class ZipDocuments implements ShouldQueue $path = $this->company->file_path(); try { - $documents = Document::whereIn('id', $this->document_ids)->get(); + $documents = Document::query()->whereIn('id', $this->document_ids)->get(); foreach ($documents as $document) { $zipFile->addFromString($this->buildFileName($document), $document->getFile()); diff --git a/app/Jobs/Mail/PaymentFailedMailer.php b/app/Jobs/Mail/PaymentFailedMailer.php index 12f3bc6f02b5..461b1a01c695 100644 --- a/app/Jobs/Mail/PaymentFailedMailer.php +++ b/app/Jobs/Mail/PaymentFailedMailer.php @@ -81,7 +81,7 @@ class PaymentFailedMailer implements ShouldQueue if ($this->payment_hash) { // $amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total; $amount =$this->payment_hash?->amount_with_fee() ?: 0; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); } //iterate through company_users diff --git a/app/Mail/Admin/AutoBillingFailureObject.php b/app/Mail/Admin/AutoBillingFailureObject.php index d72d62eceafa..a937aecf25b9 100644 --- a/app/Mail/Admin/AutoBillingFailureObject.php +++ b/app/Mail/Admin/AutoBillingFailureObject.php @@ -63,7 +63,7 @@ class AutoBillingFailureObject /* Set customized translations _NOW_ */ $t->replace(Ninja::transformTranslations($this->company->settings)); - $this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); + $this->invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); $mail_obj = new stdClass; $mail_obj->amount = $this->getAmount(); diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index debd20eaa6e6..79826b3a0345 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -171,7 +171,7 @@ class InvoiceEmailEngine extends BaseEmailEngine } if (count($expense_ids) > 0) { - $expenses = Expense::whereIn('id', $this->transformKeys($expense_ids)) + $expenses = Expense::query()->whereIn('id', $this->transformKeys($expense_ids)) ->where('invoice_documents', 1) ->cursor() ->each(function ($expense) { @@ -192,7 +192,7 @@ class InvoiceEmailEngine extends BaseEmailEngine } if (count($task_ids) > 0 && $this->invoice->company->invoice_task_documents) { - $tasks = Task::whereIn('id', $this->transformKeys($task_ids)) + $tasks = Task::query()->whereIn('id', $this->transformKeys($task_ids)) ->cursor() ->each(function ($task) { foreach ($task->documents as $document) { diff --git a/app/Models/Account.php b/app/Models/Account.php index 8af6bc7e4023..595661a4f514 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -87,6 +87,7 @@ use Laracasts\Presenter\PresentableTrait; * @method static \Illuminate\Database\Eloquent\Builder|Account first() * @method static \Illuminate\Database\Eloquent\Builder|Account with() * @method static \Illuminate\Database\Eloquent\Builder|Account count() + * @method static \Illuminate\Database\Eloquent\Builder|Account where($query) * @property-read \Illuminate\Database\Eloquent\Collection $bank_integrations * @property-read \Illuminate\Database\Eloquent\Collection $companies * @property-read \Illuminate\Database\Eloquent\Collection $company_users @@ -215,7 +216,11 @@ class Account extends BaseModel return $this->hasMany(CompanyUser::class); } - public function owner(): \Illuminate\Database\Eloquent\Relations\HasMany + /** + * Returns the owner of the Account - not a HasMany relation + * @return \App\Models\User | bool + */ + public function owner() { return $this->hasMany(CompanyUser::class)->where('is_owner', true)->first() ? $this->hasMany(CompanyUser::class)->where('is_owner', true)->first()->user : false; } diff --git a/app/Models/BankTransaction.php b/app/Models/BankTransaction.php index 2772e0d146f2..29dd6eb4300f 100644 --- a/app/Models/BankTransaction.php +++ b/app/Models/BankTransaction.php @@ -156,7 +156,7 @@ class BankTransaction extends BaseModel public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo { - return $this->belongsTo(Account::class)->withTrashed(); + return $this->belongsTo(Account::class); } public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 05fe216aa825..60071ce53b37 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -35,7 +35,11 @@ use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundExceptio * @property int $id * @property int $user_id * @property int $assigned_user_id + * @method BaseModel service() * @property \App\Models\Company $company + * @method static BaseModel find($value) + * @method BaseModel company() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\BelongsTo|\Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo|\App\Models\Company company() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\HasMany|BaseModel orderBy() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) @@ -43,26 +47,23 @@ use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundExceptio * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newModelQuery($query) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel newQuery($query) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel query() - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude(array $excludeable) - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true) - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel scopeExclude($query) - * @method static BaseModel find($value) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereId($query) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereIn($query) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel where($query) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel count() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel create($query) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel insert($query) - * @method BaseModel service() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel orderBy($column, $direction) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel invitations() * @method static \Illuminate\Database\Eloquent\Builder|BaseModel whereHas($query) * @property-read \Illuminate\Database\Eloquent\Collection $invitations * @property-read int|null $invitations_count - * @method static \Illuminate\Database\Eloquent\Builder company() * @method int companyId() * @method createInvitations() * @method Builder scopeCompany(Builder $builder) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true) + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder onlyTrashed() + * @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withoutTrashed() * @mixin \Eloquent * @mixin \Illuminate\Database\Eloquent\Builder */ diff --git a/app/Models/Company.php b/app/Models/Company.php index d9285075983e..f1fbea97fd01 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -199,6 +199,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property-read \Illuminate\Database\Eloquent\Collection $vendors * @property-read int|null $vendors_count * @property-read \Illuminate\Database\Eloquent\Collection $webhooks + * @method static \Illuminate\Database\Eloquent\Builder|Company where($query) * @property-read int|null $webhooks_count * @property int $calculate_taxes * @property mixed $tax_data @@ -439,7 +440,7 @@ class Company extends BaseModel return $this->encodePrimaryKey($this->id); } - public function account() + public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo { return $this->belongsTo(Account::class); } @@ -449,7 +450,7 @@ class Company extends BaseModel return $this->hasMany(ClientContact::class)->withTrashed(); } - public function users() + public function users(): \Illuminate\Database\Eloquent\Relations\HasManyThrough { return $this->hasManyThrough(User::class, CompanyUser::class, 'company_id', 'id', 'id', 'user_id')->withTrashed(); } diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index aeaca5d2ce39..e4c2aa550583 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -51,8 +51,8 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property-read \App\Models\Company $company * @property-read \App\Models\Gateway $gateway * @property-read mixed $hashed_id + * @method getConfigField(string $field) * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway filter(\App\Filters\QueryFilters $filters) * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|CompanyGateway newQuery() diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 018d8722e85f..f0b0f37ea274 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -678,7 +678,7 @@ class Invoice extends BaseModel } } - return Expense::whereIn('id', $this->transformKeys($expense_ids)) + return Expense::query()->whereIn('id', $this->transformKeys($expense_ids)) ->where('invoice_documents', 1) ->where('company_id', $this->company_id) ->cursor(); @@ -696,7 +696,7 @@ class Invoice extends BaseModel } } - return Task::whereIn('id', $this->transformKeys($task_ids)) + return Task::query()->whereIn('id', $this->transformKeys($task_ids)) ->whereHas('company', function ($query) { $query->where('invoice_task_documents', 1); }) diff --git a/app/Models/PurchaseOrder.php b/app/Models/PurchaseOrder.php index e634636acda0..3639469776f7 100644 --- a/app/Models/PurchaseOrder.php +++ b/app/Models/PurchaseOrder.php @@ -86,29 +86,19 @@ use Illuminate\Support\Facades\Storage; * @property int|null $updated_at * @property int|null $expense_id * @property int|null $currency_id - * @property-read \Illuminate\Database\Eloquent\Collection $activities * @property-read int|null $activities_count * @property-read \App\Models\User|null $assigned_user * @property-read \App\Models\Client|null $client * @property-read \App\Models\Company $company - * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read int|null $documents_count * @property-read \App\Models\Expense|null $expense * @property-read mixed $hashed_id - * @property-read \Illuminate\Database\Eloquent\Collection $history - * @property-read int|null $history_count - * @property-read \Illuminate\Database\Eloquent\Collection $invitations - * @property-read int|null $invitations_count * @property-read \App\Models\Invoice|null $invoice - * @property-read \Illuminate\Database\Eloquent\Collection $invoices - * @property-read int|null $invoices_count - * @property-read \Illuminate\Database\Eloquent\Collection $payments - * @property-read int|null $payments_count * @property-read \App\Models\Project|null $project * @property-read \App\Models\User $user * @property \App\Models\Vendor|null $vendor - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel company() - * @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns) + * @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder company() + * @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder exclude($columns) * @method static \Database\Factories\PurchaseOrderFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder filter(\App\Filters\QueryFilters $filters) * @method static \Illuminate\Database\Eloquent\Builder|PurchaseOrder newModelQuery() diff --git a/app/Models/Quote.php b/app/Models/Quote.php index da496f7d63dd..38a3443460da 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -108,7 +108,9 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $documents * @property-read \Illuminate\Database\Eloquent\Collection $history * @property-read \Illuminate\Database\Eloquent\Collection $invitations + * * @mixin \Eloquent + * @mixin \Illuminate\Database\Eloquent\Builder */ class Quote extends BaseModel { diff --git a/app/Models/Traits/Excludable.php b/app/Models/Traits/Excludable.php index 272c5e7cc8c4..d4da440d35d6 100644 --- a/app/Models/Traits/Excludable.php +++ b/app/Models/Traits/Excludable.php @@ -14,6 +14,8 @@ namespace App\Models\Traits; use Illuminate\Support\Facades\Schema; /** + * @method static Builder scopeExclude(Builder $builder) + * @method static Builder exclude(Builder $builder) * @template TModelClass of \Illuminate\Database\Eloquent\Model * @extends \Illuminate\Database\Eloquent\Builder * @mixin \Illuminate\Database\Eloquent\Builder @@ -33,6 +35,10 @@ trait Excludable /** * Exclude an array of elements from the result. + * + * @method static \Illuminate\Database\Eloquent\Builder exclude($columns) + * @method static \Illuminate\Database\Eloquent\Builder exclude($columns) + * * @param \Illuminate\Database\Eloquent\Builder $query * @param array $columns * diff --git a/app/Models/User.php b/app/Models/User.php index db2f87506444..7e1784d9413e 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -280,7 +280,7 @@ class User extends Authenticatable implements MustVerifyEmail * * @return \App\Models\Company $company */ - public function company(): Company + public function company(): \App\Models\Company { return $this->getCompany(); } diff --git a/app/PaymentDrivers/Authorize/AuthorizeTransaction.php b/app/PaymentDrivers/Authorize/AuthorizeTransaction.php index 7f4511a186a8..20f184a17fe2 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeTransaction.php +++ b/app/PaymentDrivers/Authorize/AuthorizeTransaction.php @@ -60,7 +60,7 @@ class AuthorizeTransaction if ($this->authorize->payment_hash->data) { $invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(','); - $invObj = Invoice::whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $invObj = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $po_numbers = $invObj->pluck('po_number')->implode(','); diff --git a/app/PaymentDrivers/Authorize/ChargePaymentProfile.php b/app/PaymentDrivers/Authorize/ChargePaymentProfile.php index 65fcb33590fd..ca032fbedd81 100644 --- a/app/PaymentDrivers/Authorize/ChargePaymentProfile.php +++ b/app/PaymentDrivers/Authorize/ChargePaymentProfile.php @@ -56,7 +56,7 @@ class ChargePaymentProfile if ($this->authorize->payment_hash->data) { $invoice_numbers = collect($this->authorize->payment_hash->data->invoices)->pluck('invoice_number')->implode(','); - $invObj = Invoice::whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $invObj = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->authorize->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $po_numbers = $invObj->pluck('po_number')->implode(','); diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 632c8c36e137..fcfd766837d9 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -279,7 +279,7 @@ class BaseDriver extends AbstractPaymentDriver public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment { $paid_invoices = $payment_hash->invoices(); - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $payment->invoices()->sync($invoices); $payment->service()->applyNumber()->save(); @@ -392,7 +392,7 @@ class BaseDriver extends AbstractPaymentDriver $fee_total = $this->payment_hash->fee_total; /*Hydrate invoices*/ - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) { if (collect($invoice->line_items)->contains('type_id', '3')) { @@ -410,7 +410,7 @@ class BaseDriver extends AbstractPaymentDriver */ public function unWindGatewayFees(PaymentHash $payment_hash) { - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) { $invoice->service()->removeUnpaidGatewayFees(); @@ -522,7 +522,7 @@ class BaseDriver extends AbstractPaymentDriver $nmo->company = $this->client->company; $nmo->settings = $this->client->company->settings; - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) { $invoice->service()->deletePdf(); @@ -567,7 +567,7 @@ class BaseDriver extends AbstractPaymentDriver $nmo->company = $this->client->company; $nmo->settings = $this->client->company->settings; - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get(); $invoices->each(function ($invoice) { $invoice->service()->deletePdf(); diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index b9c2db92b3ca..a92ae417f7a6 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -238,7 +238,7 @@ class BraintreePaymentDriver extends BaseDriver { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); if ($invoice) { $description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}"; diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 7c65fadc8508..bfeee03569d9 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -324,7 +324,7 @@ class CheckoutComPaymentDriver extends BaseDriver public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); $this->init(); diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index 9819a08b4fc8..2f1c5f6a0bff 100644 --- a/app/PaymentDrivers/GoCardless/ACH.php +++ b/app/PaymentDrivers/GoCardless/ACH.php @@ -163,7 +163,7 @@ class ACH implements MethodInterface { $this->go_cardless->ensureMandateIsReady($request->source); - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) ->withTrashed() ->first(); diff --git a/app/PaymentDrivers/GoCardless/DirectDebit.php b/app/PaymentDrivers/GoCardless/DirectDebit.php index 94328a537e5c..48274891e818 100644 --- a/app/PaymentDrivers/GoCardless/DirectDebit.php +++ b/app/PaymentDrivers/GoCardless/DirectDebit.php @@ -257,7 +257,7 @@ class DirectDebit implements MethodInterface { $this->go_cardless->ensureMandateIsReady($request->source); - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) ->withTrashed() ->first(); diff --git a/app/PaymentDrivers/GoCardless/SEPA.php b/app/PaymentDrivers/GoCardless/SEPA.php index 4ea488618282..458b34d9e225 100644 --- a/app/PaymentDrivers/GoCardless/SEPA.php +++ b/app/PaymentDrivers/GoCardless/SEPA.php @@ -162,7 +162,7 @@ class SEPA implements MethodInterface { $this->go_cardless->ensureMandateIsReady($request->source); - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) ->withTrashed() ->first(); diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index 2a251a5b5822..c798c5c1e989 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -327,7 +327,7 @@ class GoCardlessPaymentDriver extends BaseDriver ); if ($billing_request->status === 'fulfilled') { - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($hash->invoices(), 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($hash->invoices(), 'invoice_id')))->withTrashed()->get(); $this->client = $invoices->first()->client; diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index 247c6988713d..cc263acfcf0d 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -194,7 +194,7 @@ class MolliePaymentDriver extends BaseDriver public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); if ($invoice) { $description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}"; diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index bb2e9f6fef1e..cdae15876a2e 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -114,7 +114,7 @@ class SquarePaymentDriver extends BaseDriver $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; $amount = $this->convertAmount($amount); - $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); + $invoice = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first(); if ($invoice) { $description = "Invoice {$invoice->number} for {$amount} for client {$this->client->present()->name()}"; diff --git a/app/Repositories/BankTransactionRepository.php b/app/Repositories/BankTransactionRepository.php index 4130e72333e0..e16ba4f0fd5d 100644 --- a/app/Repositories/BankTransactionRepository.php +++ b/app/Repositories/BankTransactionRepository.php @@ -52,7 +52,7 @@ class BankTransactionRepository extends BaseRepository $bt->payment_id = null; } - $e = Expense::whereIn('id', $this->transformKeys(explode(",", $bt->expense_id))) + $e = Expense::query()->whereIn('id', $this->transformKeys(explode(",", $bt->expense_id))) ->cursor() ->each(function ($expense){ diff --git a/app/Repositories/Migration/PaymentMigrationRepository.php b/app/Repositories/Migration/PaymentMigrationRepository.php index 00bf928ae367..683355f4239a 100644 --- a/app/Repositories/Migration/PaymentMigrationRepository.php +++ b/app/Repositories/Migration/PaymentMigrationRepository.php @@ -120,7 +120,7 @@ class PaymentMigrationRepository extends BaseRepository $invoice_totals = array_sum(array_column($data['invoices'], 'amount')); $refund_totals = array_sum(array_column($data['invoices'], 'refunded')); - $invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get(); $payment->invoices()->saveMany($invoices); // 1:1 relationship so this is ok @@ -150,7 +150,7 @@ class PaymentMigrationRepository extends BaseRepository /** @var float $credit_totals **/ $credit_totals = array_sum(array_column($data['credits'], 'amount')); - $credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->withTrashed()->get(); + $credits = Credit::query()->whereIn('id', array_column($data['credits'], 'credit_id'))->withTrashed()->get(); $payment->credits()->saveMany($credits); diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 4400e66155ef..48fdd4a8e5e7 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -170,7 +170,7 @@ class PaymentRepository extends BaseRepository if (array_key_exists('credits', $data) && is_array($data['credits'])) { $credit_totals = array_sum(array_column($data['credits'], 'amount')); - $credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->get(); + $credits = Credit::query()->whereIn('id', array_column($data['credits'], 'credit_id'))->get(); //todo optimize into a single query foreach ($data['credits'] as $paid_credit) { diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index c9366ad83b46..91832d9f20b9 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -60,7 +60,7 @@ class InstantPayment * ['invoice_id' => xxx, 'amount' => 22.00] */ $payable_invoices = collect($this->request->payable_invoices); - $invoices = Invoice::whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->withTrashed()->get(); $invoices->each(function ($invoice) { $invoice->service() diff --git a/app/Services/Credit/CreateInvitations.php b/app/Services/Credit/CreateInvitations.php index b00a177e2044..cf413f2444c8 100644 --- a/app/Services/Credit/CreateInvitations.php +++ b/app/Services/Credit/CreateInvitations.php @@ -42,7 +42,8 @@ class CreateInvitations extends AbstractService } $contacts->each(function ($contact) { - $invitation = CreditInvitation::whereCompanyId($this->credit->company_id) + $invitation = CreditInvitation::query() + ->where('company_id', $this->credit->company_id) ->whereClientContactId($contact->id) ->whereCreditId($this->credit->id) ->withTrashed() diff --git a/app/Services/Email/EmailDefaults.php b/app/Services/Email/EmailDefaults.php index 65a104b88fdc..a374ddfa353c 100644 --- a/app/Services/Email/EmailDefaults.php +++ b/app/Services/Email/EmailDefaults.php @@ -361,7 +361,7 @@ class EmailDefaults } if (count($expense_ids) > 0) { - Expense::whereIn('id', $this->transformKeys($expense_ids)) + Expense::query()->whereIn('id', $this->transformKeys($expense_ids)) ->where('invoice_documents', 1) ->cursor() ->each(function ($expense) { @@ -370,7 +370,7 @@ class EmailDefaults } if (count($task_ids) > 0 && $this->email->company->invoice_task_documents) { - Task::whereIn('id', $this->transformKeys($task_ids)) + Task::query()->whereIn('id', $this->transformKeys($task_ids)) ->cursor() ->each(function ($task) { $this->email->email_object->documents = array_merge($this->email->email_object->documents, $task->documents->pluck('id')->toArray()); diff --git a/app/Services/Email/EmailMailable.php b/app/Services/Email/EmailMailable.php index d25ae3b3654d..399b0629e90b 100644 --- a/app/Services/Email/EmailMailable.php +++ b/app/Services/Email/EmailMailable.php @@ -57,7 +57,7 @@ class EmailMailable extends Mailable */ public function content() { - $links = Document::whereIn('id', $this->email_object->documents) + $links = Document::query()->whereIn('id', $this->email_object->documents) ->where('size', '>', $this->max_attachment_size) ->cursor() ->map(function ($document) { @@ -94,7 +94,7 @@ class EmailMailable extends Mailable return Attachment::fromData(fn () => base64_decode($file['file']), $file['name']); }); - $documents = Document::whereIn('id', $this->email_object->documents) + $documents = Document::query()->whereIn('id', $this->email_object->documents) ->where('size', '<', $this->max_attachment_size) ->cursor() ->map(function ($document) { diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 8558c0128ec6..0adec81b6ce9 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -541,8 +541,8 @@ class InvoiceService return $item; }); - Task::whereIn('id', $tasks->pluck('task_id'))->update(['invoice_id' => $this->invoice->id]); - Expense::whereIn('id', $tasks->pluck('expense_id'))->update(['invoice_id' => $this->invoice->id]); + Task::query()->whereIn('id', $tasks->pluck('task_id'))->update(['invoice_id' => $this->invoice->id]); + Expense::query()->whereIn('id', $tasks->pluck('expense_id'))->update(['invoice_id' => $this->invoice->id]); return $this; } diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index 882cba3e95bd..e0e793bd6e2b 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -38,7 +38,7 @@ class UpdateInvoicePayment { $paid_invoices = $this->payment_hash->invoices(); - $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); + $invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get(); $client = $this->payment->client; diff --git a/app/Services/Quote/CreateInvitations.php b/app/Services/Quote/CreateInvitations.php index 34468adaacfd..8ba5090c3983 100644 --- a/app/Services/Quote/CreateInvitations.php +++ b/app/Services/Quote/CreateInvitations.php @@ -41,7 +41,8 @@ class CreateInvitations } $contacts->each(function ($contact) { - $invitation = QuoteInvitation::whereCompanyId($this->quote->company_id) + $invitation = QuoteInvitation::query() + ->where('company_id',$this->quote->company_id) ->whereClientContactId($contact->id) ->whereQuoteId($this->quote->id) ->withTrashed() diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 782f08446b6a..efb30352866f 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -574,7 +574,7 @@ class SubscriptionService $credit = false; /* Get last invoice */ - $last_invoice = Invoice::where('subscription_id', $recurring_invoice->subscription_id) + $last_invoice = Invoice::query()->where('subscription_id', $recurring_invoice->subscription_id) ->where('client_id', $recurring_invoice->client_id) ->where('is_proforma', 0) ->where('is_deleted', 0) @@ -1166,7 +1166,7 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->product_ids)); if (is_array($keys)) { - return Product::whereIn('id', $keys)->get(); + return Product::query()->whereIn('id', $keys)->get(); } else { return Product::where('id', $keys)->get(); } @@ -1186,7 +1186,7 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->recurring_product_ids)); if (is_array($keys)) { - return Product::whereIn('id', $keys)->get(); + return Product::query()->whereIn('id', $keys)->get(); } else { return Product::where('id', $keys)->get(); } @@ -1207,7 +1207,7 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->optional_product_ids)); if (is_array($keys)) { - return Product::whereIn('id', $keys)->get(); + return Product::query()->whereIn('id', $keys)->get(); } else { return Product::where('id', $keys)->get(); } @@ -1227,7 +1227,7 @@ class SubscriptionService $keys = $this->transformKeys(explode(",", $this->subscription->optional_recurring_product_ids)); if (is_array($keys)) { - return Product::whereIn('id', $keys)->get(); + return Product::query()->whereIn('id', $keys)->get(); } else { return Product::where('id', $keys)->get(); } diff --git a/app/Utils/Traits/GeneratesConvertedQuoteCounter.php b/app/Utils/Traits/GeneratesConvertedQuoteCounter.php index 06cf6fa36536..314b994e1ba0 100644 --- a/app/Utils/Traits/GeneratesConvertedQuoteCounter.php +++ b/app/Utils/Traits/GeneratesConvertedQuoteCounter.php @@ -69,7 +69,7 @@ trait GeneratesConvertedQuoteCounter $number = $this->applyNumberPattern($invoice, $number, $pattern); - $check = Invoice::whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->exists(); + $check = Invoice::query()->whereCompanyId($client->company_id)->whereNumber($number)->withTrashed()->exists(); if ($check) { return false; diff --git a/database/migrations/2023_08_06_070205_create_view_dashboard_permission_migration.php b/database/migrations/2023_08_06_070205_create_view_dashboard_permission_migration.php new file mode 100644 index 000000000000..ae8dbe4456d7 --- /dev/null +++ b/database/migrations/2023_08_06_070205_create_view_dashboard_permission_migration.php @@ -0,0 +1,45 @@ +cursor()->each(function ($cu) { + $permissions = $cu->permissions; + + if (!$permissions || strlen($permissions) == 0) { + $permissions = 'view_dashboard'; + $cu->permissions = $permissions; + $cu->save(); + } else { + $permissions_array = explode(',', $permissions); + + $permissions_array[] = 'view_dashboard'; + + $modified_permissions_string = implode(",", $permissions_array); + + $cu->permissions = $modified_permissions_string; + $cu->save(); + } + }); + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +}; diff --git a/phpstan.neon b/phpstan.neon index 4514c5ecc89e..42ed89867698 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,4 +18,5 @@ parameters: - '#Call to an undefined method [a-zA-Z0-9\\_]+::company\(\)#' - '#Call to an undefined method [a-zA-Z0-9\\_]+::entityFilter\(\)#' - '#Call to an undefined method [a-zA-Z0-9\\_]+::withTrashed\(\)#' + - '#Call to an undefined method [a-zA-Z0-9\\_]+::exclude\(\)#' - '#Undefined method#' \ No newline at end of file