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();
|
final today = DateTime.now();
|
||||||
startDateAttendance = today.subtract(const Duration(days: 7));
|
startDateAttendance = today.subtract(const Duration(days: 7));
|
||||||
endDateAttendance = today.subtract(const Duration(days: 1));
|
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 ------------------
|
// ------------------ Project & Employee ------------------
|
||||||
@ -69,7 +70,8 @@ class AttendanceController extends GetxController {
|
|||||||
logSafe("Projects fetched: ${projects.length}");
|
logSafe("Projects fetched: ${projects.length}");
|
||||||
} else {
|
} else {
|
||||||
projects = [];
|
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;
|
isLoadingProjects.value = false;
|
||||||
@ -89,7 +91,8 @@ class AttendanceController extends GetxController {
|
|||||||
}
|
}
|
||||||
logSafe("Employees fetched: ${employees.length} for project $projectId");
|
logSafe("Employees fetched: ${employees.length} for project $projectId");
|
||||||
} else {
|
} 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;
|
isLoadingEmployees.value = false;
|
||||||
@ -112,13 +115,15 @@ class AttendanceController extends GetxController {
|
|||||||
|
|
||||||
XFile? image;
|
XFile? image;
|
||||||
if (imageCapture) {
|
if (imageCapture) {
|
||||||
image = await ImagePicker().pickImage(source: ImageSource.camera, imageQuality: 80);
|
image = await ImagePicker()
|
||||||
|
.pickImage(source: ImageSource.camera, imageQuality: 80);
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
logSafe("Image capture cancelled.", level: LogLevel.warning);
|
logSafe("Image capture cancelled.", level: LogLevel.warning);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final compressedBytes = await compressImageToUnder100KB(File(image.path));
|
final compressedBytes =
|
||||||
|
await compressImageToUnder100KB(File(image.path));
|
||||||
if (compressedBytes == null) {
|
if (compressedBytes == null) {
|
||||||
logSafe("Image compression failed.", level: LogLevel.error);
|
logSafe("Image compression failed.", level: LogLevel.error);
|
||||||
return false;
|
return false;
|
||||||
@ -153,7 +158,8 @@ class AttendanceController extends GetxController {
|
|||||||
logSafe("Attendance uploaded for $employeeId, action: $action");
|
logSafe("Attendance uploaded for $employeeId, action: $action");
|
||||||
return result;
|
return result;
|
||||||
} catch (e, stacktrace) {
|
} 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;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
uploadingStates[employeeId]?.value = false;
|
uploadingStates[employeeId]?.value = false;
|
||||||
@ -172,7 +178,8 @@ class AttendanceController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (permission == LocationPermission.deniedForever) {
|
if (permission == LocationPermission.deniedForever) {
|
||||||
logSafe('Location permissions are permanently denied', level: LogLevel.error);
|
logSafe('Location permissions are permanently denied',
|
||||||
|
level: LogLevel.error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,17 +188,21 @@ class AttendanceController extends GetxController {
|
|||||||
|
|
||||||
// ------------------ Attendance Logs ------------------
|
// ------------------ 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;
|
if (projectId == null) return;
|
||||||
|
|
||||||
isLoadingAttendanceLogs.value = true;
|
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) {
|
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}");
|
logSafe("Attendance logs fetched: ${attendanceLogs.length}");
|
||||||
} else {
|
} 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;
|
isLoadingAttendanceLogs.value = false;
|
||||||
@ -229,10 +240,12 @@ class AttendanceController extends GetxController {
|
|||||||
|
|
||||||
final response = await ApiService.getRegularizationLogs(projectId);
|
final response = await ApiService.getRegularizationLogs(projectId);
|
||||||
if (response != null) {
|
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}");
|
logSafe("Regularization logs fetched: ${regularizationLogs.length}");
|
||||||
} else {
|
} 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;
|
isLoadingRegularizationLogs.value = false;
|
||||||
@ -248,12 +261,14 @@ class AttendanceController extends GetxController {
|
|||||||
|
|
||||||
final response = await ApiService.getAttendanceLogView(id);
|
final response = await ApiService.getAttendanceLogView(id);
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
attendenceLogsView = response.map((e) => AttendanceLogViewModel.fromJson(e)).toList();
|
attendenceLogsView =
|
||||||
attendenceLogsView.sort((a, b) =>
|
response.map((e) => AttendanceLogViewModel.fromJson(e)).toList();
|
||||||
(b.activityTime ?? DateTime(2000)).compareTo(a.activityTime ?? DateTime(2000)));
|
attendenceLogsView.sort((a, b) => (b.activityTime ?? DateTime(2000))
|
||||||
|
.compareTo(a.activityTime ?? DateTime(2000)));
|
||||||
logSafe("Attendance log view fetched for ID: $id");
|
logSafe("Attendance log view fetched for ID: $id");
|
||||||
} else {
|
} 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;
|
isLoadingLogView.value = false;
|
||||||
@ -295,33 +310,13 @@ class AttendanceController extends GetxController {
|
|||||||
start: startDateAttendance ?? today.subtract(const Duration(days: 7)),
|
start: startDateAttendance ?? today.subtract(const Duration(days: 7)),
|
||||||
end: endDateAttendance ?? today.subtract(const Duration(days: 1)),
|
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) {
|
if (picked != null) {
|
||||||
startDateAttendance = picked.start;
|
startDateAttendance = picked.start;
|
||||||
endDateAttendance = picked.end;
|
endDateAttendance = picked.end;
|
||||||
logSafe("Date range selected: $startDateAttendance to $endDateAttendance");
|
logSafe(
|
||||||
|
"Date range selected: $startDateAttendance to $endDateAttendance");
|
||||||
|
|
||||||
await controller.fetchAttendanceLogs(
|
await controller.fetchAttendanceLogs(
|
||||||
Get.find<ProjectController>().selectedProject?.id,
|
Get.find<ProjectController>().selectedProject?.id,
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
// lib/view/attendance/tabs/attendance_logs_tab.dart
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:marco/controller/dashboard/attendance_screen_controller.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/avatar.dart';
|
||||||
import 'package:marco/helpers/widgets/my_card.dart';
|
import 'package:marco/helpers/widgets/my_card.dart';
|
||||||
import 'package:marco/helpers/widgets/my_container.dart';
|
import 'package:marco/helpers/widgets/my_container.dart';
|
||||||
@ -27,10 +26,10 @@ class AttendanceLogsTab extends StatelessWidget {
|
|||||||
return bDate.compareTo(aDate);
|
return bDate.compareTo(aDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
final dateFormat = DateFormat('dd MMM yyyy');
|
|
||||||
final dateRangeText = controller.startDateAttendance != null &&
|
final dateRangeText = controller.startDateAttendance != null &&
|
||||||
controller.endDateAttendance != 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';
|
: 'Select date range';
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
@ -44,7 +43,10 @@ class AttendanceLogsTab extends StatelessWidget {
|
|||||||
MyText.titleMedium("Attendance Logs", fontWeight: 600),
|
MyText.titleMedium("Attendance Logs", fontWeight: 600),
|
||||||
controller.isLoading.value
|
controller.isLoading.value
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
height: 20, width: 20, child: LinearProgressIndicator())
|
height: 20,
|
||||||
|
width: 20,
|
||||||
|
child: LinearProgressIndicator(),
|
||||||
|
)
|
||||||
: MyText.bodySmall(
|
: MyText.bodySmall(
|
||||||
dateRangeText,
|
dateRangeText,
|
||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
@ -70,12 +72,13 @@ class AttendanceLogsTab extends StatelessWidget {
|
|||||||
children: List.generate(logs.length, (index) {
|
children: List.generate(logs.length, (index) {
|
||||||
final employee = logs[index];
|
final employee = logs[index];
|
||||||
final currentDate = employee.checkIn != null
|
final currentDate = employee.checkIn != null
|
||||||
? DateFormat('dd MMM yyyy').format(employee.checkIn!)
|
? DateTimeUtils.formatDate(
|
||||||
|
employee.checkIn!, 'dd MMM yyyy')
|
||||||
: '';
|
: '';
|
||||||
final previousDate =
|
final previousDate =
|
||||||
index > 0 && logs[index - 1].checkIn != null
|
index > 0 && logs[index - 1].checkIn != null
|
||||||
? DateFormat('dd MMM yyyy')
|
? DateTimeUtils.formatDate(
|
||||||
.format(logs[index - 1].checkIn!)
|
logs[index - 1].checkIn!, 'dd MMM yyyy')
|
||||||
: '';
|
: '';
|
||||||
final showDateHeader =
|
final showDateHeader =
|
||||||
index == 0 || currentDate != previousDate;
|
index == 0 || currentDate != previousDate;
|
||||||
@ -136,8 +139,8 @@ class AttendanceLogsTab extends StatelessWidget {
|
|||||||
size: 16, color: Colors.green),
|
size: 16, color: Colors.green),
|
||||||
MySpacing.width(4),
|
MySpacing.width(4),
|
||||||
MyText.bodySmall(
|
MyText.bodySmall(
|
||||||
DateFormat('hh:mm a')
|
DateTimeUtils.formatDate(
|
||||||
.format(employee.checkIn!),
|
employee.checkIn!, 'hh:mm a'),
|
||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
),
|
),
|
||||||
MySpacing.width(16),
|
MySpacing.width(16),
|
||||||
@ -147,8 +150,8 @@ class AttendanceLogsTab extends StatelessWidget {
|
|||||||
size: 16, color: Colors.red),
|
size: 16, color: Colors.red),
|
||||||
MySpacing.width(4),
|
MySpacing.width(4),
|
||||||
MyText.bodySmall(
|
MyText.bodySmall(
|
||||||
DateFormat('hh:mm a')
|
DateTimeUtils.formatDate(
|
||||||
.format(employee.checkOut!),
|
employee.checkOut!, 'hh:mm a'),
|
||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:marco/controller/dashboard/attendance_screen_controller.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/avatar.dart';
|
||||||
import 'package:marco/helpers/widgets/my_card.dart';
|
import 'package:marco/helpers/widgets/my_card.dart';
|
||||||
import 'package:marco/helpers/widgets/my_container.dart';
|
import 'package:marco/helpers/widgets/my_container.dart';
|
||||||
@ -16,10 +16,6 @@ class TodaysAttendanceTab extends StatelessWidget {
|
|||||||
|
|
||||||
const TodaysAttendanceTab({super.key, required this.controller});
|
const TodaysAttendanceTab({super.key, required this.controller});
|
||||||
|
|
||||||
String _formatDate(DateTime date) {
|
|
||||||
return "${date.day}/${date.month}/${date.year}";
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
@ -37,7 +33,7 @@ class TodaysAttendanceTab extends StatelessWidget {
|
|||||||
child: MyText.titleMedium("Today's Attendance", fontWeight: 600),
|
child: MyText.titleMedium("Today's Attendance", fontWeight: 600),
|
||||||
),
|
),
|
||||||
MyText.bodySmall(
|
MyText.bodySmall(
|
||||||
_formatDate(DateTime.now()),
|
DateTimeUtils.formatDate(DateTime.now(), 'dd MMM yyyy'),
|
||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
color: Colors.grey[700],
|
color: Colors.grey[700],
|
||||||
),
|
),
|
||||||
@ -83,14 +79,14 @@ class TodaysAttendanceTab extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
const Icon(Icons.arrow_circle_right, size: 16, color: Colors.green),
|
const Icon(Icons.arrow_circle_right, size: 16, color: Colors.green),
|
||||||
MySpacing.width(4),
|
MySpacing.width(4),
|
||||||
Text(DateFormat('hh:mm a').format(employee.checkIn!)),
|
Text(DateTimeUtils.formatDate(employee.checkIn!, 'hh:mm a')),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (employee.checkOut != null) ...[
|
if (employee.checkOut != null) ...[
|
||||||
MySpacing.width(16),
|
MySpacing.width(16),
|
||||||
const Icon(Icons.arrow_circle_left, size: 16, color: Colors.red),
|
const Icon(Icons.arrow_circle_left, size: 16, color: Colors.red),
|
||||||
MySpacing.width(4),
|
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