From 0ac896e9339e2dbe8cdf1e6519a9e99c477c8801 Mon Sep 17 00:00:00 2001 From: Vaibhav Surve Date: Mon, 5 May 2025 10:55:37 +0530 Subject: [PATCH] made int type chnages for guid --- .../attendance_screen_controller.dart | 16 +++---- lib/helpers/services/api_service.dart | 16 +++---- lib/model/attendance_log_model.dart | 35 ++++++++++++---- lib/model/attendance_log_view_model.dart | 34 +++++++++++---- lib/model/attendance_model.dart | 42 ++++++++++++------- lib/model/employee_info.dart | 16 ++++--- lib/model/employee_model.dart | 34 ++++++++++----- lib/model/project_model.dart | 27 ++++++------ lib/model/regularization_log_model.dart | 26 ++++++++---- lib/view/dashboard/attendanceScreen.dart | 10 ++--- 10 files changed, 163 insertions(+), 93 deletions(-) diff --git a/lib/controller/dashboard/attendance_screen_controller.dart b/lib/controller/dashboard/attendance_screen_controller.dart index e1e915d..174c60d 100644 --- a/lib/controller/dashboard/attendance_screen_controller.dart +++ b/lib/controller/dashboard/attendance_screen_controller.dart @@ -76,7 +76,7 @@ class AttendanceController extends GetxController { isLoading.value = true; // Set loading to true before API call final response = - await ApiService.getEmployeesByProject(int.parse(projectId)); + await ApiService.getEmployeesByProject(projectId); isLoading.value = false; // Set loading to false after API call completes if (response != null) { @@ -88,9 +88,9 @@ class AttendanceController extends GetxController { } Future captureAndUploadAttendance( - int id, - int employeeId, - int projectId, { + String id, // Change from int to String + String employeeId, // Change from int to String + String projectId, { String comment = "Marked via mobile app", required int action, bool imageCapture = true, // <- add this flag @@ -167,7 +167,7 @@ class AttendanceController extends GetxController { isLoading.value = true; // Set loading to true before API call final response = await ApiService.getAttendanceLogs( - int.parse(projectId), + projectId, dateFrom: dateFrom, dateTo: dateTo, ); @@ -192,14 +192,14 @@ class AttendanceController extends GetxController { isLoading.value = true; final response = - await ApiService.getRegularizationLogs(int.parse(projectId)); + await ApiService.getRegularizationLogs(projectId); isLoading.value = false; if (response != null) { regularizationLogs = response .map((json) => RegularizationLogModel.fromJson(json)) .toList(); - update(); + update(); } else { print("Failed to fetch regularization logs for project $projectId."); } @@ -209,7 +209,7 @@ class AttendanceController extends GetxController { if (id == null) return; isLoading.value = true; // Set loading to true before API call - final response = await ApiService.getAttendanceLogView(int.parse(id)); + final response = await ApiService.getAttendanceLogView(id); isLoading.value = false; // Set loading to false after API call completes if (response != null) { diff --git a/lib/helpers/services/api_service.dart b/lib/helpers/services/api_service.dart index f5837cf..4f8e025 100644 --- a/lib/helpers/services/api_service.dart +++ b/lib/helpers/services/api_service.dart @@ -61,7 +61,7 @@ class ApiService { : null; } - static Future?> getEmployeesByProject(int projectId) async { + static Future?> getEmployeesByProject(String projectId) async { final response = await _getRequest("/attendance/project/team", queryParams: {"projectId": "$projectId"}); return response != null @@ -70,7 +70,7 @@ class ApiService { } static Future?> getAttendanceLogs( - int projectId, { + String projectId, { DateTime? dateFrom, DateTime? dateTo, }) async { @@ -88,14 +88,14 @@ class ApiService { : null; } - static Future?> getAttendanceLogView(int id) async { + static Future?> getAttendanceLogView(String id) async { final response = await _getRequest("/attendance/log/attendance/$id"); return response != null ? _parseResponse(response, label: 'Attendance Log Details') : null; } - static Future?> getRegularizationLogs(int projectId) async { + static Future?> getRegularizationLogs(String projectId) async { final response = await _getRequest("/attendance/regularize", queryParams: {"projectId": "$projectId"}); return response != null @@ -106,13 +106,13 @@ class ApiService { // ===== Upload Image ===== static Future uploadAttendanceImage( - int id, - int employeeId, + String id, + String employeeId, XFile? imageFile, double latitude, double longitude, { required String imageName, - required int projectId, + required String projectId, String comment = "", required int action, bool imageCapture = true, // <- add this flag @@ -182,7 +182,7 @@ class ApiService { // ===== Utilities ===== - static String generateImageName(int employeeId, int count) { + static String generateImageName(String employeeId, int count) { final now = DateTime.now(); final dateStr = DateFormat('yyyyMMdd_HHmmss').format(now); final imageNumber = count.toString().padLeft(3, '0'); diff --git a/lib/model/attendance_log_model.dart b/lib/model/attendance_log_model.dart index d7c284b..c4889e4 100644 --- a/lib/model/attendance_log_model.dart +++ b/lib/model/attendance_log_model.dart @@ -1,31 +1,48 @@ class AttendanceLogModel { + final String id; + final String employeeId; final String name; final String role; final DateTime? checkIn; final DateTime? checkOut; final int activity; - final int id; - final int employeeId; AttendanceLogModel({ + required this.id, + required this.employeeId, required this.name, required this.role, this.checkIn, this.checkOut, required this.activity, - required this.id, - required this.employeeId, }); factory AttendanceLogModel.fromJson(Map json) { return AttendanceLogModel( - name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(), + id: json['id']?.toString() ?? '', + employeeId: json['employeeId']?.toString() ?? '', + name: '${json['firstName'] ?? ''} ${json['lastName'] ?? ''}'.trim(), role: json['jobRoleName'] ?? '', - checkIn: json['checkInTime'] != null ? DateTime.tryParse(json['checkInTime']) : null, - checkOut: json['checkOutTime'] != null ? DateTime.tryParse(json['checkOutTime']) : null, + checkIn: json['checkInTime'] != null + ? DateTime.tryParse(json['checkInTime']) + : null, + checkOut: json['checkOutTime'] != null + ? DateTime.tryParse(json['checkOutTime']) + : null, activity: json['activity'] ?? 0, - id: json['id'] != null ? json['id'] : null, - employeeId: json['employeeId'] != null ? json['employeeId'] : null, ); } + + Map toJson() { + return { + 'id': id, + 'employeeId': employeeId, + 'firstName': name.split(' ').first, + 'lastName': name.split(' ').length > 1 ? name.split(' ').last : '', + 'jobRoleName': role, + 'checkInTime': checkIn?.toIso8601String(), + 'checkOutTime': checkOut?.toIso8601String(), + 'activity': activity, + }; + } } diff --git a/lib/model/attendance_log_view_model.dart b/lib/model/attendance_log_view_model.dart index 86f003e..6db06d6 100644 --- a/lib/model/attendance_log_view_model.dart +++ b/lib/model/attendance_log_view_model.dart @@ -20,17 +20,33 @@ class AttendanceLogViewModel { factory AttendanceLogViewModel.fromJson(Map json) { return AttendanceLogViewModel( - activityTime: json['activityTime'] != null ? DateTime.tryParse(json['activityTime']) : null, - imageUrl: json['imageUrl'], - comment: json['comment'], - thumbPreSignedUrl: json['thumbPreSignedUrl'], - preSignedUrl: json['preSignedUrl'], - longitude: json['longitude'], - latitude: json['latitude'], + activityTime: json['activityTime'] != null + ? DateTime.tryParse(json['activityTime']) + : null, + imageUrl: json['imageUrl']?.toString(), + comment: json['comment']?.toString(), + thumbPreSignedUrl: json['thumbPreSignedUrl']?.toString(), + preSignedUrl: json['preSignedUrl']?.toString(), + longitude: json['longitude']?.toString(), + latitude: json['latitude']?.toString(), ); } - String? get formattedDate => activityTime != null ? DateFormat('yyyy-MM-dd').format(activityTime!) : null; + Map toJson() { + return { + 'activityTime': activityTime?.toIso8601String(), + 'imageUrl': imageUrl, + 'comment': comment, + 'thumbPreSignedUrl': thumbPreSignedUrl, + 'preSignedUrl': preSignedUrl, + 'longitude': longitude, + 'latitude': latitude, + }; + } - String? get formattedTime => activityTime != null ? DateFormat('hh:mm a').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; } \ No newline at end of file diff --git a/lib/model/attendance_model.dart b/lib/model/attendance_model.dart index f12657c..0d6f6a1 100644 --- a/lib/model/attendance_model.dart +++ b/lib/model/attendance_model.dart @@ -1,5 +1,5 @@ class AttendanceModel { - final int id; + final String id; final String name; final String projectAddress; final String contactPerson; @@ -21,17 +21,31 @@ class AttendanceModel { required this.plannedWork, }); -factory AttendanceModel.fromJson(Map json) { - return AttendanceModel( - id: int.tryParse(json['id'].toString()) ?? 0, - name: json['name'] ?? '', - projectAddress: json['projectAddress'] ?? '', - contactPerson: json['contactPerson'] ?? '', - startDate: DateTime.tryParse(json['startDate'].toString()) ?? DateTime.now(), - endDate: DateTime.tryParse(json['endDate'].toString()) ?? DateTime.now(), - teamSize: int.tryParse(json['teamSize'].toString()) ?? 0, - completedWork: int.tryParse(json['completedWork'].toString()) ?? 0, - plannedWork: int.tryParse(json['plannedWork'].toString()) ?? 0, - ); -} + factory AttendanceModel.fromJson(Map json) { + return AttendanceModel( + id: json['id']?.toString() ?? '', + name: json['name'] ?? '', + projectAddress: json['projectAddress'] ?? '', + contactPerson: json['contactPerson'] ?? '', + startDate: DateTime.tryParse(json['startDate']?.toString() ?? '') ?? DateTime.now(), + endDate: DateTime.tryParse(json['endDate']?.toString() ?? '') ?? DateTime.now(), + teamSize: int.tryParse(json['teamSize']?.toString() ?? '') ?? 0, + completedWork: int.tryParse(json['completedWork']?.toString() ?? '') ?? 0, + plannedWork: int.tryParse(json['plannedWork']?.toString() ?? '') ?? 0, + ); + } + + Map toJson() { + return { + 'id': id, + 'name': name, + 'projectAddress': projectAddress, + 'contactPerson': contactPerson, + 'startDate': startDate.toIso8601String(), + 'endDate': endDate.toIso8601String(), + 'teamSize': teamSize, + 'completedWork': completedWork, + 'plannedWork': plannedWork, + }; + } } diff --git a/lib/model/employee_info.dart b/lib/model/employee_info.dart index e5b09ab..8ea355c 100644 --- a/lib/model/employee_info.dart +++ b/lib/model/employee_info.dart @@ -1,5 +1,5 @@ class EmployeeInfo { - final int id; + final String id; final String firstName; final String lastName; final String gender; @@ -11,9 +11,9 @@ class EmployeeInfo { final String emergencyContactPerson; final String aadharNumber; final bool isActive; - final String? photo; // Nullable photo + final String? photo; final String applicationUserId; - final int jobRoleId; + final String jobRoleId; EmployeeInfo({ required this.id, @@ -33,10 +33,9 @@ class EmployeeInfo { required this.jobRoleId, }); - // Factory constructor to create an instance from JSON factory EmployeeInfo.fromJson(Map json) { return EmployeeInfo( - id: json['id'], + id: json['id']?.toString() ?? '', firstName: json['firstName'] ?? '', lastName: json['lastName'] ?? '', gender: json['gender'] ?? '', @@ -48,13 +47,12 @@ class EmployeeInfo { emergencyContactPerson: json['emergencyContactPerson'] ?? '', aadharNumber: json['aadharNumber'] ?? '', isActive: json['isActive'] ?? false, - photo: json['photo'], // Photo can be null - applicationUserId: json['applicationUserId'] ?? '', - jobRoleId: json['jobRoleId'] ?? 0, + photo: json['photo'], + applicationUserId: json['applicationUserId']?.toString() ?? '', + jobRoleId: json['jobRoleId']?.toString() ?? '', ); } - // Convert the EmployeeInfo instance to a Map (for storage or API) Map toJson() { return { 'id': id, diff --git a/lib/model/employee_model.dart b/lib/model/employee_model.dart index 7602c06..6dd4c8b 100644 --- a/lib/model/employee_model.dart +++ b/lib/model/employee_model.dart @@ -1,12 +1,12 @@ class EmployeeModel { - final int id; - final int employeeId; + final String id; + final String employeeId; final String name; final String designation; final String checkIn; final String checkOut; final int activity; - int action; + int action; EmployeeModel({ required this.id, @@ -15,20 +15,34 @@ class EmployeeModel { required this.designation, required this.checkIn, required this.checkOut, - required this.action, required this.activity, + required this.action, }); factory EmployeeModel.fromJson(Map json) { return EmployeeModel( - id: json['id'] ?? 0, - employeeId: json['employeeId'] ?? 0, - name: '${json['firstName']} ${json['lastName']}', + id: json['id']?.toString() ?? '', + employeeId: json['employeeId']?.toString() ?? '', + name: '${json['firstName'] ?? ''} ${json['lastName'] ?? ''}'.trim(), designation: json['jobRoleName'] ?? '', - checkIn: json['checkIn'] ?? '-', // Make sure your API returns this field - checkOut: json['checkOut'] ?? '-', - action: json['action'] ?? 0, // Make sure your API returns this field + checkIn: json['checkIn']?.toString() ?? '-', + checkOut: json['checkOut']?.toString() ?? '-', + action: json['action'] ?? 0, activity: json['activity'] ?? 0, ); } + + Map toJson() { + return { + 'id': id, + 'employeeId': employeeId, + 'firstName': name.split(' ').first, + 'lastName': name.split(' ').length > 1 ? name.split(' ').last : '', + 'jobRoleName': designation, + 'checkIn': checkIn, + 'checkOut': checkOut, + 'action': action, + 'activity': activity, + }; + } } diff --git a/lib/model/project_model.dart b/lib/model/project_model.dart index dc020fd..066e2ac 100644 --- a/lib/model/project_model.dart +++ b/lib/model/project_model.dart @@ -1,17 +1,16 @@ class ProjectModel { - final int id; // Unique identifier for the project - final String name; // Name of the project - final String projectAddress; // Address of the project - final String contactPerson; // Contact person for the project - final DateTime startDate; // Start date of the project - final DateTime endDate; // End date of the project - final int teamSize; // Number of people in the team - final int completedWork; // Completed work percentage - final int plannedWork; // Planned work for the project - final int projectStatusId; // Status ID for the project - final int tenantId; // Tenant ID associated with the project + final String id; + final String name; + final String projectAddress; + final String contactPerson; + final DateTime startDate; + final DateTime endDate; + final int teamSize; + final int completedWork; + final int plannedWork; + final String projectStatusId; + final String? tenantId; - // Constructor ProjectModel({ required this.id, required this.name, @@ -23,7 +22,7 @@ class ProjectModel { required this.completedWork, required this.plannedWork, required this.projectStatusId, - required this.tenantId, + this.tenantId, }); // Factory method to create an instance of ProjectModel from a JSON object @@ -39,7 +38,7 @@ class ProjectModel { completedWork: json['completedWork'], plannedWork: json['plannedWork'], projectStatusId: json['projectStatusId'], - tenantId: json['tenantId'], + tenantId: json['tenantId'], ); } diff --git a/lib/model/regularization_log_model.dart b/lib/model/regularization_log_model.dart index c332e72..95c8650 100644 --- a/lib/model/regularization_log_model.dart +++ b/lib/model/regularization_log_model.dart @@ -1,6 +1,6 @@ class RegularizationLogModel { - final int id; - final int employeeId; + final String id; + final String employeeId; final String name; final String role; final DateTime? checkIn; @@ -17,20 +17,32 @@ class RegularizationLogModel { required this.activity, }); - factory RegularizationLogModel.fromJson(Map json) { return RegularizationLogModel( - id: json['id'] ?? 0, - employeeId: json['employeeId'] ?? 0, + id: json['id']?.toString() ?? '', + employeeId: json['employeeId']?.toString() ?? '', name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(), role: json['jobRoleName'] ?? '', checkIn: json['checkInTime'] != null - ? DateTime.tryParse(json['checkInTime']) + ? DateTime.tryParse(json['checkInTime'].toString()) : null, checkOut: json['checkOutTime'] != null - ? DateTime.tryParse(json['checkOutTime']) + ? DateTime.tryParse(json['checkOutTime'].toString()) : null, activity: json['activity'] ?? 0, ); } + + Map toJson() { + return { + 'id': id, + 'employeeId': employeeId, + 'firstName': name.split(' ').first, + 'lastName': name.split(' ').length > 1 ? name.split(' ').last : '', + 'jobRoleName': role, + 'checkInTime': checkIn?.toIso8601String(), + 'checkOutTime': checkOut?.toIso8601String(), + 'activity': activity, + }; + } } diff --git a/lib/view/dashboard/attendanceScreen.dart b/lib/view/dashboard/attendanceScreen.dart index 3cc6356..187c370 100644 --- a/lib/view/dashboard/attendanceScreen.dart +++ b/lib/view/dashboard/attendanceScreen.dart @@ -138,7 +138,7 @@ class _AttendanceScreenState extends State with UIMixin { null ? attendanceController.projects .firstWhereOrNull((proj) => - proj.id.toString() == + proj.id== attendanceController .selectedProjectId) ?.name ?? @@ -274,7 +274,7 @@ class _AttendanceScreenState extends State with UIMixin { await attendanceController.captureAndUploadAttendance( employee.id, employee.employeeId, - int.parse(attendanceController.selectedProjectId!), + attendanceController.selectedProjectId!, comment: actionText, action: updatedAction, ); @@ -611,7 +611,7 @@ class _AttendanceScreenState extends State with UIMixin { await attendanceController.captureAndUploadAttendance( log.id, log.employeeId, - int.parse(attendanceController.selectedProjectId!), + attendanceController.selectedProjectId!, comment: actionText, action: updatedAction, imageCapture: imageCapture, @@ -808,7 +808,7 @@ class _AttendanceScreenState extends State with UIMixin { .captureAndUploadAttendance( log.id, log.employeeId, - int.parse(attendanceController.selectedProjectId!), + attendanceController.selectedProjectId!, comment: "Accepted", action: 4, // Approve action imageCapture: false, @@ -861,7 +861,7 @@ class _AttendanceScreenState extends State with UIMixin { .captureAndUploadAttendance( log.id, log.employeeId, - int.parse(attendanceController.selectedProjectId!), + attendanceController.selectedProjectId!, comment: "Rejected", action: 5, // Reject action imageCapture: false,