grouped the attendence logs #10

Merged
vaibhav.surve merged 1 commits from Vaibhav_Task-#176 into main 2025-05-05 10:20:39 +00:00
2 changed files with 365 additions and 334 deletions

View File

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:geolocator/geolocator.dart'; import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:marco/helpers/services/api_service.dart'; import 'package:marco/helpers/services/api_service.dart';
import 'package:marco/model/attendance_model.dart'; import 'package:marco/model/attendance_model.dart';
import 'package:marco/model/project_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."); 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( Future<void> fetchRegularizationLogs(
String? projectId, { String? projectId, {

View File

@ -340,6 +340,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
Widget reportsTab(BuildContext context) { Widget reportsTab(BuildContext context) {
final attendanceController = Get.find<AttendanceController>(); final attendanceController = Get.find<AttendanceController>();
final groupedLogs = attendanceController.groupLogsByCheckInDate();
final columns = [ final columns = [
DataColumn(label: MyText.labelLarge('Name', color: contentTheme.primary)), 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)), label: MyText.labelLarge('Action', color: contentTheme.primary)),
]; ];
final rows = attendanceController.attendanceLogs.reversed List<DataRow> rows = [];
.toList()
.asMap() // Iterate over grouped logs
.entries groupedLogs.forEach((checkInDate, logs) {
.map((entry) { // Add a row for the check-in date as a header
var log = entry.value; rows.add(DataRow(cells: [
return 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( DataCell(
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -375,12 +385,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
MyText.bodyMedium( // MyText.bodyMedium(
log.checkIn != null // log.checkIn != null
? DateFormat('dd MMM yyyy').format(log.checkIn!) // ? DateFormat('dd MMM yyyy').format(log.checkIn!)
: '-', // : '-',
fontWeight: 600, // fontWeight: 600,
), // ),
MyText.bodyMedium( MyText.bodyMedium(
log.checkIn != null log.checkIn != null
? DateFormat('hh:mm a').format(log.checkIn!) ? DateFormat('hh:mm a').format(log.checkIn!)
@ -395,12 +405,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
MyText.bodyMedium( // MyText.bodyMedium(
log.checkOut != null // log.checkOut != null
? DateFormat('dd MMM yyyy').format(log.checkOut!) // ? DateFormat('dd MMM yyyy').format(log.checkOut!)
: '-', // : '-',
fontWeight: 600, // fontWeight: 600,
), // ),
MyText.bodyMedium( MyText.bodyMedium(
log.checkOut != null log.checkOut != null
? DateFormat('hh:mm a').format(log.checkOut!) ? DateFormat('hh:mm a').format(log.checkOut!)
@ -418,7 +428,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
shape: const RoundedRectangleBorder( shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)), borderRadius:
BorderRadius.vertical(top: Radius.circular(16)),
), ),
backgroundColor: Theme.of(context).cardColor, backgroundColor: Theme.of(context).cardColor,
builder: (context) { builder: (context) {
@ -452,7 +463,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
), ),
const Divider(thickness: 1, height: 24), const Divider(thickness: 1, height: 24),
], ],
if (attendanceController.attendenceLogsView.isNotEmpty) if (attendanceController
.attendenceLogsView.isNotEmpty)
...attendanceController.attendenceLogsView ...attendanceController.attendenceLogsView
.map((log) => Row( .map((log) => Row(
mainAxisAlignment: mainAxisAlignment:
@ -494,7 +506,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
child: const Padding( child: const Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: 4.0), right: 4.0),
child: Icon(Icons.location_on, child: Icon(
Icons.location_on,
size: 18, size: 18,
color: Colors.blue), color: Colors.blue),
), ),
@ -537,8 +550,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
height: 40, height: 40,
width: 40, width: 40,
fit: BoxFit.cover, fit: BoxFit.cover,
errorBuilder: (context, error, errorBuilder: (context,
stackTrace) { error, stackTrace) {
return Icon( return Icon(
Icons.broken_image, Icons.broken_image,
size: 40, size: 40,
@ -546,7 +559,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
}, },
) )
: Icon(Icons.broken_image, : 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 != null &&
log.checkIn!.isBefore( log.checkIn!.isBefore(
DateTime.now().subtract( DateTime.now().subtract(
Duration(days: 2))))) Duration(
days: 2)))))
? ButtonActions.requestRegularize ? ButtonActions.requestRegularize
: ButtonActions.checkOut, : ButtonActions.checkOut,
), ),
), ),
) ),
]); ]));
}).toList(); }
});
return SingleChildScrollView( return SingleChildScrollView(
// Wrap the Column in SingleChildScrollView to handle overflow
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [