base commit
This commit is contained in:
48
app/Services/Employee/EmployeeService.php
Normal file
48
app/Services/Employee/EmployeeService.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Employee;
|
||||
|
||||
use App\Enums\EmploymentStatus;
|
||||
use App\Models\Employee;
|
||||
use App\Models\User;
|
||||
use App\Notifications\EmployeeTerminatedNotification;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class EmployeeService
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function create(array $data): Employee
|
||||
{
|
||||
return Employee::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function update(Employee $employee, array $data): Employee
|
||||
{
|
||||
$employee->update($data);
|
||||
|
||||
return $employee->refresh();
|
||||
}
|
||||
|
||||
public function terminate(Employee $employee, ?Carbon $date = null): Employee
|
||||
{
|
||||
$employee->update([
|
||||
'employment_status' => EmploymentStatus::Terminated,
|
||||
'termination_date' => $date ?? now(),
|
||||
]);
|
||||
|
||||
Notification::send(
|
||||
User::role('hr_manager')->get(),
|
||||
new EmployeeTerminatedNotification($employee),
|
||||
);
|
||||
|
||||
return $employee->refresh();
|
||||
}
|
||||
}
|
||||
34
app/Services/Employee/EmployeeStatisticsService.php
Normal file
34
app/Services/Employee/EmployeeStatisticsService.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Employee;
|
||||
|
||||
use App\DTOs\EmployeeSummaryDto;
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Models\Employee;
|
||||
use App\Services\Vacation\VacationBalanceService;
|
||||
|
||||
class EmployeeStatisticsService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly VacationBalanceService $vacationBalanceService,
|
||||
) {}
|
||||
|
||||
public function summary(Employee $employee): EmployeeSummaryDto
|
||||
{
|
||||
return new EmployeeSummaryDto(
|
||||
vacationTaken: $this->vacationBalanceService->takenAnnualDays($employee),
|
||||
vacationRemaining: $this->vacationBalanceService->remainingAnnualDays($employee),
|
||||
sickLeaveCount: $employee->sickLeaves()->count(),
|
||||
reportsCount: $employee->disciplinaryReports()->count(),
|
||||
bonusesTotal: (float) $employee->bonuses()->sum('amount'),
|
||||
giftsCount: $employee->gifts()->count(),
|
||||
upcomingLeave: $employee->vacations()
|
||||
->where('status', ApprovalStatus::Approved)
|
||||
->where('start_date', '>=', now()->toDateString())
|
||||
->orderBy('start_date')
|
||||
->get(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user