Refactor employee management by implementing automatic employee number generation, updating national ID handling, and enhancing localization for gender and nationality fields across various resources. Adjust form components and validation logic to improve user experience and data integrity.

This commit is contained in:
Mekan1206 committed 2026-08-02 21:06:37 +05:00
1 parent 28cbef8eb5
commit eed46157cd
25 files changed
+1175 -51

No files matched your search

+28 -6
View File
@@ -22,13 +22,13 @@
it('skips duplicate employees during import', function (): void {
Employee::factory()->create([
'employee_number' => 'EMP-90001',
'national_id' => '1234567890',
'national_id' => 'TM',
]);
$rows = [[
'employee_number' => 'EMP-90001',
'full_name' => 'Duplicate Employee',
'national_id' => '1234567890',
'national_id' => 'TM',
'department' => 'Engineering',
'position' => 'Developer',
'shift' => 'Day Shift',
@@ -68,6 +68,29 @@
]);
});
it('imports valid employee rows without an employee number', function (): void {
$rows = [[
'full_name' => 'Auto Number Employee',
'gender' => 'male',
'birth_date' => '1992-02-20',
'department' => 'Engineering',
'position' => 'Developer',
'shift' => 'Day Shift',
'hire_date' => '2024-04-01',
]];
$result = $this->importService->import(ImportType::Employees, $rows);
expect($result->imported)->toBe(1)
->and($result->skipped)->toBe(0)
->and($result->failed)->toBe(0);
$employee = Employee::query()->where('full_name', 'Auto Number Employee')->first();
expect($employee)->not->toBeNull()
->and($employee->employee_number)->toBe('EMP-00001');
});
it('reports validation errors for invalid employee rows', function (): void {
$rows = [[
'employee_number' => '',
@@ -93,8 +116,7 @@
$errors = $this->transformer->validate($dto);
expect($errors)->toContain('Employee number is required.')
->and($errors)->toContain('Full name is required.')
expect($errors)->toContain('Full name is required.')
->and($errors)->toContain('Department "Missing Department" was not found.')
->and($errors)->toContain('Position "Missing Position" was not found.')
->and($errors)->toContain('Shift "Missing Shift" was not found.');
@@ -103,7 +125,7 @@
it('detects duplicates by employee number or national id', function (): void {
Employee::factory()->create([
'employee_number' => 'EMP-80001',
'national_id' => '9988776655',
'national_id' => 'TM',
]);
$duplicateByNumber = EmployeeRowDto::fromMappedRow([
@@ -114,7 +136,7 @@
$duplicateByNationalId = EmployeeRowDto::fromMappedRow([
'employee_number' => 'EMP-80002',
'full_name' => 'Another Person',
'national_id' => '9988776655',
'national_id' => 'TM',
]);
expect($this->transformer->isDuplicate($duplicateByNumber))->toBeTrue()
+13
View File
@@ -35,6 +35,19 @@
expect(NavigationGroup::LeaveManagement->getLabel())->toBe('Dynç alyş dolandyryşy');
});
it('returns translated filament navigation group labels at request time', function (): void {
$admin = createAdminUser(['locale' => 'tk']);
$this->actingAs($admin);
App::setLocale('tk');
$groups = filament()->getNavigation();
$labels = collect($groups)->map->getLabel()->filter()->values()->all();
expect($labels)->toContain('Gurama', 'Işgärler', 'Dynç alyş dolandyryşy', 'Ýazgylar');
});
it('returns translated filament resource navigation labels', function (): void {
App::setLocale('tk');
+26
View File
@@ -84,6 +84,32 @@
->and($employee->documents)->toHaveCount(1);
});
it('generates an employee number on save when number is blank', function (): void {
$employee = Employee::factory()->create([
'employee_number' => '',
]);
expect($employee->employee_number)->toBe('EMP-00001');
});
it('does not overwrite an existing employee number on update', function (): void {
$employee = Employee::factory()->create([
'employee_number' => 'EMP-CUSTOM',
]);
$employee->update(['full_name' => 'Updated Name']);
expect($employee->fresh()->employee_number)->toBe('EMP-CUSTOM');
});
it('increments employee numbers sequentially', function (): void {
$first = Employee::factory()->create(['employee_number' => '']);
$second = Employee::factory()->create(['employee_number' => '']);
expect($first->employee_number)->toBe('EMP-00001')
->and($second->employee_number)->toBe('EMP-00002');
});
it('enforces a unique employee number', function (): void {
Employee::factory()->create(['employee_number' => 'EMP-UNIQUE']);
+23 -3
View File
@@ -26,7 +26,6 @@
$shift = Shift::factory()->create();
$employee = $this->service->create([
'employee_number' => 'EMP-10001',
'full_name' => 'John Doe',
'gender' => 'male',
'birth_date' => '1990-05-15',
@@ -39,16 +38,37 @@
]);
expect($employee)->toBeInstanceOf(Employee::class)
->and($employee->employee_number)->toBe('EMP-10001')
->and($employee->employee_number)->toBe('EMP-00001')
->and($employee->full_name)->toBe('John Doe')
->and($employee->employment_status)->toBe(EmploymentStatus::Active);
$this->assertDatabaseHas('employees', [
'employee_number' => 'EMP-10001',
'employee_number' => 'EMP-00001',
'full_name' => 'John Doe',
]);
});
it('creates an employee with an explicit employee number', function (): void {
$department = Department::factory()->create();
$position = Position::factory()->create();
$shift = Shift::factory()->create();
$employee = $this->service->create([
'employee_number' => 'EMP-10001',
'full_name' => 'Jane Doe',
'gender' => 'female',
'birth_date' => '1991-06-20',
'phone' => '+993 61 92 92 48',
'department_id' => $department->id,
'position_id' => $position->id,
'shift_id' => $shift->id,
'employment_status' => EmploymentStatus::Active,
'hire_date' => '2024-02-01',
]);
expect($employee->employee_number)->toBe('EMP-10001');
});
it('terminates an employee and notifies hr managers', function (): void {
$employee = Employee::factory()->active()->create();
$terminationDate = Carbon::parse('2025-06-30');