base commit

This commit is contained in:
Mekan1206
2026-07-30 17:24:40 +05:00
commit a794dacd39
345 changed files with 29597 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace App\Services\Vacation;
use App\Enums\ApprovalStatus;
use App\Enums\VacationType;
use App\Models\Employee;
class VacationBalanceService
{
public function entitlement(): int
{
return (int) config('hr.annual_leave_days');
}
public function takenAnnualDays(Employee $employee, ?int $year = null): int
{
$year ??= (int) now()->year;
return (int) $employee->vacations()
->where('type', VacationType::Annual)
->where('status', ApprovalStatus::Approved)
->whereYear('start_date', $year)
->sum('days');
}
public function remainingAnnualDays(Employee $employee): int
{
return $this->entitlement() - $this->takenAnnualDays($employee);
}
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace App\Services\Vacation;
use App\Enums\ApprovalStatus;
use App\Models\User;
use App\Models\Vacation;
use App\Notifications\VacationApprovedNotification;
use App\Notifications\VacationSubmittedNotification;
use App\Services\Leave\LeaveDaysCalculator;
use Carbon\Carbon;
use Illuminate\Support\Facades\Notification;
class VacationService
{
public function __construct(
private readonly LeaveDaysCalculator $leaveDaysCalculator,
) {}
/**
* @param array<string, mixed> $data
*/
public function submit(array $data): Vacation
{
$startDate = Carbon::parse($data['start_date']);
$endDate = Carbon::parse($data['end_date']);
$vacation = Vacation::create([
...$data,
'days' => $this->leaveDaysCalculator->between($startDate, $endDate),
'status' => ApprovalStatus::Pending,
]);
Notification::send(
User::role('hr_manager')->get(),
new VacationSubmittedNotification($vacation),
);
return $vacation;
}
public function approve(Vacation $vacation, User $approver): void
{
$vacation->update([
'status' => ApprovalStatus::Approved,
'approved_by' => $approver->id,
'approved_at' => now(),
]);
Notification::send(
User::role('hr_manager')->get(),
new VacationApprovedNotification($vacation),
);
}
public function reject(Vacation $vacation, User $approver): void
{
$vacation->update([
'status' => ApprovalStatus::Rejected,
'approved_by' => $approver->id,
'approved_at' => now(),
]);
}
}