Show overtime checkin when a user does not have a schedule for the day or the schedule ended for the day

This commit is contained in:
Marc Rejohn Castillano 2026-03-18 04:51:45 +08:00
parent 3e3e4d560e
commit 84837c4bf2

View File

@ -426,17 +426,19 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
.map((s) => s.endTime)
.reduce((a, b) => a.isAfter(b) ? a : b)
: null;
final isPastScheduleEnd =
final hasScheduleEnded =
latestScheduleEnd != null && now.isAfter(latestScheduleEnd);
// If the user has an approved IT Service Request override, treat it as a "schedule" for
// purposes of showing the normal check-in UI (even if the duty schedule list is empty).
final hasEffectiveSchedule = hasScheduleToday || hasGeofenceOverride;
// (Note: this override should not prevent the overtime check-in from being shown.)
// Show overtime check-in when the user has no schedule today, or their last
// scheduled shift has already ended.
final showOvertimeCard =
(activeOvertimeLog.isEmpty && _overtimeLogId == null) &&
activeLog.isEmpty &&
(!hasEffectiveSchedule || isPastScheduleEnd);
(!hasScheduleToday || hasScheduleEnded);
if (kDebugMode && showOvertimeCard) {
final assignedSchedules = schedules
@ -447,7 +449,7 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
final assignedTodaySchedules = todaySchedule;
debugPrint(
'Attendance: showOvertimeCard=true (profile=${profile.id}, hasScheduleToday=$hasScheduleToday, isPastScheduleEnd=$isPastScheduleEnd, schedules=${schedules.length}, assigned=${assignedSchedules.length}, assignedToday=${assignedTodaySchedules.length})',
'Attendance: showOvertimeCard=true (profile=${profile.id}, hasScheduleToday=$hasScheduleToday, hasScheduleEnded=$hasScheduleEnded, schedules=${schedules.length}, assigned=${assignedSchedules.length}, assignedToday=${assignedTodaySchedules.length})',
);
if (assignedSchedules.isNotEmpty) {
@ -716,7 +718,12 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
if (activeOvertimeLog.isNotEmpty || _overtimeLogId != null)
_buildActiveOvertimeCard(context, theme, colors, activeOvertimeLog)
else if (showOvertimeCard)
_buildOvertimeCard(context, theme, colors)
_buildOvertimeCard(
context,
theme,
colors,
hasScheduleToday: hasScheduleToday,
)
else
...todaySchedule.map((schedule) {
// All logs for this schedule.
@ -1405,12 +1412,17 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
}
}
/// Card shown when user has no schedule offers overtime check-in.
/// Card shown when user has no active schedule (or their schedule has ended).
/// Offers overtime check-in.
Widget _buildOvertimeCard(
BuildContext context,
ThemeData theme,
ColorScheme colors,
) {
ColorScheme colors, {
required bool hasScheduleToday,
}) {
final headerText = hasScheduleToday
? 'Your scheduled shift has ended.'
: 'No schedule assigned for today.';
return Card(
child: Padding(
padding: const EdgeInsets.all(16),
@ -1423,7 +1435,7 @@ class _CheckInTabState extends ConsumerState<_CheckInTab> {
const SizedBox(width: 8),
Expanded(
child: Text(
'No schedule assigned for today.',
headerText,
style: theme.textTheme.bodyMedium?.copyWith(
color: colors.onSurfaceVariant,
),