Added report cache console
This commit is contained in:
parent
085afcc534
commit
f9e6edcf6d
81
app/Console/Commands/ReportReminder.php
Normal file
81
app/Console/Commands/ReportReminder.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Common\Report;
|
||||
use App\Utilities\Reports as Utility;
|
||||
use App\Utilities\Overrider;
|
||||
use Date;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ReportReminder extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reminder:report';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Calculate reminders for reports';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// Disable model cache
|
||||
config(['laravel-model-caching.enabled' => 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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user