fix phone dashboard
This commit is contained in:
+171
-32
@@ -1,40 +1,179 @@
|
||||
class DashboardMetrics {
|
||||
final int totalReservations;
|
||||
final int activeReservations;
|
||||
final double totalRevenue;
|
||||
final int totalVehicles;
|
||||
final int availableVehicles;
|
||||
final int totalCustomers;
|
||||
final double occupancyRate;
|
||||
final DashboardKpis kpis;
|
||||
final List<DashboardRecentReservation> recentReservations;
|
||||
final List<DashboardSourceBreakdown> sourceBreakdown;
|
||||
final DashboardSubscription? subscription;
|
||||
|
||||
const DashboardMetrics({
|
||||
required this.totalReservations,
|
||||
required this.activeReservations,
|
||||
required this.totalRevenue,
|
||||
required this.totalVehicles,
|
||||
required this.availableVehicles,
|
||||
required this.totalCustomers,
|
||||
required this.occupancyRate,
|
||||
required this.kpis,
|
||||
required this.recentReservations,
|
||||
required this.sourceBreakdown,
|
||||
required this.subscription,
|
||||
});
|
||||
|
||||
factory DashboardMetrics.fromJson(Map<String, dynamic> json) =>
|
||||
DashboardMetrics(
|
||||
totalReservations: json['totalReservations'] as int? ?? 0,
|
||||
activeReservations: json['activeReservations'] as int? ?? 0,
|
||||
totalRevenue: (json['totalRevenue'] as num?)?.toDouble() ?? 0,
|
||||
totalVehicles: json['totalVehicles'] as int? ?? 0,
|
||||
availableVehicles: json['availableVehicles'] as int? ?? 0,
|
||||
totalCustomers: json['totalCustomers'] as int? ?? 0,
|
||||
occupancyRate: (json['occupancyRate'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
factory DashboardMetrics.fromJson(Map<String, dynamic> json) {
|
||||
final kpiJson = json['kpis'] as Map<String, dynamic>?;
|
||||
|
||||
factory DashboardMetrics.empty() => const DashboardMetrics(
|
||||
totalReservations: 0,
|
||||
activeReservations: 0,
|
||||
totalRevenue: 0,
|
||||
totalVehicles: 0,
|
||||
availableVehicles: 0,
|
||||
totalCustomers: 0,
|
||||
occupancyRate: 0,
|
||||
return DashboardMetrics(
|
||||
kpis: DashboardKpis.fromJson(kpiJson ?? json),
|
||||
recentReservations: (json['recentReservations'] as List<dynamic>?)
|
||||
?.map(
|
||||
(e) => DashboardRecentReservation.fromJson(
|
||||
e as Map<String, dynamic>,
|
||||
),
|
||||
)
|
||||
.toList() ??
|
||||
const [],
|
||||
sourceBreakdown: (json['sourceBreakdown'] as List<dynamic>?)
|
||||
?.map(
|
||||
(e) => DashboardSourceBreakdown.fromJson(
|
||||
e as Map<String, dynamic>,
|
||||
),
|
||||
)
|
||||
.toList() ??
|
||||
const [],
|
||||
subscription: json['subscription'] is Map<String, dynamic>
|
||||
? DashboardSubscription.fromJson(
|
||||
json['subscription'] as Map<String, dynamic>,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
factory DashboardMetrics.empty() => DashboardMetrics(
|
||||
kpis: DashboardKpis.empty(),
|
||||
recentReservations: const [],
|
||||
sourceBreakdown: const [],
|
||||
subscription: null,
|
||||
);
|
||||
}
|
||||
|
||||
class DashboardKpis {
|
||||
final int totalBookings;
|
||||
final int activeVehicles;
|
||||
final double monthlyRevenue;
|
||||
final int totalCustomers;
|
||||
final double bookingsChange;
|
||||
final double vehiclesChange;
|
||||
final double revenueChange;
|
||||
final double customersChange;
|
||||
|
||||
const DashboardKpis({
|
||||
required this.totalBookings,
|
||||
required this.activeVehicles,
|
||||
required this.monthlyRevenue,
|
||||
required this.totalCustomers,
|
||||
required this.bookingsChange,
|
||||
required this.vehiclesChange,
|
||||
required this.revenueChange,
|
||||
required this.customersChange,
|
||||
});
|
||||
|
||||
factory DashboardKpis.fromJson(Map<String, dynamic> json) => DashboardKpis(
|
||||
totalBookings:
|
||||
(json['totalBookings'] as num?)?.toInt() ??
|
||||
(json['totalReservations'] as num?)?.toInt() ??
|
||||
0,
|
||||
activeVehicles:
|
||||
(json['activeVehicles'] as num?)?.toInt() ??
|
||||
(json['availableVehicles'] as num?)?.toInt() ??
|
||||
(json['totalVehicles'] as num?)?.toInt() ??
|
||||
0,
|
||||
monthlyRevenue:
|
||||
(json['monthlyRevenue'] as num?)?.toDouble() ??
|
||||
(json['totalRevenue'] as num?)?.toDouble() ??
|
||||
0,
|
||||
totalCustomers: (json['totalCustomers'] as num?)?.toInt() ?? 0,
|
||||
bookingsChange: (json['bookingsChange'] as num?)?.toDouble() ?? 0,
|
||||
vehiclesChange: (json['vehiclesChange'] as num?)?.toDouble() ?? 0,
|
||||
revenueChange: (json['revenueChange'] as num?)?.toDouble() ?? 0,
|
||||
customersChange: (json['customersChange'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
|
||||
factory DashboardKpis.empty() => const DashboardKpis(
|
||||
totalBookings: 0,
|
||||
activeVehicles: 0,
|
||||
monthlyRevenue: 0,
|
||||
totalCustomers: 0,
|
||||
bookingsChange: 0,
|
||||
vehiclesChange: 0,
|
||||
revenueChange: 0,
|
||||
customersChange: 0,
|
||||
);
|
||||
}
|
||||
|
||||
class DashboardRecentReservation {
|
||||
final String id;
|
||||
final String bookingRef;
|
||||
final String customerName;
|
||||
final String vehicleName;
|
||||
final DateTime startDate;
|
||||
final DateTime endDate;
|
||||
final String status;
|
||||
final double totalAmount;
|
||||
|
||||
const DashboardRecentReservation({
|
||||
required this.id,
|
||||
required this.bookingRef,
|
||||
required this.customerName,
|
||||
required this.vehicleName,
|
||||
required this.startDate,
|
||||
required this.endDate,
|
||||
required this.status,
|
||||
required this.totalAmount,
|
||||
});
|
||||
|
||||
factory DashboardRecentReservation.fromJson(Map<String, dynamic> json) =>
|
||||
DashboardRecentReservation(
|
||||
id: json['id'] as String,
|
||||
bookingRef: json['bookingRef'] as String? ?? '',
|
||||
customerName: json['customerName'] as String? ?? 'Unknown customer',
|
||||
vehicleName: json['vehicleName'] as String? ?? 'Unknown vehicle',
|
||||
startDate: DateTime.tryParse(json['startDate'] as String? ?? '') ??
|
||||
DateTime.now(),
|
||||
endDate: DateTime.tryParse(json['endDate'] as String? ?? '') ??
|
||||
DateTime.now(),
|
||||
status: json['status'] as String? ?? 'UNKNOWN',
|
||||
totalAmount: (json['totalAmount'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class DashboardSourceBreakdown {
|
||||
final String source;
|
||||
final int count;
|
||||
final double revenue;
|
||||
|
||||
const DashboardSourceBreakdown({
|
||||
required this.source,
|
||||
required this.count,
|
||||
required this.revenue,
|
||||
});
|
||||
|
||||
factory DashboardSourceBreakdown.fromJson(Map<String, dynamic> json) =>
|
||||
DashboardSourceBreakdown(
|
||||
source: json['source'] as String? ?? 'UNKNOWN',
|
||||
count: (json['count'] as num?)?.toInt() ?? 0,
|
||||
revenue: (json['revenue'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
class DashboardSubscription {
|
||||
final String status;
|
||||
final String? planName;
|
||||
final DateTime? trialEndsAt;
|
||||
|
||||
const DashboardSubscription({
|
||||
required this.status,
|
||||
required this.planName,
|
||||
required this.trialEndsAt,
|
||||
});
|
||||
|
||||
factory DashboardSubscription.fromJson(Map<String, dynamic> json) =>
|
||||
DashboardSubscription(
|
||||
status: json['status'] as String? ?? 'ACTIVE',
|
||||
planName: json['planName'] as String?,
|
||||
trialEndsAt: json['trialEndsAt'] == null
|
||||
? null
|
||||
: DateTime.tryParse(json['trialEndsAt'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user