dstpabuaran.com/app/Http/Controllers/Admin/HR/AttendanceController.php
Yoga Pangestu 67e5a6271f Add tests for CheckAttendancePenaltiesJob to validate attendance penalties logic
- Implement tests to ensure job skips execution on weekends, when penalties are zero, or when no payroll period exists.
- Validate late penalty creation for late check-ins and ensure no penalties for on-time or early check-ins.
- Test absent penalties for employees without attendance records.
- Ensure no duplicate penalties are created and that payroll recalculations are accurate after penalties are applied.
- Handle multiple employees and edge cases, including employees without associated users.
- Verify that the job can be dispatched to the queue and has the correct retry configuration.
2026-07-31 11:13:46 +07:00

66 lines
2.0 KiB
PHP

<?php
namespace App\Http\Controllers\Admin\HR;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\HR\AttendanceRequest;
use App\Models\Attendance;
use App\Services\Admin\HR\AttendanceService;
use App\Settings\HRSettings;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
class AttendanceController extends Controller
{
public function __construct(
private AttendanceService $service
) {}
public function index(Request $request): Response
{
$year = $request->integer('year', now()->year);
$month = $request->integer('month', now()->month);
$hrSettings = app(HRSettings::class);
return Inertia::render('admin/hr/attendance/index', [
'attendances' => $this->service->getByMonth($year, $month),
'todayAttendance' => $this->service->getToday(),
'currentYear' => $year,
'currentMonth' => $month,
'monthStats' => $this->service->getMonthStats($year, $month),
'hrSettings' => [
'scheduled_check_in_time' => $hrSettings->scheduled_check_in_time,
'scheduled_check_out_time' => $hrSettings->scheduled_check_out_time,
],
]);
}
public function store(AttendanceRequest $request): RedirectResponse
{
return $this->handleAction(
fn () => $this->service->checkIn($request->validated()),
'Berhasil check-in.',
'admin.hr.attendances.index'
);
}
public function update(AttendanceRequest $request, Attendance $attendance): RedirectResponse
{
return $this->handleAction(
fn () => $this->service->checkOut($attendance, $request->validated()),
'Berhasil check-out.',
'admin.hr.attendances.index'
);
}
public function byDate(Request $request): ?array
{
$date = $request->query('date', now()->toDateString());
return $this->service->getByDate($date);
}
}