This commit is contained in:
PhyoThandar
2020-10-16 13:46:02 +06:30
parent ff12b2c24b
commit 0e9e3da0c4
7 changed files with 154 additions and 21 deletions

View File

@@ -20,16 +20,29 @@ import 'invoice_editor.dart';
import 'invoice_list_row.dart';
class InvoiceList extends StatefulWidget {
final bool onlyFcs;
const InvoiceList({Key key, this.onlyFcs}) : super(key: key);
@override
_InvoiceListState createState() => _InvoiceListState();
}
class _InvoiceListState extends State<InvoiceList> {
bool _isLoading = false;
bool _showPaid = false;
var _controller = ScrollController();
@override
void initState() {
super.initState();
// Provider.of<InvoiceModel>(context, listen: false).initPaidInvoice(true);
// _controller.addListener(() {
// if (_showPaid &&
// _controller.position.pixels == _controller.position.maxScrollExtent) {
// Provider.of<InvoiceModel>(context, listen: false)
// .loadMorePaidInvoices();
// }
// });
}
@override
@@ -41,6 +54,9 @@ class _InvoiceListState extends State<InvoiceList> {
Widget build(BuildContext context) {
var owner = true;
var invoiceModel = Provider.of<InvoiceModel>(context);
bool onlyFcs = widget.onlyFcs;
var invoices =
_showPaid ? invoiceModel.paidInvoices : invoiceModel.invoices;
final popupMenu = LocalPopupMenuButton(
popmenus: [
@@ -49,7 +65,7 @@ class _InvoiceListState extends State<InvoiceList> {
LocalPopupMenu(id: 2, textKey: "invoice.popupmenu.paid")
],
popupMenuCallback: (p) => this.setState(() {
// _showDelivered = p.id == 2;
_showPaid = p.id == 2;
}),
);
@@ -95,10 +111,9 @@ class _InvoiceListState extends State<InvoiceList> {
scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 15),
shrinkWrap: true,
itemCount: invoiceModel.invoices.length,
itemCount: invoices.length,
itemBuilder: (BuildContext context, int index) {
return InvoiceListRow(
invoice: invoiceModel.invoices[index]);
return InvoiceListRow(invoice: invoices[index]);
}),
),
],

View File

@@ -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);
}
}

View File

@@ -5,6 +5,7 @@ import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
import 'package:image_downloader/image_downloader.dart';
class PaymentPDFScreen extends StatefulWidget {
final String path;
@@ -39,7 +40,11 @@ class _PaymentPDFScreenState extends State<PaymentPDFScreen>
actions: <Widget>[
IconButton(
icon: Icon(Icons.file_download),
onPressed: () {},
onPressed: () async {
print('image path => ${widget.path}');
await ImageDownloader.downloadImage(widget.path,
destination: AndroidDestinationType.directoryDownloads);
},
),
IconButton(
icon: Icon(Icons.share),