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
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<bool> 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) {

View File

@ -61,7 +61,7 @@ class ApiService {
: null;
}
static Future<List<dynamic>?> getEmployeesByProject(int projectId) async {
static Future<List<dynamic>?> 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<List<dynamic>?> getAttendanceLogs(
int projectId, {
String projectId, {
DateTime? dateFrom,
DateTime? dateTo,
}) async {
@ -88,14 +88,14 @@ class ApiService {
: 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");
return response != null
? _parseResponse(response, label: 'Attendance Log Details')
: null;
}
static Future<List<dynamic>?> getRegularizationLogs(int projectId) async {
static Future<List<dynamic>?> 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<bool> 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');

View File

@ -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<String, dynamic> 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<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) {
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<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 {
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<String, dynamic> 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<String, dynamic> 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<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 {
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<String, dynamic> 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<String, dynamic> toJson() {
return {
'id': id,

View File

@ -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<String, dynamic> 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<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 {
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'],
);
}

View File

@ -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<String, dynamic> 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<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
? attendanceController.projects
.firstWhereOrNull((proj) =>
proj.id.toString() ==
proj.id==
attendanceController
.selectedProjectId)
?.name ??
@ -274,7 +274,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> 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<AttendanceScreen> 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<AttendanceScreen> 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<AttendanceScreen> with UIMixin {
.captureAndUploadAttendance(
log.id,
log.employeeId,
int.parse(attendanceController.selectedProjectId!),
attendanceController.selectedProjectId!,
comment: "Rejected",
action: 5, // Reject action
imageCapture: false,