Update: 2026-08-08 12:58:16
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
// fuel_admin_models.dart — نماذج بيانات محفظة الوقود (لوحة إدارة سيرو)
|
||||
|
||||
class FuelStation {
|
||||
final int id;
|
||||
final String nameAr;
|
||||
final String? chainName;
|
||||
final String? city;
|
||||
final String? address;
|
||||
final double? lat;
|
||||
final double? lng;
|
||||
final String? phone;
|
||||
final double discountPercent;
|
||||
final bool isActive;
|
||||
|
||||
/// أرقام الأداء: محطة بلا صرف اسمٌ في جدول لا شريك يعمل.
|
||||
final int redeemCount;
|
||||
final double redeemTotal;
|
||||
final String? lastRedeemAt;
|
||||
|
||||
FuelStation({
|
||||
required this.id,
|
||||
required this.nameAr,
|
||||
required this.discountPercent,
|
||||
required this.isActive,
|
||||
this.chainName,
|
||||
this.city,
|
||||
this.address,
|
||||
this.lat,
|
||||
this.lng,
|
||||
this.phone,
|
||||
this.redeemCount = 0,
|
||||
this.redeemTotal = 0,
|
||||
this.lastRedeemAt,
|
||||
});
|
||||
|
||||
factory FuelStation.fromJson(Map<String, dynamic> j) => FuelStation(
|
||||
id: int.tryParse(j['id'].toString()) ?? 0,
|
||||
nameAr: j['name_ar']?.toString() ?? '',
|
||||
chainName: j['chain_name']?.toString(),
|
||||
city: j['city']?.toString(),
|
||||
address: j['address']?.toString(),
|
||||
lat: double.tryParse(j['lat']?.toString() ?? ''),
|
||||
lng: double.tryParse(j['lng']?.toString() ?? ''),
|
||||
phone: j['phone']?.toString(),
|
||||
discountPercent:
|
||||
double.tryParse(j['discount_percent']?.toString() ?? '0') ?? 0,
|
||||
isActive: j['is_active'] == true,
|
||||
redeemCount: int.tryParse(j['redeem_count']?.toString() ?? '0') ?? 0,
|
||||
redeemTotal: double.tryParse(j['redeem_total']?.toString() ?? '0') ?? 0,
|
||||
lastRedeemAt: j['last_redeem_at']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
class FuelStationsPage {
|
||||
final List<FuelStation> stations;
|
||||
|
||||
/// حالة المنتج نفسه. قرار المالك: تُجهَّز الشاشات ولا يُشغَّل المنتج إلا
|
||||
/// بعد إتمام الاتفاق مع سلسلة المحطات — فالشاشة تعمل كاملةً بينما
|
||||
/// المنتج مُطفأ، والفرق يجب أن يكون ظاهراً لا مخفياً.
|
||||
final bool productActive;
|
||||
|
||||
FuelStationsPage({required this.stations, required this.productActive});
|
||||
|
||||
factory FuelStationsPage.fromJson(Map<String, dynamic> j) => FuelStationsPage(
|
||||
stations: (j['stations'] is List)
|
||||
? (j['stations'] as List)
|
||||
.map((s) => FuelStation.fromJson(Map<String, dynamic>.from(s)))
|
||||
.toList()
|
||||
: <FuelStation>[],
|
||||
productActive: j['product_active'] == true,
|
||||
);
|
||||
}
|
||||
|
||||
class FuelVoucher {
|
||||
final int id;
|
||||
final String driverId;
|
||||
final String code;
|
||||
final double amountAuthorized;
|
||||
final double amountRedeemed;
|
||||
final String currency;
|
||||
final String status;
|
||||
final String? station;
|
||||
final String? redeemedAt;
|
||||
final String? createdAt;
|
||||
|
||||
FuelVoucher({
|
||||
required this.id,
|
||||
required this.driverId,
|
||||
required this.code,
|
||||
required this.amountAuthorized,
|
||||
required this.amountRedeemed,
|
||||
required this.currency,
|
||||
required this.status,
|
||||
this.station,
|
||||
this.redeemedAt,
|
||||
this.createdAt,
|
||||
});
|
||||
|
||||
factory FuelVoucher.fromJson(Map<String, dynamic> j) => FuelVoucher(
|
||||
id: int.tryParse(j['id'].toString()) ?? 0,
|
||||
driverId: j['driver_id']?.toString() ?? '',
|
||||
code: j['code']?.toString() ?? '',
|
||||
amountAuthorized:
|
||||
double.tryParse(j['amount_authorized']?.toString() ?? '0') ?? 0,
|
||||
amountRedeemed:
|
||||
double.tryParse(j['amount_redeemed']?.toString() ?? '0') ?? 0,
|
||||
currency: j['currency']?.toString() ?? '',
|
||||
status: j['status']?.toString() ?? '',
|
||||
station: j['station']?.toString(),
|
||||
redeemedAt: j['redeemed_at']?.toString(),
|
||||
createdAt: j['created_at']?.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
class FuelDrawdownsPage {
|
||||
final List<FuelVoucher> vouchers;
|
||||
final double lentTotal;
|
||||
final double collectedTotal;
|
||||
final double outstandingTotal;
|
||||
final int driversCount;
|
||||
|
||||
FuelDrawdownsPage({
|
||||
required this.vouchers,
|
||||
required this.lentTotal,
|
||||
required this.collectedTotal,
|
||||
required this.outstandingTotal,
|
||||
required this.driversCount,
|
||||
});
|
||||
|
||||
factory FuelDrawdownsPage.fromJson(Map<String, dynamic> j) {
|
||||
final s = Map<String, dynamic>.from(j['summary'] ?? {});
|
||||
return FuelDrawdownsPage(
|
||||
vouchers: (j['vouchers'] is List)
|
||||
? (j['vouchers'] as List)
|
||||
.map((v) => FuelVoucher.fromJson(Map<String, dynamic>.from(v)))
|
||||
.toList()
|
||||
: <FuelVoucher>[],
|
||||
lentTotal: double.tryParse(s['lent_total']?.toString() ?? '0') ?? 0,
|
||||
collectedTotal:
|
||||
double.tryParse(s['collected_total']?.toString() ?? '0') ?? 0,
|
||||
outstandingTotal:
|
||||
double.tryParse(s['outstanding_total']?.toString() ?? '0') ?? 0,
|
||||
driversCount: int.tryParse(s['drivers_count']?.toString() ?? '0') ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user