grouped the attendence logs
This commit is contained in:
parent
f4ed63a8ab
commit
f2c125172d
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/model/attendance_model.dart';
|
||||
import 'package:marco/model/project_model.dart';
|
||||
@ -182,6 +182,22 @@ class AttendanceController extends GetxController {
|
||||
print("Failed to fetch attendance logs for project $projectId.");
|
||||
}
|
||||
}
|
||||
Map<String, List<AttendanceLogModel>> groupLogsByCheckInDate() {
|
||||
final groupedLogs = <String, List<AttendanceLogModel>>{};
|
||||
|
||||
for (var log in attendanceLogs) {
|
||||
final checkInDate = log.checkIn != null
|
||||
? DateFormat('dd MMM yyyy').format(log.checkIn!)
|
||||
: 'Unknown';
|
||||
|
||||
if (!groupedLogs.containsKey(checkInDate)) {
|
||||
groupedLogs[checkInDate] = [];
|
||||
}
|
||||
groupedLogs[checkInDate]!.add(log);
|
||||
}
|
||||
|
||||
return groupedLogs;
|
||||
}
|
||||
|
||||
Future<void> fetchRegularizationLogs(
|
||||
String? projectId, {
|
||||
|
@ -340,6 +340,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
|
||||
Widget reportsTab(BuildContext context) {
|
||||
final attendanceController = Get.find<AttendanceController>();
|
||||
final groupedLogs = attendanceController.groupLogsByCheckInDate();
|
||||
|
||||
final columns = [
|
||||
DataColumn(label: MyText.labelLarge('Name', color: contentTheme.primary)),
|
||||
@ -352,13 +353,22 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
label: MyText.labelLarge('Action', color: contentTheme.primary)),
|
||||
];
|
||||
|
||||
final rows = attendanceController.attendanceLogs.reversed
|
||||
.toList()
|
||||
.asMap()
|
||||
.entries
|
||||
.map((entry) {
|
||||
var log = entry.value;
|
||||
return DataRow(cells: [
|
||||
List<DataRow> rows = [];
|
||||
|
||||
// Iterate over grouped logs
|
||||
groupedLogs.forEach((checkInDate, logs) {
|
||||
// Add a row for the check-in date as a header
|
||||
rows.add(DataRow(cells: [
|
||||
DataCell(MyText.bodyMedium(checkInDate, fontWeight: 600)),
|
||||
DataCell(MyText.bodyMedium('')), // Placeholder for other columns
|
||||
DataCell(MyText.bodyMedium('')), // Placeholder for other columns
|
||||
DataCell(MyText.bodyMedium('')), // Placeholder for other columns
|
||||
DataCell(MyText.bodyMedium('')), // Placeholder for other columns
|
||||
]));
|
||||
|
||||
// Add rows for each log in this group
|
||||
for (var log in logs) {
|
||||
rows.add(DataRow(cells: [
|
||||
DataCell(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -375,12 +385,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
MyText.bodyMedium(
|
||||
log.checkIn != null
|
||||
? DateFormat('dd MMM yyyy').format(log.checkIn!)
|
||||
: '-',
|
||||
fontWeight: 600,
|
||||
),
|
||||
// MyText.bodyMedium(
|
||||
// log.checkIn != null
|
||||
// ? DateFormat('dd MMM yyyy').format(log.checkIn!)
|
||||
// : '-',
|
||||
// fontWeight: 600,
|
||||
// ),
|
||||
MyText.bodyMedium(
|
||||
log.checkIn != null
|
||||
? DateFormat('hh:mm a').format(log.checkIn!)
|
||||
@ -395,12 +405,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
MyText.bodyMedium(
|
||||
log.checkOut != null
|
||||
? DateFormat('dd MMM yyyy').format(log.checkOut!)
|
||||
: '-',
|
||||
fontWeight: 600,
|
||||
),
|
||||
// MyText.bodyMedium(
|
||||
// log.checkOut != null
|
||||
// ? DateFormat('dd MMM yyyy').format(log.checkOut!)
|
||||
// : '-',
|
||||
// fontWeight: 600,
|
||||
// ),
|
||||
MyText.bodyMedium(
|
||||
log.checkOut != null
|
||||
? DateFormat('hh:mm a').format(log.checkOut!)
|
||||
@ -418,7 +428,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(16)),
|
||||
),
|
||||
backgroundColor: Theme.of(context).cardColor,
|
||||
builder: (context) {
|
||||
@ -452,7 +463,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
),
|
||||
const Divider(thickness: 1, height: 24),
|
||||
],
|
||||
if (attendanceController.attendenceLogsView.isNotEmpty)
|
||||
if (attendanceController
|
||||
.attendenceLogsView.isNotEmpty)
|
||||
...attendanceController.attendenceLogsView
|
||||
.map((log) => Row(
|
||||
mainAxisAlignment:
|
||||
@ -494,7 +506,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: 4.0),
|
||||
child: Icon(Icons.location_on,
|
||||
child: Icon(
|
||||
Icons.location_on,
|
||||
size: 18,
|
||||
color: Colors.blue),
|
||||
),
|
||||
@ -537,8 +550,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
height: 40,
|
||||
width: 40,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error,
|
||||
stackTrace) {
|
||||
errorBuilder: (context,
|
||||
error, stackTrace) {
|
||||
return Icon(
|
||||
Icons.broken_image,
|
||||
size: 40,
|
||||
@ -546,7 +559,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
},
|
||||
)
|
||||
: Icon(Icons.broken_image,
|
||||
size: 40, color: Colors.grey),
|
||||
size: 40,
|
||||
color: Colors.grey),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -695,17 +709,18 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||
log.checkIn != null &&
|
||||
log.checkIn!.isBefore(
|
||||
DateTime.now().subtract(
|
||||
Duration(days: 2)))))
|
||||
Duration(
|
||||
days: 2)))))
|
||||
? ButtonActions.requestRegularize
|
||||
: ButtonActions.checkOut,
|
||||
),
|
||||
),
|
||||
)
|
||||
]);
|
||||
}).toList();
|
||||
),
|
||||
]));
|
||||
}
|
||||
});
|
||||
|
||||
return SingleChildScrollView(
|
||||
// Wrap the Column in SingleChildScrollView to handle overflow
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user