File: D:/HostingSpaces/SBogers10/vebon.komma.pro/app/Console/Commands/RemindRejectedAudits.php
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Contracts\Bus\SelfHandling;
class RemindRejectedAudits extends Command implements SelfHandling
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'reminder:rejected-audits';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command will send an reminder email to the members with an open audit that has been rejected';
/**
* Create a new command instance.
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$this->comment($this->description);
\Log::info($this->description);
//Load the auditService
$auditService = \App::make('KommaApp\Audit\AuditService');
$this->comment('Get the rejected open audits, with a deadline two weeks from now');
\Log::info('Get the rejected open audits, with a deadline two weeks from now');
$twoWeeks = Carbon::today()->addWeeks(2);
//Get all the unclosed audits
$audits = $auditService->getRejectedAuditsByDeadline($twoWeeks);
if ($audits->count() == 0) {
$this->comment('No audits found with deadline in two weeks, abort');
\Log::info('No audits found with deadline in two weeks, abort');
//Stop
return;
}
$this->comment($audits->count() . ' members will receive a reminder email');
\Log::info($audits->count() . ' members will receive a reminder email');
$auditService->sendReminderEmails($audits, 'rejected');
$this->comment('All emails queued and ready to send');
\Log::info('All emails queued and ready to send');
}
}