You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/models/gas_refill/gas_refill_model.dart

82 lines
2.5 KiB
Dart

3 years ago
import 'package:test_sa/models/gas_refill/gas_refill_details.dart';
import 'package:test_sa/models/lookup.dart';
3 years ago
import '../call_request_for_work_order_model.dart';
class GasRefillModel {
3 years ago
int id;
//String userId;
3 years ago
String clientName;
String title;
Lookup status;
2 years ago
Lookup building;
Lookup floor;
Department department;
3 years ago
List<GasRefillDetails> details;
DateTime startDate, endDate, expectedDate;
3 years ago
GasRefillModel({
this.id,
3 years ago
//this.userId,
3 years ago
this.clientName,
this.title,
this.status,
this.details,
this.building,
this.floor,
this.startDate,
this.endDate,
this.expectedDate,
this.department,
3 years ago
});
bool validate() {
if (title == null) return false;
if (status == null) return false;
// if (building == null) return false;
// if (floor == null) return false;
// if (department == null) return false;
// if (startDate == null) return false;
// if (endDate == null) return false;
if (details == null && details.isEmpty) return false;
3 years ago
return true;
}
fromGasRefillModel(GasRefillModel model) {
3 years ago
id = model.id;
3 years ago
//userId = model.userId;
3 years ago
clientName = model.clientName;
title = model.title;
status = Lookup.fromStatus(model.status);
3 years ago
details = model.details.map((e) => GasRefillDetails.fromDetails(e)).toList();
building = model.building;
floor = model.floor;
department = model.department;
startDate = model.startDate;
endDate = model.endDate;
expectedDate = model.expectedDate;
3 years ago
}
factory GasRefillModel.fromJson(Map<String, dynamic> parsedJson) {
3 years ago
List<GasRefillDetails> details = [];
if (parsedJson["gazRefillDetails"] != null) {
3 years ago
List list = parsedJson["gazRefillDetails"];
3 years ago
details = list.map((e) => GasRefillDetails.fromJson(e)).toList();
}
return GasRefillModel(
id: parsedJson["id"],
3 years ago
//userId: parsedJson["uid"],
title: parsedJson["gazRefillNo"],
clientName: parsedJson["site"] == null ? null : parsedJson["site"]["custName"],
status: Lookup.fromJson(parsedJson["status"] ?? {}),
3 years ago
details: details,
building: Lookup.fromJson(parsedJson["building"] ?? {}),
floor: Lookup.fromJson(parsedJson["floor"] ?? {}),
department: Department.fromJson(parsedJson["department"] ?? {}),
startDate: DateTime.tryParse(parsedJson['startDate'] ?? ""),
endDate: DateTime.tryParse(parsedJson['endDate'] ?? ""),
expectedDate: DateTime.tryParse(parsedJson['expectedDate'] ?? ""),
3 years ago
);
}
}