workouttest_util/lib/model/customer_property.dart
2023-02-10 19:48:58 +01:00

72 lines
2.0 KiB
Dart

// ignore: depend_on_referenced_packages
import 'package:intl/intl.dart';
import '../util/logging.dart';
class CustomerProperty with Logging {
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) {
customerPropertyId = json['customerPropertyId'];
propertyId = json['propertyId'];
customerId = json['customerId'];
dateAdd = DateTime.parse(json['dateAdd']);
if (dateAdd != null) {
dateYmd = DateFormat('yyyy-MM-dd').format(dateAdd!);
dateYm = DateFormat('yyyy-MM').format(dateAdd!);
dateY = DateFormat('yyyy').format(dateAdd!);
}
propertyValue = json['propertyValue'];
print("Json $json, ${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();
}
}