add structure
This commit is contained in:
423
lib/pages/do/do_creation_todelete.dart
Normal file
423
lib/pages/do/do_creation_todelete.dart
Normal file
@@ -0,0 +1,423 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/po_model.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/do.dart';
|
||||
import 'package:fcs/vo/po.dart';
|
||||
import 'package:fcs/widget/img_file.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:progress/progress.dart';
|
||||
import 'package:fcs/widget/my_data_table.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import 'do_creation_form.dart';
|
||||
|
||||
class DoCreation extends StatefulWidget {
|
||||
final POSubmission poSubmission;
|
||||
const DoCreation({this.poSubmission});
|
||||
@override
|
||||
_DoCreationState createState() => _DoCreationState();
|
||||
}
|
||||
|
||||
class _DoCreationState extends State<DoCreation> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
bool _isLoading = false;
|
||||
TextEditingController _podate = new TextEditingController();
|
||||
TextEditingController _ponumber = new TextEditingController();
|
||||
TextEditingController _postatus = new TextEditingController();
|
||||
POSubmission poSubmission = POSubmission();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
this.poSubmission = widget.poSubmission;
|
||||
_podate.text = dateFormatter.format(this.poSubmission.poDate);
|
||||
_ponumber.text = this.poSubmission.poNumber.toString();
|
||||
_postatus.text = this.poSubmission.status;
|
||||
_isLoading = true;
|
||||
_load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
List<POLine> poLines =
|
||||
await Provider.of<POSubmissionModel>(context, listen: false)
|
||||
.loadPOLines(poSubmission.id);
|
||||
var _poDos = await Provider.of<POSubmissionModel>(context, listen: false)
|
||||
.loadDOs(poSubmission);
|
||||
setState(() {
|
||||
this.poSubmission.poLines = poLines;
|
||||
this.poSubmission.dos = _poDos.dos;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
Widget doDateBox(BuildContext context, DOSubmission doSubmission) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.date"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
dateFormatter.format(doSubmission.deliveryDate),
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget doNumberBox(BuildContext context, DOSubmission doSubmission) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.do_num"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
doSubmission.doNumber,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget driverBox(BuildContext context, DOSubmission doSubmission) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.driver"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
doSubmission.driverName,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget carNoBox(BuildContext context, DOSubmission doSubmission) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.car"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
doSubmission.carNo,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget doStatusBox(BuildContext context, DOSubmission doSubmission) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.status"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
doSubmission.status,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget driverLicence(BuildContext context, DOSubmission doSubmission) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.licence"),
|
||||
ImageFile(
|
||||
enabled: false,
|
||||
title: "Receipt File",
|
||||
initialImgUrl: doSubmission.driverLicenceUrl,
|
||||
onFile: (file) {}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModle = Provider.of<LanguageModel>(context);
|
||||
|
||||
final poDateBox = Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 15),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.date"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_podate.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final poNumberBox = Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "do.po_num"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_ponumber.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final poStatusBox = Container(
|
||||
padding: EdgeInsets.only(left: 20, top: 5),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "po.status"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
_postatus.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("do.title"),
|
||||
style: languageModle.isEng
|
||||
? TextStyle(fontSize: 18)
|
||||
: TextStyle(fontSize: 18, fontFamily: 'MyanmarUnicode')),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: primaryColor,
|
||||
heroTag: "btn2",
|
||||
onPressed: () async {
|
||||
if (poSubmission.poLines
|
||||
.fold<int>(0, (p, e) => p + e.balanceQty) ==
|
||||
0) {
|
||||
showMsgDialog(context, "Error", "Zero PO balance qty");
|
||||
return;
|
||||
}
|
||||
|
||||
final bool successful = await Navigator.push<bool>(
|
||||
context, MaterialPageRoute(builder: (context) => DOForm()));
|
||||
if (successful != null && successful) _load();
|
||||
},
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10, right: 10),
|
||||
child: Card(
|
||||
elevation: 23,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
poDateBox,
|
||||
poNumberBox,
|
||||
poStatusBox,
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columnSpacing: 15,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "po.product"),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "do.po_qty"),
|
||||
),
|
||||
MyDataColumn(
|
||||
label:
|
||||
LocalText(context, "do.po_balance_qty"),
|
||||
),
|
||||
],
|
||||
rows:
|
||||
getPoProductRow(widget.poSubmission.poLines),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: getDos(poSubmission.dos),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
List<MyDataRow> getPoProductRow(List<POLine> poLines) {
|
||||
return poLines.map((p) {
|
||||
return MyDataRow(
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.productName,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.qty.toString(), style: textStyle),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.balanceQty.toString(), style: textStyle),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<Widget> getDos(List<DOSubmission> dos) {
|
||||
return dos.map((d) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(left: 10, right: 10),
|
||||
child: Card(
|
||||
child: Theme(
|
||||
data: ThemeData(accentColor: Colors.grey),
|
||||
child: ExpansionTile(
|
||||
onExpansionChanged: (e) => _onExpend(context, e, d),
|
||||
title: ListTile(
|
||||
title: Text(dateFormatter.format(d.deliveryDate)),
|
||||
subtitle: Text(d.doNumber),
|
||||
),
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(right: 20),
|
||||
child: InkWell(
|
||||
child: Icon(Icons.edit),
|
||||
onTap: () async {
|
||||
final bool successful =
|
||||
await Navigator.push<bool>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DOForm(
|
||||
doSubmission: d,
|
||||
)));
|
||||
if (successful != null && successful) _load();
|
||||
},
|
||||
)),
|
||||
),
|
||||
doDateBox(context, d),
|
||||
doNumberBox(context, d),
|
||||
doStatusBox(context, d),
|
||||
driverBox(context, d),
|
||||
carNoBox(context, d),
|
||||
driverLicence(context, d),
|
||||
Container(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columnSpacing: 15,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "do.product"),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "do.do_qty"),
|
||||
),
|
||||
],
|
||||
rows: getdoProductRow(d.doLines),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<MyDataRow> getdoProductRow(List<DOLine> doLines) {
|
||||
return doLines.map((p) {
|
||||
return MyDataRow(
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.productName,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.qty.toString(), style: textStyle),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_onExpend(BuildContext context, expended, DOSubmission doSub) async {
|
||||
if (!expended) return;
|
||||
POSubmissionModel poModel = Provider.of<POSubmissionModel>(context);
|
||||
var _doSub = await poModel.loadDOLines(doSub);
|
||||
setState(() {
|
||||
doSub = _doSub;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user