add payment
This commit is contained in:
@@ -437,6 +437,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
invoice.fcsShipmentID = widget.fcsShipment.id;
|
||||
invoice.invoiceDate = _invoice.invoiceDate;
|
||||
invoice.paymentMethod = _invoice.paymentMethod;
|
||||
invoice.customDuties = _invoice.customDuties;
|
||||
|
||||
await invoiceModel.createInvoice(invoice);
|
||||
Navigator.pop(context, true);
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/helpers/api_helper.dart';
|
||||
import 'package:fcs/helpers/firebase_helper.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_shipment_list.dart';
|
||||
import 'package:fcs/pages/invoice/model/invoice_model.dart';
|
||||
import 'package:fcs/pages/invoice/payment_pdf_screen.dart';
|
||||
import 'package:fcs/pages/widgets/local_popup_menu_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_popupmenu.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
@@ -38,8 +33,9 @@ class _InvoiceListState extends State<InvoiceList> {
|
||||
}
|
||||
});
|
||||
|
||||
Provider.of<InvoiceModel>(context, listen: false)
|
||||
.initData(widget.forCustomer, true, false);
|
||||
InvoiceModel invoiceModel =
|
||||
Provider.of<InvoiceModel>(context, listen: false);
|
||||
invoiceModel.initData(widget.forCustomer, true, false);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -49,7 +45,6 @@ class _InvoiceListState extends State<InvoiceList> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var owner = true;
|
||||
var invoiceModel = Provider.of<InvoiceModel>(context);
|
||||
|
||||
final popupMenu = LocalPopupMenuButton(
|
||||
@@ -98,8 +93,9 @@ class _InvoiceListState extends State<InvoiceList> {
|
||||
color: Colors.white, fontSize: 20),
|
||||
actions: <Widget>[popupMenu],
|
||||
),
|
||||
floatingActionButton: owner
|
||||
? FloatingActionButton.extended(
|
||||
floatingActionButton: widget.forCustomer
|
||||
? null
|
||||
: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
_newInvoice();
|
||||
},
|
||||
@@ -107,8 +103,7 @@ class _InvoiceListState extends State<InvoiceList> {
|
||||
label:
|
||||
LocalText(context, 'invoices.add', color: Colors.white),
|
||||
backgroundColor: primaryColor,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
@@ -118,9 +113,9 @@ class _InvoiceListState extends State<InvoiceList> {
|
||||
controller: _controller,
|
||||
separatorBuilder: (context, index) => Divider(
|
||||
color: Colors.black,
|
||||
height: 1,
|
||||
),
|
||||
scrollDirection: Axis.vertical,
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: invoiceModel.invoices.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
|
||||
@@ -1,137 +1,75 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/invoice/invoice_info.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
import 'payment_page.dart';
|
||||
import 'payment_pdf_screen.dart';
|
||||
import 'payment/payment_page.dart';
|
||||
import '../widgets/pdf_screen.dart';
|
||||
|
||||
class InvoiceListRow extends StatefulWidget {
|
||||
class InvoiceListRow extends StatelessWidget {
|
||||
final dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
final Invoice invoice;
|
||||
InvoiceListRow({Key key, this.invoice}) : super(key: key);
|
||||
|
||||
@override
|
||||
_InvoiceListRowState createState() => _InvoiceListRowState();
|
||||
}
|
||||
|
||||
class _InvoiceListRowState extends State<InvoiceListRow> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
final double dotSize = 15.0;
|
||||
Invoice _invoice = new Invoice();
|
||||
String pdfPath = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.invoice != null) {
|
||||
_invoice = widget.invoice;
|
||||
}
|
||||
|
||||
fromAsset('assets/Invoice-A092(A)-32.pdf', 'Invoice-A092(A)-32.pdf')
|
||||
.then((f) {
|
||||
setState(() {
|
||||
pdfPath = f.path;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<File> fromAsset(String asset, String filename) async {
|
||||
// To open from assets, you can copy them to the app storage folder, and the access them "locally"
|
||||
Completer<File> completer = Completer();
|
||||
print('asset => $asset');
|
||||
print('assest => ${await rootBundle.load(asset)}');
|
||||
try {
|
||||
var dir = await getApplicationDocumentsDirectory();
|
||||
File file = File("${dir.path}/$filename");
|
||||
var data = await rootBundle.load(asset);
|
||||
print('data => $data');
|
||||
var bytes = data.buffer.asUint8List();
|
||||
await file.writeAsBytes(bytes, flush: true);
|
||||
completer.complete(file);
|
||||
} catch (e) {
|
||||
throw Exception('Error parsing asset file! ===> ' + e.toString());
|
||||
}
|
||||
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var owner = true;
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 15, right: 15),
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => PDFScreen(
|
||||
title: invoice.invoiceNumber,
|
||||
url: invoice.invoiceURL,
|
||||
)));
|
||||
},
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
owner
|
||||
? Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => PaymentPDFScreen(
|
||||
url: _invoice.invoiceURL,
|
||||
)))
|
||||
: Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => PaymentPDFScreen(
|
||||
url: _invoice.invoiceURL,
|
||||
)));
|
||||
},
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 5, right: 10),
|
||||
child: Icon(
|
||||
FontAwesomeIcons.fileInvoice,
|
||||
color: primaryColor,
|
||||
size: 30,
|
||||
),
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 5, right: 10),
|
||||
child: Icon(
|
||||
FontAwesomeIcons.fileInvoice,
|
||||
color: primaryColor,
|
||||
size: 30,
|
||||
),
|
||||
new Expanded(
|
||||
),
|
||||
new Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 0),
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: new Text(
|
||||
_invoice.invoiceNumber == null
|
||||
? ''
|
||||
: _invoice.invoiceNumber,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
new Text(
|
||||
invoice.invoiceNumber ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
||||
child: new Text(
|
||||
dateFormatter.format(_invoice.invoiceDate),
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
new Text(
|
||||
invoice.status ?? "",
|
||||
style: new TextStyle(
|
||||
fontSize: 13.0, color: primaryColor),
|
||||
),
|
||||
new Text(
|
||||
dateFormatter.format(invoice.invoiceDate),
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.all(0),
|
||||
// child: getStatus(_invoice.status),
|
||||
// ),
|
||||
_invoice.status == invoice_issued_status
|
||||
invoice.status == invoice_issued_status
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0),
|
||||
child: InkWell(
|
||||
@@ -143,27 +81,29 @@ class _InvoiceListRowState extends State<InvoiceListRow> {
|
||||
color: primaryColor,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Text("Payment"),
|
||||
padding: const EdgeInsets.only(left: 3.0),
|
||||
child: Text(
|
||||
"Payment",
|
||||
style: TextStyle(fontSize: 12, color: Colors.black),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PaymentPage(invoice: _invoice)));
|
||||
builder: (context) => PaymentPage(invoice: invoice)));
|
||||
},
|
||||
)),
|
||||
)
|
||||
: Container(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: InkWell(
|
||||
child: Icon(
|
||||
child: IconButton(
|
||||
icon: Icon(
|
||||
Icons.more_vert,
|
||||
color: primaryColor,
|
||||
),
|
||||
onTap: () {
|
||||
onPressed: () {
|
||||
var act = actionSheet(context);
|
||||
showCupertinoModalPopup(
|
||||
context: context, builder: (BuildContext context) => act);
|
||||
@@ -194,7 +134,7 @@ class _InvoiceListRowState extends State<InvoiceListRow> {
|
||||
//to go invoice info page
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => InvoiceInfo(invoice: _invoice)));
|
||||
builder: (context) => InvoiceInfo(invoice: invoice)));
|
||||
},
|
||||
)
|
||||
],
|
||||
|
||||
@@ -2,8 +2,6 @@ import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/domain/entities/discount.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/rate.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/discount/discount_list.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -227,151 +225,6 @@ class InvoiceTable extends StatelessWidget {
|
||||
),
|
||||
));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(left: 5.0, right: 5.0, top: 20.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 1,
|
||||
// child: Container(
|
||||
// alignment: Alignment.centerRight,
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.handling_fee',
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(width: 50),
|
||||
// Expanded(
|
||||
// child: Text(
|
||||
// '\$ ${invoice.getHandlingFee().toStringAsFixed(2) ?? ""}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// )))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 1,
|
||||
// child: Container(
|
||||
// alignment: Alignment.centerRight,
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.delivery_fee',
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// )),
|
||||
// Switch(
|
||||
// value: (invoice.deliveryFee ?? 0) > 0,
|
||||
// onChanged: (value) {
|
||||
// if (deliveryFeeSelected != null) {
|
||||
// deliveryFeeSelected(value);
|
||||
// }
|
||||
// },
|
||||
// activeTrackColor: primaryColor.withOpacity(0.8),
|
||||
// activeColor: primaryColor,
|
||||
// ),
|
||||
// Expanded(
|
||||
// child:
|
||||
// Text('\$ ${invoice.getDeliveryFee().toStringAsFixed(2)}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// )))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(child: Text('')),
|
||||
// Expanded(
|
||||
// flex: 2,
|
||||
// child: Divider(
|
||||
// thickness: 3,
|
||||
// )),
|
||||
// ],
|
||||
// )));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 2,
|
||||
// child: Center(
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.net_amount',
|
||||
// color: Colors.black,
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Expanded(
|
||||
// child: Text(
|
||||
// '\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: primaryColor)))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
// dataRow.insert(
|
||||
// dataRow.length,
|
||||
// Container(
|
||||
// padding: const EdgeInsets.only(
|
||||
// left: 5.0, right: 5.0, top: 10.0, bottom: 10.0),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// flex: 2,
|
||||
// child: Center(
|
||||
// child: LocalText(
|
||||
// context,
|
||||
// 'invoice.balance',
|
||||
// color: Colors.black,
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// Expanded(
|
||||
// child: Text(
|
||||
// '\$ ${invoice.getTotalBalance(rate).toStringAsFixed(2)}',
|
||||
// textAlign: TextAlign.end,
|
||||
// style: TextStyle(
|
||||
// fontSize: 18,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: primaryColor)))
|
||||
// ],
|
||||
// ),
|
||||
// ));
|
||||
|
||||
return dataRow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:fcs/config.dart';
|
||||
import 'package:fcs/data/services/services.dart';
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/helpers/api_helper.dart';
|
||||
import 'package:fcs/domain/entities/payment.dart';
|
||||
import 'package:fcs/helpers/firebase_helper.dart';
|
||||
import 'package:fcs/helpers/paginator.dart';
|
||||
import 'package:fcs/pages/main/model/base_model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as Path;
|
||||
|
||||
class InvoiceModel extends BaseModel {
|
||||
final log = Logger('InvoiceModel');
|
||||
@@ -135,11 +133,33 @@ class InvoiceModel extends BaseModel {
|
||||
_invoices = [];
|
||||
}
|
||||
|
||||
Future<Invoice> getInvoice(String id) async {
|
||||
String path = "/$invoices_collection";
|
||||
try {
|
||||
var ref = Firestore.instance.collection("$path").document(id);
|
||||
var snap = await ref.get(source: Source.server);
|
||||
if (snap.exists) {
|
||||
var s = Invoice.fromMap(snap.data, snap.documentID);
|
||||
return s;
|
||||
}
|
||||
} catch (e) {
|
||||
log.warning("Error!! $e");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> pay(Payment payment, File file) async {
|
||||
String path = Path.join(receipt_labels_files_path, user.id);
|
||||
String url = await uploadStorage(path, file);
|
||||
payment.paymentReceiptURL = url;
|
||||
return Services.instance.invoiceService.pay(payment);
|
||||
}
|
||||
|
||||
Future<void> updatePaymentStatus(Payment payment) async {
|
||||
return Services.instance.invoiceService.updatPaymentStatus(payment);
|
||||
}
|
||||
|
||||
Future<void> createInvoice(Invoice invoice) async {
|
||||
File file = await downloadPDF("invoice", invoice.toMap());
|
||||
String url = await uploadStorage("pdfs", file);
|
||||
print("uploaded url: $url");
|
||||
invoice.invoiceURL = url;
|
||||
return Services.instance.invoiceService.createInvoice(invoice);
|
||||
}
|
||||
|
||||
|
||||
319
lib/pages/invoice/payment/payment_page.dart
Normal file
319
lib/pages/invoice/payment/payment_page.dart
Normal file
@@ -0,0 +1,319 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/domain/constants.dart';
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/domain/entities/payment.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/invoice/model/invoice_model.dart';
|
||||
import 'package:fcs/pages/invoice/payment/payment_page_edit.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/image_file_picker.dart';
|
||||
import 'package:fcs/pages/widgets/img_picker.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_button.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:fcs/pages/widgets/show_img.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class PaymentPage extends StatefulWidget {
|
||||
final Invoice invoice;
|
||||
PaymentPage({this.invoice});
|
||||
|
||||
@override
|
||||
_PaymentPageState createState() => _PaymentPageState();
|
||||
}
|
||||
|
||||
class _PaymentPageState extends State<PaymentPage> {
|
||||
TextEditingController _amountController = new TextEditingController();
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
|
||||
Invoice _invoice = new Invoice();
|
||||
bool _isLoading = false;
|
||||
|
||||
bool isNew;
|
||||
File _file;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_invoice = widget.invoice;
|
||||
_loadInvoice();
|
||||
}
|
||||
|
||||
_loadInvoice() async {
|
||||
InvoiceModel invoiceModel =
|
||||
Provider.of<InvoiceModel>(context, listen: false);
|
||||
Invoice i = await invoiceModel.getInvoice(_invoice.id);
|
||||
setState(() {
|
||||
_invoice = i;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final amountBox = InputText(
|
||||
labelTextKey: 'pm.amount',
|
||||
controller: _amountController,
|
||||
iconData: FontAwesomeIcons.moneyBill);
|
||||
|
||||
final receiptFileBox = Row(children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Text("Attach receipt"),
|
||||
),
|
||||
LocalImagePicker(
|
||||
color: primaryColor,
|
||||
title: "Receipt",
|
||||
onFile: (f) => _file = f,
|
||||
)
|
||||
]);
|
||||
|
||||
final payBtnBox = LocalButton(
|
||||
callBack: _pay,
|
||||
textKey: "pm.pay",
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("pm_.title")),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
children: <Widget>[
|
||||
amountBox,
|
||||
SizedBox(height: 10),
|
||||
Align(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: receiptFileBox,
|
||||
),
|
||||
alignment: Alignment.centerLeft,
|
||||
),
|
||||
payBtnBox,
|
||||
SizedBox(height: 15),
|
||||
LocalTitle(textKey: "pm.receipt"),
|
||||
Column(
|
||||
children: getCustomFeeRows(context),
|
||||
),
|
||||
SizedBox(height: 25),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
getCustomFeeRows(BuildContext context) {
|
||||
List<Widget> dataRow = [];
|
||||
|
||||
dataRow = _invoice?.payments?.map((p) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 5.0, bottom: 5.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Text(
|
||||
'${p.paymentDate != null ? dateFormatter.format(p.paymentDate) : ""}'),
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
LocalImagePicker(
|
||||
key: ValueKey(p.id),
|
||||
enabled: false,
|
||||
initialImgUrl: p.paymentReceiptURL,
|
||||
title: "Receipt",
|
||||
color: primaryColor,
|
||||
)
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [Text('\$ ${p.amount}'), Text('${p.status}')],
|
||||
))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: p.status == payment_pending_status
|
||||
? [
|
||||
InkWell(
|
||||
onTap: () => _confirm(p),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => _cancel(p),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.close, color: primaryColor),
|
||||
),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
})?.toList() ??
|
||||
[];
|
||||
|
||||
dataRow.insert(
|
||||
0,
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 15.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text('Receipt', style: TextStyle(color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text('Amount',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text('Actions',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey))),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: LocalText(
|
||||
context,
|
||||
'pm.remaining_balance',
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'\$ ${widget.invoice.balance.toStringAsFixed(2)}',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 16.0)))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Container(),
|
||||
),
|
||||
],
|
||||
),
|
||||
));
|
||||
return dataRow;
|
||||
}
|
||||
|
||||
_confirm(Payment payment) {
|
||||
payment.status = payment_confirmed_status;
|
||||
showConfirmDialog(context, "invoice.payment.confirm.confirm",
|
||||
() => _updatePayment(payment));
|
||||
}
|
||||
|
||||
_cancel(Payment payment) {
|
||||
payment.status = payment_canceled_status;
|
||||
showConfirmDialog(context, "invoice.payment.cancel.confirm",
|
||||
() => _updatePayment(payment));
|
||||
}
|
||||
|
||||
_updatePayment(Payment payment) async {
|
||||
payment.invoiceID = widget.invoice.id;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
InvoiceModel invoiceModel =
|
||||
Provider.of<InvoiceModel>(context, listen: false);
|
||||
await invoiceModel.updatePaymentStatus(payment);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_pay() async {
|
||||
if (_file == null) {
|
||||
showMsgDialog(context, "Error", "Expect receipt attachment");
|
||||
return;
|
||||
}
|
||||
double amount = double.tryParse(_amountController.text) ?? 0;
|
||||
if (amount <= 0) {
|
||||
showMsgDialog(context, "Error", "Expect valid amount");
|
||||
return;
|
||||
}
|
||||
Payment payment = Payment(invoiceID: _invoice.id, amount: amount);
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
InvoiceModel invoiceModel =
|
||||
Provider.of<InvoiceModel>(context, listen: false);
|
||||
await invoiceModel.pay(payment, _file);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,301 +0,0 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/domain/entities/invoice.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/localization/app_translations.dart';
|
||||
import 'package:fcs/pages/invoice/payment_page_edit.dart';
|
||||
import 'package:fcs/pages/widgets/image_file_picker.dart';
|
||||
import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:fcs/pages/widgets/show_img.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class PaymentPage extends StatefulWidget {
|
||||
final Invoice invoice;
|
||||
PaymentPage({this.invoice});
|
||||
|
||||
@override
|
||||
_PaymentPageState createState() => _PaymentPageState();
|
||||
}
|
||||
|
||||
class _PaymentPageState extends State<PaymentPage> {
|
||||
TextEditingController _amountController = new TextEditingController();
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
|
||||
Invoice _invoice = new Invoice();
|
||||
bool _isLoading = false;
|
||||
|
||||
bool isNew;
|
||||
File _file;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.invoice != null) {
|
||||
_invoice = widget.invoice;
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
final DateFormat dateFormat = DateFormat("d MMM yyyy");
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final amountBox = InputText(
|
||||
labelTextKey: 'pm.amount',
|
||||
controller: _amountController,
|
||||
iconData: FontAwesomeIcons.moneyBill);
|
||||
|
||||
final receiptFileBox = Row(children: [
|
||||
LocalText(context, 'pm.attachment', fontSize: 16, color: Colors.grey),
|
||||
_file != null
|
||||
? InkWell(
|
||||
onTap: () async {
|
||||
await _dialog(context);
|
||||
},
|
||||
child: Chip(
|
||||
label: Icon(Icons.image, color: primaryColor),
|
||||
),
|
||||
)
|
||||
: IconButton(
|
||||
icon: Icon(Icons.attachment, color: primaryColor),
|
||||
onPressed: () async {
|
||||
await _dialog(context);
|
||||
}),
|
||||
]);
|
||||
|
||||
final payBox = Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
Container(
|
||||
height: 50,
|
||||
width: 100,
|
||||
alignment: Alignment.center,
|
||||
child: Text(AppTranslations.of(context).text("pm.pay"),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.white, fontSize: 14)),
|
||||
color: primaryColor)
|
||||
]);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("pm_.title")),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
children: <Widget>[
|
||||
amountBox,
|
||||
SizedBox(height: 10),
|
||||
receiptFileBox,
|
||||
SizedBox(height: 10),
|
||||
payBox,
|
||||
Divider(),
|
||||
SizedBox(height: 10),
|
||||
LocalTitle(textKey: "pm.receipt"),
|
||||
Column(
|
||||
children: getCustomFeeRows(context),
|
||||
),
|
||||
SizedBox(height: 25),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
getCustomFeeRows(BuildContext context) {
|
||||
List<Widget> dataRow = [];
|
||||
|
||||
dataRow = [].asMap().entries.map((receipt) {
|
||||
var r = receipt.value;
|
||||
var k = receipt.key + 1;
|
||||
return Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding:
|
||||
const EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0, bottom: 5.0),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => PaymentPageEdit(receipt: r)));
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(flex: 2, child: Text('${r.date}')),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShowImage(
|
||||
// localImage: attachment.value.fileUrl,
|
||||
localImage: 'assets/logo.jpg',
|
||||
url: null,
|
||||
fileName: 'image')));
|
||||
},
|
||||
child: Chip(
|
||||
label: Icon(Icons.image, color: primaryColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(flex: 1, child: Center(child: Text('pending'))),
|
||||
Expanded(flex: 1, child: Center(child: Text('\$ ${r.amount}'))),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
dataRow.insert(
|
||||
0,
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 10.0, bottom: 15.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('Date', style: TextStyle(color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text('File',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text('Status',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey))),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Text('Fee',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey))),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
dataRow.insert(
|
||||
dataRow.length,
|
||||
Container(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 15.0, bottom: 15.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Center(
|
||||
child: LocalText(
|
||||
context,
|
||||
'pm.remaining_balance',
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Container(),
|
||||
),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: Text('\$ 300',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 16.0)))),
|
||||
],
|
||||
),
|
||||
));
|
||||
return dataRow;
|
||||
}
|
||||
|
||||
Future<void> _dialog(BuildContext context) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
content: Container(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.camera,
|
||||
size: 30,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
// Navigator.pop(context);
|
||||
// cameraPress();
|
||||
var selectedFile =
|
||||
await pickImage(ImageSource.camera);
|
||||
setState(() {
|
||||
_file = selectedFile;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
Text("Camera")
|
||||
],
|
||||
),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.photo_library,
|
||||
size: 30,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
// Navigator.pop(context);
|
||||
// photoPress();
|
||||
var selectedFile =
|
||||
await pickImage(ImageSource.gallery);
|
||||
setState(() {
|
||||
_file = selectedFile;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
Text("Gallery")
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
pickImage(ImageSource source) async {
|
||||
var tempImage = await ImagePicker.pickImage(source: source);
|
||||
return tempImage;
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fcs/helpers/cache_mgr.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_pdfview/flutter_pdfview.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
class PaymentPDFScreen extends StatefulWidget {
|
||||
final String url;
|
||||
|
||||
PaymentPDFScreen({Key key, this.url}) : super(key: key);
|
||||
|
||||
_PaymentPDFScreenState createState() => _PaymentPDFScreenState();
|
||||
}
|
||||
|
||||
class _PaymentPDFScreenState extends State<PaymentPDFScreen>
|
||||
with WidgetsBindingObserver {
|
||||
final Completer<PDFViewController> _controller =
|
||||
Completer<PDFViewController>();
|
||||
int pages = 0;
|
||||
int currentPage = 0;
|
||||
bool isReady = false;
|
||||
String errorMessage = '';
|
||||
bool _isLoading = true;
|
||||
|
||||
void initState() {
|
||||
super.initState();
|
||||
download();
|
||||
}
|
||||
|
||||
File file;
|
||||
Future<void> download() async {
|
||||
try {
|
||||
File f = await PdfCacheMgr.pdfs.getSingleFile(widget.url);
|
||||
setState(() {
|
||||
file = f;
|
||||
});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
backgroundColor: Colors.white,
|
||||
shadowColor: Colors.transparent,
|
||||
title: LocalText(context, 'invoice.pdf',
|
||||
color: Colors.white, fontSize: 20),
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back, color: primaryColor),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.share,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: _share,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: <Widget>[
|
||||
_isLoading
|
||||
? Container()
|
||||
: PDFView(
|
||||
filePath: file?.path ?? "",
|
||||
enableSwipe: true,
|
||||
swipeHorizontal: true,
|
||||
autoSpacing: false,
|
||||
pageFling: true,
|
||||
pageSnap: true,
|
||||
defaultPage: currentPage,
|
||||
fitPolicy: FitPolicy.BOTH,
|
||||
preventLinkNavigation:
|
||||
false, // if set to true the link is handled in flutter
|
||||
onRender: (_pages) {
|
||||
print(('pages => $pages'));
|
||||
setState(() {
|
||||
pages = _pages;
|
||||
isReady = true;
|
||||
});
|
||||
},
|
||||
onViewCreated: (PDFViewController pdfViewController) {
|
||||
_controller.complete(pdfViewController);
|
||||
},
|
||||
onLinkHandler: (String uri) {
|
||||
print('goto uri: $uri');
|
||||
},
|
||||
onPageChanged: (int page, int total) {
|
||||
print('page change: $page/$total');
|
||||
setState(() {
|
||||
currentPage = page;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_share() async {
|
||||
final RenderBox box = context.findRenderObject();
|
||||
await Share.shareFiles([file.path],
|
||||
mimeTypes: ["application/pdf"],
|
||||
subject: "Invoice",
|
||||
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user