diff --git a/lib/model/attendance/attendence_action_button.dart b/lib/model/attendance/attendence_action_button.dart index 7ab8f65..08b725e 100644 --- a/lib/model/attendance/attendence_action_button.dart +++ b/lib/model/attendance/attendence_action_button.dart @@ -147,16 +147,25 @@ class _AttendanceActionButtonState extends State { pickedTime.minute, ); - if (selectedDateTime.isAfter(checkInTime)) { - return selectedDateTime; - } else { + final now = DateTime.now(); + + if (selectedDateTime.isBefore(checkInTime)) { showAppSnackbar( title: "Invalid Time", - message: "Please select a time after check-in time.", + message: "Time must be after check-in.", + type: SnackbarType.warning, + ); + return null; + } else if (selectedDateTime.isAfter(now)) { + showAppSnackbar( + title: "Invalid Time", + message: "Future time is not allowed.", type: SnackbarType.warning, ); return null; } + + return selectedDateTime; } return null; } @@ -217,6 +226,30 @@ class _AttendanceActionButtonState extends State { break; } + DateTime? selectedTime; + + // ✅ New condition: Yesterday Check-In + CheckOut action + final isYesterdayCheckIn = widget.employee.checkIn != null && + DateUtils.isSameDay( + widget.employee.checkIn, + DateTime.now().subtract(const Duration(days: 1)), + ); + + if (isYesterdayCheckIn && + widget.employee.checkOut == null && + actionText == ButtonActions.checkOut) { + selectedTime = await showTimePickerForRegularization( + context: context, + checkInTime: widget.employee.checkIn!, + ); + + if (selectedTime == null) { + widget.attendanceController.uploadingStates[uniqueLogKey]?.value = + false; + return; + } + } + final userComment = await _showCommentBottomSheet(context, actionText); if (userComment == null || userComment.isEmpty) { widget.attendanceController.uploadingStates[uniqueLogKey]?.value = false; @@ -225,13 +258,14 @@ class _AttendanceActionButtonState extends State { bool success = false; if (actionText == ButtonActions.requestRegularize) { - final selectedTime = await showTimePickerForRegularization( - context: context, - checkInTime: widget.employee.checkIn!, - ); - if (selectedTime != null) { + final regularizeTime = selectedTime ?? + await showTimePickerForRegularization( + context: context, + checkInTime: widget.employee.checkIn!, + ); + if (regularizeTime != null) { final formattedSelectedTime = - DateFormat("hh:mm a").format(selectedTime); + DateFormat("hh:mm a").format(regularizeTime); success = await widget.attendanceController.captureAndUploadAttendance( widget.employee.id, widget.employee.employeeId, @@ -242,6 +276,18 @@ class _AttendanceActionButtonState extends State { markTime: formattedSelectedTime, ); } + } else if (selectedTime != null) { + // ✅ If selectedTime was picked in the new condition + final formattedSelectedTime = DateFormat("hh:mm a").format(selectedTime); + success = await widget.attendanceController.captureAndUploadAttendance( + widget.employee.id, + widget.employee.employeeId, + selectedProjectId, + comment: userComment, + action: updatedAction, + imageCapture: imageCapture, + markTime: formattedSelectedTime, + ); } else { success = await widget.attendanceController.captureAndUploadAttendance( widget.employee.id,