- Adjusted indentation and formatting in login, permissions, profile, and security pages for better readability. - Enhanced the clarity of conditional statements and function calls in permissions and profile components. - Updated type definitions in vite-env.d.ts for better code structure. - Cleaned up array mapping syntax in ProductTest.php for consistency.
91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\HR;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\HR\EmployeeRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\User;
|
|
use App\Services\Admin\HR\EmployeeService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class EmployeeController extends Controller
|
|
{
|
|
public function __construct(
|
|
private EmployeeService $service
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/hr/employee/index', [
|
|
'employees' => $this->service->paginated(
|
|
...$request->validatedWithDefaults(),
|
|
filters: $request->only(['employment_status', 'is_active', 'gender']),
|
|
),
|
|
'filters' => $request->only(['employment_status', 'is_active', 'gender']),
|
|
]);
|
|
}
|
|
|
|
public function create(): Response
|
|
{
|
|
return Inertia::render('admin/hr/employee/create');
|
|
}
|
|
|
|
public function store(EmployeeRequest $request): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->create($request->validated()),
|
|
'Pegawai berhasil ditambahkan.',
|
|
'admin.hr.employees.index'
|
|
);
|
|
}
|
|
|
|
public function edit(User $user): Response
|
|
{
|
|
$user->load(['userProfile', 'employee']);
|
|
|
|
return Inertia::render('admin/hr/employee/edit', [
|
|
'employee' => $user,
|
|
]);
|
|
}
|
|
|
|
public function update(EmployeeRequest $request, User $user): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->update($user, $request->validated()),
|
|
'Pegawai berhasil diperbarui.',
|
|
'admin.hr.employees.index'
|
|
);
|
|
}
|
|
|
|
public function destroy(User $user): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->delete($user),
|
|
'Pegawai berhasil dihapus.',
|
|
'admin.hr.employees.index'
|
|
);
|
|
}
|
|
|
|
public function toggleActive(User $user): RedirectResponse
|
|
{
|
|
$employee = $this->service->toggleActive($user);
|
|
$status = $employee->is_active ? 'diaktifkan' : 'dinonaktifkan';
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => "Pegawai berhasil {$status}."]);
|
|
|
|
return to_route('admin.hr.employees.index');
|
|
}
|
|
|
|
public function resetPassword(User $user): RedirectResponse
|
|
{
|
|
return $this->handleAction(
|
|
fn () => $this->service->resetPassword($user),
|
|
'Kata sandi pegawai berhasil direset ke kata sandi default.',
|
|
'admin.hr.employees.index'
|
|
);
|
|
}
|
|
}
|