55 lines
1.8 KiB
Dart
55 lines
1.8 KiB
Dart
class CommodityRateHistory {
|
|
final int? id;
|
|
final String commodityCode;
|
|
final String? commodityName;
|
|
final String? purity;
|
|
final double rate;
|
|
final DateTime effectiveAt;
|
|
final String? source;
|
|
final int? createdBy;
|
|
final DateTime? createdAt;
|
|
|
|
CommodityRateHistory({
|
|
this.id,
|
|
required this.commodityCode,
|
|
this.commodityName,
|
|
this.purity,
|
|
required this.rate,
|
|
required this.effectiveAt,
|
|
this.source,
|
|
this.createdBy,
|
|
this.createdAt,
|
|
});
|
|
|
|
factory CommodityRateHistory.fromJson(Map<String, dynamic> json) {
|
|
return CommodityRateHistory(
|
|
id: json['id'] is int ? json['id'] : int.tryParse(json['id']?.toString() ?? ''),
|
|
commodityCode: (json['commodityCode'] ?? json['commodity_code'] ?? json['commodityName'] ?? json['commodity_name'] ?? '').toString(),
|
|
commodityName: json['commodityName'] ?? json['commodity_name'],
|
|
purity: json['purity'],
|
|
rate: (json['rate'] as num?)?.toDouble() ?? 0.0,
|
|
effectiveAt: json['effectiveAt'] != null
|
|
? DateTime.parse(json['effectiveAt'].toString())
|
|
: (json['effective_at'] != null ? DateTime.parse(json['effective_at'].toString()) : DateTime.now()),
|
|
source: json['source'],
|
|
createdBy: json['createdBy'] ?? json['created_by'],
|
|
createdAt: json['createdAt'] != null
|
|
? DateTime.parse(json['createdAt'].toString())
|
|
: (json['created_at'] != null ? DateTime.parse(json['created_at'].toString()) : null),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
if (id != null) 'id': id,
|
|
'commodityCode': commodityCode,
|
|
'commodityName': commodityName ?? commodityCode,
|
|
if (purity != null) 'purity': purity,
|
|
'rate': rate,
|
|
'effectiveAt': effectiveAt.toIso8601String(),
|
|
if (source != null) 'source': source,
|
|
if (createdBy != null) 'createdBy': createdBy,
|
|
};
|
|
}
|
|
}
|