diff --git a/app/Console/Commands/ChargeRenewalInvoices.php b/app/Console/Commands/ChargeRenewalInvoices.php index 6ccdd59b4d..2a33e6b730 100644 --- a/app/Console/Commands/ChargeRenewalInvoices.php +++ b/app/Console/Commands/ChargeRenewalInvoices.php @@ -73,7 +73,7 @@ class ChargeRenewalInvoices extends Command ->orderBy('id') ->get(); - $this->info(count($invoices).' invoices found'); + $this->info($invoices->count() . ' invoices found'); foreach ($invoices as $invoice) { diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 28f994a86e..57862d5a2a 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -122,9 +122,9 @@ class CheckData extends Command ->withTrashed() ->get(); - $this->logMessage(count($invoices) . ' draft sent invoices'); + $this->logMessage($invoices->count() . ' draft sent invoices'); - if (count($invoices) > 0) { + if ($invoices->count() > 0) { $this->isValid = false; } @@ -190,9 +190,9 @@ class CheckData extends Command ->havingRaw('count(users.id) > 1') ->get(['users.oauth_user_id']); - $this->logMessage(count($users) . ' users with duplicate oauth ids'); + $this->logMessage($users->count() . ' users with duplicate oauth ids'); - if (count($users) > 0) { + if ($users->count() > 0) { $this->isValid = false; } @@ -308,9 +308,9 @@ class CheckData extends Command ->whereNull('contact_key') ->orderBy('id') ->get(['id']); - $this->logMessage(count($contacts) . ' contacts without a contact_key'); + $this->logMessage($contacts->count() . ' contacts without a contact_key'); - if (count($contacts) > 0) { + if ($contacts->count() > 0) { $this->isValid = false; } @@ -339,9 +339,9 @@ class CheckData extends Command } $clients = $clients->get(['clients.id', 'clients.user_id', 'clients.account_id']); - $this->logMessage(count($clients) . ' clients without any contacts'); + $this->logMessage($clients->count() . ' clients without any contacts'); - if (count($clients) > 0) { + if ($clients->count() > 0) { $this->isValid = false; } @@ -374,9 +374,9 @@ class CheckData extends Command } $clients = $clients->get(['clients.id', DB::raw('count(contacts.id)')]); - $this->logMessage(count($clients) . ' clients without a single primary contact'); + $this->logMessage($clients->count() . ' clients without a single primary contact'); - if (count($clients) > 0) { + if ($clients->count() > 0) { $this->isValid = false; } } @@ -423,9 +423,9 @@ class CheckData extends Command ->havingRaw('count(invitations.id) = 0') ->get(['invoices.id', 'invoices.user_id', 'invoices.account_id', 'invoices.client_id']); - $this->logMessage(count($invoices) . ' invoices without any invitations'); + $this->logMessage($invoices->count() . ' invoices without any invitations'); - if (count($invoices) > 0) { + if ($invoices->count() > 0) { $this->isValid = false; } @@ -512,9 +512,9 @@ class CheckData extends Command ->where("{$table}.{$accountId}", '!=', DB::raw("{$tableName}.account_id")) ->get(["{$table}.id"]); - if (count($records)) { + if ($records->count()) { $this->isValid = false; - $this->logMessage(count($records) . " {$table} records with incorrect {$entityType} account id"); + $this->logMessage($records->count() . " {$table} records with incorrect {$entityType} account id"); if ($this->option('fix') == 'true') { foreach ($records as $record) { @@ -549,9 +549,9 @@ class CheckData extends Command ->groupBy('clients.id') ->havingRaw('clients.paid_to_date != sum(coalesce(payments.amount - payments.refunded, 0)) and clients.paid_to_date != 999999999.9999') ->get(['clients.id', 'clients.paid_to_date', DB::raw('sum(coalesce(payments.amount - payments.refunded, 0)) as amount')]); - $this->logMessage(count($clients) . ' clients with incorrect paid to date'); + $this->logMessage($clients->count() . ' clients with incorrect paid to date'); - if (count($clients) > 0) { + if ($clients->count() > 0) { $this->isValid = false; } @@ -580,9 +580,9 @@ class CheckData extends Command ->havingRaw('(invoices.amount - invoices.balance) != coalesce(sum(payments.amount - payments.refunded), 0)') ->get(['invoices.id', 'invoices.amount', 'invoices.balance', DB::raw('coalesce(sum(payments.amount - payments.refunded), 0)')]); - $this->logMessage(count($invoices) . ' invoices with incorrect balances'); + $this->logMessage($invoices->count() . ' invoices with incorrect balances'); - if (count($invoices) > 0) { + if ($invoices->count() > 0) { $this->isValid = false; } } @@ -608,9 +608,9 @@ class CheckData extends Command $clients = $clients->groupBy('clients.id', 'clients.balance') ->orderBy('accounts.company_id', 'DESC') ->get(['accounts.company_id', 'clients.account_id', 'clients.id', 'clients.balance', 'clients.paid_to_date', DB::raw('sum(invoices.balance) actual_balance')]); - $this->logMessage(count($clients) . ' clients with incorrect balance/activities'); + $this->logMessage($clients->count() . ' clients with incorrect balance/activities'); - if (count($clients) > 0) { + if ($clients->count() > 0) { $this->isValid = false; } diff --git a/app/Console/Commands/RemoveOrphanedDocuments.php b/app/Console/Commands/RemoveOrphanedDocuments.php index c6d9214240..f53e1f6ac0 100644 --- a/app/Console/Commands/RemoveOrphanedDocuments.php +++ b/app/Console/Commands/RemoveOrphanedDocuments.php @@ -32,7 +32,7 @@ class RemoveOrphanedDocuments extends Command $documents = Document::whereRaw('invoice_id IS NULL AND expense_id IS NULL AND updated_at <= ?', [new DateTime('-1 hour')]) ->get(); - $this->info(count($documents).' orphaned document(s) found'); + $this->info($documents->count() . ' orphaned document(s) found'); foreach ($documents as $document) { $document->delete(); diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php index 01fa4a44c8..6c74b8a44a 100644 --- a/app/Console/Commands/SendRecurringInvoices.php +++ b/app/Console/Commands/SendRecurringInvoices.php @@ -98,7 +98,7 @@ class SendRecurringInvoices extends Command ->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND is_public IS TRUE AND frequency_id > 0 AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today]) ->orderBy('id', 'asc') ->get(); - $this->info(count($invoices).' recurring invoice(s) found'); + $this->info($invoices->count() . ' recurring invoice(s) found'); foreach ($invoices as $recurInvoice) { $shouldSendToday = $recurInvoice->shouldSendToday(); @@ -140,7 +140,7 @@ class SendRecurringInvoices extends Command [$today->format('Y-m-d')]) ->orderBy('invoices.id', 'asc') ->get(); - $this->info(count($delayedAutoBillInvoices).' due recurring invoice instance(s) found'); + $this->info($delayedAutoBillInvoices->count() . ' due recurring invoice instance(s) found'); /** @var Invoice $invoice */ foreach ($delayedAutoBillInvoices as $invoice) { @@ -172,7 +172,7 @@ class SendRecurringInvoices extends Command ->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today]) ->orderBy('id', 'asc') ->get(); - $this->info(count($expenses).' recurring expenses(s) found'); + $this->info($expenses->count() . ' recurring expenses(s) found'); foreach ($expenses as $expense) { $shouldSendToday = $expense->shouldSendToday(); diff --git a/app/Console/Commands/SendReminders.php b/app/Console/Commands/SendReminders.php index 4d0788cdaf..29889158eb 100644 --- a/app/Console/Commands/SendReminders.php +++ b/app/Console/Commands/SendReminders.php @@ -92,7 +92,7 @@ class SendReminders extends Command private function chargeLateFees() { $accounts = $this->accountRepo->findWithFees(); - $this->info(count($accounts) . ' accounts found with fees'); + $this->info($accounts->count() . ' accounts found with fees'); foreach ($accounts as $account) { if (! $account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) { @@ -100,7 +100,7 @@ class SendReminders extends Command } $invoices = $this->invoiceRepo->findNeedingReminding($account, false); - $this->info($account->name . ': ' . count($invoices) . ' invoices found'); + $this->info($account->name . ': ' . $invoices->count() . ' invoices found'); foreach ($invoices as $invoice) { if ($reminder = $account->getInvoiceReminder($invoice, false)) { @@ -128,7 +128,7 @@ class SendReminders extends Command // standard reminders $invoices = $this->invoiceRepo->findNeedingReminding($account); - $this->info($account->name . ': ' . count($invoices) . ' invoices found'); + $this->info($account->name . ': ' . $invoices->count() . ' invoices found'); foreach ($invoices as $invoice) { if ($reminder = $account->getInvoiceReminder($invoice)) { @@ -142,7 +142,7 @@ class SendReminders extends Command // endless reminders $invoices = $this->invoiceRepo->findNeedingEndlessReminding($account); - $this->info($account->name . ': ' . count($invoices) . ' endless invoices found'); + $this->info($account->name . ': ' . $invoices->count() . ' endless invoices found'); foreach ($invoices as $invoice) { if ($invoice->last_sent_date == date('Y-m-d')) { @@ -159,7 +159,7 @@ class SendReminders extends Command $scheduledReports = ScheduledReport::where('send_date', '<=', date('Y-m-d')) ->with('user', 'account.company') ->get(); - $this->info(count($scheduledReports) . ' scheduled reports'); + $this->info($scheduledReports->count() . ' scheduled reports'); foreach ($scheduledReports as $scheduledReport) { $user = $scheduledReport->user; diff --git a/app/Console/Commands/SendRenewalInvoices.php b/app/Console/Commands/SendRenewalInvoices.php index ce661153fb..dcd1bcc2e0 100644 --- a/app/Console/Commands/SendRenewalInvoices.php +++ b/app/Console/Commands/SendRenewalInvoices.php @@ -60,10 +60,10 @@ class SendRenewalInvoices extends Command $companies = Company::whereRaw("datediff(plan_expires, curdate()) = 10 and (plan = 'pro' or plan = 'enterprise')") ->orderBy('id') ->get(); - $this->info(count($companies).' companies found renewing in 10 days'); + $this->info($companies->count() . ' companies found renewing in 10 days'); foreach ($companies as $company) { - if (! count($company->accounts)) { + if (! $company->accounts->count()) { continue; } diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 090a51e26b..efd652bb03 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -452,7 +452,7 @@ class AccountController extends BaseController { $account = Auth::user()->account; $account->load('account_gateways'); - $count = count($account->account_gateways); + $count = $account->account_gateways->count(); $trashedCount = AccountGateway::scope()->withTrashed()->count(); if ($accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) { @@ -737,7 +737,7 @@ class AccountController extends BaseController return $font->id == $account->header_font_id || $font->id == $account->body_font_id; }); - if ($account->live_preview && count($fonts)) { + if ($account->live_preview && $fonts->count()) { $account->live_preview = false; Session::flash('warning', trans('texts.live_preview_disabled')); } diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 559840caaa..5a112b9baa 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -152,7 +152,7 @@ class AccountGatewayController extends BaseController 'config' => false, 'gateways' => $gateways, 'creditCardTypes' => $creditCards, - 'countGateways' => count($currentGateways), + 'countGateways' => $currentGateways->count(), ]; } diff --git a/app/Http/Controllers/DashboardApiController.php b/app/Http/Controllers/DashboardApiController.php index d87ea27139..0ca7eb6475 100644 --- a/app/Http/Controllers/DashboardApiController.php +++ b/app/Http/Controllers/DashboardApiController.php @@ -43,12 +43,12 @@ class DashboardApiController extends BaseAPIController $data = [ 'id' => 1, - 'paidToDate' => count($paidToDate) && $paidToDate[0]->value ? $paidToDate[0]->value : 0, - 'paidToDateCurrency' => count($paidToDate) && $paidToDate[0]->currency_id ? $paidToDate[0]->currency_id : 0, - 'balances' => count($balances) && $balances[0]->value ? $balances[0]->value : 0, - 'balancesCurrency' => count($balances) && $balances[0]->currency_id ? $balances[0]->currency_id : 0, - 'averageInvoice' => count($averageInvoice) && $averageInvoice[0]->invoice_avg ? $averageInvoice[0]->invoice_avg : 0, - 'averageInvoiceCurrency' => count($averageInvoice) && $averageInvoice[0]->currency_id ? $averageInvoice[0]->currency_id : 0, + 'paidToDate' => $paidToDate->count() && $paidToDate[0]->value ? $paidToDate[0]->value : 0, + 'paidToDateCurrency' => $paidToDate->count() && $paidToDate[0]->currency_id ? $paidToDate[0]->currency_id : 0, + 'balances' => $balances->count() && $balances[0]->value ? $balances[0]->value : 0, + 'balancesCurrency' => $balances->count() && $balances[0]->currency_id ? $balances[0]->currency_id : 0, + 'averageInvoice' => $averageInvoice->count() && $averageInvoice[0]->invoice_avg ? $averageInvoice[0]->invoice_avg : 0, + 'averageInvoiceCurrency' => $averageInvoice->count() && $averageInvoice[0]->currency_id ? $averageInvoice[0]->currency_id : 0, 'invoicesSent' => $metrics ? $metrics->invoices_sent : 0, 'activeClients' => $metrics ? $metrics->active_clients : 0, 'activities' => $this->createCollection($activities, new ActivityTransformer(), ENTITY_ACTIVITY), diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 1d6f931099..d69b9f150c 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -83,7 +83,7 @@ class DashboardController extends BaseController 'tasks' => $tasks, 'showBlueVinePromo' => $showBlueVinePromo, 'showWhiteLabelExpired' => $showWhiteLabelExpired, - 'showExpenses' => count($expenses) && $account->isModuleEnabled(ENTITY_EXPENSE), + 'showExpenses' => $expenses->count() && $account->isModuleEnabled(ENTITY_EXPENSE), 'headerClass' => in_array(\App::getLocale(), ['lt', 'pl', 'cs', 'sl', 'tr_TR']) ? 'in-large' : 'in-thin', 'footerClass' => in_array(\App::getLocale(), ['lt', 'pl', 'cs', 'sl', 'tr_TR']) ? '' : 'in-thin', ]; diff --git a/app/Jobs/DownloadInvoices.php b/app/Jobs/DownloadInvoices.php index 4304e3cc21..4c6c88adaf 100644 --- a/app/Jobs/DownloadInvoices.php +++ b/app/Jobs/DownloadInvoices.php @@ -54,34 +54,5 @@ class DownloadInvoices extends Job $zip->finish(); exit; - - /* - // if queues are disabled download a zip file - if (config('queue.default') === 'sync' || count($this->invoices) <= 10) { - $zip = Archive::instance_by_useragent(date('Y-m-d') . '-Invoice_PDFs'); - foreach ($this->invoices as $invoice) { - $zip->add_file($invoice->getFileName(), $invoice->getPDFString()); - } - $zip->finish(); - exit; - - // otherwise sends the PDFs in an email - } else { - $data = []; - foreach ($this->invoices as $invoice) { - $data[] = [ - 'name' => $invoice->getFileName(), - 'data' => $invoice->getPDFString(), - ]; - } - - $subject = trans('texts.invoices_are_attached'); - $data = [ - 'documents' => $data - ]; - - $userMailer->sendMessage($this->user, $subject, false, $data); - } - */ } } diff --git a/app/Models/Account.php b/app/Models/Account.php index bd7594b696..05bf022ffb 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -501,7 +501,7 @@ class Account extends Eloquent if ($gatewayId) { return $this->getGatewayConfig($gatewayId) != false; } else { - return count($this->account_gateways) > 0; + return $this->account_gateways->count() > 0; } } diff --git a/app/Models/Client.php b/app/Models/Client.php index 7d992d6c90..ed98781ff4 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -351,7 +351,7 @@ class Client extends EntityModel return $this->name; } - if (! count($this->contacts)) { + if (! $this->contacts->count()) { return ''; } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 84799bb0c6..8b18e1c0db 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1470,18 +1470,18 @@ class Invoice extends EntityModel implements BalanceAffecting */ public function countDocuments($expenses = false) { - $count = count($this->documents); + $count = $this->documents->count(); foreach ($this->expenses as $expense) { if ($expense->invoice_documents) { - $count += count($expense->documents); + $count += $expense->documents->count(); } } if ($expenses) { foreach ($expenses as $expense) { if ($expense->invoice_documents) { - $count += count($expense->documents); + $count += $expense->documents->count(); } } } @@ -1511,7 +1511,7 @@ class Invoice extends EntityModel implements BalanceAffecting public function hasExpenseDocuments() { foreach ($this->expenses as $expense) { - if ($expense->invoice_documents && count($expense->documents)) { + if ($expense->invoice_documents && $expense->documents->count()) { return true; } } diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index d3075c2dd0..6eba13206c 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -270,7 +270,7 @@ class ContactMailer extends Mailer $invitation = $payment->invitation; } else { $user = $payment->user; - $contact = count($client->contacts) ? $client->contacts[0] : ''; + $contact = $client->contacts->count() ? $client->contacts[0] : ''; $invitation = $payment->invoice->invitations[0]; } diff --git a/app/Ninja/PaymentDrivers/StripePaymentDriver.php b/app/Ninja/PaymentDrivers/StripePaymentDriver.php index 901d2a3071..2be1c5b833 100644 --- a/app/Ninja/PaymentDrivers/StripePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/StripePaymentDriver.php @@ -114,7 +114,7 @@ class StripePaymentDriver extends BasePaymentDriver $this->tokenResponse = $response->getData(); // import Stripe tokens created before payment methods table was added - if (! count($customer->payment_methods)) { + if (! $customer->payment_methods->count()) { if ($paymentMethod = $this->createPaymentMethod($customer)) { $customer->default_payment_method_id = $paymentMethod->id; $customer->save(); diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index 07ffa87899..d39f8464d6 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -175,7 +175,7 @@ class InvoicePresenter extends EntityPresenter { $client = $this->entity->client; - return count($client->contacts) ? $client->contacts[0]->email : ''; + return $client->contacts->count() ? $client->contacts[0]->email : ''; } public function autoBillEmailMessage() @@ -271,7 +271,7 @@ class InvoicePresenter extends EntityPresenter foreach ($invoice->payments as $payment) { $label = trans('texts.view_payment'); - if (count($invoice->payments) > 1) { + if ($invoice->payments->count() > 1) { $label .= ' - ' . $invoice->account->formatMoney($payment->amount, $invoice->client); } $actions[] = ['url' => $payment->present()->url, 'label' => $label]; diff --git a/app/Ninja/Reports/InvoiceReport.php b/app/Ninja/Reports/InvoiceReport.php index 54b5353e9c..8b353230ab 100644 --- a/app/Ninja/Reports/InvoiceReport.php +++ b/app/Ninja/Reports/InvoiceReport.php @@ -59,7 +59,7 @@ class InvoiceReport extends AbstractReport foreach ($clients->get() as $client) { foreach ($client->invoices as $invoice) { - $payments = count($invoice->payments) ? $invoice->payments : [false]; + $payments = $invoice->payments->count() ? $invoice->payments : [false]; foreach ($payments as $payment) { $this->data[] = [ $this->isExport ? $client->getDisplayName() : $client->present()->link, diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 294f92772a..8f0fd67a41 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -804,7 +804,7 @@ class InvoiceRepository extends BaseRepository $client->load('contacts'); $sendInvoiceIds = []; - if (! count($client->contacts)) { + if (! $client->contacts->count()) { return $invoice; } diff --git a/app/Services/BankAccountService.php b/app/Services/BankAccountService.php index 4738e0eaf9..245741caac 100644 --- a/app/Services/BankAccountService.php +++ b/app/Services/BankAccountService.php @@ -165,7 +165,7 @@ class BankAccountService extends BaseService } // if we can't find a match skip the account - if (count($bankAccounts) && ! $obj->account_name) { + if ($bankAccounts->count() && ! $obj->account_name) { return false; } diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index b8508f6f37..7c927660b9 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -947,7 +947,7 @@ class ImportService $this->maps['client'][$name] = $client->id; $this->maps['client_ids'][$client->public_id] = $client->id; } - if (count($client->contacts) && $name = strtolower(trim($client->contacts[0]->email))) { + if ($client->contacts->count() && $name = strtolower(trim($client->contacts[0]->email))) { $this->maps['client'][$name] = $client->id; $this->maps['client_ids'][$client->public_id] = $client->id; }