added the refresh for attendence tab
This commit is contained in:
parent
9fbf82b05c
commit
21fe8f7d63
3
devtools_options.yaml
Normal file
3
devtools_options.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
description: This file stores settings for Dart & Flutter DevTools.
|
||||||
|
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
|
||||||
|
extensions:
|
@ -6,7 +6,7 @@ import 'package:intl/intl.dart';
|
|||||||
|
|
||||||
|
|
||||||
class ApiService {
|
class ApiService {
|
||||||
static const String baseUrl = "https://api.marcoaiot.com/api";
|
static const String baseUrl = "https://stageapi.marcoaiot.com/api";
|
||||||
|
|
||||||
// ===== Common Helpers =====
|
// ===== Common Helpers =====
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ class ApiService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
final response =
|
final response =
|
||||||
await _getRequest("/attendance/project/team", queryParams: query);
|
await _getRequest("/attendance/project/log", queryParams: query);
|
||||||
return response != null
|
return response != null
|
||||||
? _parseResponse(response, label: 'Attendance Logs')
|
? _parseResponse(response, label: 'Attendance Logs')
|
||||||
: null;
|
: null;
|
||||||
|
@ -8,7 +8,7 @@ class AuthService {
|
|||||||
static Future<Map<String, String>?> loginUser(Map<String, dynamic> data) async {
|
static Future<Map<String, String>?> loginUser(Map<String, dynamic> data) async {
|
||||||
try {
|
try {
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
Uri.parse('https://api.marcoaiot.com/api/auth/login'),
|
Uri.parse('https://stageapi.marcoaiot.com/api/auth/login'),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: jsonEncode(data),
|
body: jsonEncode(data),
|
||||||
);
|
);
|
||||||
|
23
lib/helpers/utils/attendance_actions.dart
Normal file
23
lib/helpers/utils/attendance_actions.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
// Define action texts
|
||||||
|
class ButtonActions {
|
||||||
|
static const String checkIn = "Check In";
|
||||||
|
static const String checkOut = "Check Out";
|
||||||
|
static const String requestRegularize = " Request Regularize";
|
||||||
|
static const String rejected = "Rejected";
|
||||||
|
static const String approved = "Approved";
|
||||||
|
static const String requested = "Requested";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map action texts to colors
|
||||||
|
class AttendanceActionColors {
|
||||||
|
static const Map<String, Color> colors = {
|
||||||
|
ButtonActions.checkIn: Colors.green,
|
||||||
|
ButtonActions.checkOut: Colors.red,
|
||||||
|
ButtonActions.requestRegularize: Colors.blue,
|
||||||
|
ButtonActions.rejected: Colors.orange,
|
||||||
|
ButtonActions.approved: Colors.green,
|
||||||
|
ButtonActions.requested: Colors.yellow,
|
||||||
|
};
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
class AttendanceLogModel {
|
class AttendanceLogModel {
|
||||||
final String name;
|
final String name;
|
||||||
|
final int employeeId;
|
||||||
final String role;
|
final String role;
|
||||||
final DateTime? checkIn;
|
final DateTime? checkIn;
|
||||||
final DateTime? checkOut;
|
final DateTime? checkOut;
|
||||||
@ -13,16 +14,22 @@ class AttendanceLogModel {
|
|||||||
this.checkOut,
|
this.checkOut,
|
||||||
required this.activity,
|
required this.activity,
|
||||||
required this.id,
|
required this.id,
|
||||||
|
required this.employeeId,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory AttendanceLogModel.fromJson(Map<String, dynamic> json) {
|
factory AttendanceLogModel.fromJson(Map<String, dynamic> json) {
|
||||||
return AttendanceLogModel(
|
return AttendanceLogModel(
|
||||||
name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(),
|
name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(),
|
||||||
role: json['jobRoleName'] ?? '',
|
role: json['jobRoleName'] ?? '',
|
||||||
checkIn: json['checkInTime'] != null ? DateTime.tryParse(json['checkInTime']) : null,
|
checkIn: json['checkInTime'] != null
|
||||||
checkOut: json['checkOutTime'] != null ? DateTime.tryParse(json['checkOutTime']) : null,
|
? DateTime.tryParse(json['checkInTime'])
|
||||||
|
: null,
|
||||||
|
checkOut: json['checkOutTime'] != null
|
||||||
|
? DateTime.tryParse(json['checkOutTime'])
|
||||||
|
: null,
|
||||||
activity: json['activity'] ?? 0,
|
activity: json['activity'] ?? 0,
|
||||||
id: json['id'] != null ? json['id'] : null,
|
id: json['id'] != null ? json['id'] : null,
|
||||||
|
employeeId: json['employeeId'] != null ? json['employeeId'] : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,36 @@
|
|||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class AttendanceLogViewModel {
|
class AttendanceLogViewModel {
|
||||||
final DateTime? activityTime;
|
final DateTime? activityTime;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final String? description;
|
final String? comment;
|
||||||
|
final String? thumbPreSignedUrl;
|
||||||
|
final String? preSignedUrl;
|
||||||
|
|
||||||
AttendanceLogViewModel({
|
AttendanceLogViewModel({
|
||||||
this.activityTime,
|
this.activityTime,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.description,
|
this.comment,
|
||||||
|
this.thumbPreSignedUrl,
|
||||||
|
this.preSignedUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory AttendanceLogViewModel.fromJson(Map<String, dynamic> json) {
|
factory AttendanceLogViewModel.fromJson(Map<String, dynamic> json) {
|
||||||
return AttendanceLogViewModel(
|
return AttendanceLogViewModel(
|
||||||
activityTime: json['activityTime'] != null ? DateTime.tryParse(json['activityTime']) : null,
|
activityTime: json['activityTime'] != null
|
||||||
|
? DateTime.tryParse(json['activityTime'])
|
||||||
|
: null,
|
||||||
imageUrl: json['imageUrl'],
|
imageUrl: json['imageUrl'],
|
||||||
description: json['description'],
|
comment: json['comment'],
|
||||||
|
thumbPreSignedUrl: json['thumbPreSignedUrl'],
|
||||||
|
preSignedUrl: json['preSignedUrl'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String? get formattedDate => activityTime != null ? DateFormat('yyyy-MM-dd').format(activityTime!) : null;
|
String? get formattedDate => activityTime != null
|
||||||
|
? DateFormat('yyyy-MM-dd').format(activityTime!)
|
||||||
|
: null;
|
||||||
|
|
||||||
String? get formattedTime => activityTime != null ? DateFormat('hh:mm a').format(activityTime!) : null;
|
String? get formattedTime =>
|
||||||
}
|
activityTime != null ? DateFormat('hh:mm a').format(activityTime!) : null;
|
||||||
|
}
|
||||||
|
@ -16,6 +16,10 @@ import 'package:marco/helpers/widgets/my_text.dart';
|
|||||||
import 'package:marco/view/layouts/layout.dart';
|
import 'package:marco/view/layouts/layout.dart';
|
||||||
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
|
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
import 'package:marco/helpers/utils/permission_constants.dart'; // Make sure this import is correct
|
||||||
|
import 'package:marco/helpers/utils/attendance_actions.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_refresh_wrapper.dart';
|
||||||
|
|
||||||
class AttendanceScreen extends StatefulWidget {
|
class AttendanceScreen extends StatefulWidget {
|
||||||
const AttendanceScreen({super.key});
|
const AttendanceScreen({super.key});
|
||||||
@ -26,163 +30,186 @@ class AttendanceScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||||
AttendanceController attendanceController = Get.put(AttendanceController());
|
AttendanceController attendanceController = Get.put(AttendanceController());
|
||||||
|
PermissionController permissionController = Get.find();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Layout(
|
return Layout(
|
||||||
child: GetBuilder(
|
child: MyRefreshWrapper(
|
||||||
init: attendanceController,
|
onRefresh: () async {
|
||||||
tag: 'attendance_dashboard_controller',
|
// Call your controller's refresh logic
|
||||||
builder: (controller) {
|
if (attendanceController.selectedProjectId != null) {
|
||||||
return Column(
|
await attendanceController.fetchEmployeesByProject(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
attendanceController.selectedProjectId!);
|
||||||
children: [
|
await attendanceController
|
||||||
Padding(
|
.fetchAttendanceLogs(attendanceController.selectedProjectId!);
|
||||||
padding: MySpacing.x(flexSpacing),
|
} else {
|
||||||
child: Row(
|
await attendanceController.fetchProjects();
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
}
|
||||||
children: [
|
},
|
||||||
MyText.titleMedium("Attendance",
|
child: GetBuilder(
|
||||||
fontSize: 18, fontWeight: 600),
|
init: attendanceController,
|
||||||
MyBreadcrumb(
|
tag: 'attendance_dashboard_controller',
|
||||||
children: [
|
builder: (controller) {
|
||||||
MyBreadcrumbItem(name: 'Dashboard'),
|
return Column(
|
||||||
MyBreadcrumbItem(name: 'Attendance', active: true),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
],
|
children: [
|
||||||
),
|
Padding(
|
||||||
],
|
padding: MySpacing.x(flexSpacing),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
MyText.titleMedium("Attendance",
|
||||||
|
fontSize: 18, fontWeight: 600),
|
||||||
|
MyBreadcrumb(
|
||||||
|
children: [
|
||||||
|
MyBreadcrumbItem(name: 'Dashboard'),
|
||||||
|
MyBreadcrumbItem(name: 'Attendance', active: true),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
MySpacing.height(flexSpacing),
|
||||||
MySpacing.height(flexSpacing),
|
Padding(
|
||||||
Padding(
|
padding: MySpacing.x(flexSpacing / 2),
|
||||||
padding: MySpacing.x(flexSpacing / 2),
|
child: Column(
|
||||||
child: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
MySpacing.height(flexSpacing),
|
||||||
MySpacing.height(flexSpacing),
|
// Project selection dropdown
|
||||||
// Move project selection here
|
Row(
|
||||||
Row(
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
children: [
|
||||||
children: [
|
Expanded(
|
||||||
Expanded(
|
child: MyContainer.bordered(
|
||||||
child: MyContainer.bordered(
|
padding: MySpacing.xy(8, 8),
|
||||||
padding: MySpacing.xy(8, 8),
|
child: PopupMenuButton<String>(
|
||||||
child: PopupMenuButton<String>(
|
onSelected: (value) {
|
||||||
onSelected: (value) {
|
setState(() {
|
||||||
setState(() {
|
attendanceController.selectedProjectId =
|
||||||
attendanceController.selectedProjectId =
|
value;
|
||||||
value;
|
attendanceController
|
||||||
attendanceController
|
.fetchEmployeesByProject(value);
|
||||||
.fetchEmployeesByProject(value);
|
attendanceController
|
||||||
attendanceController
|
.fetchAttendanceLogs(value);
|
||||||
.fetchAttendanceLogs(value);
|
});
|
||||||
attendanceController
|
},
|
||||||
.fetchAttendanceLogs(value);
|
itemBuilder: (BuildContext context) {
|
||||||
});
|
if (attendanceController.projects.isEmpty) {
|
||||||
},
|
return [
|
||||||
itemBuilder: (BuildContext context) {
|
PopupMenuItem<String>(
|
||||||
if (attendanceController.projects.isEmpty) {
|
value: '',
|
||||||
return [
|
child: MyText.bodySmall('No Data',
|
||||||
PopupMenuItem<String>(
|
fontWeight: 600),
|
||||||
value: '',
|
)
|
||||||
child: MyText.bodySmall('No Data',
|
];
|
||||||
fontWeight: 600),
|
}
|
||||||
)
|
return attendanceController.projects
|
||||||
];
|
.map((project) {
|
||||||
}
|
return PopupMenuItem<String>(
|
||||||
return attendanceController.projects
|
value: project.id.toString(),
|
||||||
.map((project) {
|
height: 32,
|
||||||
return PopupMenuItem<String>(
|
child: MyText.bodySmall(
|
||||||
value: project.id.toString(),
|
project.name,
|
||||||
height: 32,
|
color: theme.colorScheme.onSurface,
|
||||||
child: MyText.bodySmall(
|
fontWeight: 600,
|
||||||
project.name,
|
),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
},
|
||||||
|
color: theme.cardTheme.color,
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
MyText.labelSmall(
|
||||||
|
attendanceController.selectedProjectId !=
|
||||||
|
null
|
||||||
|
? attendanceController.projects
|
||||||
|
.firstWhereOrNull((proj) =>
|
||||||
|
proj.id.toString() ==
|
||||||
|
attendanceController
|
||||||
|
.selectedProjectId)
|
||||||
|
?.name ??
|
||||||
|
'Select a Project'
|
||||||
|
: 'Select a Project',
|
||||||
color: theme.colorScheme.onSurface,
|
color: theme.colorScheme.onSurface,
|
||||||
fontWeight: 600,
|
|
||||||
),
|
),
|
||||||
);
|
Icon(LucideIcons.chevron_down,
|
||||||
}).toList();
|
size: 20,
|
||||||
},
|
color: theme.colorScheme.onSurface),
|
||||||
color: theme.cardTheme.color,
|
],
|
||||||
child: Row(
|
),
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
MyText.labelSmall(
|
|
||||||
attendanceController.selectedProjectId !=
|
|
||||||
null
|
|
||||||
? attendanceController.projects
|
|
||||||
.firstWhereOrNull((proj) =>
|
|
||||||
proj.id.toString() ==
|
|
||||||
attendanceController
|
|
||||||
.selectedProjectId)
|
|
||||||
?.name ??
|
|
||||||
'Select a Project'
|
|
||||||
: 'Select a Project',
|
|
||||||
color: theme.colorScheme.onSurface,
|
|
||||||
),
|
|
||||||
Icon(LucideIcons.chevron_down,
|
|
||||||
size: 20,
|
|
||||||
color: theme.colorScheme.onSurface),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
MySpacing.height(flexSpacing),
|
||||||
MySpacing.height(flexSpacing),
|
MyFlex(
|
||||||
MyFlex(
|
children: [
|
||||||
children: [
|
MyFlexItem(
|
||||||
MyFlexItem(
|
child: Obx(() {
|
||||||
child: DefaultTabController(
|
bool hasRegularizationPermission =
|
||||||
length: 3,
|
permissionController.hasPermission(
|
||||||
child: MyCard.bordered(
|
Permissions.regularizeAttendance);
|
||||||
borderRadiusAll: 4,
|
|
||||||
border:
|
final tabs = <Tab>[
|
||||||
Border.all(color: Colors.grey.withAlpha(50)),
|
const Tab(text: 'Employee List'),
|
||||||
shadow: MyShadow(
|
const Tab(text: 'Logs'),
|
||||||
elevation: 1,
|
if (hasRegularizationPermission)
|
||||||
position: MyShadowPosition.bottom),
|
const Tab(text: 'Regularization'),
|
||||||
paddingAll: 10,
|
];
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
final views = <Widget>[
|
||||||
children: [
|
employeeListTab(),
|
||||||
TabBar(
|
reportsTab(context),
|
||||||
labelColor: theme.colorScheme.primary,
|
if (hasRegularizationPermission)
|
||||||
unselectedLabelColor: theme
|
regularizationTab(context),
|
||||||
.colorScheme.onSurface
|
];
|
||||||
.withAlpha(150),
|
|
||||||
tabs: const [
|
return DefaultTabController(
|
||||||
Tab(text: 'Employee List'),
|
length: tabs.length,
|
||||||
Tab(text: 'Logs'),
|
child: MyCard.bordered(
|
||||||
Tab(text: 'Regularization'),
|
borderRadiusAll: 4,
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.grey.withAlpha(50)),
|
||||||
|
shadow: MyShadow(
|
||||||
|
elevation: 1,
|
||||||
|
position: MyShadowPosition.bottom),
|
||||||
|
paddingAll: 10,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
TabBar(
|
||||||
|
labelColor: theme.colorScheme.primary,
|
||||||
|
unselectedLabelColor: theme
|
||||||
|
.colorScheme.onSurface
|
||||||
|
.withAlpha(150),
|
||||||
|
tabs: tabs,
|
||||||
|
),
|
||||||
|
MySpacing.height(16),
|
||||||
|
SizedBox(
|
||||||
|
height: 500,
|
||||||
|
child: TabBarView(children: views),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
MySpacing.height(16),
|
),
|
||||||
SizedBox(
|
);
|
||||||
height: 500,
|
}),
|
||||||
child: TabBarView(
|
|
||||||
children: [
|
|
||||||
employeeListTab(),
|
|
||||||
reportsTab(context),
|
|
||||||
regularizationTab(context),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -228,11 +255,10 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
// Set action text based on employee's activity value
|
// Set action text based on employee's activity value
|
||||||
if (activity == 1) {
|
if (activity == 1) {
|
||||||
actionText = "Check In";
|
actionText = "Check In";
|
||||||
} else if (activity == 0) {
|
} else if (activity == 0 || activity == 4) {
|
||||||
actionText = "Check Out";
|
actionText = "Check Out";
|
||||||
} else if (activity == 4) {
|
} else if (activity == 2) {
|
||||||
// Activity 4 logic
|
actionText = "Request Regularize";
|
||||||
actionText = "Check In";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return DataRow(cells: [
|
return DataRow(cells: [
|
||||||
@ -252,28 +278,22 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
String actionText;
|
String actionText;
|
||||||
|
|
||||||
if (activity == 0 || activity == 4) {
|
if (activity == 0 || activity == 4) {
|
||||||
// The user is currently checked in (activity == 0), so they need to check out
|
|
||||||
updatedAction = 0;
|
updatedAction = 0;
|
||||||
actionText = "Check In";
|
actionText = ButtonActions.checkIn;
|
||||||
} else {
|
} else {
|
||||||
// The user is currently checked out (activity == 1), so they need to check in
|
|
||||||
updatedAction = 1;
|
updatedAction = 1;
|
||||||
actionText = "Check Out";
|
actionText = ButtonActions.checkOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the method to capture attendance with the updated action
|
|
||||||
final success =
|
final success =
|
||||||
await attendanceController.captureAndUploadAttendance(
|
await attendanceController.captureAndUploadAttendance(
|
||||||
employee.id, // Pass the employee's ID
|
employee.id,
|
||||||
employee.employeeId,
|
employee.employeeId,
|
||||||
|
int.parse(attendanceController.selectedProjectId!),
|
||||||
int.parse(attendanceController
|
comment: actionText,
|
||||||
.selectedProjectId!), // Pass the selected project ID
|
|
||||||
comment: actionText, // Action text (Check In / Check Out)
|
|
||||||
action: updatedAction,
|
action: updatedAction,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Show success or failure message
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
@ -284,23 +304,25 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (success) {
|
if (success) {
|
||||||
// Fetch the updated list of employees and logs after the attendance upload
|
|
||||||
attendanceController.fetchEmployeesByProject(
|
attendanceController.fetchEmployeesByProject(
|
||||||
attendanceController.selectedProjectId!);
|
attendanceController.selectedProjectId!);
|
||||||
attendanceController.fetchAttendanceLogs(
|
attendanceController.fetchAttendanceLogs(
|
||||||
attendanceController.selectedProjectId!);
|
attendanceController.selectedProjectId!);
|
||||||
// You can add more fetch calls if necessary, such as regularization logs.
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
padding: EdgeInsets.symmetric(
|
backgroundColor: AttendanceActionColors.colors[
|
||||||
vertical: 4, horizontal: 6), // Adjust padding
|
(activity == 0 || activity == 4)
|
||||||
minimumSize: Size(60, 20), // Adjust minimum size for the button
|
? ButtonActions.checkIn
|
||||||
textStyle: TextStyle(fontSize: 12), // Smaller font size
|
: ButtonActions.checkOut],
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
|
||||||
|
minimumSize: const Size(60, 20),
|
||||||
|
textStyle: const TextStyle(fontSize: 12),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text((activity == 0 || activity == 4)
|
||||||
activity == 0 || activity == 4 ? 'Check In' : 'Check Out'),
|
? ButtonActions.checkIn
|
||||||
)),
|
: ButtonActions.checkOut),
|
||||||
|
))
|
||||||
]);
|
]);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@ -360,6 +382,9 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
DataColumn(
|
DataColumn(
|
||||||
label: MyText.labelLarge('Check-Out',
|
label: MyText.labelLarge('Check-Out',
|
||||||
color: contentTheme.primary)),
|
color: contentTheme.primary)),
|
||||||
|
DataColumn(
|
||||||
|
label: MyText.labelLarge('View',
|
||||||
|
color: contentTheme.primary)),
|
||||||
DataColumn(
|
DataColumn(
|
||||||
label: MyText.labelLarge('Action',
|
label: MyText.labelLarge('Action',
|
||||||
color: contentTheme.primary)),
|
color: contentTheme.primary)),
|
||||||
@ -370,36 +395,57 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
MyText.bodyMedium(log.name, fontWeight: 600)),
|
MyText.bodyMedium(log.name, fontWeight: 600)),
|
||||||
DataCell(
|
DataCell(
|
||||||
MyText.bodyMedium(log.role, fontWeight: 600)),
|
MyText.bodyMedium(log.role, fontWeight: 600)),
|
||||||
DataCell(MyText.bodyMedium(
|
|
||||||
log.checkIn != null
|
|
||||||
? DateFormat('dd MMM yyyy hh:mm a')
|
|
||||||
.format(log.checkIn!)
|
|
||||||
: '-',
|
|
||||||
fontWeight: 600,
|
|
||||||
)),
|
|
||||||
DataCell(MyText.bodyMedium(
|
|
||||||
log.checkOut != null
|
|
||||||
? DateFormat('dd MMM yyyy hh:mm a')
|
|
||||||
.format(log.checkOut!)
|
|
||||||
: '-',
|
|
||||||
fontWeight: 600,
|
|
||||||
)),
|
|
||||||
DataCell(
|
DataCell(
|
||||||
ElevatedButton(
|
Column(
|
||||||
style: ElevatedButton.styleFrom(
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
padding: EdgeInsets.symmetric(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
vertical: 4,
|
children: [
|
||||||
horizontal: 6), // Adjust padding
|
MyText.bodyMedium(
|
||||||
minimumSize:
|
log.checkIn != null
|
||||||
Size(60, 20), // Adjust minimum size
|
? DateFormat('dd MMM yyyy')
|
||||||
textStyle: TextStyle(
|
.format(log.checkIn!)
|
||||||
fontSize: 12), // Smaller font size
|
: '-',
|
||||||
),
|
fontWeight: 600,
|
||||||
|
),
|
||||||
|
MyText.bodyMedium(
|
||||||
|
log.checkIn != null
|
||||||
|
? DateFormat('hh:mm a')
|
||||||
|
.format(log.checkIn!)
|
||||||
|
: '',
|
||||||
|
fontWeight: 600,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DataCell(
|
||||||
|
Column(
|
||||||
|
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('hh:mm a')
|
||||||
|
.format(log.checkOut!)
|
||||||
|
: '',
|
||||||
|
fontWeight: 600,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
DataCell(
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.visibility, size: 18),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
// Call fetchLogsView to load the log data
|
await attendanceController
|
||||||
await attendanceController.fetchLogsView(log.id
|
.fetchLogsView(log.id.toString());
|
||||||
.toString()); // Assuming `log.id` is available
|
|
||||||
// Open the bottom sheet to display the log details
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
@ -419,33 +465,118 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
"Attendance Log Details",
|
"Attendance Log Details",
|
||||||
fontWeight: 700),
|
fontWeight: 700),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
// Display the log details
|
if (attendanceController
|
||||||
|
.attendenceLogsView.isNotEmpty)
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment
|
||||||
|
.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: MyText.bodyMedium(
|
||||||
|
"Date",
|
||||||
|
fontWeight: 600)),
|
||||||
|
Expanded(
|
||||||
|
child: MyText.bodyMedium(
|
||||||
|
"Time",
|
||||||
|
fontWeight: 600)),
|
||||||
|
Expanded(
|
||||||
|
child: MyText.bodyMedium(
|
||||||
|
"Description",
|
||||||
|
fontWeight: 600)),
|
||||||
|
Expanded(
|
||||||
|
child: MyText.bodyMedium(
|
||||||
|
"Image",
|
||||||
|
fontWeight: 600)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const Divider(
|
||||||
|
thickness: 1, height: 24),
|
||||||
if (attendanceController
|
if (attendanceController
|
||||||
.attendenceLogsView.isNotEmpty)
|
.attendenceLogsView.isNotEmpty)
|
||||||
...attendanceController
|
...attendanceController
|
||||||
.attendenceLogsView
|
.attendenceLogsView
|
||||||
.map((log) => Column(
|
.map((log) {
|
||||||
crossAxisAlignment:
|
return Row(
|
||||||
CrossAxisAlignment
|
mainAxisAlignment:
|
||||||
.start,
|
MainAxisAlignment
|
||||||
children: [
|
.spaceBetween,
|
||||||
MyText.bodyMedium(
|
children: [
|
||||||
"Date: ${log.formattedDate ?? '-'}",
|
Expanded(
|
||||||
fontWeight: 600,
|
child: MyText.bodyMedium(
|
||||||
),
|
log.formattedDate ??
|
||||||
MyText.bodyMedium(
|
'-',
|
||||||
"Time: ${log.formattedTime ?? '-'}",
|
fontWeight: 600)),
|
||||||
fontWeight: 600,
|
Expanded(
|
||||||
),
|
child: MyText.bodyMedium(
|
||||||
MyText.bodyMedium(
|
log.formattedTime ??
|
||||||
"Description: ${log.description ?? '-'}",
|
'-',
|
||||||
fontWeight: 600,
|
fontWeight: 600)),
|
||||||
),
|
Expanded(
|
||||||
const Divider(
|
child: MyText.bodyMedium(
|
||||||
thickness: 1,
|
log.comment ?? '-',
|
||||||
height: 24),
|
fontWeight: 600)),
|
||||||
],
|
Expanded(
|
||||||
)),
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
if (log.preSignedUrl !=
|
||||||
|
null) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) =>
|
||||||
|
Dialog(
|
||||||
|
child:
|
||||||
|
Image.network(
|
||||||
|
log.preSignedUrl!,
|
||||||
|
fit: BoxFit
|
||||||
|
.cover,
|
||||||
|
height: 400,
|
||||||
|
errorBuilder:
|
||||||
|
(context,
|
||||||
|
error,
|
||||||
|
stackTrace) {
|
||||||
|
return Icon(
|
||||||
|
Icons
|
||||||
|
.broken_image,
|
||||||
|
size: 50,
|
||||||
|
color: Colors
|
||||||
|
.grey);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: log.thumbPreSignedUrl !=
|
||||||
|
null
|
||||||
|
? Image.network(
|
||||||
|
log.thumbPreSignedUrl!,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
height: 40,
|
||||||
|
width: 40,
|
||||||
|
errorBuilder:
|
||||||
|
(context,
|
||||||
|
error,
|
||||||
|
stackTrace) {
|
||||||
|
return Icon(
|
||||||
|
Icons
|
||||||
|
.broken_image,
|
||||||
|
size: 40,
|
||||||
|
color: Colors
|
||||||
|
.grey);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
Icons
|
||||||
|
.broken_image,
|
||||||
|
size: 40,
|
||||||
|
color:
|
||||||
|
Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
Align(
|
Align(
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
@ -453,16 +584,100 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
Navigator.pop(context),
|
Navigator.pop(context),
|
||||||
child: const Text("Close"),
|
child: const Text("Close"),
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
child: const Text('View'),
|
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
|
|
||||||
|
// The action button
|
||||||
|
DataCell(ElevatedButton(
|
||||||
|
onPressed: () async {
|
||||||
|
if (attendanceController.selectedProjectId ==
|
||||||
|
null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
"Please select a project first")),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the updated action based on the employee's activity
|
||||||
|
// Determine the updated action based on current activity
|
||||||
|
int updatedAction;
|
||||||
|
String actionText;
|
||||||
|
|
||||||
|
if (log.activity == 0 || log.activity == 4) {
|
||||||
|
// Needs to Check In
|
||||||
|
updatedAction = 0;
|
||||||
|
actionText = "Check In";
|
||||||
|
} else if (log.activity == 1) {
|
||||||
|
// Needs to Check Out
|
||||||
|
updatedAction = 1;
|
||||||
|
actionText = "Check Out";
|
||||||
|
} else if (log.activity == 2) {
|
||||||
|
// Needs to Request Regularize
|
||||||
|
updatedAction = 2;
|
||||||
|
actionText = "Request Regularize";
|
||||||
|
} else {
|
||||||
|
// Default case (fallback)
|
||||||
|
updatedAction = 0;
|
||||||
|
actionText = "Unknown Action";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the method to capture and upload attendance
|
||||||
|
final success = await attendanceController
|
||||||
|
.captureAndUploadAttendance(
|
||||||
|
log.id,
|
||||||
|
log.employeeId,
|
||||||
|
int.parse(attendanceController
|
||||||
|
.selectedProjectId!), // Pass the selected project ID
|
||||||
|
comment:
|
||||||
|
actionText, // Action text (Check In/Check Out)
|
||||||
|
action: updatedAction, // Updated action
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show success or failure message
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(
|
||||||
|
success
|
||||||
|
? 'Attendance marked successfully!'
|
||||||
|
: 'Image upload failed.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (success) {
|
||||||
|
// Fetch updated logs and employees
|
||||||
|
attendanceController.fetchEmployeesByProject(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
attendanceController.fetchAttendanceLogs(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: AttendanceActionColors.colors[
|
||||||
|
(log.activity == 0 || log.activity == 4)
|
||||||
|
? ButtonActions.checkIn
|
||||||
|
: ButtonActions.checkOut],
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
vertical: 4, horizontal: 6),
|
||||||
|
minimumSize: Size(60, 20),
|
||||||
|
textStyle: TextStyle(fontSize: 12),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
(log.activity == 0 || log.activity == 4)
|
||||||
|
? ButtonActions.checkIn
|
||||||
|
: (log.activity == 2)
|
||||||
|
? ButtonActions.requestRegularize
|
||||||
|
: ButtonActions.checkOut,
|
||||||
|
),
|
||||||
|
)),
|
||||||
]))
|
]))
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
@ -529,20 +744,50 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
MyText.bodyMedium(log.name, fontWeight: 600)),
|
MyText.bodyMedium(log.name, fontWeight: 600)),
|
||||||
DataCell(
|
DataCell(
|
||||||
MyText.bodyMedium(log.role, fontWeight: 600)),
|
MyText.bodyMedium(log.role, fontWeight: 600)),
|
||||||
DataCell(MyText.bodyMedium(
|
DataCell(
|
||||||
log.checkIn != null
|
Column(
|
||||||
? DateFormat('dd MMM yyyy hh:mm a')
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
.format(log.checkIn!)
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
: '-',
|
children: [
|
||||||
fontWeight: 600,
|
MyText.bodyMedium(
|
||||||
)),
|
log.checkIn != null
|
||||||
DataCell(MyText.bodyMedium(
|
? DateFormat('dd/MMM/yyyy')
|
||||||
log.checkOut != null
|
.format(log.checkIn!)
|
||||||
? DateFormat('dd MMM yyyy hh:mm a')
|
: '-',
|
||||||
.format(log.checkOut!)
|
fontWeight: 600,
|
||||||
: '-',
|
),
|
||||||
fontWeight: 600,
|
MyText.bodyMedium(
|
||||||
)),
|
log.checkIn != null
|
||||||
|
? DateFormat('hh:mm a')
|
||||||
|
.format(log.checkIn!)
|
||||||
|
: '',
|
||||||
|
fontWeight: 600,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DataCell(
|
||||||
|
Column(
|
||||||
|
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('hh:mm a')
|
||||||
|
.format(log.checkOut!)
|
||||||
|
: '',
|
||||||
|
fontWeight: 600,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
DataCell(IconButton(
|
DataCell(IconButton(
|
||||||
icon: Icon(Icons.info_outline,
|
icon: Icon(Icons.info_outline,
|
||||||
color: contentTheme.primary),
|
color: contentTheme.primary),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user