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