Files
fcs/lib/domain/entities/pickup.dart

148 lines
3.9 KiB
Dart
Raw Normal View History

2021-09-14 11:03:03 +06:30
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:fcs/domain/entities/package.dart';
2021-10-09 17:08:28 +06:30
import 'package:fcs/domain/vo/delivery_address.dart';
2021-09-14 11:03:03 +06:30
class Pickup {
String? id;
DateTime? pickupDate;
2021-10-09 17:08:28 +06:30
String? pickupNumber;
DateTime? fromTime;
DateTime? toTime;
//for customer
String? customerID;
String? customerName;
String? customerRemark;
2021-09-14 11:03:03 +06:30
String? staffId;
String? staffName;
String? staffPhoneNumber;
2021-10-09 17:08:28 +06:30
2021-09-14 11:03:03 +06:30
String? fcsID;
String? status;
2021-10-09 17:08:28 +06:30
String? rescheduleRemark;
String? zoneID;
String? zoneName;
DeliveryAddress? pickupAddress;
2021-09-14 11:03:03 +06:30
2021-10-09 09:27:51 +06:30
// for complete
String? completeRemark;
List<String> photoUrls;
2021-09-14 11:03:03 +06:30
List<Package> packages;
Pickup(
{this.id,
2021-10-09 17:08:28 +06:30
this.customerID,
this.customerName,
2021-09-14 11:03:03 +06:30
this.staffId,
this.staffName,
this.staffPhoneNumber,
this.pickupDate,
this.fromTime,
this.toTime,
this.fcsID,
this.status,
2021-10-09 09:27:51 +06:30
this.packages = const [],
2021-10-09 17:08:28 +06:30
this.photoUrls = const [],
this.completeRemark,
this.customerRemark,
this.pickupNumber,
this.rescheduleRemark,
this.zoneID,
this.zoneName,
this.pickupAddress});
2021-09-14 11:03:03 +06:30
@override
bool operator ==(Object other) => other is Pickup && other.id == id;
@override
int get hashCode => id.hashCode;
2021-10-09 17:08:28 +06:30
bool isChangedForEdit(Pickup pickup) {
return pickup.completeRemark != this.completeRemark;
2021-09-14 11:03:03 +06:30
}
factory Pickup.fromMap(Map<String, dynamic> map, String id) {
var _pickupDate = (map['pickup_date'] as Timestamp);
2021-10-09 17:08:28 +06:30
var _fromTime = map['pickup_time_from'] == null
? null
: (map['pickup_time_from'] as Timestamp);
var _toTime = map['pickup_time_to'] == null
? null
: (map['pickup_time_to'] as Timestamp);
var da = map['pickup_address'];
var _da = da != null ? DeliveryAddress.fromMap(da, da["id"]) : null;
List<String> _photoUrls =
map['photo_urls'] == null ? [] : List.from(map['photo_urls']);
2021-09-14 11:03:03 +06:30
return Pickup(
id: id,
2021-10-09 17:08:28 +06:30
pickupDate: _pickupDate.toDate().toLocal(),
pickupNumber: map['pickup_number'],
pickupAddress: _da,
fromTime: _fromTime?.toDate().toLocal() ?? null,
toTime: _toTime?.toDate().toLocal() ?? null,
staffId: map['pickup_staff_id'],
staffName: map['pickup_staff_name'],
customerID: map['customer_id'],
customerName: map['customer_name'],
customerRemark: map['customer_remark'] ?? "",
completeRemark: map['complete_remark'] ?? "",
rescheduleRemark: map['reschedule_remark'],
zoneID: map['zone_id'],
zoneName: map['zone_name'],
status: map['status'],
photoUrls: _photoUrls);
}
factory Pickup.fromJson(Map<String, dynamic> json) {
return Pickup(
id: json['id'],
pickupDate: DateTime.parse(json['pickup_date']),
pickupNumber: json['pickup_number'],
fromTime: DateTime.parse(json['pickup_date']),
toTime: DateTime.parse(json['pickup_date']),
staffId: json['pickup_staff_id'],
staffName: json['pickup_staff_name'],
customerID: json['customer_id'],
customerName: json['customer_name'],
customerRemark: json['customer_remark'] ?? "",
completeRemark: json['complete_remark'] ?? "",
rescheduleRemark: json['reschedule_remark'],
zoneID: json['zone_id'],
zoneName: json['zone_name'],
status: json['status'],
);
2021-09-14 11:03:03 +06:30
}
Map<String, dynamic> toMap() {
return {
"id": id,
"pickup_date": pickupDate?.toUtc().toIso8601String(),
'from_time': fromTime,
'to_time': toTime,
'staff_id': staffId,
'staff_name': staffName,
"staff_phone_number": staffPhoneNumber,
2021-10-09 17:08:28 +06:30
'user_id': customerID,
'user_name': customerName,
2021-09-14 11:03:03 +06:30
'status': status,
};
}
2021-10-09 09:27:51 +06:30
Map<String, dynamic> toMapForComplete() {
return {
"id": id,
"complete_remark": completeRemark,
2021-10-09 17:08:28 +06:30
'photo_urls': photoUrls,
2021-10-09 09:27:51 +06:30
};
}
2021-09-14 11:03:03 +06:30
@override
String toString() {
return 'Pickup{id: $id}';
}
}