import 'package:cloud_firestore/cloud_firestore.dart'; import 'buyer.dart'; import 'do.dart'; import 'po.dart'; import 'role.dart'; import 'user.dart'; class DocLog { String id; String docID; String docType; String ownerID; String ownerName; DateTime date; String actionerID; String actionerName; Map docData; String data; String getDesc(List privileges) { if (docType == "po") { return getPO().status; } else if (docType == "do") { return getDO().status; } else if (docType == "buyer") { return getBuyer().status; } else if (docType == "user") { User user=getUser(); return "${user.status}\nprivileges:${user.getLogDesc(privileges)}"; } return "-"; } DocLog( {this.id, this.docID, this.docType, this.date, this.ownerID, this.ownerName, this.actionerID, this.actionerName, this.docData}); factory DocLog.fromMap(Map map, String id) { var date = (map['date'] as Timestamp); return DocLog( id: id, docID: map['doc_id'], docType: map['doc_type'], ownerID: map['owner_id'], ownerName: map['owner_name'], actionerID: map['actioner_id'], actionerName: map['actioner_name'], date: date == null ? null : date.toDate(), docData: map['doc_data'], ); } Buyer getBuyer() { return Buyer.fromMap(docData.cast(), docID); } POSubmission getPO() { return POSubmission.fromMap(docData.cast(), docID); } DOSubmission getDO() { return DOSubmission.fromMap(docData.cast(), docID); } User getUser() { return User.fromMap(docData.cast(), docID); } }