update carton and add staff name
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/widgets/dialog_input.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/my_data_table.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'cargo_type_editor.dart';
|
||||
import 'total_weight_edit.dart';
|
||||
|
||||
typedef OnAdd(CargoType cargoType);
|
||||
typedef OnRemove(CargoType cargoType);
|
||||
@@ -28,6 +28,8 @@ class _CargoTableState extends State<CargoTable> {
|
||||
double totalWeight = 0;
|
||||
List<CargoType> _cargos = [];
|
||||
double remainingWeight = 0;
|
||||
List<String> _list = [];
|
||||
List<String> _types = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -35,25 +37,36 @@ class _CargoTableState extends State<CargoTable> {
|
||||
widget.cargoTypes.length == 0 ? this.totalWeight : remainingWeight;
|
||||
this._cargos = widget.cargoTypes.length == 0 ? [] : this._cargos;
|
||||
|
||||
return MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.type",
|
||||
color: Colors.grey,
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columnSpacing: 40,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.type",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.weight",
|
||||
color: Colors.grey,
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.qty",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: getCargoRows(context),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.weight",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
rows: getCargoRows(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -61,49 +74,51 @@ class _CargoTableState extends State<CargoTable> {
|
||||
if (widget.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
List<String> _list = [];
|
||||
List<String> _types = [];
|
||||
|
||||
CargoType cargo;
|
||||
|
||||
print("copy remainingWeight>>>${this.remainingWeight}");
|
||||
|
||||
var rows = widget.cargoTypes.map((c) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
if (this.totalWeight <= 0) {
|
||||
showMsgDialog(context, "Error", "Please insert total weight");
|
||||
return;
|
||||
}
|
||||
// if (this.totalWeight <= 0) {
|
||||
// showMsgDialog(context, "Error", "Please insert total weight");
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (c.isCutomDuty) return;
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor(
|
||||
cargo: c,
|
||||
)));
|
||||
if (widget.onAdd != null) widget.onAdd(cargo);
|
||||
if (cargo == null) return;
|
||||
// if (c.isCutomDuty) return;
|
||||
// CargoType cargo = await Navigator.push<CargoType>(
|
||||
// context,
|
||||
// CupertinoPageRoute(
|
||||
// builder: (context) => CargoTypeEditor(
|
||||
// cargo: c,
|
||||
// )));
|
||||
// if (widget.onAdd != null) widget.onAdd(cargo);
|
||||
// if (cargo == null) return;
|
||||
|
||||
this._cargos.add(cargo);
|
||||
if (this.remainingWeight <= 0) return;
|
||||
this.remainingWeight -= cargo.weight;
|
||||
// this._cargos.add(cargo);
|
||||
// if (this.remainingWeight <= 0) return;
|
||||
// this.remainingWeight -= cargo.weight;
|
||||
|
||||
this._cargos.forEach((c) {
|
||||
_list.add(c.name);
|
||||
});
|
||||
widget.cargoTypes.forEach((c) {
|
||||
_types.add(c.name);
|
||||
});
|
||||
// this._cargos.forEach((c) {
|
||||
// _list.add(c.name);
|
||||
// });
|
||||
// widget.cargoTypes.forEach((c) {
|
||||
// _types.add(c.name);
|
||||
// });
|
||||
|
||||
if (this._cargos.length == widget.cargoTypes.length - 1) {
|
||||
_types.forEach((t) {
|
||||
if (!_list.contains(t)) {
|
||||
widget.cargoTypes.forEach((c) {
|
||||
if (c.name == t) {
|
||||
c.weight = this.remainingWeight;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// if (this._cargos.length == widget.cargoTypes.length - 1) {
|
||||
// _types.forEach((t) {
|
||||
// if (!_list.contains(t)) {
|
||||
// widget.cargoTypes.forEach((c) {
|
||||
// if (c.name == t) {
|
||||
// c.weight = this.remainingWeight;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(Row(
|
||||
@@ -118,12 +133,106 @@ class _CargoTableState extends State<CargoTable> {
|
||||
),
|
||||
],
|
||||
)),
|
||||
MyDataCell(
|
||||
c.isCutomDuty
|
||||
? InkWell(
|
||||
onTap: () async {
|
||||
String _t = await showDialog(
|
||||
context: context,
|
||||
builder: (_) => DialogInput(
|
||||
label: "cargo.qty", value: c.qty.toString()));
|
||||
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
c.qty = int.parse(_t);
|
||||
});
|
||||
},
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 40,
|
||||
padding: const EdgeInsets.all(7.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: primaryColor),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
||||
),
|
||||
child: new Text(
|
||||
c.qty == null ? "" : c.qty.toString(),
|
||||
style: textStyle,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: new Text(
|
||||
"-",
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(c.weight == null ? "0.00" : c.weight.toStringAsFixed(2),
|
||||
style: textStyle),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
if (this.totalWeight <= 0) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please insert total weight");
|
||||
return;
|
||||
}
|
||||
|
||||
String _t = await showDialog(
|
||||
context: context,
|
||||
builder: (_) => DialogInput(
|
||||
label: "cargo.weight",
|
||||
value: c.weight.toStringAsFixed(2)));
|
||||
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
c.weight = double.parse(_t);
|
||||
});
|
||||
|
||||
cargo = c;
|
||||
this._cargos.add(cargo);
|
||||
if (this.remainingWeight <= 0) return;
|
||||
this.remainingWeight -= cargo.weight;
|
||||
|
||||
this._cargos.forEach((c) {
|
||||
_list.add(c.name);
|
||||
});
|
||||
|
||||
widget.cargoTypes.forEach((c) {
|
||||
_types.add(c.name);
|
||||
});
|
||||
|
||||
if (this._cargos.length == widget.cargoTypes.length - 1) {
|
||||
_types.forEach((t) {
|
||||
if (!_list.contains(t)) {
|
||||
widget.cargoTypes.forEach((c) {
|
||||
if (c.name == t) {
|
||||
c.weight = this.remainingWeight;
|
||||
setState(() {
|
||||
this._cargos = [];
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
this.remainingWeight = this.totalWeight;
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(7.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: primaryColor),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
||||
),
|
||||
child: Text(
|
||||
c.weight == null ? "0.00" : c.weight.toStringAsFixed(2),
|
||||
style: textStyle),
|
||||
),
|
||||
),
|
||||
widget.onRemove == null
|
||||
? SizedBox(
|
||||
width: 50,
|
||||
@@ -155,20 +264,23 @@ class _CargoTableState extends State<CargoTable> {
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)),
|
||||
MyDataCell(Text("")),
|
||||
MyDataCell(
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 40.0),
|
||||
padding: const EdgeInsets.only(right: 48.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
double _t = await Navigator.of(context).push<double>(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
TotalWeightEdit(totalWeight: totalWeight)));
|
||||
String _t = await showDialog(
|
||||
context: context,
|
||||
builder: (_) => DialogInput(
|
||||
label: "shipment.cargo.total",
|
||||
value: totalWeight.toStringAsFixed(2)));
|
||||
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
totalWeight = _t;
|
||||
totalWeight = double.parse(_t);
|
||||
remainingWeight = totalWeight;
|
||||
});
|
||||
},
|
||||
@@ -190,11 +302,6 @@ class _CargoTableState extends State<CargoTable> {
|
||||
return rows;
|
||||
}
|
||||
|
||||
double getRemainBalance(double total) {
|
||||
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
|
||||
return _r;
|
||||
}
|
||||
|
||||
List<MyDataRow> _getCargoRows(BuildContext context) {
|
||||
if (widget.cargoTypes == null) {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user