merge
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/domain/entities/receipt.dart';
|
||||
import 'package:fcs/helpers/pagination.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
||||
class InvoiceModel extends BaseModel {
|
||||
final log = Logger('InvoiceModel');
|
||||
|
||||
Pagination pagination;
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
|
||||
List<Invoice> invoices = [
|
||||
Invoice(
|
||||
invoiceNumber: 'A092(A)-30',
|
||||
@@ -137,19 +147,92 @@ class InvoiceModel extends BaseModel {
|
||||
])
|
||||
];
|
||||
|
||||
List<Invoice> get pending {
|
||||
List<Invoice> _i = invoices.where((e) => e.status == "Pending").toList()
|
||||
..sort((e1, e2) {
|
||||
return e2.invoiceNumber.compareTo(e1.invoiceNumber);
|
||||
});
|
||||
return _i;
|
||||
List<Invoice> paidInvoices = [];
|
||||
|
||||
bool endOfPaidInvoices = false;
|
||||
bool isLoading = false;
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
super.privilegeChanged();
|
||||
// _loadInvoices();
|
||||
}
|
||||
|
||||
List<Invoice> get paided {
|
||||
return invoices.where((e) => e.status == "Paid").toList()
|
||||
..sort((e1, e2) {
|
||||
return e2.invoiceNumber.compareTo(e1.invoiceNumber);
|
||||
Future<void> _loadInvoices() async {
|
||||
if (user == null || !user.hasInvoices()) return;
|
||||
String path = "/$invoices/";
|
||||
if (listener != null) listener.cancel();
|
||||
invoices = [];
|
||||
try {
|
||||
listener = Firestore.instance
|
||||
.collection("$path")
|
||||
.snapshots()
|
||||
.listen((QuerySnapshot snapshot) {
|
||||
invoices.clear();
|
||||
invoices = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Invoice.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> initPaidInvoice(bool onlyFcs) {
|
||||
if (onlyFcs) {
|
||||
if (user == null ||
|
||||
!((user.hasPackages() ||
|
||||
user.hasReceiving() ||
|
||||
user.hasProcessing()))) return null;
|
||||
}
|
||||
if (pagination != null) pagination.close();
|
||||
paidInvoices = [];
|
||||
endOfPaidInvoices = false;
|
||||
isLoading = false;
|
||||
|
||||
var pageQuery = Firestore.instance
|
||||
.collection("/$invoices");
|
||||
// .collection(
|
||||
// "/users/8OTfsbVvsUOn1SLxy1OrKk7Y_yNKkVoGalPcIlcHnAY/messages")
|
||||
// .orderBy("date", descending: true);
|
||||
// .where("is_delivered", isEqualTo: true)
|
||||
// .where("is_deleted", isEqualTo: false);
|
||||
if (!onlyFcs) {
|
||||
pageQuery = pageQuery.where("user_id", isEqualTo: user.id);
|
||||
}
|
||||
// pageQuery = pageQuery.orderBy("current_status_date", descending: true);
|
||||
pagination = new Pagination(pageQuery, rowPerLoad: 20);
|
||||
pagination.stream.listen((doc) {
|
||||
if (doc == null) {
|
||||
endOfPaidInvoices = true;
|
||||
} else {
|
||||
paidInvoices.add(Invoice.fromMap(doc.data, doc.documentID));
|
||||
// var m = Message.fromMap(doc.data, doc.documentID);
|
||||
// deliveredPackages.add(Package(
|
||||
// id: m.id,
|
||||
// status: package_delivered_status,
|
||||
// currentStatus: package_delivered_status,
|
||||
// currentStatusDate: m.date,
|
||||
// trackingID: (count++).toString(),
|
||||
// market: m.message));
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<bool> loadMorePaidInvoices() {
|
||||
if (pagination != null && !isLoading && !endOfPaidInvoices) {
|
||||
isLoading = true;
|
||||
notifyListeners();
|
||||
pagination.load().then((value) {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void initUser(user) {
|
||||
@@ -158,6 +241,15 @@ class InvoiceModel extends BaseModel {
|
||||
|
||||
@override
|
||||
logout() async {
|
||||
if (listener != null) await listener.cancel();
|
||||
invoices = [];
|
||||
}
|
||||
|
||||
Future<void> create(Invoice invoice) {
|
||||
// return Services.instance.fcsShipmentService.createFcsShipment(fcsShipment);
|
||||
}
|
||||
|
||||
Future<void> update(Invoice invoice) {
|
||||
// return Services.instance.fcsShipmentService.updateFcsShipment(fcsShipment);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user