Fix employee creation logic and consistency
This commit is contained in:
@@ -218,9 +218,10 @@ class EmployeeController extends Controller
|
||||
'phone' => 'required|string|max:20',
|
||||
'date_of_birth' => 'required|date',
|
||||
'gender' => 'required|in:male,female,other',
|
||||
'profile_image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'profile_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'shift_id' => 'nullable|exists:shifts,id',
|
||||
'attendance_policy_id' => 'nullable|exists:attendance_policies,id',
|
||||
'salary' => 'required|numeric|min:0',
|
||||
|
||||
// Employment details
|
||||
'branch_id' => 'required|exists:branches,id',
|
||||
@@ -281,6 +282,17 @@ class EmployeeController extends Controller
|
||||
return redirect()->back()->withErrors($validator)->withInput();
|
||||
}
|
||||
|
||||
// Plan limit check
|
||||
if (isSaas()) {
|
||||
$creator = User::find(creatorId());
|
||||
if ($creator && $creator->type === 'company' && $creator->plan) {
|
||||
$count = User::where('type', 'employee')->whereIn('created_by', getCompanyAndUsersId())->count();
|
||||
if ($count >= $creator->plan->max_employees) {
|
||||
return redirect()->back()->with('error', __('Your plan limit for employees has been reached.'))->withInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\DB::beginTransaction();
|
||||
|
||||
// Create User model object
|
||||
@@ -356,10 +368,6 @@ class EmployeeController extends Controller
|
||||
$employee->created_by = creatorId();
|
||||
$employee->save();
|
||||
|
||||
if (!$employee->save()) {
|
||||
throw new \Exception('Failed to save employee data');
|
||||
}
|
||||
|
||||
// Handle document uploads
|
||||
if ($request->has('documents') && is_array($request->documents)) {
|
||||
foreach ($request->documents as $index => $document) {
|
||||
@@ -533,6 +541,7 @@ class EmployeeController extends Controller
|
||||
'profile_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'shift_id' => 'nullable|exists:shifts,id',
|
||||
'attendance_policy_id' => 'nullable|exists:attendance_policies,id',
|
||||
'salary' => 'required|numeric|min:0',
|
||||
|
||||
// Employment details
|
||||
'branch_id' => 'required|exists:branches,id',
|
||||
@@ -553,9 +562,9 @@ class EmployeeController extends Controller
|
||||
'emergency_contact_number' => 'required|string|max:20',
|
||||
|
||||
// Banking information
|
||||
'bank_name' => 'required|string|max:255',
|
||||
'account_holder_name' => 'required|string|max:255',
|
||||
'account_number' => 'required|string|max:50',
|
||||
'bank_name' => 'nullable|string|max:255',
|
||||
'account_holder_name' => 'nullable|string|max:255',
|
||||
'account_number' => 'nullable|string|max:50',
|
||||
'bank_identifier_code' => 'nullable|string|max:50',
|
||||
'bank_branch' => 'nullable|string|max:255',
|
||||
'tax_payer_id' => 'nullable|string|max:50',
|
||||
|
||||
Reference in New Issue
Block a user