chnages date display as per utils
This commit is contained in:
parent
092fe21252
commit
93f9a6e738
@ -55,7 +55,8 @@ class AttendanceController extends GetxController {
|
||||
final today = DateTime.now();
|
||||
startDateAttendance = today.subtract(const Duration(days: 7));
|
||||
endDateAttendance = today.subtract(const Duration(days: 1));
|
||||
logSafe("Default date range set: $startDateAttendance to $endDateAttendance");
|
||||
logSafe(
|
||||
"Default date range set: $startDateAttendance to $endDateAttendance");
|
||||
}
|
||||
|
||||
// ------------------ Project & Employee ------------------
|
||||
@ -69,7 +70,8 @@ class AttendanceController extends GetxController {
|
||||
logSafe("Projects fetched: ${projects.length}");
|
||||
} else {
|
||||
projects = [];
|
||||
logSafe("Failed to fetch projects or no projects available.", level: LogLevel.error);
|
||||
logSafe("Failed to fetch projects or no projects available.",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingProjects.value = false;
|
||||
@ -89,7 +91,8 @@ class AttendanceController extends GetxController {
|
||||
}
|
||||
logSafe("Employees fetched: ${employees.length} for project $projectId");
|
||||
} else {
|
||||
logSafe("Failed to fetch employees for project $projectId", level: LogLevel.error);
|
||||
logSafe("Failed to fetch employees for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingEmployees.value = false;
|
||||
@ -112,13 +115,15 @@ class AttendanceController extends GetxController {
|
||||
|
||||
XFile? image;
|
||||
if (imageCapture) {
|
||||
image = await ImagePicker().pickImage(source: ImageSource.camera, imageQuality: 80);
|
||||
image = await ImagePicker()
|
||||
.pickImage(source: ImageSource.camera, imageQuality: 80);
|
||||
if (image == null) {
|
||||
logSafe("Image capture cancelled.", level: LogLevel.warning);
|
||||
return false;
|
||||
}
|
||||
|
||||
final compressedBytes = await compressImageToUnder100KB(File(image.path));
|
||||
final compressedBytes =
|
||||
await compressImageToUnder100KB(File(image.path));
|
||||
if (compressedBytes == null) {
|
||||
logSafe("Image compression failed.", level: LogLevel.error);
|
||||
return false;
|
||||
@ -153,7 +158,8 @@ class AttendanceController extends GetxController {
|
||||
logSafe("Attendance uploaded for $employeeId, action: $action");
|
||||
return result;
|
||||
} catch (e, stacktrace) {
|
||||
logSafe("Error uploading attendance", level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
logSafe("Error uploading attendance",
|
||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||
return false;
|
||||
} finally {
|
||||
uploadingStates[employeeId]?.value = false;
|
||||
@ -172,7 +178,8 @@ class AttendanceController extends GetxController {
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
logSafe('Location permissions are permanently denied', level: LogLevel.error);
|
||||
logSafe('Location permissions are permanently denied',
|
||||
level: LogLevel.error);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -181,17 +188,21 @@ class AttendanceController extends GetxController {
|
||||
|
||||
// ------------------ Attendance Logs ------------------
|
||||
|
||||
Future<void> fetchAttendanceLogs(String? projectId, {DateTime? dateFrom, DateTime? dateTo}) async {
|
||||
Future<void> fetchAttendanceLogs(String? projectId,
|
||||
{DateTime? dateFrom, DateTime? dateTo}) async {
|
||||
if (projectId == null) return;
|
||||
|
||||
isLoadingAttendanceLogs.value = true;
|
||||
|
||||
final response = await ApiService.getAttendanceLogs(projectId, dateFrom: dateFrom, dateTo: dateTo);
|
||||
final response = await ApiService.getAttendanceLogs(projectId,
|
||||
dateFrom: dateFrom, dateTo: dateTo);
|
||||
if (response != null) {
|
||||
attendanceLogs = response.map((e) => AttendanceLogModel.fromJson(e)).toList();
|
||||
attendanceLogs =
|
||||
response.map((e) => AttendanceLogModel.fromJson(e)).toList();
|
||||
logSafe("Attendance logs fetched: ${attendanceLogs.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch attendance logs for project $projectId", level: LogLevel.error);
|
||||
logSafe("Failed to fetch attendance logs for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingAttendanceLogs.value = false;
|
||||
@ -229,10 +240,12 @@ class AttendanceController extends GetxController {
|
||||
|
||||
final response = await ApiService.getRegularizationLogs(projectId);
|
||||
if (response != null) {
|
||||
regularizationLogs = response.map((e) => RegularizationLogModel.fromJson(e)).toList();
|
||||
regularizationLogs =
|
||||
response.map((e) => RegularizationLogModel.fromJson(e)).toList();
|
||||
logSafe("Regularization logs fetched: ${regularizationLogs.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch regularization logs for project $projectId", level: LogLevel.error);
|
||||
logSafe("Failed to fetch regularization logs for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingRegularizationLogs.value = false;
|
||||
@ -248,12 +261,14 @@ class AttendanceController extends GetxController {
|
||||
|
||||
final response = await ApiService.getAttendanceLogView(id);
|
||||
if (response != null) {
|
||||
attendenceLogsView = response.map((e) => AttendanceLogViewModel.fromJson(e)).toList();
|
||||
attendenceLogsView.sort((a, b) =>
|
||||
(b.activityTime ?? DateTime(2000)).compareTo(a.activityTime ?? DateTime(2000)));
|
||||
attendenceLogsView =
|
||||
response.map((e) => AttendanceLogViewModel.fromJson(e)).toList();
|
||||
attendenceLogsView.sort((a, b) => (b.activityTime ?? DateTime(2000))
|
||||
.compareTo(a.activityTime ?? DateTime(2000)));
|
||||
logSafe("Attendance log view fetched for ID: $id");
|
||||
} else {
|
||||
logSafe("Failed to fetch attendance log view for ID $id", level: LogLevel.error);
|
||||
logSafe("Failed to fetch attendance log view for ID $id",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
|
||||
isLoadingLogView.value = false;
|
||||
@ -295,33 +310,13 @@ class AttendanceController extends GetxController {
|
||||
start: startDateAttendance ?? today.subtract(const Duration(days: 7)),
|
||||
end: endDateAttendance ?? today.subtract(const Duration(days: 1)),
|
||||
),
|
||||
builder: (context, child) {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: 400,
|
||||
height: 500,
|
||||
child: Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: const Color(0xFF5F84FF),
|
||||
onPrimary: Colors.white,
|
||||
onSurface: Colors.teal.shade800,
|
||||
),
|
||||
textButtonTheme: TextButtonThemeData(
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.teal),
|
||||
),
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
startDateAttendance = picked.start;
|
||||
endDateAttendance = picked.end;
|
||||
logSafe("Date range selected: $startDateAttendance to $endDateAttendance");
|
||||
logSafe(
|
||||
"Date range selected: $startDateAttendance to $endDateAttendance");
|
||||
|
||||
await controller.fetchAttendanceLogs(
|
||||
Get.find<ProjectController>().selectedProject?.id,
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
// lib/view/attendance/tabs/attendance_logs_tab.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
|
||||
import 'package:marco/helpers/utils/date_time_utils.dart';
|
||||
import 'package:marco/helpers/widgets/avatar.dart';
|
||||
import 'package:marco/helpers/widgets/my_card.dart';
|
||||
import 'package:marco/helpers/widgets/my_container.dart';
|
||||
@ -27,10 +26,10 @@ class AttendanceLogsTab extends StatelessWidget {
|
||||
return bDate.compareTo(aDate);
|
||||
});
|
||||
|
||||
final dateFormat = DateFormat('dd MMM yyyy');
|
||||
final dateRangeText = controller.startDateAttendance != null &&
|
||||
controller.endDateAttendance != null
|
||||
? '${dateFormat.format(controller.endDateAttendance!)} - ${dateFormat.format(controller.startDateAttendance!)}'
|
||||
? '${DateTimeUtils.formatDate(controller.startDateAttendance!, 'dd MMM yyyy')} - '
|
||||
'${DateTimeUtils.formatDate(controller.endDateAttendance!, 'dd MMM yyyy')}'
|
||||
: 'Select date range';
|
||||
|
||||
return Column(
|
||||
@ -44,7 +43,10 @@ class AttendanceLogsTab extends StatelessWidget {
|
||||
MyText.titleMedium("Attendance Logs", fontWeight: 600),
|
||||
controller.isLoading.value
|
||||
? const SizedBox(
|
||||
height: 20, width: 20, child: LinearProgressIndicator())
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: LinearProgressIndicator(),
|
||||
)
|
||||
: MyText.bodySmall(
|
||||
dateRangeText,
|
||||
fontWeight: 600,
|
||||
@ -70,12 +72,13 @@ class AttendanceLogsTab extends StatelessWidget {
|
||||
children: List.generate(logs.length, (index) {
|
||||
final employee = logs[index];
|
||||
final currentDate = employee.checkIn != null
|
||||
? DateFormat('dd MMM yyyy').format(employee.checkIn!)
|
||||
? DateTimeUtils.formatDate(
|
||||
employee.checkIn!, 'dd MMM yyyy')
|
||||
: '';
|
||||
final previousDate =
|
||||
index > 0 && logs[index - 1].checkIn != null
|
||||
? DateFormat('dd MMM yyyy')
|
||||
.format(logs[index - 1].checkIn!)
|
||||
? DateTimeUtils.formatDate(
|
||||
logs[index - 1].checkIn!, 'dd MMM yyyy')
|
||||
: '';
|
||||
final showDateHeader =
|
||||
index == 0 || currentDate != previousDate;
|
||||
@ -136,8 +139,8 @@ class AttendanceLogsTab extends StatelessWidget {
|
||||
size: 16, color: Colors.green),
|
||||
MySpacing.width(4),
|
||||
MyText.bodySmall(
|
||||
DateFormat('hh:mm a')
|
||||
.format(employee.checkIn!),
|
||||
DateTimeUtils.formatDate(
|
||||
employee.checkIn!, 'hh:mm a'),
|
||||
fontWeight: 600,
|
||||
),
|
||||
MySpacing.width(16),
|
||||
@ -147,8 +150,8 @@ class AttendanceLogsTab extends StatelessWidget {
|
||||
size: 16, color: Colors.red),
|
||||
MySpacing.width(4),
|
||||
MyText.bodySmall(
|
||||
DateFormat('hh:mm a')
|
||||
.format(employee.checkOut!),
|
||||
DateTimeUtils.formatDate(
|
||||
employee.checkOut!, 'hh:mm a'),
|
||||
fontWeight: 600,
|
||||
),
|
||||
],
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
|
||||
import 'package:marco/helpers/utils/date_time_utils.dart';
|
||||
import 'package:marco/helpers/widgets/avatar.dart';
|
||||
import 'package:marco/helpers/widgets/my_card.dart';
|
||||
import 'package:marco/helpers/widgets/my_container.dart';
|
||||
@ -16,10 +16,6 @@ class TodaysAttendanceTab extends StatelessWidget {
|
||||
|
||||
const TodaysAttendanceTab({super.key, required this.controller});
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return "${date.day}/${date.month}/${date.year}";
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
@ -37,7 +33,7 @@ class TodaysAttendanceTab extends StatelessWidget {
|
||||
child: MyText.titleMedium("Today's Attendance", fontWeight: 600),
|
||||
),
|
||||
MyText.bodySmall(
|
||||
_formatDate(DateTime.now()),
|
||||
DateTimeUtils.formatDate(DateTime.now(), 'dd MMM yyyy'),
|
||||
fontWeight: 600,
|
||||
color: Colors.grey[700],
|
||||
),
|
||||
@ -83,14 +79,14 @@ class TodaysAttendanceTab extends StatelessWidget {
|
||||
children: [
|
||||
const Icon(Icons.arrow_circle_right, size: 16, color: Colors.green),
|
||||
MySpacing.width(4),
|
||||
Text(DateFormat('hh:mm a').format(employee.checkIn!)),
|
||||
Text(DateTimeUtils.formatDate(employee.checkIn!, 'hh:mm a')),
|
||||
],
|
||||
),
|
||||
if (employee.checkOut != null) ...[
|
||||
MySpacing.width(16),
|
||||
const Icon(Icons.arrow_circle_left, size: 16, color: Colors.red),
|
||||
MySpacing.width(4),
|
||||
Text(DateFormat('hh:mm a').format(employee.checkOut!)),
|
||||
Text(DateTimeUtils.formatDate(employee.checkOut!, 'hh:mm a')),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user