feat: Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
class EarningModel {
|
||||
EarningModel({
|
||||
required this.id,
|
||||
required this.rate,
|
||||
required this.businessName,
|
||||
required this.businessAvatar,
|
||||
required this.businessSkill,
|
||||
required this.workHours,
|
||||
required this.amount,
|
||||
required this.status,
|
||||
required this.paidAt,
|
||||
required this.clockInAt,
|
||||
required this.clockOutAt,
|
||||
this.breakIn,
|
||||
this.breakOut,
|
||||
required this.eventName,
|
||||
required this.eventDate,
|
||||
});
|
||||
|
||||
factory EarningModel.fromJson(Map<String, dynamic> json) {
|
||||
final assignment = json['assignment'] as Map<String, dynamic>;
|
||||
final positionData = assignment['position'] as Map<String, dynamic>;
|
||||
final eventData = positionData['shift']['event'] as Map<String, dynamic>;
|
||||
final businessData = eventData['business'] as Map<String, dynamic>;
|
||||
|
||||
return EarningModel(
|
||||
id: json['id'] as String? ?? '',
|
||||
rate: (json['rate'] as num? ?? 0).toDouble(),
|
||||
businessName: businessData['name'] as String? ?? '',
|
||||
businessAvatar: businessData['avatar'] as String? ?? '',
|
||||
businessSkill:
|
||||
positionData['business_skill']['skill']['name'] as String? ?? '',
|
||||
workHours: (json['work_hours'] as num? ?? 0).toDouble(),
|
||||
amount: (json['amount'] as num? ?? 0).toDouble(),
|
||||
status: json['status'] as String? ?? 'failed',
|
||||
paidAt: DateTime.tryParse(
|
||||
json['paid_at'] as String? ?? '',
|
||||
),
|
||||
clockInAt: DateTime.parse(
|
||||
assignment['clock_in'] ?? assignment['start_at'] as String,
|
||||
),
|
||||
clockOutAt: DateTime.parse(
|
||||
assignment['clock_out'] ?? assignment['end_at'] as String,
|
||||
),
|
||||
breakIn: DateTime.tryParse(assignment['break_in'] ?? ''),
|
||||
breakOut: DateTime.tryParse(assignment['break_out'] ?? ''),
|
||||
eventName: eventData['name'] as String? ?? '',
|
||||
eventDate: DateTime.parse(eventData['date'] as String? ?? ''),
|
||||
);
|
||||
}
|
||||
|
||||
final String id;
|
||||
final double rate;
|
||||
final String businessName;
|
||||
final String businessAvatar;
|
||||
final String businessSkill;
|
||||
final double workHours;
|
||||
final double amount;
|
||||
final String status;
|
||||
final DateTime? paidAt;
|
||||
final DateTime clockInAt;
|
||||
final DateTime clockOutAt;
|
||||
final DateTime? breakIn;
|
||||
final DateTime? breakOut;
|
||||
final String eventName;
|
||||
final DateTime eventDate;
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
class EarningsSummaryModel {
|
||||
EarningsSummaryModel({
|
||||
required this.totalEarningsByWeek,
|
||||
required this.totalEarningsByMonth,
|
||||
required this.totalWorkedHoursByWeek,
|
||||
required this.totalWorkedHoursByMonth,
|
||||
required this.payoutByWeek,
|
||||
required this.payoutByMonth,
|
||||
required this.startDatePeriod,
|
||||
required this.endDatePeriod,
|
||||
required this.maxEarningInPeriod,
|
||||
required this.minEarningInPeriod,
|
||||
});
|
||||
|
||||
//TODO: Additional fields that are used in the Earnings History screen are for now returning default values.
|
||||
factory EarningsSummaryModel.fromJson(Map<String, dynamic> json) {
|
||||
final time = DateTime.now();
|
||||
return EarningsSummaryModel(
|
||||
totalEarningsByWeek: (json['weekly_earnings'] as num?)?.toDouble() ?? 0,
|
||||
totalEarningsByMonth: (json['monthly_earnings'] as num?)?.toDouble() ?? 0,
|
||||
totalWorkedHoursByWeek: (json['weekly_hours'] as num?)?.toDouble() ?? 0,
|
||||
totalWorkedHoursByMonth: (json['monthly_hours'] as num?)?.toDouble() ?? 0,
|
||||
payoutByWeek: 0,
|
||||
payoutByMonth: 0,
|
||||
startDatePeriod: DateTime(time.year, time.month),
|
||||
endDatePeriod: DateTime(time.year, time.month, 28),
|
||||
maxEarningInPeriod: 0,
|
||||
minEarningInPeriod: 0,
|
||||
);
|
||||
}
|
||||
|
||||
final double totalEarningsByWeek;
|
||||
final double totalEarningsByMonth;
|
||||
final double totalWorkedHoursByWeek;
|
||||
final double totalWorkedHoursByMonth;
|
||||
final double payoutByWeek;
|
||||
final double payoutByMonth;
|
||||
final DateTime? startDatePeriod;
|
||||
final DateTime? endDatePeriod;
|
||||
final int maxEarningInPeriod;
|
||||
final int minEarningInPeriod;
|
||||
|
||||
EarningsSummaryModel copyWith({
|
||||
double? totalEarningsByWeek,
|
||||
double? totalEarningsByMonth,
|
||||
double? totalWorkedHoursByWeek,
|
||||
double? totalWorkedHoursByMonth,
|
||||
double? payoutByWeek,
|
||||
double? payoutByMonth,
|
||||
DateTime? startDatePeriod,
|
||||
DateTime? endDatePeriod,
|
||||
int? maxEarningInPeriod,
|
||||
int? minEarningInPeriod,
|
||||
}) {
|
||||
return EarningsSummaryModel(
|
||||
totalEarningsByWeek: totalEarningsByWeek ?? this.totalEarningsByWeek,
|
||||
totalEarningsByMonth: totalEarningsByMonth ?? this.totalEarningsByMonth,
|
||||
totalWorkedHoursByWeek:
|
||||
totalWorkedHoursByWeek ?? this.totalWorkedHoursByWeek,
|
||||
totalWorkedHoursByMonth:
|
||||
totalWorkedHoursByMonth ?? this.totalWorkedHoursByMonth,
|
||||
payoutByWeek: payoutByWeek ?? this.payoutByWeek,
|
||||
payoutByMonth: payoutByMonth ?? this.payoutByMonth,
|
||||
startDatePeriod: startDatePeriod,
|
||||
endDatePeriod: endDatePeriod,
|
||||
maxEarningInPeriod: maxEarningInPeriod ?? this.maxEarningInPeriod,
|
||||
minEarningInPeriod: minEarningInPeriod ?? this.minEarningInPeriod,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user