diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index c6f9ab71ff2a..5327459eb90a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -14,6 +14,7 @@ namespace App\Console; use App\Jobs\Cron\RecurringInvoicesCron; use App\Jobs\Ninja\AdjustEmailQuota; use App\Jobs\Ninja\CheckDbStatus; +use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Util\ReminderJob; use App\Jobs\Util\SendFailedEmails; use App\Jobs\Util\UpdateExchangeRates; @@ -47,6 +48,8 @@ class Kernel extends ConsoleKernel $schedule->job(new ReminderJob)->daily(); + $schedule->job(new CompanySizeCheck)->daily(); + $schedule->job(new UpdateExchangeRates)->daily(); /* Run hosted specific jobs */ diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 5e90ad1ed17a..2c4ff1fc26e8 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -293,7 +293,7 @@ class BaseController extends Controller * Thresholds for displaying large account on first load */ if (request()->has('first_load') && request()->input('first_load') == 'true') { - if (auth()->user()->getCompany()->invoices->count() > 1000 || auth()->user()->getCompany()->products->count() > 1000 || auth()->user()->getCompany()->clients->count() > 1000) { + if (auth()->user()->getCompany()->is_large) { $data = $mini_load; } else { $data = $first_load; diff --git a/app/Jobs/Ninja/CompanySizeCheck.php b/app/Jobs/Ninja/CompanySizeCheck.php new file mode 100644 index 000000000000..3b06d793ea83 --- /dev/null +++ b/app/Jobs/Ninja/CompanySizeCheck.php @@ -0,0 +1,77 @@ +check(); + } else { + //multiDB environment, need to + foreach (MultiDB::$dbs as $db) { + + MultiDB::setDB($db); + + $this->check(); + } + } + + } + + private function check() + { + + Company::cursor()->each(function ($company) + { + + if($company->invoices->count() > 1000 || $company->products->count() > 1000 || $company->clients->count() > 1000) + { + $company->is_large = true; + $company->save(); + } + + }); + + } + +} diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 1132d59e3588..56825e801481 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -27,6 +27,8 @@ class Gateway extends StaticModel 'fields' => 'json', ]; + protected $dateFormat = 'Y-m-d H:i:s.u'; + /** * @return mixed */ diff --git a/database/migrations/2020_07_05_084934_company_too_large_attribute.php b/database/migrations/2020_07_05_084934_company_too_large_attribute.php new file mode 100644 index 000000000000..a87cdbec2fa0 --- /dev/null +++ b/database/migrations/2020_07_05_084934_company_too_large_attribute.php @@ -0,0 +1,30 @@ +boolean('is_large')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}