// 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 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 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(); } }