workouttest_util/lib/model/customer_property.dart
2023-01-28 12:53:16 +01:00

70 lines
1.9 KiB
Dart

import 'package:intl/intl.dart';
class CustomerProperty {
int? customerPropertyId;
late int propertyId;
late int customerId;
DateTime? dateAdd;
String? dateYmd;
String? dateYm;
String? dateY;
late double propertyValue;
bool newData = false;
CustomerProperty(
{required this.propertyId,
required this.customerId,
required this.dateAdd,
required this.propertyValue});
CustomerProperty.fromJson(Map json) {
this.customerPropertyId = json['customerPropertyId'];
this.propertyId = json['propertyId'];
this.customerId = json['customerId'];
this.dateAdd = DateTime.parse(json['dateAdd']);
if (this.dateAdd != null) {
dateYmd = DateFormat('yyyy-MM-dd').format(this.dateAdd!);
dateYm = DateFormat('yyyy-MM').format(this.dateAdd!);
dateY = DateFormat('yyyy').format(this.dateAdd!);
}
this.propertyValue = json['propertyValue'];
print("Json $json, ${this.toString()}");
}
Map<String, dynamic> toJson() {
if (customerPropertyId != null) {
return {
"customerPropertyId": this.customerPropertyId,
"propertyId": this.propertyId,
"customerId": this.customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"propertyValue": this.propertyValue
};
} else {
return {
"propertyId": this.propertyId,
"customerId": this.customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"propertyValue": this.propertyValue
};
}
}
String toString() {
Map<String, dynamic> json = {
"customerPropertyId": this.customerPropertyId,
"propertyId": this.propertyId,
"customerId": this.customerId,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(this.dateAdd!),
"propertyValue": this.propertyValue,
"dateYmd": this.dateYmd,
"dateYm": this.dateYm,
"dateY": this.dateY,
};
return json.toString();
}
}