add structure
This commit is contained in:
27
lib/pages/po/po_files.dart
Normal file
27
lib/pages/po/po_files.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
class POFiles {
|
||||
File poPaymentFile, storageChargeFile;
|
||||
List<File> poPaymentFilesAdded=[];
|
||||
List<String> poPaymentFilesRemoved=[]; // only url
|
||||
bool poFileChanged = false, storageFileChanged = false;
|
||||
|
||||
set addPoPaymentFile(File file) {
|
||||
poPaymentFilesAdded.add(file);
|
||||
poFileChanged = true;
|
||||
}
|
||||
|
||||
set removePoPaymentFile(String url) {
|
||||
poPaymentFilesRemoved.add(url);
|
||||
poFileChanged = true;
|
||||
}
|
||||
|
||||
set setStorageChargeFile(File file) {
|
||||
storageChargeFile = file;
|
||||
storageFileChanged = true;
|
||||
}
|
||||
|
||||
bool get anyChanged => poFileChanged || storageFileChanged;
|
||||
|
||||
|
||||
}
|
||||
208
lib/pages/po/po_item.dart
Normal file
208
lib/pages/po/po_item.dart
Normal file
@@ -0,0 +1,208 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/product_model.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/po.dart';
|
||||
import 'package:fcs/vo/product.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import '../util.dart';
|
||||
|
||||
class POItem extends StatefulWidget {
|
||||
final POLine poLine;
|
||||
const POItem({Key key, this.poLine}) : super(key: key);
|
||||
@override
|
||||
_POItemState createState() => _POItemState();
|
||||
}
|
||||
|
||||
class _POItemState extends State<POItem> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
String currentProductID;
|
||||
TextEditingController _qty = new TextEditingController();
|
||||
POLine poLine = POLine();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.poLine != null) {
|
||||
this.poLine = widget.poLine;
|
||||
|
||||
this._qty.text = this.poLine.qty.toString();
|
||||
this.currentProductID = this.poLine.productID;
|
||||
this.poLine.action = "update";
|
||||
} else {
|
||||
this.poLine.action = "create";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget showProducts(BuildContext context, ProductModel productModel) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
FontAwesomeIcons.tag,
|
||||
color: primaryColor,
|
||||
size: 20,
|
||||
),
|
||||
SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
new Flexible(
|
||||
child: Container(
|
||||
width: 170.0,
|
||||
child: DropdownButton<String>(
|
||||
value: currentProductID,
|
||||
isExpanded: true,
|
||||
hint: Text(
|
||||
'Select Product',
|
||||
style: labelStyle,
|
||||
),
|
||||
onChanged: changedProduct,
|
||||
items: productModel.products
|
||||
.map<DropdownMenuItem<String>>((Product product) {
|
||||
return new DropdownMenuItem<String>(
|
||||
value: product.id,
|
||||
child: new Text(product.name, style: textStyle),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void changedProduct(selected) {
|
||||
setState(() {
|
||||
// currentProductID = selected;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var productModel = Provider.of<ProductModel>(context);
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
|
||||
final volumeBox = Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: TextFormField(
|
||||
controller: _qty,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: new InputDecoration(
|
||||
labelText: AppTranslations.of(context).text("po.volume"),
|
||||
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.sortNumericUpAlt,
|
||||
color: primaryColor,
|
||||
),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value.isEmpty) {
|
||||
return AppTranslations.of(context).text("po.form.volume");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"po",
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
),
|
||||
actions: <Widget>[
|
||||
// IconButton(
|
||||
// icon: Icon(Icons.delete),
|
||||
// onPressed: () {
|
||||
// _delete();
|
||||
// },
|
||||
// ),
|
||||
IconButton(
|
||||
icon: Icon(Icons.save),
|
||||
onPressed: () {
|
||||
if (!_formKey.currentState.validate()) return;
|
||||
_save();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||
children: <Widget>[
|
||||
volumeBox,
|
||||
showProducts(context, productModel)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
_save() {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
this.poLine.productID = currentProductID;
|
||||
var product =
|
||||
Provider.of<ProductModel>(context).getProduct(currentProductID);
|
||||
this.poLine.productName = product.name;
|
||||
this.poLine.price = product.price;
|
||||
this.poLine.qty = int.parse(_qty.text);
|
||||
this.poLine.amount = this.poLine.price * this.poLine.qty;
|
||||
Navigator.pop<POLine>(context, this.poLine);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_delete() {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
this.poLine.action = "delete";
|
||||
Navigator.pop<POLine>(context, this.poLine);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
601
lib/pages/po/po_submission_form.dart
Normal file
601
lib/pages/po/po_submission_form.dart
Normal file
@@ -0,0 +1,601 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/log_model.dart';
|
||||
import 'package:fcs/model/main_model.dart';
|
||||
import 'package:fcs/model/po_model.dart';
|
||||
import 'package:fcs/model/product_model.dart';
|
||||
import 'package:fcs/pages/po/po_item.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/attach.dart';
|
||||
import 'package:fcs/vo/po.dart';
|
||||
import 'package:fcs/widget/img_file.dart';
|
||||
import 'package:fcs/widget/label_widgets.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/number_cell.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import '../../util.dart';
|
||||
import '../document_log_page.dart';
|
||||
import '../util.dart';
|
||||
import 'po_files.dart';
|
||||
|
||||
class POSubmissionForm extends StatefulWidget {
|
||||
final POSubmission poSubmission;
|
||||
|
||||
POSubmissionForm({this.poSubmission});
|
||||
|
||||
@override
|
||||
_POSubmissionFormState createState() => _POSubmissionFormState();
|
||||
}
|
||||
|
||||
class _POSubmissionFormState extends State<POSubmissionForm> {
|
||||
final numberFormatter = new NumberFormat("#,###");
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy - hh:mm a');
|
||||
MultiImgController multiImgController = MultiImgController();
|
||||
|
||||
TextEditingController _numberController = new TextEditingController();
|
||||
TextEditingController _storage = new TextEditingController();
|
||||
TextEditingController _comment = new TextEditingController();
|
||||
TextEditingController _name = new TextEditingController();
|
||||
TextEditingController _bizName = new TextEditingController();
|
||||
|
||||
List<POLine> poLines = new List();
|
||||
bool _isLoading = false;
|
||||
bool _isNew = true;
|
||||
int _amount = 0;
|
||||
String _date = "", _status = "";
|
||||
POSubmission poSubmission = POSubmission();
|
||||
AttachFile attachFile;
|
||||
POFiles files = POFiles();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.poSubmission != null) {
|
||||
_isNew = false;
|
||||
poSubmission = widget.poSubmission;
|
||||
|
||||
_date = dateFormatter.format(poSubmission.poDate);
|
||||
_numberController.text = poSubmission.poNumber.toString();
|
||||
_comment.text = poSubmission.comment;
|
||||
_name.text = poSubmission.userName;
|
||||
_bizName.text = poSubmission.bizName;
|
||||
poLines = poSubmission.poLines;
|
||||
_status = poSubmission.status;
|
||||
_storage.text = poSubmission.storageCharge.toString();
|
||||
multiImgController.setImageUrls = poSubmission.poReceiptUrls;
|
||||
|
||||
Provider.of<POSubmissionModel>(context, listen: false)
|
||||
.loadPOLines(poSubmission.id)
|
||||
.then((poLines) {
|
||||
setState(() {
|
||||
this.poSubmission.poLines = poLines;
|
||||
_amount = poSubmission.getAmount;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
_amount = 0;
|
||||
_date = dateFormatter.format(DateTime.now());
|
||||
var productModel = Provider.of<ProductModel>(context, listen: false);
|
||||
productModel.products.forEach((p) {
|
||||
var _poLine = POLine(
|
||||
productID: p.id,
|
||||
productName: p.name,
|
||||
price: p.price,
|
||||
balanceQty: 0,
|
||||
qty: 0,
|
||||
amount: 0);
|
||||
poSubmission.poLines.add(_poLine);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
bool isBuyer = mainModel.user.isBuyer();
|
||||
var logModel = Provider.of<LogModel>(context);
|
||||
|
||||
final dateBox = Container(
|
||||
padding: EdgeInsets.only(top: 15, left: 20, bottom: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.date"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(_date, style: textStyle),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final numberBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 20, bottom: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.number"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_numberController.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final userNameBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 20, bottom: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.name"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Text(
|
||||
_name.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
final bizNameBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 20, bottom: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.biz"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Text(
|
||||
_bizName.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final statusBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 20),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.status"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_status,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
final commentBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 20),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.comment"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_comment.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final amountBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 10),
|
||||
child: labeledText(context, formatNumber(_amount), "po.amount",
|
||||
number: true));
|
||||
|
||||
final storageBox = Container(
|
||||
padding: EdgeInsets.only(top: 5, left: 20),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.storage_charge"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_storage.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
final poPaymentBox = Container(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.po_payment_receipt"),
|
||||
MultiImageFile(
|
||||
enabled: isBuyer
|
||||
? _isNew || this.poSubmission.isPending() ? true : false
|
||||
: false,
|
||||
controller: multiImgController,
|
||||
title: "Receipt File",
|
||||
)
|
||||
]));
|
||||
|
||||
final storagePaymentBox = Container(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Row(children: <Widget>[
|
||||
LocalText(context, "po.storage_receipt"),
|
||||
ImageFile(
|
||||
enabled: isBuyer
|
||||
? _isNew || this.poSubmission.isPending() ? true : false
|
||||
: false,
|
||||
initialImgUrl: this.poSubmission.storageReceiptUrl,
|
||||
title: "Receipt File",
|
||||
onFile: (file) {
|
||||
this.files.setStorageChargeFile = file;
|
||||
}),
|
||||
]));
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("po"),
|
||||
style: Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(fontSize: 18)
|
||||
: TextStyle(fontSize: 18, fontFamily: 'MyanmarUnicode')),
|
||||
actions: <Widget>[
|
||||
_isNew || !mainModel.showHistoryBtn()
|
||||
? Container()
|
||||
: IconButton(
|
||||
icon: Icon(Icons.history),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
DocumentLogPage(docID: poSubmission.id)),
|
||||
);
|
||||
},
|
||||
),
|
||||
isBuyer && (_isNew || poSubmission.isPending())
|
||||
? IconButton(
|
||||
icon: Icon(Icons.send),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "po.confirm", () {
|
||||
_submit();
|
||||
});
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
isBuyer
|
||||
? Container()
|
||||
: PopupMenuButton(
|
||||
onSelected: _select,
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
enabled: poSubmission.isPending(),
|
||||
value: 1,
|
||||
child: Text("Approve PO"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: poSubmission.isPending(),
|
||||
value: 2,
|
||||
child: Text("Reject PO"),
|
||||
),
|
||||
PopupMenuItem(
|
||||
enabled: mainModel.user.isOwner() &&
|
||||
poSubmission.isApproved(),
|
||||
value: 3,
|
||||
child: Text("Cancel PO"),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
// floatingActionButton: isBuyer && (_isNew || poSubmission.isPending())
|
||||
// ? FloatingActionButton(
|
||||
// backgroundColor: primaryColor,
|
||||
// child: Icon(Icons.add),
|
||||
// onPressed: () async {
|
||||
// final POLine poLine = await Navigator.push<POLine>(
|
||||
// context,
|
||||
// MaterialPageRoute(builder: (context) => POItem()),
|
||||
// );
|
||||
// _save(poLine);
|
||||
// },
|
||||
// )
|
||||
// : null,
|
||||
body: Container(
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
dateBox,
|
||||
Divider(),
|
||||
_isNew ? Container() : numberBox,
|
||||
_isNew ? Container() : Divider(),
|
||||
_isNew ? Container() : userNameBox,
|
||||
_isNew ? Container() : Divider(),
|
||||
_isNew ? Container() : bizNameBox,
|
||||
_isNew ? Container() : Divider(),
|
||||
_isNew ? Container() : statusBox,
|
||||
_isNew ||
|
||||
widget.poSubmission.comment == null ||
|
||||
widget.poSubmission.comment == ''
|
||||
? Container()
|
||||
: Divider(),
|
||||
_isNew ||
|
||||
widget.poSubmission.comment == null ||
|
||||
widget.poSubmission.comment == ''
|
||||
? Container()
|
||||
: commentBox,
|
||||
_isNew ? Container() : Divider(),
|
||||
amountBox,
|
||||
Divider(),
|
||||
poPaymentBox,
|
||||
Divider(),
|
||||
_isNew || !poSubmission.hasStorageCharge()
|
||||
? Container()
|
||||
: storageBox,
|
||||
_isNew || !poSubmission.hasStorageCharge()
|
||||
? Container()
|
||||
: Divider(),
|
||||
_isNew || !poSubmission.hasStorageCharge()
|
||||
? Container()
|
||||
: storagePaymentBox,
|
||||
_isNew || !poSubmission.hasStorageCharge()
|
||||
? Container()
|
||||
: Divider(),
|
||||
Container(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columnSpacing: 7,
|
||||
columns: _isNew
|
||||
? [
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.product")),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.price"),
|
||||
numeric: true),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.volume"),
|
||||
numeric: true),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.amount"),
|
||||
numeric: true),
|
||||
]
|
||||
: [
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.product")),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.price"),
|
||||
numeric: true),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.balance.volume"),
|
||||
numeric: true),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.volume"),
|
||||
numeric: true),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.amount"),
|
||||
numeric: true),
|
||||
],
|
||||
rows: getProductRow(poSubmission.poLines),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_select(s) {
|
||||
if (s == 1) {
|
||||
showConfirmDialog(context, "po.approve.confirm", () {
|
||||
_approve();
|
||||
});
|
||||
} else if (s == 2) {
|
||||
showCommentDialog(context, (comment) {
|
||||
this.poSubmission.comment = comment;
|
||||
_reject();
|
||||
});
|
||||
} else if (s == 3) {
|
||||
showConfirmDialog(context, "po.cancel.confirm", () {
|
||||
_cancel();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
List<MyDataRow> getProductRow(List<POLine> poLines) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
bool isBuyer = mainModel.user.isBuyer();
|
||||
|
||||
ProductModel productModel = Provider.of<ProductModel>(context);
|
||||
if (poLines.isNotEmpty) {
|
||||
poLines.forEach((d) {
|
||||
productModel.products.forEach((p) {
|
||||
if (p.id == d.productID) {
|
||||
d.displayOrder = p.displayOrder;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
poLines.sort((p1, p2) => p1.displayOrder.compareTo(p2.displayOrder));
|
||||
}
|
||||
|
||||
return poLines.map((p) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
if (!isBuyer) return;
|
||||
|
||||
if (_isNew || this.poSubmission.isPending()) {
|
||||
var poLine = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => POItem(
|
||||
poLine: p,
|
||||
)),
|
||||
);
|
||||
_save(poLine);
|
||||
}
|
||||
},
|
||||
cells: _isNew
|
||||
? [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.productName,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(NumberCell(p.price)),
|
||||
MyDataCell(
|
||||
Container(
|
||||
alignment: Alignment.centerRight,
|
||||
width: 100,
|
||||
child: NumberCell(
|
||||
p.qty,
|
||||
textStyle: textStyleOdd,
|
||||
),
|
||||
),
|
||||
),
|
||||
MyDataCell(NumberCell(p.amount)),
|
||||
]
|
||||
: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.productName,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(NumberCell(p.price)),
|
||||
MyDataCell(NumberCell(p.balanceQty)),
|
||||
MyDataCell(NumberCell(p.qty)),
|
||||
MyDataCell(NumberCell(p.amount)),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_save(POLine poLine) {
|
||||
if (poLine == null) return;
|
||||
if (poLine.action == "create") {
|
||||
if (poSubmission.poLines.contains(poLine)) {
|
||||
showMsgDialog(context, "Error", "Duplicate line");
|
||||
return;
|
||||
}
|
||||
poSubmission.poLines.add(poLine);
|
||||
} else if (poLine.action == "delete") {
|
||||
poSubmission.poLines.remove(poLine);
|
||||
}
|
||||
setState(() {
|
||||
_amount = poSubmission.getAmount;
|
||||
});
|
||||
}
|
||||
|
||||
_submit() async {
|
||||
if (poSubmission.poLines.length == 0) {
|
||||
showMsgDialog(context, "Error", "No product line");
|
||||
return;
|
||||
}
|
||||
List<POLine> _poLines = [];
|
||||
poSubmission.poLines.forEach((p) => p.qty <= 0 ? _poLines.add(p) : p);
|
||||
poSubmission.poLines.removeWhere((p) => p.qty <= 0);
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
POSubmissionModel poModel = Provider.of<POSubmissionModel>(context);
|
||||
if (_isNew) {
|
||||
await poModel.createPO(poSubmission, multiImgController.getAddedFile);
|
||||
} else {
|
||||
if (poSubmission.hasStorageCharge()) {
|
||||
if (files.storageChargeFile == null) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please insert storage charge file");
|
||||
return;
|
||||
}
|
||||
}
|
||||
await poModel.updatePO(poSubmission, multiImgController.getAddedFile,
|
||||
multiImgController.getDeletedUrl);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_poLines.forEach((e) {
|
||||
if (!poSubmission.poLines.contains(e)) poSubmission.poLines.add(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_approve() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
var oldStatus = poSubmission.status;
|
||||
try {
|
||||
POSubmissionModel poModel = Provider.of<POSubmissionModel>(context);
|
||||
|
||||
poSubmission.status = "approved";
|
||||
await poModel.approvePO(poSubmission);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
poSubmission.status = oldStatus;
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_reject() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
POSubmissionModel poModel = Provider.of<POSubmissionModel>(context);
|
||||
await poModel.rejectPO(poSubmission);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_cancel() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
POSubmissionModel poModel = Provider.of<POSubmissionModel>(context);
|
||||
await poModel.cancelPO(poSubmission);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
291
lib/pages/po/po_submission_list.dart
Normal file
291
lib/pages/po/po_submission_list.dart
Normal file
@@ -0,0 +1,291 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/main_model.dart';
|
||||
import 'package:fcs/model/po_model.dart';
|
||||
import 'package:fcs/pages/po/po_submission_form.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/po.dart';
|
||||
import 'package:fcs/vo/popup_menu.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/popupmenu.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
class SubmissionList extends StatefulWidget {
|
||||
@override
|
||||
_SubmissionListState createState() => _SubmissionListState();
|
||||
}
|
||||
|
||||
class _SubmissionListState extends State<SubmissionList> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
final double dotSize = 10.0;
|
||||
PopupMenu selectedChoices = poMenus[0];
|
||||
POSubmission poSubmission;
|
||||
DateTime _selectedDate = DateTime.now();
|
||||
String status;
|
||||
int _selectedIndex = 0;
|
||||
int _dateIndex = 0;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
var poModel = Provider.of<POSubmissionModel>(context, listen: false);
|
||||
_selectedIndex = poModel.popupMenu.index;
|
||||
_dateIndex = poModel.dateIndex;
|
||||
_selectedDate = poModel.selectedDate;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<Null> _selectDate(BuildContext context) async {
|
||||
var poSubmissionModel = Provider.of<POSubmissionModel>(context);
|
||||
|
||||
final DateTime picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate,
|
||||
firstDate: DateTime(2015, 8),
|
||||
lastDate: DateTime(2101),
|
||||
builder: (BuildContext context, Widget child) {
|
||||
return Theme(
|
||||
data: ThemeData.light().copyWith(
|
||||
primaryColor: primaryColor, //Head background
|
||||
accentColor: secondaryColor, //selection color
|
||||
dialogBackgroundColor: Colors.white, //Background color
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
if (picked != null) {
|
||||
var pickedDate = new DateTime(picked.year, picked.month, picked.day);
|
||||
var currentDate = new DateTime(
|
||||
DateTime.now().year, DateTime.now().month, DateTime.now().day);
|
||||
|
||||
this._dateIndex = pickedDate == currentDate ? 0 : 1;
|
||||
setState(() {
|
||||
_selectedDate = picked;
|
||||
poSubmissionModel.filterData(
|
||||
this.status, _selectedDate, this._selectedIndex, this._dateIndex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var poSubmissionModel = Provider.of<POSubmissionModel>(context);
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
bool isBuyer = mainModel.user.isBuyer();
|
||||
var languageModle = Provider.of<LanguageModel>(context);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(
|
||||
AppTranslations.of(context).text("po.title"),
|
||||
style: languageModle.isEng
|
||||
? TextStyle()
|
||||
: TextStyle(fontFamily: 'MyanmarUnicode'),
|
||||
),
|
||||
actions: <Widget>[
|
||||
InkWell(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
"assets/date_filter.png",
|
||||
color: Colors.white,
|
||||
width: 25,
|
||||
),
|
||||
_dateIndex == 0
|
||||
? Container()
|
||||
: Positioned(
|
||||
bottom: 15,
|
||||
right: 10,
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: new BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: secondaryColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () => _selectDate(context),
|
||||
),
|
||||
PopupMenuButton<PopupMenu>(
|
||||
elevation: 3.2,
|
||||
onSelected: (selected) {
|
||||
setState(() {
|
||||
_selectedIndex = selected.index;
|
||||
});
|
||||
if (selected.status == 'All') {
|
||||
status = null;
|
||||
} else {
|
||||
status = selected.status;
|
||||
}
|
||||
poSubmissionModel.filterData(
|
||||
status, _selectedDate, _selectedIndex, _dateIndex);
|
||||
},
|
||||
icon: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: new BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Icons.filter_list,
|
||||
color: primaryColor,
|
||||
),
|
||||
_selectedIndex != 0
|
||||
? Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: new BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: secondaryColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
)),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return statusMenu.map((PopupMenu choice) {
|
||||
return PopupMenuItem<PopupMenu>(
|
||||
value: choice,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(choice.status),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
_selectedIndex != null &&
|
||||
_selectedIndex == choice.index
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: Colors.grey,
|
||||
)
|
||||
: Container(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}),
|
||||
],
|
||||
),
|
||||
floatingActionButton: isBuyer
|
||||
? FloatingActionButton(
|
||||
backgroundColor: primaryColor,
|
||||
heroTag: "btn2",
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => POSubmissionForm()),
|
||||
),
|
||||
child: Icon(Icons.add),
|
||||
)
|
||||
: null,
|
||||
body: new ListView.builder(
|
||||
scrollDirection: Axis.vertical,
|
||||
padding: EdgeInsets.only(left: 15, right: 15, top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: poSubmissionModel.pos.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Card(
|
||||
elevation: 10,
|
||||
color: Colors.white,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => POSubmissionForm(
|
||||
poSubmission: poSubmissionModel.pos[index],
|
||||
)),
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: new Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
new Padding(
|
||||
padding: new EdgeInsets.symmetric(
|
||||
horizontal: 15.0 - dotSize / 2),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(5.0),
|
||||
child: Image.asset(
|
||||
"assets/pay.png",
|
||||
width: 40,
|
||||
height: 40,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
new Expanded(
|
||||
child: new Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
poSubmissionModel.pos[index].poNumber
|
||||
.toString(),
|
||||
style: new TextStyle(
|
||||
fontSize: 12.0, color: Colors.black),
|
||||
),
|
||||
new Text(
|
||||
dateFormatter.format(
|
||||
poSubmissionModel.pos[index].poDate),
|
||||
style: new TextStyle(
|
||||
fontSize: 12.0, color: Colors.grey),
|
||||
),
|
||||
!isBuyer
|
||||
? new Text(
|
||||
poSubmissionModel
|
||||
.pos[index].userName
|
||||
.toString(),
|
||||
style: new TextStyle(
|
||||
fontSize: 12.0,
|
||||
color: Colors.grey),
|
||||
)
|
||||
: Container()
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 18.0),
|
||||
child: getStatus(poSubmissionModel.pos[index].status),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user