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

@@ -2,6 +2,7 @@ import 'package.dart';
import 'receipt.dart'; import 'receipt.dart';
class Invoice { class Invoice {
String id;
String invoiceNumber; String invoiceNumber;
DateTime invoiceDate; DateTime invoiceDate;
String customerName; String customerName;
@@ -16,7 +17,8 @@ class Invoice {
List<String> receiptPhotos; List<String> receiptPhotos;
Invoice( Invoice(
{this.invoiceNumber, {this.id,
this.invoiceNumber,
this.invoiceDate, this.invoiceDate,
this.customerName, this.customerName,
this.customerPhoneNumber, this.customerPhoneNumber,
@@ -29,4 +31,21 @@ class Invoice {
this.receipts}); this.receipts});
double get getAmount => packages.fold(0, (p, e) => (e.rate * e.weight) + p); 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'],
);
}
} }

View File

@@ -20,16 +20,29 @@ import 'invoice_editor.dart';
import 'invoice_list_row.dart'; import 'invoice_list_row.dart';
class InvoiceList extends StatefulWidget { class InvoiceList extends StatefulWidget {
final bool onlyFcs;
const InvoiceList({Key key, this.onlyFcs}) : super(key: key);
@override @override
_InvoiceListState createState() => _InvoiceListState(); _InvoiceListState createState() => _InvoiceListState();
} }
class _InvoiceListState extends State<InvoiceList> { class _InvoiceListState extends State<InvoiceList> {
bool _isLoading = false; bool _isLoading = false;
bool _showPaid = false;
var _controller = ScrollController();
@override @override
void initState() { void initState() {
super.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 @override
@@ -41,6 +54,9 @@ class _InvoiceListState extends State<InvoiceList> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
var owner = true; var owner = true;
var invoiceModel = Provider.of<InvoiceModel>(context); var invoiceModel = Provider.of<InvoiceModel>(context);
bool onlyFcs = widget.onlyFcs;
var invoices =
_showPaid ? invoiceModel.paidInvoices : invoiceModel.invoices;
final popupMenu = LocalPopupMenuButton( final popupMenu = LocalPopupMenuButton(
popmenus: [ popmenus: [
@@ -49,7 +65,7 @@ class _InvoiceListState extends State<InvoiceList> {
LocalPopupMenu(id: 2, textKey: "invoice.popupmenu.paid") LocalPopupMenu(id: 2, textKey: "invoice.popupmenu.paid")
], ],
popupMenuCallback: (p) => this.setState(() { popupMenuCallback: (p) => this.setState(() {
// _showDelivered = p.id == 2; _showPaid = p.id == 2;
}), }),
); );
@@ -95,10 +111,9 @@ class _InvoiceListState extends State<InvoiceList> {
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
padding: EdgeInsets.only(top: 15), padding: EdgeInsets.only(top: 15),
shrinkWrap: true, shrinkWrap: true,
itemCount: invoiceModel.invoices.length, itemCount: invoices.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return InvoiceListRow( return InvoiceListRow(invoice: invoices[index]);
invoice: invoiceModel.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/invoice.dart';
import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/domain/entities/package.dart';
import 'package:fcs/domain/entities/receipt.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:fcs/pages/main/model/base_model.dart';
import 'package:logging/logging.dart';
class InvoiceModel extends BaseModel { class InvoiceModel extends BaseModel {
final log = Logger('InvoiceModel');
Pagination pagination;
StreamSubscription<QuerySnapshot> listener;
List<Invoice> invoices = [ List<Invoice> invoices = [
Invoice( Invoice(
invoiceNumber: 'A092(A)-30', invoiceNumber: 'A092(A)-30',
@@ -137,19 +147,92 @@ class InvoiceModel extends BaseModel {
]) ])
]; ];
List<Invoice> get pending { List<Invoice> paidInvoices = [];
List<Invoice> _i = invoices.where((e) => e.status == "Pending").toList()
..sort((e1, e2) { bool endOfPaidInvoices = false;
return e2.invoiceNumber.compareTo(e1.invoiceNumber); bool isLoading = false;
});
return _i; @override
void privilegeChanged() {
super.privilegeChanged();
// _loadInvoices();
} }
List<Invoice> get paided { Future<void> _loadInvoices() async {
return invoices.where((e) => e.status == "Paid").toList() if (user == null || !user.hasInvoices()) return;
..sort((e1, e2) { String path = "/$invoices/";
return e2.invoiceNumber.compareTo(e1.invoiceNumber); 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) { void initUser(user) {
@@ -158,6 +241,15 @@ class InvoiceModel extends BaseModel {
@override @override
logout() async { logout() async {
if (listener != null) await listener.cancel();
invoices = []; 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/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart'; import 'package:flutter_pdfview/flutter_pdfview.dart';
import 'package:image_downloader/image_downloader.dart';
class PaymentPDFScreen extends StatefulWidget { class PaymentPDFScreen extends StatefulWidget {
final String path; final String path;
@@ -39,7 +40,11 @@ class _PaymentPDFScreenState extends State<PaymentPDFScreen>
actions: <Widget>[ actions: <Widget>[
IconButton( IconButton(
icon: Icon(Icons.file_download), icon: Icon(Icons.file_download),
onPressed: () {}, onPressed: () async {
print('image path => ${widget.path}');
await ImageDownloader.downloadImage(widget.path,
destination: AndroidDestinationType.directoryDownloads);
},
), ),
IconButton( IconButton(
icon: Icon(Icons.share), icon: Icon(Icons.share),

View File

@@ -297,8 +297,8 @@ class _HomePageState extends State<HomePage> {
CupertinoPageRoute(builder: (context) => InvoiceList()))); CupertinoPageRoute(builder: (context) => InvoiceList())));
final invoicesBtnFcs = TaskButton("invoices.btn", final invoicesBtnFcs = TaskButton("invoices.btn",
icon: FontAwesomeIcons.fileInvoice, icon: FontAwesomeIcons.fileInvoice,
btnCallback: () => Navigator.of(context).push<void>( btnCallback: () => Navigator.of(context).push<void>(CupertinoPageRoute(
CupertinoPageRoute(builder: (context) => InvoiceList()))); builder: (context) => InvoiceList(onlyFcs: true))));
final discountBtn = TaskButton("discount.btn", final discountBtn = TaskButton("discount.btn",
icon: Entypo.price_ribbon, icon: Entypo.price_ribbon,

View File

@@ -108,6 +108,7 @@ class _CustomEditorState extends State<CustomEditor> {
CustomDuty _customduty = CustomDuty( CustomDuty _customduty = CustomDuty(
productType: _productController.text, productType: _productController.text,
fee: double.parse(_feeController.text)); fee: double.parse(_feeController.text));
print('_customduty => $_customduty');
if (_isNew) { if (_isNew) {
await shipmentRateModel.addCustomDuty(_customduty); await shipmentRateModel.addCustomDuty(_customduty);
} else { } else {
@@ -125,8 +126,7 @@ class _CustomEditorState extends State<CustomEditor> {
} }
_delete() { _delete() {
showConfirmDialog( showConfirmDialog(context, "cargo.edit.delete.confirm", _deleteCustomDuty);
context, "cargo.edit.delete.confirm", _deleteCustomDuty);
} }
_deleteCustomDuty() async { _deleteCustomDuty() async {

View File

@@ -307,10 +307,12 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
try { try {
var shipmentRateModel = var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false); Provider.of<ShipmentRateModel>(context, listen: false);
Rate _rate = Rate( Rate _rate = new Rate(
deliveryFee: double.parse(_deliveryFee.text), deliveryFee: double.parse(_deliveryFee.text),
freeDeliveryWeight: double.parse(_minWeight.text), freeDeliveryWeight: double.parse(_minWeight.text),
volumetricRatio: double.parse(_volumetricRatio.text)); volumetricRatio: double.parse(_volumetricRatio.text));
Rate r = new Rate();
print('_rate =>$r');
await shipmentRateModel.updateRate(_rate); await shipmentRateModel.updateRate(_rate);
Navigator.pop(context); Navigator.pop(context);
} catch (e) { } catch (e) {