HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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');
    }
}