feat: 근태관리/직원관리 API 구현
- AttendanceController, AttendanceService 추가 - EmployeeController, EmployeeService 추가 - Attendance 모델 및 마이그레이션 추가 - TenantUserProfile에 employee_status 컬럼 추가 - DepartmentService 트리 조회 기능 개선 - Swagger 문서 추가 (AttendanceApi, EmployeeApi) - API 라우트 등록
This commit is contained in:
25
app/Http/Requests/Attendance/CheckInRequest.php
Normal file
25
app/Http/Requests/Attendance/CheckInRequest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CheckInRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'nullable|integer|exists:users,id',
|
||||
'check_in' => 'nullable|date_format:H:i:s',
|
||||
'gps_data' => 'nullable|array',
|
||||
'gps_data.latitude' => 'nullable|numeric',
|
||||
'gps_data.longitude' => 'nullable|numeric',
|
||||
'gps_data.accuracy' => 'nullable|numeric',
|
||||
];
|
||||
}
|
||||
}
|
||||
25
app/Http/Requests/Attendance/CheckOutRequest.php
Normal file
25
app/Http/Requests/Attendance/CheckOutRequest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CheckOutRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'nullable|integer|exists:users,id',
|
||||
'check_out' => 'nullable|date_format:H:i:s',
|
||||
'gps_data' => 'nullable|array',
|
||||
'gps_data.latitude' => 'nullable|numeric',
|
||||
'gps_data.longitude' => 'nullable|numeric',
|
||||
'gps_data.accuracy' => 'nullable|numeric',
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Requests/Attendance/IndexRequest.php
Normal file
29
app/Http/Requests/Attendance/IndexRequest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class IndexRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'nullable|integer|min:1',
|
||||
'date' => 'nullable|date',
|
||||
'date_from' => 'nullable|date',
|
||||
'date_to' => 'nullable|date|after_or_equal:date_from',
|
||||
'status' => 'nullable|in:onTime,late,absent,vacation,businessTrip,fieldWork,overtime,remote',
|
||||
'department_id' => 'nullable|integer|min:1',
|
||||
'sort_by' => 'nullable|in:base_date,status,created_at',
|
||||
'sort_dir' => 'nullable|in:asc,desc',
|
||||
'page' => 'nullable|integer|min:1',
|
||||
'per_page' => 'nullable|integer|min:1|max:100',
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Requests/Attendance/MonthlyStatsRequest.php
Normal file
22
app/Http/Requests/Attendance/MonthlyStatsRequest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class MonthlyStatsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'year' => 'nullable|integer|min:2000|max:2100',
|
||||
'month' => 'nullable|integer|min:1|max:12',
|
||||
'user_id' => 'nullable|integer|exists:users,id',
|
||||
];
|
||||
}
|
||||
}
|
||||
50
app/Http/Requests/Attendance/StoreRequest.php
Normal file
50
app/Http/Requests/Attendance/StoreRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'required|integer|exists:users,id',
|
||||
'base_date' => 'required|date',
|
||||
'status' => 'nullable|in:onTime,late,absent,vacation,businessTrip,fieldWork,overtime,remote',
|
||||
'remarks' => 'nullable|string|max:500',
|
||||
|
||||
// json_details 필드
|
||||
'check_in' => 'nullable|date_format:H:i:s',
|
||||
'check_out' => 'nullable|date_format:H:i:s',
|
||||
'gps_data' => 'nullable|array',
|
||||
'gps_data.check_in' => 'nullable|array',
|
||||
'gps_data.check_in.latitude' => 'nullable|numeric',
|
||||
'gps_data.check_in.longitude' => 'nullable|numeric',
|
||||
'gps_data.check_out' => 'nullable|array',
|
||||
'gps_data.check_out.latitude' => 'nullable|numeric',
|
||||
'gps_data.check_out.longitude' => 'nullable|numeric',
|
||||
'external_work' => 'nullable|array',
|
||||
'external_work.location' => 'nullable|string|max:255',
|
||||
'external_work.purpose' => 'nullable|string|max:500',
|
||||
'work_minutes' => 'nullable|integer|min:0',
|
||||
'overtime_minutes' => 'nullable|integer|min:0',
|
||||
'late_minutes' => 'nullable|integer|min:0',
|
||||
'early_leave_minutes' => 'nullable|integer|min:0',
|
||||
'vacation_type' => 'nullable|string|max:50',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'user_id.required' => __('validation.required', ['attribute' => '사용자']),
|
||||
'base_date.required' => __('validation.required', ['attribute' => '기준일']),
|
||||
];
|
||||
}
|
||||
}
|
||||
40
app/Http/Requests/Attendance/UpdateRequest.php
Normal file
40
app/Http/Requests/Attendance/UpdateRequest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Attendance;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'status' => 'nullable|in:onTime,late,absent,vacation,businessTrip,fieldWork,overtime,remote',
|
||||
'remarks' => 'nullable|string|max:500',
|
||||
|
||||
// json_details 필드
|
||||
'check_in' => 'nullable|date_format:H:i:s',
|
||||
'check_out' => 'nullable|date_format:H:i:s',
|
||||
'gps_data' => 'nullable|array',
|
||||
'gps_data.check_in' => 'nullable|array',
|
||||
'gps_data.check_in.latitude' => 'nullable|numeric',
|
||||
'gps_data.check_in.longitude' => 'nullable|numeric',
|
||||
'gps_data.check_out' => 'nullable|array',
|
||||
'gps_data.check_out.latitude' => 'nullable|numeric',
|
||||
'gps_data.check_out.longitude' => 'nullable|numeric',
|
||||
'external_work' => 'nullable|array',
|
||||
'external_work.location' => 'nullable|string|max:255',
|
||||
'external_work.purpose' => 'nullable|string|max:500',
|
||||
'work_minutes' => 'nullable|integer|min:0',
|
||||
'overtime_minutes' => 'nullable|integer|min:0',
|
||||
'late_minutes' => 'nullable|integer|min:0',
|
||||
'early_leave_minutes' => 'nullable|integer|min:0',
|
||||
'vacation_type' => 'nullable|string|max:50',
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Http/Requests/Employee/IndexRequest.php
Normal file
27
app/Http/Requests/Employee/IndexRequest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Employee;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class IndexRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'q' => 'nullable|string|max:100',
|
||||
'status' => 'nullable|in:active,leave,resigned',
|
||||
'department_id' => 'nullable|integer|min:1',
|
||||
'has_account' => 'nullable|in:0,1,true,false',
|
||||
'sort_by' => 'nullable|in:created_at,name,employee_status,department_id',
|
||||
'sort_dir' => 'nullable|in:asc,desc',
|
||||
'page' => 'nullable|integer|min:1',
|
||||
'per_page' => 'nullable|integer|min:1|max:100',
|
||||
];
|
||||
}
|
||||
}
|
||||
68
app/Http/Requests/Employee/StoreRequest.php
Normal file
68
app/Http/Requests/Employee/StoreRequest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Employee;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
// users 테이블 필드
|
||||
'user_id' => 'nullable|string|max:50|unique:users,user_id',
|
||||
'name' => 'required|string|max:100',
|
||||
'email' => 'required|email|max:255|unique:users,email',
|
||||
'phone' => 'nullable|string|max:20',
|
||||
'password' => 'nullable|string|min:8',
|
||||
'is_active' => 'nullable|boolean',
|
||||
|
||||
// tenant_user_profiles 테이블 필드
|
||||
'department_id' => 'nullable|integer|exists:departments,id',
|
||||
'position_key' => 'nullable|string|max:50',
|
||||
'job_title_key' => 'nullable|string|max:50',
|
||||
'work_location_key' => 'nullable|string|max:50',
|
||||
'employment_type_key' => 'nullable|string|max:50',
|
||||
'employee_status' => 'nullable|in:active,leave,resigned',
|
||||
'manager_user_id' => 'nullable|integer|exists:users,id',
|
||||
'profile_photo_path' => 'nullable|string|max:255',
|
||||
'display_name' => 'nullable|string|max:100',
|
||||
|
||||
// json_extra 필드
|
||||
'employee_code' => 'nullable|string|max:50',
|
||||
'resident_number' => 'nullable|string|max:255',
|
||||
'gender' => 'nullable|in:male,female',
|
||||
'address' => 'nullable|array',
|
||||
'address.zipCode' => 'nullable|string|max:10',
|
||||
'address.address1' => 'nullable|string|max:255',
|
||||
'address.address2' => 'nullable|string|max:255',
|
||||
'salary' => 'nullable|numeric|min:0',
|
||||
'hire_date' => 'nullable|date',
|
||||
'rank' => 'nullable|string|max:50',
|
||||
'bank_account' => 'nullable|array',
|
||||
'bank_account.bankName' => 'nullable|string|max:50',
|
||||
'bank_account.accountNumber' => 'nullable|string|max:50',
|
||||
'bank_account.accountHolder' => 'nullable|string|max:50',
|
||||
'work_type' => 'nullable|in:regular,daily,temporary,external',
|
||||
'contract_info' => 'nullable|array',
|
||||
'contract_info.start_date' => 'nullable|date',
|
||||
'contract_info.end_date' => 'nullable|date',
|
||||
'contract_info.external_company' => 'nullable|string|max:100',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => __('validation.required', ['attribute' => '이름']),
|
||||
'email.required' => __('validation.required', ['attribute' => '이메일']),
|
||||
'email.email' => __('validation.email', ['attribute' => '이메일']),
|
||||
'email.unique' => __('validation.unique', ['attribute' => '이메일']),
|
||||
];
|
||||
}
|
||||
}
|
||||
79
app/Http/Requests/Employee/UpdateRequest.php
Normal file
79
app/Http/Requests/Employee/UpdateRequest.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Employee;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$employeeId = $this->route('id');
|
||||
|
||||
return [
|
||||
// users 테이블 필드
|
||||
'name' => 'nullable|string|max:100',
|
||||
'email' => [
|
||||
'nullable',
|
||||
'email',
|
||||
'max:255',
|
||||
Rule::unique('users', 'email')->ignore($this->getOriginalUserId()),
|
||||
],
|
||||
'phone' => 'nullable|string|max:20',
|
||||
'is_active' => 'nullable|boolean',
|
||||
|
||||
// tenant_user_profiles 테이블 필드
|
||||
'department_id' => 'nullable|integer|exists:departments,id',
|
||||
'position_key' => 'nullable|string|max:50',
|
||||
'job_title_key' => 'nullable|string|max:50',
|
||||
'work_location_key' => 'nullable|string|max:50',
|
||||
'employment_type_key' => 'nullable|string|max:50',
|
||||
'employee_status' => 'nullable|in:active,leave,resigned',
|
||||
'manager_user_id' => 'nullable|integer|exists:users,id',
|
||||
'profile_photo_path' => 'nullable|string|max:255',
|
||||
'display_name' => 'nullable|string|max:100',
|
||||
|
||||
// json_extra 필드
|
||||
'employee_code' => 'nullable|string|max:50',
|
||||
'resident_number' => 'nullable|string|max:255',
|
||||
'gender' => 'nullable|in:male,female',
|
||||
'address' => 'nullable|array',
|
||||
'address.zipCode' => 'nullable|string|max:10',
|
||||
'address.address1' => 'nullable|string|max:255',
|
||||
'address.address2' => 'nullable|string|max:255',
|
||||
'salary' => 'nullable|numeric|min:0',
|
||||
'hire_date' => 'nullable|date',
|
||||
'rank' => 'nullable|string|max:50',
|
||||
'bank_account' => 'nullable|array',
|
||||
'bank_account.bankName' => 'nullable|string|max:50',
|
||||
'bank_account.accountNumber' => 'nullable|string|max:50',
|
||||
'bank_account.accountHolder' => 'nullable|string|max:50',
|
||||
'work_type' => 'nullable|in:regular,daily,temporary,external',
|
||||
'contract_info' => 'nullable|array',
|
||||
'contract_info.start_date' => 'nullable|date',
|
||||
'contract_info.end_date' => 'nullable|date',
|
||||
'contract_info.external_company' => 'nullable|string|max:100',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 사원 프로필의 user_id 가져오기
|
||||
*/
|
||||
private function getOriginalUserId(): ?int
|
||||
{
|
||||
$employeeId = $this->route('id');
|
||||
if (! $employeeId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$profile = \App\Models\Tenants\TenantUserProfile::find($employeeId);
|
||||
|
||||
return $profile?->user_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user