_handleButtonPressed
This commit is contained in:
parent
71f9e54d58
commit
8a729f23fe
@ -147,16 +147,25 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
||||
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<AttendanceActionButton> {
|
||||
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<AttendanceActionButton> {
|
||||
|
||||
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<AttendanceActionButton> {
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user