v1.0.12 customer properties and membership

This commit is contained in:
Tibor Bossanyi
2023-03-01 17:44:41 +01:00
parent 6ac35b67ab
commit 31717c6c5e
9 changed files with 193 additions and 25 deletions
+11
View File
@@ -1,5 +1,6 @@
import 'dart:collection';
import 'package:intl/intl.dart';
import 'package:workouttest_util/model/customer_membership.dart';
import 'customer_property.dart';
@@ -31,6 +32,8 @@ class Customer {
int? lifeLong;
LinkedHashMap<String, CustomerProperty> properties = LinkedHashMap();
List<CustomerProperty> customerProperties = [];
List<CustomerMembership> memberships = [];
Customer(
{customerId,
@@ -83,6 +86,14 @@ class Customer {
dateAdd = json['dateAdd'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateAdd']);
dateChange = json['dateChange'] == null ? DateTime.parse("0000-00-00") : DateTime.parse(json['dateChange']);
if (json['properties'] != null && json['properties'].length > 0) {
customerProperties = json['properties'].map<CustomerProperty>((detail) => CustomerProperty.fromJson(detail)).toList();
}
if (json['memberships'] != null && json['memberships'].length > 0) {
memberships = json['memberships'].map<CustomerMembership>((detail) => CustomerMembership.fromJson(detail)).toList();
}
}
Map<String, dynamic> toJson() => {
+13 -12
View File
@@ -1,21 +1,22 @@
import 'package:intl/intl.dart';
class CustomerMembership {
late int membershipId;
late int customerId;
late DateTime startDate;
int? customerId;
DateTime? startDate;
CustomerMembership.fromJson(Map json) {
membershipId = json['membershipId'];
customerId = json['customerId'];
startDate = json['startDate'];
customerId = json['customerId'] ?? 0;
startDate = json['startDate'] == null ? null : DateTime.parse(json['startDate']);
}
Map<String, dynamic> toJson() => {
"membershipId": membershipId,
"customerId": customerId,
"startDate": startDate,
};
Map<String, dynamic> toJson() => {
"membershipId": membershipId,
"customerId": customerId ?? 0,
"startDate": startDate == null ? "" : DateFormat('yyyy-MM-dd HH:mm:ss').format(startDate!),
};
@override
String toString() => toJson().toString();
}
String toString() => toJson().toString();
}
+5 -9
View File
@@ -4,7 +4,7 @@ import '../util/logging.dart';
class CustomerProperty with Logging {
int? customerPropertyId;
late int propertyId;
late int customerId;
int? customerId;
DateTime? dateAdd;
String? dateYmd;
String? dateYm;
@@ -12,16 +12,12 @@ class CustomerProperty with Logging {
late double propertyValue;
bool newData = false;
CustomerProperty(
{required propertyId,
required customerId,
required dateAdd,
required propertyValue});
CustomerProperty({required propertyId, required customerId, required dateAdd, required propertyValue});
CustomerProperty.fromJson(Map json) {
customerPropertyId = json['customerPropertyId'];
propertyId = json['propertyId'];
customerId = json['customerId'];
customerId = json['customerId'] ?? 0;
dateAdd = DateTime.parse(json['dateAdd']);
if (dateAdd != null) {
@@ -40,14 +36,14 @@ class CustomerProperty with Logging {
return {
"customerPropertyId": customerPropertyId,
"propertyId": propertyId,
"customerId": customerId,
"customerId": customerId ?? 0,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
"propertyValue": propertyValue
};
} else {
return {
"propertyId": propertyId,
"customerId": customerId,
"customerId": customerId ?? 0,
"dateAdd": DateFormat('yyyy-MM-dd HH:mm:ss').format(dateAdd!),
"propertyValue": propertyValue
};
+30
View File
@@ -566,4 +566,34 @@ class CustomerRepository with Logging {
}
return allProperties;
}
void initCustomerProperties() {
List<Property>? properties = Cache().getProperties();
Customer? customer = Cache().userLoggedIn;
if (customer == null || customer.customerProperties.isEmpty || properties == null) {
return;
}
for (var property in properties) {
CustomerProperty? customerProperty = getCustomerPropertyById(property.propertyId);
if (customerProperty != null) {
customer.properties[property.propertyName] = customerProperty;
}
}
}
CustomerProperty? getCustomerPropertyById(int id) {
CustomerProperty? property;
Customer? customer = Cache().userLoggedIn;
if (customer == null) {
return property;
}
for (var customerProperty in customer.customerProperties) {
if (customerProperty.propertyId == id) {
property = customerProperty;
break;
}
}
return property;
}
}