From f9e6edcf6dc1781987d41f237c09cc5db6814ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 15 Jun 2021 10:33:36 +0300 Subject: [PATCH] Added report cache console --- app/Console/Commands/ReportReminder.php | 81 +++++++++++++++++++++++++ app/Console/Kernel.php | 1 + 2 files changed, 82 insertions(+) create mode 100644 app/Console/Commands/ReportReminder.php diff --git a/app/Console/Commands/ReportReminder.php b/app/Console/Commands/ReportReminder.php new file mode 100644 index 000000000..d8816e883 --- /dev/null +++ b/app/Console/Commands/ReportReminder.php @@ -0,0 +1,81 @@ + false]); + + // Get all companies + $companies = Company::enabled()->withCount('reports')->cursor(); + + foreach ($companies as $company) { + // Has company reports + if (!$company->reports_count) { + continue; + } + + $this->info('Sending invoice reminders for ' . $company->name . ' company.'); + + // Set company + $company->makeCurrent(); + + $this->remind(); + } + + Company::forgetCurrent(); + } + + protected function remind() + { + $reports = Report::orderBy('name')->get(); + + foreach ($reports as $report) { + if (!Utility::canShow($report->class)) { + continue; + } + + $class = Utility::getClassInstance($report, false); + + if (empty($class)) { + continue; + } + + $ttl = 3600 * 6; // 6 hours + + Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) { + return $class->getGrandTotal(); + }); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 88648f393..17d8ce4aa 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -29,6 +29,7 @@ class Kernel extends ConsoleKernel $schedule_time = config('app.schedule_time'); + $schedule->command('reminder:report')->everySixHours(); $schedule->command('reminder:invoice')->dailyAt($schedule_time); $schedule->command('reminder:bill')->dailyAt($schedule_time); $schedule->command('recurring:check')->dailyAt($schedule_time);