116 lines
3.2 KiB
Dart
116 lines
3.2 KiB
Dart
import 'package:intl/intl.dart';
|
|
|
|
class Employee {
|
|
final String id;
|
|
final String firstName;
|
|
final String lastName;
|
|
final String? photo;
|
|
final String jobRoleId;
|
|
final String jobRoleName;
|
|
|
|
Employee({
|
|
required this.id,
|
|
required this.firstName,
|
|
required this.lastName,
|
|
this.photo,
|
|
required this.jobRoleId,
|
|
required this.jobRoleName,
|
|
});
|
|
|
|
factory Employee.fromJson(Map<String, dynamic> json) {
|
|
return Employee(
|
|
id: json['id'],
|
|
firstName: json['firstName'] ?? '',
|
|
lastName: json['lastName'] ?? '',
|
|
photo: json['photo']?.toString(),
|
|
jobRoleId: json['jobRoleId'] ?? '',
|
|
jobRoleName: json['jobRoleName'] ?? '',
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'firstName': firstName,
|
|
'lastName': lastName,
|
|
'photo': photo,
|
|
'jobRoleId': jobRoleId,
|
|
'jobRoleName': jobRoleName,
|
|
};
|
|
}
|
|
}
|
|
|
|
class AttendanceLogViewModel {
|
|
final String id;
|
|
final String? comment;
|
|
final Employee employee;
|
|
final DateTime? activityTime;
|
|
final int activity;
|
|
final String? photo;
|
|
final String? thumbPreSignedUrl;
|
|
final String? preSignedUrl;
|
|
final String? longitude;
|
|
final String? latitude;
|
|
final DateTime? updatedOn;
|
|
final Employee? updatedByEmployee;
|
|
final String? documentId;
|
|
|
|
AttendanceLogViewModel({
|
|
required this.id,
|
|
this.comment,
|
|
required this.employee,
|
|
this.activityTime,
|
|
required this.activity,
|
|
this.photo,
|
|
this.thumbPreSignedUrl,
|
|
this.preSignedUrl,
|
|
this.longitude,
|
|
this.latitude,
|
|
this.updatedOn,
|
|
this.updatedByEmployee,
|
|
this.documentId,
|
|
});
|
|
|
|
factory AttendanceLogViewModel.fromJson(Map<String, dynamic> json) {
|
|
return AttendanceLogViewModel(
|
|
id: json['id'],
|
|
comment: json['comment']?.toString(),
|
|
employee: Employee.fromJson(json['employee']),
|
|
activityTime: json['activityTime'] != null ? DateTime.tryParse(json['activityTime']) : null,
|
|
activity: json['activity'] ?? 0,
|
|
photo: json['photo']?.toString(),
|
|
thumbPreSignedUrl: json['thumbPreSignedUrl']?.toString(),
|
|
preSignedUrl: json['preSignedUrl']?.toString(),
|
|
longitude: json['longitude']?.toString(),
|
|
latitude: json['latitude']?.toString(),
|
|
updatedOn: json['updatedOn'] != null ? DateTime.tryParse(json['updatedOn']) : null,
|
|
updatedByEmployee: json['updatedByEmployee'] != null ? Employee.fromJson(json['updatedByEmployee']) : null,
|
|
documentId: json['documentId']?.toString(),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'comment': comment,
|
|
'employee': employee.toJson(),
|
|
'activityTime': activityTime?.toIso8601String(),
|
|
'activity': activity,
|
|
'photo': photo,
|
|
'thumbPreSignedUrl': thumbPreSignedUrl,
|
|
'preSignedUrl': preSignedUrl,
|
|
'longitude': longitude,
|
|
'latitude': latitude,
|
|
'updatedOn': updatedOn?.toIso8601String(),
|
|
'updatedByEmployee': updatedByEmployee?.toJson(),
|
|
'documentId': documentId,
|
|
};
|
|
}
|
|
|
|
String? get formattedDate =>
|
|
activityTime != null ? DateFormat('yyyy-MM-dd').format(activityTime!) : null;
|
|
|
|
String? get formattedTime =>
|
|
activityTime != null ? DateFormat('hh:mm a').format(activityTime!) : null;
|
|
}
|