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.selectedProjectId!);
|
||||||
attendanceController.fetchAttendanceLogs(
|
attendanceController.fetchAttendanceLogs(
|
||||||
attendanceController.selectedProjectId!);
|
attendanceController.selectedProjectId!);
|
||||||
|
attendanceController
|
||||||
|
.fetchProjectData(attendanceController.selectedProjectId!);
|
||||||
|
attendanceController.update();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
@ -503,11 +506,19 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
DataCell(
|
DataCell(
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
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) {
|
if (attendanceController.selectedProjectId == null) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
content: Text("Please select a project first")),
|
content: Text("Please select a project first"),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -515,15 +526,36 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
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) {
|
||||||
|
DateTime currentDate = DateTime.now();
|
||||||
|
DateTime twoDaysAgo =
|
||||||
|
currentDate.subtract(Duration(days: 2));
|
||||||
|
|
||||||
|
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;
|
updatedAction = 1;
|
||||||
actionText = "Check Out";
|
actionText = "Check Out";
|
||||||
|
}
|
||||||
} else if (log.activity == 2) {
|
} else if (log.activity == 2) {
|
||||||
updatedAction = 2;
|
updatedAction = 2;
|
||||||
actionText = "Request Regularize";
|
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 {
|
} else {
|
||||||
updatedAction = 0;
|
updatedAction = 0;
|
||||||
actionText = "Unknown Action";
|
actionText = "Unknown Action";
|
||||||
@ -542,7 +574,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(success
|
content: Text(success
|
||||||
? 'Attendance marked successfully!'
|
? 'Attendance marked successfully!'
|
||||||
: 'Image upload failed.')),
|
: 'Image upload failed.'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
@ -550,11 +583,20 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
attendanceController.selectedProjectId!);
|
attendanceController.selectedProjectId!);
|
||||||
attendanceController.fetchAttendanceLogs(
|
attendanceController.fetchAttendanceLogs(
|
||||||
attendanceController.selectedProjectId!);
|
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.rejected
|
||||||
|
: (log.activity == 4 &&
|
||||||
|
log.checkOut != null &&
|
||||||
|
log.checkIn != null &&
|
||||||
|
DateTime.now().difference(log.checkIn!).inDays <= 2)
|
||||||
? ButtonActions.checkIn
|
? ButtonActions.checkIn
|
||||||
: (log.activity == 2)
|
: (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.requestRegularize
|
||||||
: ButtonActions.checkOut,
|
: ButtonActions.checkOut,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
]);
|
]);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user