-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#465 - feat: added employee notification about upcoming medical exam …
…or ohs training
- Loading branch information
1 parent
ace38c4
commit 092ecc9
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
app/Console/Commands/SendNotificationAboutUpcomingMedicalExamsForEmployees.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Carbon; | ||
use Toby\Enums\UserHistoryType; | ||
use Toby\Models\User; | ||
use Toby\Notifications\UpcomingMedicalExamForEmployeeNotification; | ||
|
||
class SendNotificationAboutUpcomingMedicalExamsForEmployees extends Command | ||
{ | ||
protected $signature = "toby:send-notification-about-medical-exams-for-employees"; | ||
protected $description = "Send notifications about upcoming medical exams."; | ||
|
||
public function handle(): void | ||
{ | ||
$usersUpcomingMedicalExams = User::query() | ||
->whereRelation("histories", function ($query): void { | ||
$query->where("type", UserHistoryType::MedicalExam) | ||
->where("to", ">", Carbon::now()) | ||
->where("to", "<=", Carbon::now()->addMonth()); | ||
})->get(); | ||
|
||
if ($usersUpcomingMedicalExams->isEmpty()) { | ||
return; | ||
} | ||
|
||
foreach ($usersUpcomingMedicalExams as $user) { | ||
$user->notify(new UpcomingMedicalExamForEmployeeNotification($user)); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
app/Console/Commands/SendNotificationAboutUpcomingOhsTrainingForEmployees.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Carbon; | ||
use Toby\Enums\UserHistoryType; | ||
use Toby\Models\User; | ||
use Toby\Notifications\UpcomingOhsTrainingForEmployeeNotification; | ||
|
||
class SendNotificationAboutUpcomingOhsTrainingForEmployees extends Command | ||
{ | ||
protected $signature = "toby:send-notification-about-ohs-training-for-employees"; | ||
protected $description = "Send notifications about upcoming ohs trainings."; | ||
|
||
public function handle(): void | ||
{ | ||
$usersUpcomingOhsTrainings = User::query() | ||
->whereRelation("histories", function ($query): void { | ||
$query->where("type", UserHistoryType::OhsTraining) | ||
->where("to", ">", Carbon::now()) | ||
->where("to", "<=", Carbon::now()->addMonth()); | ||
})->get(); | ||
|
||
if ($usersUpcomingOhsTrainings->isEmpty()) { | ||
return; | ||
} | ||
|
||
foreach ($usersUpcomingOhsTrainings as $user) { | ||
$user->notify(new UpcomingOhsTrainingForEmployeeNotification($user)); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/Notifications/UpcomingMedicalExamForEmployeeNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Support\Carbon; | ||
use Toby\Models\User; | ||
use Toby\Slack\Elements\SlackMessage; | ||
|
||
class UpcomingMedicalExamForEmployeeNotification extends QueuedNotification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct( | ||
protected User $user, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function via(): array | ||
{ | ||
return [Channels::MAIL]; | ||
} | ||
|
||
public function toSlack(): SlackMessage | ||
{ | ||
$lastMedicalExamDate = $this->user->lastMedicalExam(); | ||
|
||
return (new SlackMessage()) | ||
->text(__("The deadline for occupational health examinations for you is about to expire - :date (overdue :difference days)", [ | ||
"date" => $lastMedicalExamDate->to->toDisplayString(), | ||
"difference" => (int)$lastMedicalExamDate->to->diffInDays(Carbon::today(), true), | ||
])); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/Notifications/UpcomingOhsTrainingForEmployeeNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Support\Carbon; | ||
use Toby\Models\User; | ||
use Toby\Slack\Elements\SlackMessage; | ||
|
||
class UpcomingOhsTrainingForEmployeeNotification extends QueuedNotification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct( | ||
protected User $user, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function via(): array | ||
{ | ||
return [Channels::MAIL]; | ||
} | ||
|
||
public function toSlack(): SlackMessage | ||
{ | ||
$lastOhsTrainingDate = $this->user->lastOhsTraining(); | ||
|
||
return (new SlackMessage()) | ||
->text(__("The deadline for occupational ohs training for you is about to expire - :date (overdue :difference days)", [ | ||
"date" => $lastOhsTrainingDate->to->toDisplayString(), | ||
"difference" => (int)$lastOhsTrainingDate->to->diffInDays(Carbon::today(), true), | ||
])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters