handelled the condition

This commit is contained in:
Vaibhav Surve 2025-05-07 10:11:44 +05:30
parent be96ac0de7
commit fb21885c32

View File

@ -624,12 +624,11 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
),
DataCell(
Obx(() {
// Check if any record for this employee is uploading
final uniqueLogKey = '${log.employeeId}_${log.id}';
final isUploading =
attendanceController.uploadingStates[uniqueLogKey]?.value ??
false;
// Check if both checkIn and checkOut exist and the date is yesterday
final isYesterday = log.checkIn != null &&
log.checkOut != null &&
DateUtils.isSameDay(log.checkIn!,
@ -637,21 +636,26 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
DateUtils.isSameDay(log.checkOut!,
DateTime.now().subtract(Duration(days: 1)));
final isTodayApproved = log.activity == 4 &&
DateUtils.isSameDay(
log.checkIn ?? DateTime(2000), DateTime.now());
final isApprovedButNotToday =
log.activity == 4 && !isTodayApproved;
final isButtonDisabled = isUploading ||
isYesterday ||
log.activity == 2 ||
log.activity == 5 ||
isApprovedButNotToday;
return SizedBox(
width: 90,
height: 25,
child: ElevatedButton(
onPressed: isUploading ||
isYesterday ||
log.activity == 2 ||
log.activity == 5 ||
(log.activity == 4 &&
!(DateUtils.isSameDay(
log.checkIn ?? DateTime(2000),
DateTime.now())))
onPressed: isButtonDisabled
? null
: () async {
// Set the uploading state for the employee when the action starts
attendanceController.uploadingStates[uniqueLogKey] =
RxBool(true);
@ -666,17 +670,16 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
return;
}
// Existing logic for updating action
int updatedAction;
String actionText;
bool imageCapture = true;
if (log.activity == 0) {
updatedAction = 0;
actionText = "Check In";
} else if (log.activity == 1) {
DateTime currentDate = DateTime.now();
DateTime twoDaysAgo =
currentDate.subtract(Duration(days: 2));
final twoDaysAgo =
DateTime.now().subtract(Duration(days: 2));
if (log.checkOut == null &&
log.checkIn != null &&
@ -695,11 +698,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
} else if (log.activity == 2) {
updatedAction = 2;
actionText = "Request Regularize";
} else if (log.activity == 4 &&
log.checkOut != null &&
log.checkIn != null &&
DateTime.now().difference(log.checkIn!).inDays <=
2) {
} else if (isTodayApproved) {
updatedAction = 0;
actionText = "Check In";
} else {
@ -707,7 +706,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
actionText = "Unknown Action";
}
// Proceed with capturing and uploading attendance
final success = await attendanceController
.captureAndUploadAttendance(
log.id,
@ -718,7 +716,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
imageCapture: imageCapture,
);
// Show result in SnackBar
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(success
@ -727,12 +724,10 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
),
);
// Reset the uploading state after the action is complete
attendanceController.uploadingStates[uniqueLogKey] =
RxBool(false);
if (success) {
// Update the UI with the new data
attendanceController.fetchEmployeesByProject(
attendanceController.selectedProjectId!);
attendanceController.fetchAttendanceLogs(
@ -746,15 +741,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
},
style: ElevatedButton.styleFrom(
backgroundColor: isYesterday
? Colors
.grey // Button color for the disabled state (Yesterday's date)
: (log.activity == 4 &&
log.checkOut != null &&
log.checkIn != null &&
DateTime.now()
.difference(log.checkIn!)
.inDays <=
2)
? Colors.grey
: isTodayApproved
? Colors.green
: AttendanceActionColors.colors[(log.activity == 0)
? ButtonActions.checkIn
@ -774,20 +762,14 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
),
)
: Text(
(log.activity == 5)
log.activity == 5
? ButtonActions.rejected
: (log.activity == 4 &&
log.checkOut != null &&
log.checkIn != null &&
DateTime.now()
.difference(log.checkIn!)
.inDays <=
2)
: isTodayApproved
? ButtonActions.checkIn
: (log.activity == 2)
? "Requested"
: (log.activity == 4)
: log.activity == 4
? ButtonActions.approved
: log.activity == 2
? ButtonActions.requested
: (log.activity == 0 &&
!(log.checkIn != null &&
log.checkOut != null &&
@ -803,17 +785,16 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
.inDays <=
2)
? ButtonActions.checkOut
: (log.activity == 2 ||
(log.activity == 1 &&
: (log.activity == 1 &&
log.checkOut ==
null &&
log.checkIn !=
null &&
log.checkIn != null &&
log.checkIn!.isBefore(
DateTime.now()
.subtract(Duration(
.subtract(
Duration(
days:
2)))))
2))))
? ButtonActions
.requestRegularize
: ButtonActions.checkOut,