_handleButtonPressed

This commit is contained in:
Vaibhav Surve 2025-07-10 17:58:52 +05:30
parent 71f9e54d58
commit 8a729f23fe

View File

@ -147,16 +147,25 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
pickedTime.minute, pickedTime.minute,
); );
if (selectedDateTime.isAfter(checkInTime)) { final now = DateTime.now();
return selectedDateTime;
} else { if (selectedDateTime.isBefore(checkInTime)) {
showAppSnackbar( showAppSnackbar(
title: "Invalid Time", 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, type: SnackbarType.warning,
); );
return null; return null;
} }
return selectedDateTime;
} }
return null; return null;
} }
@ -217,6 +226,30 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
break; 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); final userComment = await _showCommentBottomSheet(context, actionText);
if (userComment == null || userComment.isEmpty) { if (userComment == null || userComment.isEmpty) {
widget.attendanceController.uploadingStates[uniqueLogKey]?.value = false; widget.attendanceController.uploadingStates[uniqueLogKey]?.value = false;
@ -225,13 +258,14 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
bool success = false; bool success = false;
if (actionText == ButtonActions.requestRegularize) { if (actionText == ButtonActions.requestRegularize) {
final selectedTime = await showTimePickerForRegularization( final regularizeTime = selectedTime ??
context: context, await showTimePickerForRegularization(
checkInTime: widget.employee.checkIn!, context: context,
); checkInTime: widget.employee.checkIn!,
if (selectedTime != null) { );
if (regularizeTime != null) {
final formattedSelectedTime = final formattedSelectedTime =
DateFormat("hh:mm a").format(selectedTime); DateFormat("hh:mm a").format(regularizeTime);
success = await widget.attendanceController.captureAndUploadAttendance( success = await widget.attendanceController.captureAndUploadAttendance(
widget.employee.id, widget.employee.id,
widget.employee.employeeId, widget.employee.employeeId,
@ -242,6 +276,18 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
markTime: formattedSelectedTime, 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 { } else {
success = await widget.attendanceController.captureAndUploadAttendance( success = await widget.attendanceController.captureAndUploadAttendance(
widget.employee.id, widget.employee.id,