Files
fcs/lib/pages/invoice/invoice_editor.dart

397 lines
16 KiB
Dart
Raw Normal View History

2020-06-02 14:56:51 +06:30
import 'package:fcs/pages/invoice/package_addition.dart';
import 'package:fcs/theme/theme.dart';
import 'package:fcs/vo/invoice.dart';
import 'package:fcs/vo/package.dart';
import 'package:fcs/widget/bottom_up_page_route.dart';
import 'package:fcs/widget/local_text.dart';
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:fcs/widget/multi_img_controller.dart';
import 'package:fcs/widget/multi_img_file.dart';
import 'package:fcs/widget/my_data_table.dart';
import 'package:fcs/widget/progress.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../util.dart';
class InvoiceEditor extends StatefulWidget {
final Invoice invoice;
InvoiceEditor({this.invoice});
@override
_InvoiceEditorState createState() => _InvoiceEditorState();
}
class _InvoiceEditorState extends State<InvoiceEditor> {
var dateFormatter = new DateFormat('dd MMM yyyy');
TextEditingController _invoiceNumberController = new TextEditingController();
TextEditingController _dateController = new TextEditingController();
TextEditingController _nameController = new TextEditingController();
TextEditingController _phoneController = new TextEditingController();
TextEditingController _discountController = new TextEditingController();
TextEditingController _amountController = new TextEditingController();
TextEditingController _statusController = new TextEditingController();
MultiImgController multiImgController = MultiImgController();
Invoice _invoice;
bool _isLoading = false;
List<Package> _packages = [];
@override
void initState() {
super.initState();
if (widget.invoice != null) {
_invoice = widget.invoice;
_invoiceNumberController.text = _invoice.invoiceNumber;
_dateController.text = dateFormatter.format(_invoice.invoiceDate);
_nameController.text = _invoice.customerName;
_phoneController.text = _invoice.customerPhoneNumber;
_amountController.text = _invoice.amount.toString();
_statusController.text = _invoice.status.toString();
_packages = _invoice.packages;
} else {
_packages = [
Package(
shipmentNumber: "A202",
receiverNumber: "3",
boxNumber: "1",
rate: 7,
packageType: "General",
weight: 25,
status: "Received",
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon',
arrivedDate: DateTime(2020, 6, 1),
),
Package(
shipmentNumber: "A202",
receiverNumber: "3",
boxNumber: "2",
rate: 7,
packageType: "General",
weight: 20,
status: "Received",
arrivedDate: DateTime(2020, 6, 1),
receiverAddress: '1 Bo Yar Nyunt St.\nDagon Tsp, Yangon'),
];
}
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: new IconButton(
icon: new Icon(Icons.close),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: primaryColor,
title: LocalText(context, 'invoice.form.title',
color: Colors.white, fontSize: 20),
),
body: Card(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
fcsInput('Invoice Date', Icons.date_range,
controller: _dateController),
widget.invoice == null
? Container()
: Container(
padding: EdgeInsets.only(top: 5),
child: TextFormField(
controller: _invoiceNumberController,
readOnly: true,
decoration: InputDecoration(
fillColor: Colors.white,
labelText: 'Invoice Number',
labelStyle:
TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
icon: Icon(
Icons.pages,
color: Colors.grey,
),
)),
),
widget.invoice == null
? Container(
padding: EdgeInsets.only(top: 5),
child: TextFormField(
initialValue: "U Nyi",
cursorColor: primaryColor,
decoration: InputDecoration(
fillColor: Colors.white,
labelText: 'Customer Name',
labelStyle:
TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.grey, width: 1.0)),
icon: Icon(
Icons.account_box,
color: Colors.grey,
),
suffixIcon: IconButton(
icon: Icon(
Icons.search,
color: Colors.grey,
),
onPressed: () {})),
),
)
: Container(),
widget.invoice == null
? Container()
: Container(
padding: EdgeInsets.only(top: 0),
child: TextFormField(
controller: _nameController,
readOnly: true,
decoration: InputDecoration(
fillColor: Colors.white,
labelText: 'Customer Name',
labelStyle:
TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
icon: Icon(
Icons.account_box,
color: Colors.grey,
),
)),
),
widget.invoice == null
? Container()
: TextFormField(
controller: _phoneController,
readOnly: true,
decoration: InputDecoration(
fillColor: Colors.white,
labelText: 'Customer Phone Number',
labelStyle:
TextStyle(fontSize: 16, color: Colors.grey),
filled: true,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
icon: Icon(
Icons.phone,
color: Colors.grey,
),
)),
Container(
padding: EdgeInsets.only(top: 0),
child: fcsInput('Amount', FontAwesomeIcons.moneyBill,
controller: _amountController),
),
Container(
padding: EdgeInsets.only(top: 5),
child: fcsInput('Discount', FontAwesomeIcons.tag,
controller: _discountController),
),
widget.invoice == null
? Container()
: Container(
padding: EdgeInsets.only(top: 5),
child: TextFormField(
controller: _statusController,
decoration: InputDecoration(
fillColor: Colors.white,
labelText: 'Status',
filled: true,
icon: Image.asset(
'assets/status.png',
width: 24,
height: 24,
color: Colors.grey[700],
),
)),
),
SizedBox(
height: 20,
),
ExpansionTile(
title: Text('Payment Attachment'),
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 20),
child: Row(children: <Widget>[
LocalText(
context,
"invoice.payment",
color: Colors.grey,
fontSize: 14,
),
MultiImageFile(
enabled: true,
controller: multiImgController,
title: "Receipt File",
)
])),
SizedBox(
height: 25,
),
],
),
ExpansionTile(
title: Text('Package Informations'),
children: <Widget>[
Container(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: MyDataTable(
headingRowHeight: 40,
columnSpacing: 20,
columns: [
MyDataColumn(
label: LocalText(
context,
"package.number",
color: Colors.grey,
),
),
MyDataColumn(
label: LocalText(
context,
"package.rate",
color: Colors.grey,
),
),
MyDataColumn(
label: LocalText(
context,
"package.weight",
color: Colors.grey,
),
),
MyDataColumn(
label: LocalText(
context,
"package.amount",
color: Colors.grey,
),
),
],
rows: getPackageRow(context),
),
),
),
Container(
padding: EdgeInsets.only(top: 20),
child: Align(
alignment: Alignment.bottomRight,
child: FloatingActionButton.extended(
icon: Icon(Icons.add),
label: Text(AppTranslations.of(context)
.text("invoice.add_package")),
backgroundColor: primaryColor,
onPressed: () {
Navigator.of(context)
.push(BottomUpPageRoute(PackageAddition()));
},
),
),
),
SizedBox(height: 25),
],
),
]),
)),
widget.invoice == null
? Align(
alignment: Alignment.bottomCenter,
child: Center(
child: Container(
width: 250,
child: FlatButton(
child: Text('Create invoice'),
color: primaryColor,
textColor: Colors.white,
onPressed: () {
Navigator.pop(context);
},
),
)))
: Container(
child: Column(
children: <Widget>[
Align(
alignment: Alignment.bottomCenter,
child: Center(
child: Container(
width: 250,
child: FlatButton(
child: Text('Save invoice'),
color: primaryColor,
textColor: Colors.white,
onPressed: () {
Navigator.pop(context);
},
),
))),
],
2020-06-02 15:30:11 +06:30
)),
widget.invoice == null
? Container()
: Align(
alignment: Alignment.bottomCenter,
child: Center(
child: Container(
width: 250,
child: FlatButton(
child: Text('Confirm Payment'),
color: primaryColor,
textColor: Colors.white,
onPressed: () {
Navigator.pop(context);
},
),
)))
2020-06-02 14:56:51 +06:30
],
),
),
),
);
}
List<MyDataRow> getPackageRow(BuildContext context) {
return _packages.map((p) {
return MyDataRow(
onSelectChanged: (bool selected) {},
cells: [
MyDataCell(new Text(
p.packageNumber == null ? "" : p.packageNumber,
style: textStyle,
)),
MyDataCell(
new Text(p.rate.toString(), style: textStyle),
),
MyDataCell(
new Text("${p.weight.toString()} lb", style: textStyle),
),
MyDataCell(
new Text(p.price == null ? "" : "\$ " + p.price.toString(),
style: textStyle),
),
],
);
}).toList();
}
}