merge
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package.dart';
|
||||
import 'receipt.dart';
|
||||
|
||||
class Invoice {
|
||||
String id;
|
||||
String invoiceNumber;
|
||||
DateTime invoiceDate;
|
||||
String customerName;
|
||||
@@ -16,7 +17,8 @@ class Invoice {
|
||||
List<String> receiptPhotos;
|
||||
|
||||
Invoice(
|
||||
{this.invoiceNumber,
|
||||
{this.id,
|
||||
this.invoiceNumber,
|
||||
this.invoiceDate,
|
||||
this.customerName,
|
||||
this.customerPhoneNumber,
|
||||
@@ -29,4 +31,21 @@ class Invoice {
|
||||
this.receipts});
|
||||
|
||||
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p);
|
||||
|
||||
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
|
||||
return Invoice(
|
||||
id: docID,
|
||||
invoiceNumber: map['invoice_number'],
|
||||
invoiceDate: map['invoice_date'],
|
||||
customerName: map['customer_name'],
|
||||
customerPhoneNumber: map['phone_number'],
|
||||
amount: map['amount'],
|
||||
status: map['status'],
|
||||
discount: map['discount'],
|
||||
paymentAttachment: map['payment_attachment'],
|
||||
packages: map['packages'],
|
||||
receiptPhotos: map['receiptPhotos'],
|
||||
receipts: map['receipts'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -297,8 +297,8 @@ class _HomePageState extends State<HomePage> {
|
||||
CupertinoPageRoute(builder: (context) => InvoiceList())));
|
||||
final invoicesBtnFcs = TaskButton("invoices.btn",
|
||||
icon: FontAwesomeIcons.fileInvoice,
|
||||
btnCallback: () => Navigator.of(context).push<void>(
|
||||
CupertinoPageRoute(builder: (context) => InvoiceList())));
|
||||
btnCallback: () => Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) => InvoiceList(onlyFcs: true))));
|
||||
|
||||
final discountBtn = TaskButton("discount.btn",
|
||||
icon: Entypo.price_ribbon,
|
||||
|
||||
@@ -108,6 +108,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
CustomDuty _customduty = CustomDuty(
|
||||
productType: _productController.text,
|
||||
fee: double.parse(_feeController.text));
|
||||
print('_customduty => $_customduty');
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCustomDuty(_customduty);
|
||||
} else {
|
||||
@@ -125,8 +126,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
}
|
||||
|
||||
_delete() {
|
||||
showConfirmDialog(
|
||||
context, "cargo.edit.delete.confirm", _deleteCustomDuty);
|
||||
showConfirmDialog(context, "cargo.edit.delete.confirm", _deleteCustomDuty);
|
||||
}
|
||||
|
||||
_deleteCustomDuty() async {
|
||||
|
||||
@@ -307,10 +307,12 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
Rate _rate = Rate(
|
||||
Rate _rate = new Rate(
|
||||
deliveryFee: double.parse(_deliveryFee.text),
|
||||
freeDeliveryWeight: double.parse(_minWeight.text),
|
||||
volumetricRatio: double.parse(_volumetricRatio.text));
|
||||
Rate r = new Rate();
|
||||
print('_rate =>$r');
|
||||
await shipmentRateModel.updateRate(_rate);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user