submitAttendanceDetails method
void
submitAttendanceDetails({
- required List<
AttendeeModel> attendeeList, - required List<
AttendanceLogModel> attendanceLogs, - required bool onMarked(
- dynamic val
- bool? createOplog,
- required bool isSingleSession,
Implementation
void submitAttendanceDetails(
{required List<AttendeeModel> attendeeList,
required List<AttendanceLogModel> attendanceLogs,
required bool Function(dynamic val) onMarked,
bool? createOplog,
required bool isSingleSession}) async {
final existingLogs = await attendanceLogDataRepository?.search(
AttendanceLogSearchModel(
registerId: attendanceLogs.firstOrNull?.registerId,
),
) ??
[];
// Mapping attendance logs for submission
final hcmAttendanceLogs = attendanceLogs.map(
(e) {
final existingLog = existingLogs.where(
(ele) {
return isSingleSession == true
? ele.individualId == e.individualId &&
ele.registerId == e.registerId &&
((ele.type == 'ENTRY' &&
e.type == 'ENTRY' &&
ele.time == e.time) ||
(ele.type == 'EXIT' &&
e.type == 'EXIT' &&
ele.time == e.time))
: ele.individualId == e.individualId &&
ele.registerId == e.registerId &&
ele.time == e.time &&
ele.type == e.type &&
ele.clientReferenceId != null
? true
: false;
},
).toList();
return e.copyWith(
rowVersion: 1,
clientReferenceId: (existingLog).isNotEmpty
? existingLog.last.clientReferenceId
: IdGen.i.identifier,
clientAuditDetails: ClientAuditDetails(
createdBy: AttendanceSingleton().loggedInUserUuid,
createdTime: DateTime.now().millisecondsSinceEpoch,
lastModifiedTime: DateTime.now().millisecondsSinceEpoch,
lastModifiedBy: AttendanceSingleton().loggedInUserUuid,
),
auditDetails: AuditDetails(
createdBy: AttendanceSingleton().loggedInUserUuid,
createdTime: DateTime.now().millisecondsSinceEpoch,
lastModifiedTime: DateTime.now().millisecondsSinceEpoch,
lastModifiedBy: AttendanceSingleton().loggedInUserUuid,
),
);
},
).toList();
// Grouping individuals and creating attendance logs
final groupedIndividuals =
hcmAttendanceLogs.groupListsBy((ele) => ele.individualId);
for (final log in groupedIndividuals.entries) {
final createOpLog = (createOplog ?? false) &&
(log.value.where((l) => l.type == 'ENTRY').lastOrNull?.time !=
log.value.where((l) => l.type == 'EXIT').lastOrNull?.time);
await createAttendanceLog(
log.value,
'ENTRY',
createOpLog,
);
await createAttendanceLog(
log.value,
'EXIT',
createOpLog,
);
}
}