made int type chnages for guid

This commit is contained in:
Vaibhav Surve 2025-05-05 10:55:37 +05:30
parent 7a103c8f22
commit 0ac896e933
10 changed files with 163 additions and 93 deletions

View File

@ -76,7 +76,7 @@ class AttendanceController extends GetxController {
isLoading.value = true; // Set loading to true before API call isLoading.value = true; // Set loading to true before API call
final response = final response =
await ApiService.getEmployeesByProject(int.parse(projectId)); await ApiService.getEmployeesByProject(projectId);
isLoading.value = false; // Set loading to false after API call completes isLoading.value = false; // Set loading to false after API call completes
if (response != null) { if (response != null) {
@ -88,9 +88,9 @@ class AttendanceController extends GetxController {
} }
Future<bool> captureAndUploadAttendance( Future<bool> captureAndUploadAttendance(
int id, String id, // Change from int to String
int employeeId, String employeeId, // Change from int to String
int projectId, { String projectId, {
String comment = "Marked via mobile app", String comment = "Marked via mobile app",
required int action, required int action,
bool imageCapture = true, // <- add this flag bool imageCapture = true, // <- add this flag
@ -167,7 +167,7 @@ class AttendanceController extends GetxController {
isLoading.value = true; // Set loading to true before API call isLoading.value = true; // Set loading to true before API call
final response = await ApiService.getAttendanceLogs( final response = await ApiService.getAttendanceLogs(
int.parse(projectId), projectId,
dateFrom: dateFrom, dateFrom: dateFrom,
dateTo: dateTo, dateTo: dateTo,
); );
@ -192,14 +192,14 @@ class AttendanceController extends GetxController {
isLoading.value = true; isLoading.value = true;
final response = final response =
await ApiService.getRegularizationLogs(int.parse(projectId)); await ApiService.getRegularizationLogs(projectId);
isLoading.value = false; isLoading.value = false;
if (response != null) { if (response != null) {
regularizationLogs = response regularizationLogs = response
.map((json) => RegularizationLogModel.fromJson(json)) .map((json) => RegularizationLogModel.fromJson(json))
.toList(); .toList();
update(); update();
} else { } else {
print("Failed to fetch regularization logs for project $projectId."); print("Failed to fetch regularization logs for project $projectId.");
} }
@ -209,7 +209,7 @@ class AttendanceController extends GetxController {
if (id == null) return; if (id == null) return;
isLoading.value = true; // Set loading to true before API call 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 isLoading.value = false; // Set loading to false after API call completes
if (response != null) { if (response != null) {

View File

@ -61,7 +61,7 @@ class ApiService {
: null; : null;
} }
static Future<List<dynamic>?> getEmployeesByProject(int projectId) async { static Future<List<dynamic>?> getEmployeesByProject(String projectId) async {
final response = await _getRequest("/attendance/project/team", final response = await _getRequest("/attendance/project/team",
queryParams: {"projectId": "$projectId"}); queryParams: {"projectId": "$projectId"});
return response != null return response != null
@ -70,7 +70,7 @@ class ApiService {
} }
static Future<List<dynamic>?> getAttendanceLogs( static Future<List<dynamic>?> getAttendanceLogs(
int projectId, { String projectId, {
DateTime? dateFrom, DateTime? dateFrom,
DateTime? dateTo, DateTime? dateTo,
}) async { }) async {
@ -88,14 +88,14 @@ class ApiService {
: null; : null;
} }
static Future<List<dynamic>?> getAttendanceLogView(int id) async { static Future<List<dynamic>?> getAttendanceLogView(String id) async {
final response = await _getRequest("/attendance/log/attendance/$id"); final response = await _getRequest("/attendance/log/attendance/$id");
return response != null return response != null
? _parseResponse(response, label: 'Attendance Log Details') ? _parseResponse(response, label: 'Attendance Log Details')
: null; : null;
} }
static Future<List<dynamic>?> getRegularizationLogs(int projectId) async { static Future<List<dynamic>?> getRegularizationLogs(String projectId) async {
final response = await _getRequest("/attendance/regularize", final response = await _getRequest("/attendance/regularize",
queryParams: {"projectId": "$projectId"}); queryParams: {"projectId": "$projectId"});
return response != null return response != null
@ -106,13 +106,13 @@ class ApiService {
// ===== Upload Image ===== // ===== Upload Image =====
static Future<bool> uploadAttendanceImage( static Future<bool> uploadAttendanceImage(
int id, String id,
int employeeId, String employeeId,
XFile? imageFile, XFile? imageFile,
double latitude, double latitude,
double longitude, { double longitude, {
required String imageName, required String imageName,
required int projectId, required String projectId,
String comment = "", String comment = "",
required int action, required int action,
bool imageCapture = true, // <- add this flag bool imageCapture = true, // <- add this flag
@ -182,7 +182,7 @@ class ApiService {
// ===== Utilities ===== // ===== Utilities =====
static String generateImageName(int employeeId, int count) { static String generateImageName(String employeeId, int count) {
final now = DateTime.now(); final now = DateTime.now();
final dateStr = DateFormat('yyyyMMdd_HHmmss').format(now); final dateStr = DateFormat('yyyyMMdd_HHmmss').format(now);
final imageNumber = count.toString().padLeft(3, '0'); final imageNumber = count.toString().padLeft(3, '0');

View File

@ -1,31 +1,48 @@
class AttendanceLogModel { class AttendanceLogModel {
final String id;
final String employeeId;
final String name; final String name;
final String role; final String role;
final DateTime? checkIn; final DateTime? checkIn;
final DateTime? checkOut; final DateTime? checkOut;
final int activity; final int activity;
final int id;
final int employeeId;
AttendanceLogModel({ AttendanceLogModel({
required this.id,
required this.employeeId,
required this.name, required this.name,
required this.role, required this.role,
this.checkIn, this.checkIn,
this.checkOut, this.checkOut,
required this.activity, required this.activity,
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(), id: json['id']?.toString() ?? '',
employeeId: json['employeeId']?.toString() ?? '',
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,
employeeId: json['employeeId'] != null ? json['employeeId'] : null,
); );
} }
Map<String, dynamic> 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,
};
}
} }

View File

@ -20,17 +20,33 @@ class AttendanceLogViewModel {
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
imageUrl: json['imageUrl'], ? DateTime.tryParse(json['activityTime'])
comment: json['comment'], : null,
thumbPreSignedUrl: json['thumbPreSignedUrl'], imageUrl: json['imageUrl']?.toString(),
preSignedUrl: json['preSignedUrl'], comment: json['comment']?.toString(),
longitude: json['longitude'], thumbPreSignedUrl: json['thumbPreSignedUrl']?.toString(),
latitude: json['latitude'], 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<String, dynamic> 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;
} }

View File

@ -1,5 +1,5 @@
class AttendanceModel { class AttendanceModel {
final int id; final String id;
final String name; final String name;
final String projectAddress; final String projectAddress;
final String contactPerson; final String contactPerson;
@ -21,17 +21,31 @@ class AttendanceModel {
required this.plannedWork, required this.plannedWork,
}); });
factory AttendanceModel.fromJson(Map<String, dynamic> json) { factory AttendanceModel.fromJson(Map<String, dynamic> json) {
return AttendanceModel( return AttendanceModel(
id: int.tryParse(json['id'].toString()) ?? 0, id: json['id']?.toString() ?? '',
name: json['name'] ?? '', name: json['name'] ?? '',
projectAddress: json['projectAddress'] ?? '', projectAddress: json['projectAddress'] ?? '',
contactPerson: json['contactPerson'] ?? '', contactPerson: json['contactPerson'] ?? '',
startDate: DateTime.tryParse(json['startDate'].toString()) ?? DateTime.now(), startDate: DateTime.tryParse(json['startDate']?.toString() ?? '') ?? DateTime.now(),
endDate: DateTime.tryParse(json['endDate'].toString()) ?? DateTime.now(), endDate: DateTime.tryParse(json['endDate']?.toString() ?? '') ?? DateTime.now(),
teamSize: int.tryParse(json['teamSize'].toString()) ?? 0, teamSize: int.tryParse(json['teamSize']?.toString() ?? '') ?? 0,
completedWork: int.tryParse(json['completedWork'].toString()) ?? 0, completedWork: int.tryParse(json['completedWork']?.toString() ?? '') ?? 0,
plannedWork: int.tryParse(json['plannedWork'].toString()) ?? 0, plannedWork: int.tryParse(json['plannedWork']?.toString() ?? '') ?? 0,
); );
} }
Map<String, dynamic> toJson() {
return {
'id': id,
'name': name,
'projectAddress': projectAddress,
'contactPerson': contactPerson,
'startDate': startDate.toIso8601String(),
'endDate': endDate.toIso8601String(),
'teamSize': teamSize,
'completedWork': completedWork,
'plannedWork': plannedWork,
};
}
} }

View File

@ -1,5 +1,5 @@
class EmployeeInfo { class EmployeeInfo {
final int id; final String id;
final String firstName; final String firstName;
final String lastName; final String lastName;
final String gender; final String gender;
@ -11,9 +11,9 @@ class EmployeeInfo {
final String emergencyContactPerson; final String emergencyContactPerson;
final String aadharNumber; final String aadharNumber;
final bool isActive; final bool isActive;
final String? photo; // Nullable photo final String? photo;
final String applicationUserId; final String applicationUserId;
final int jobRoleId; final String jobRoleId;
EmployeeInfo({ EmployeeInfo({
required this.id, required this.id,
@ -33,10 +33,9 @@ class EmployeeInfo {
required this.jobRoleId, required this.jobRoleId,
}); });
// Factory constructor to create an instance from JSON
factory EmployeeInfo.fromJson(Map<String, dynamic> json) { factory EmployeeInfo.fromJson(Map<String, dynamic> json) {
return EmployeeInfo( return EmployeeInfo(
id: json['id'], id: json['id']?.toString() ?? '',
firstName: json['firstName'] ?? '', firstName: json['firstName'] ?? '',
lastName: json['lastName'] ?? '', lastName: json['lastName'] ?? '',
gender: json['gender'] ?? '', gender: json['gender'] ?? '',
@ -48,13 +47,12 @@ class EmployeeInfo {
emergencyContactPerson: json['emergencyContactPerson'] ?? '', emergencyContactPerson: json['emergencyContactPerson'] ?? '',
aadharNumber: json['aadharNumber'] ?? '', aadharNumber: json['aadharNumber'] ?? '',
isActive: json['isActive'] ?? false, isActive: json['isActive'] ?? false,
photo: json['photo'], // Photo can be null photo: json['photo'],
applicationUserId: json['applicationUserId'] ?? '', applicationUserId: json['applicationUserId']?.toString() ?? '',
jobRoleId: json['jobRoleId'] ?? 0, jobRoleId: json['jobRoleId']?.toString() ?? '',
); );
} }
// Convert the EmployeeInfo instance to a Map (for storage or API)
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
'id': id, 'id': id,

View File

@ -1,12 +1,12 @@
class EmployeeModel { class EmployeeModel {
final int id; final String id;
final int employeeId; final String employeeId;
final String name; final String name;
final String designation; final String designation;
final String checkIn; final String checkIn;
final String checkOut; final String checkOut;
final int activity; final int activity;
int action; int action;
EmployeeModel({ EmployeeModel({
required this.id, required this.id,
@ -15,20 +15,34 @@ class EmployeeModel {
required this.designation, required this.designation,
required this.checkIn, required this.checkIn,
required this.checkOut, required this.checkOut,
required this.action,
required this.activity, required this.activity,
required this.action,
}); });
factory EmployeeModel.fromJson(Map<String, dynamic> json) { factory EmployeeModel.fromJson(Map<String, dynamic> json) {
return EmployeeModel( return EmployeeModel(
id: json['id'] ?? 0, id: json['id']?.toString() ?? '',
employeeId: json['employeeId'] ?? 0, employeeId: json['employeeId']?.toString() ?? '',
name: '${json['firstName']} ${json['lastName']}', name: '${json['firstName'] ?? ''} ${json['lastName'] ?? ''}'.trim(),
designation: json['jobRoleName'] ?? '', designation: json['jobRoleName'] ?? '',
checkIn: json['checkIn'] ?? '-', // Make sure your API returns this field checkIn: json['checkIn']?.toString() ?? '-',
checkOut: json['checkOut'] ?? '-', checkOut: json['checkOut']?.toString() ?? '-',
action: json['action'] ?? 0, // Make sure your API returns this field action: json['action'] ?? 0,
activity: json['activity'] ?? 0, activity: json['activity'] ?? 0,
); );
} }
Map<String, dynamic> 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,
};
}
} }

View File

@ -1,17 +1,16 @@
class ProjectModel { class ProjectModel {
final int id; // Unique identifier for the project final String id;
final String name; // Name of the project final String name;
final String projectAddress; // Address of the project final String projectAddress;
final String contactPerson; // Contact person for the project final String contactPerson;
final DateTime startDate; // Start date of the project final DateTime startDate;
final DateTime endDate; // End date of the project final DateTime endDate;
final int teamSize; // Number of people in the team final int teamSize;
final int completedWork; // Completed work percentage final int completedWork;
final int plannedWork; // Planned work for the project final int plannedWork;
final int projectStatusId; // Status ID for the project final String projectStatusId;
final int tenantId; // Tenant ID associated with the project final String? tenantId;
// Constructor
ProjectModel({ ProjectModel({
required this.id, required this.id,
required this.name, required this.name,
@ -23,7 +22,7 @@ class ProjectModel {
required this.completedWork, required this.completedWork,
required this.plannedWork, required this.plannedWork,
required this.projectStatusId, required this.projectStatusId,
required this.tenantId, this.tenantId,
}); });
// Factory method to create an instance of ProjectModel from a JSON object // Factory method to create an instance of ProjectModel from a JSON object
@ -39,7 +38,7 @@ class ProjectModel {
completedWork: json['completedWork'], completedWork: json['completedWork'],
plannedWork: json['plannedWork'], plannedWork: json['plannedWork'],
projectStatusId: json['projectStatusId'], projectStatusId: json['projectStatusId'],
tenantId: json['tenantId'], tenantId: json['tenantId'],
); );
} }

View File

@ -1,6 +1,6 @@
class RegularizationLogModel { class RegularizationLogModel {
final int id; final String id;
final int employeeId; final String employeeId;
final String name; final String name;
final String role; final String role;
final DateTime? checkIn; final DateTime? checkIn;
@ -17,20 +17,32 @@ class RegularizationLogModel {
required this.activity, required this.activity,
}); });
factory RegularizationLogModel.fromJson(Map<String, dynamic> json) { factory RegularizationLogModel.fromJson(Map<String, dynamic> json) {
return RegularizationLogModel( return RegularizationLogModel(
id: json['id'] ?? 0, id: json['id']?.toString() ?? '',
employeeId: json['employeeId'] ?? 0, employeeId: json['employeeId']?.toString() ?? '',
name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(), name: "${json['firstName'] ?? ''} ${json['lastName'] ?? ''}".trim(),
role: json['jobRoleName'] ?? '', role: json['jobRoleName'] ?? '',
checkIn: json['checkInTime'] != null checkIn: json['checkInTime'] != null
? DateTime.tryParse(json['checkInTime']) ? DateTime.tryParse(json['checkInTime'].toString())
: null, : null,
checkOut: json['checkOutTime'] != null checkOut: json['checkOutTime'] != null
? DateTime.tryParse(json['checkOutTime']) ? DateTime.tryParse(json['checkOutTime'].toString())
: null, : null,
activity: json['activity'] ?? 0, activity: json['activity'] ?? 0,
); );
} }
Map<String, dynamic> 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,
};
}
} }

View File

@ -138,7 +138,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
null null
? attendanceController.projects ? attendanceController.projects
.firstWhereOrNull((proj) => .firstWhereOrNull((proj) =>
proj.id.toString() == proj.id==
attendanceController attendanceController
.selectedProjectId) .selectedProjectId)
?.name ?? ?.name ??
@ -274,7 +274,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
await attendanceController.captureAndUploadAttendance( await attendanceController.captureAndUploadAttendance(
employee.id, employee.id,
employee.employeeId, employee.employeeId,
int.parse(attendanceController.selectedProjectId!), attendanceController.selectedProjectId!,
comment: actionText, comment: actionText,
action: updatedAction, action: updatedAction,
); );
@ -611,7 +611,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
await attendanceController.captureAndUploadAttendance( await attendanceController.captureAndUploadAttendance(
log.id, log.id,
log.employeeId, log.employeeId,
int.parse(attendanceController.selectedProjectId!), attendanceController.selectedProjectId!,
comment: actionText, comment: actionText,
action: updatedAction, action: updatedAction,
imageCapture: imageCapture, imageCapture: imageCapture,
@ -808,7 +808,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
.captureAndUploadAttendance( .captureAndUploadAttendance(
log.id, log.id,
log.employeeId, log.employeeId,
int.parse(attendanceController.selectedProjectId!), attendanceController.selectedProjectId!,
comment: "Accepted", comment: "Accepted",
action: 4, // Approve action action: 4, // Approve action
imageCapture: false, imageCapture: false,
@ -861,7 +861,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
.captureAndUploadAttendance( .captureAndUploadAttendance(
log.id, log.id,
log.employeeId, log.employeeId,
int.parse(attendanceController.selectedProjectId!), attendanceController.selectedProjectId!,
comment: "Rejected", comment: "Rejected",
action: 5, // Reject action action: 5, // Reject action
imageCapture: false, imageCapture: false,