
* #126 - vacation request reminders * #126 - fix workdays * #126 - changes * #126 - cs fix * #5 - bump codestyle * #126 - fix * #126 - fix * #126 - fix * #126 - fix * #126 - tests * #126 - fix * #126 - fix * #126 - fix seeders * #126 - fix * #126 - tests Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Toby\Infrastructure\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Carbon;
|
|
use Toby\Domain\Enums\Role;
|
|
use Toby\Domain\Notifications\VacationRequestsSummaryNotification;
|
|
use Toby\Domain\VacationRequestStatesRetriever;
|
|
use Toby\Eloquent\Models\User;
|
|
use Toby\Eloquent\Models\VacationRequest;
|
|
|
|
class SendVacationRequestSummariesToApprovers extends Command
|
|
{
|
|
protected $signature = "toby:send-vacation-request-reminders";
|
|
protected $description = "Sends vacation request reminders to approvers if they didn't approve";
|
|
|
|
public function handle(): void
|
|
{
|
|
$users = User::query()
|
|
->whereIn("role", [Role::AdministrativeApprover, Role::TechnicalApprover, Role::Administrator])
|
|
->get();
|
|
|
|
foreach ($users as $user) {
|
|
$vacationRequests = VacationRequest::query()
|
|
->states(VacationRequestStatesRetriever::waitingForUserActionStates($user))
|
|
->get();
|
|
|
|
if ($vacationRequests->isNotEmpty()) {
|
|
$user->notify(new VacationRequestsSummaryNotification(Carbon::today(), $vacationRequests));
|
|
}
|
|
}
|
|
}
|
|
}
|