handelled button action

This commit is contained in:
Vaibhav Surve 2025-05-03 15:06:02 +05:30
parent 70943aad01
commit a026242319

View File

@ -291,6 +291,9 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
attendanceController.selectedProjectId!); attendanceController.selectedProjectId!);
attendanceController.fetchAttendanceLogs( attendanceController.fetchAttendanceLogs(
attendanceController.selectedProjectId!); attendanceController.selectedProjectId!);
attendanceController
.fetchProjectData(attendanceController.selectedProjectId!);
attendanceController.update();
} }
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
@ -503,58 +506,97 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
), ),
DataCell( DataCell(
ElevatedButton( ElevatedButton(
onPressed: () async { onPressed: (log.activity == 5 ||
if (attendanceController.selectedProjectId == null) { (log.activity == 4 &&
ScaffoldMessenger.of(context).showSnackBar( !(log.checkOut != null &&
const SnackBar( log.checkIn != null &&
content: Text("Please select a project first")), DateTime.now().difference(log.checkIn!).inDays <=
); 2)))
return; ? null
} : () async {
if (attendanceController.selectedProjectId == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Please select a project first"),
),
);
return;
}
int updatedAction; int updatedAction;
String actionText; String actionText;
if (log.activity == 0 || log.activity == 4) { if (log.activity == 0) {
updatedAction = 0; updatedAction = 0;
actionText = "Check In"; actionText = "Check In";
} else if (log.activity == 1) { } else if (log.activity == 1) {
updatedAction = 1; DateTime currentDate = DateTime.now();
actionText = "Check Out"; DateTime twoDaysAgo =
} else if (log.activity == 2) { currentDate.subtract(Duration(days: 2));
updatedAction = 2;
actionText = "Request Regularize";
} else {
updatedAction = 0;
actionText = "Unknown Action";
}
final success = if (log.checkOut == null &&
await attendanceController.captureAndUploadAttendance( log.checkIn != null &&
log.id, log.checkIn!.isBefore(twoDaysAgo)) {
log.employeeId, updatedAction = 2;
int.parse(attendanceController.selectedProjectId!), actionText = "Request Regularize";
comment: actionText, } else if (log.checkOut != null &&
action: updatedAction, log.checkOut!.isBefore(twoDaysAgo)) {
); updatedAction = 2;
actionText = "Request Regularize";
} else {
updatedAction = 1;
actionText = "Check Out";
}
} 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) {
updatedAction = 0;
actionText = "Check In";
} else {
updatedAction = 0;
actionText = "Unknown Action";
}
ScaffoldMessenger.of(context).showSnackBar( final success =
SnackBar( await attendanceController.captureAndUploadAttendance(
content: Text(success log.id,
? 'Attendance marked successfully!' log.employeeId,
: 'Image upload failed.')), int.parse(attendanceController.selectedProjectId!),
); comment: actionText,
action: updatedAction,
);
if (success) { ScaffoldMessenger.of(context).showSnackBar(
attendanceController.fetchEmployeesByProject( SnackBar(
attendanceController.selectedProjectId!); content: Text(success
attendanceController.fetchAttendanceLogs( ? 'Attendance marked successfully!'
attendanceController.selectedProjectId!); : 'Image upload failed.'),
} ),
}, );
if (success) {
attendanceController.fetchEmployeesByProject(
attendanceController.selectedProjectId!);
attendanceController.fetchAttendanceLogs(
attendanceController.selectedProjectId!);
await attendanceController.fetchRegularizationLogs(
attendanceController.selectedProjectId!);
await attendanceController.fetchProjectData(
attendanceController.selectedProjectId!);
attendanceController.update();
}
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: AttendanceActionColors.colors[ backgroundColor: (log.activity == 4 &&
(log.activity == 0 || log.activity == 4) log.checkOut != null &&
log.checkIn != null &&
DateTime.now().difference(log.checkIn!).inDays <= 2)
? Colors.green
: AttendanceActionColors.colors[(log.activity == 0)
? ButtonActions.checkIn ? ButtonActions.checkIn
: ButtonActions.checkOut], : ButtonActions.checkOut],
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6), padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
@ -562,14 +604,36 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
textStyle: const TextStyle(fontSize: 12), textStyle: const TextStyle(fontSize: 12),
), ),
child: Text( child: Text(
(log.activity == 0 || log.activity == 4) (log.activity == 5)
? ButtonActions.checkIn ? ButtonActions.rejected
: (log.activity == 2) : (log.activity == 4 &&
? ButtonActions.requestRegularize log.checkOut != null &&
: ButtonActions.checkOut, log.checkIn != null &&
DateTime.now().difference(log.checkIn!).inDays <= 2)
? ButtonActions.checkIn
: (log.activity == 4)
? ButtonActions.approved
: (log.activity == 0)
? ButtonActions.checkIn
: (log.activity == 1 &&
log.checkOut != null &&
DateTime.now()
.difference(log.checkOut!)
.inDays <=
2)
? ButtonActions.checkOut
: (log.activity == 2 ||
(log.activity == 1 &&
log.checkOut == null &&
log.checkIn != null &&
log.checkIn!.isBefore(
DateTime.now().subtract(
Duration(days: 2)))))
? ButtonActions.requestRegularize
: ButtonActions.checkOut,
), ),
), ),
), )
]); ]);
}).toList(); }).toList();