base commit
This commit is contained in:
29
app/Observers/DisciplinaryReportObserver.php
Normal file
29
app/Observers/DisciplinaryReportObserver.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\DisciplinaryReport;
|
||||
use App\Models\User;
|
||||
use App\Notifications\DisciplinaryReportCreatedNotification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class DisciplinaryReportObserver
|
||||
{
|
||||
public function creating(DisciplinaryReport $report): void
|
||||
{
|
||||
if ($report->created_by === null) {
|
||||
$report->created_by = Auth::id();
|
||||
}
|
||||
}
|
||||
|
||||
public function created(DisciplinaryReport $report): void
|
||||
{
|
||||
Notification::send(
|
||||
User::role('hr_manager')->get(),
|
||||
new DisciplinaryReportCreatedNotification($report),
|
||||
);
|
||||
}
|
||||
}
|
||||
17
app/Observers/EmployeeDocumentObserver.php
Normal file
17
app/Observers/EmployeeDocumentObserver.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\EmployeeDocument;
|
||||
|
||||
class EmployeeDocumentObserver
|
||||
{
|
||||
public function creating(EmployeeDocument $document): void
|
||||
{
|
||||
if ($document->uploaded_at === null) {
|
||||
$document->uploaded_at = now();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
app/Observers/SickLeaveObserver.php
Normal file
27
app/Observers/SickLeaveObserver.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\SickLeave;
|
||||
use App\Services\Leave\LeaveDaysCalculator;
|
||||
|
||||
class SickLeaveObserver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LeaveDaysCalculator $leaveDaysCalculator,
|
||||
) {}
|
||||
|
||||
public function saving(SickLeave $sickLeave): void
|
||||
{
|
||||
if ($sickLeave->start_date === null || $sickLeave->end_date === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sickLeave->days = $this->leaveDaysCalculator->between(
|
||||
$sickLeave->start_date,
|
||||
$sickLeave->end_date,
|
||||
);
|
||||
}
|
||||
}
|
||||
35
app/Observers/UnpaidLeaveObserver.php
Normal file
35
app/Observers/UnpaidLeaveObserver.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\UnpaidLeave;
|
||||
use App\Services\Leave\LeaveDaysCalculator;
|
||||
|
||||
class UnpaidLeaveObserver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LeaveDaysCalculator $leaveDaysCalculator,
|
||||
) {}
|
||||
|
||||
public function creating(UnpaidLeave $unpaidLeave): void
|
||||
{
|
||||
if ($unpaidLeave->status === null) {
|
||||
$unpaidLeave->status = ApprovalStatus::Pending;
|
||||
}
|
||||
}
|
||||
|
||||
public function saving(UnpaidLeave $unpaidLeave): void
|
||||
{
|
||||
if ($unpaidLeave->start_date === null || $unpaidLeave->end_date === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$unpaidLeave->days = $this->leaveDaysCalculator->between(
|
||||
$unpaidLeave->start_date,
|
||||
$unpaidLeave->end_date,
|
||||
);
|
||||
}
|
||||
}
|
||||
35
app/Observers/VacationObserver.php
Normal file
35
app/Observers/VacationObserver.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\Vacation;
|
||||
use App\Services\Leave\LeaveDaysCalculator;
|
||||
|
||||
class VacationObserver
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LeaveDaysCalculator $leaveDaysCalculator,
|
||||
) {}
|
||||
|
||||
public function creating(Vacation $vacation): void
|
||||
{
|
||||
if ($vacation->status === null) {
|
||||
$vacation->status = ApprovalStatus::Pending;
|
||||
}
|
||||
}
|
||||
|
||||
public function saving(Vacation $vacation): void
|
||||
{
|
||||
if ($vacation->start_date === null || $vacation->end_date === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$vacation->days = $this->leaveDaysCalculator->between(
|
||||
$vacation->start_date,
|
||||
$vacation->end_date,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user