update carton from packages
This commit is contained in:
@@ -54,19 +54,19 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
List<DeliveryAddress> _deliveryAddresses = [];
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
List<CargoType> _cargoTypes = [];
|
||||
|
||||
Carton _carton;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||
User _user;
|
||||
String _selectedCartonType;
|
||||
String _selectedMixType;
|
||||
String _selectedMixBoxType;
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
FcsShipment _fcsShipment;
|
||||
List<FcsShipment> _fcsShipments;
|
||||
Carton _mixCarton;
|
||||
List<Carton> _cartons = [];
|
||||
List<Carton> _mixCartons = [];
|
||||
CartonSize selectedCatonSize;
|
||||
@@ -90,11 +90,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_heightController.text = _carton.height.toString();
|
||||
_lengthController.text = _carton.length.toString();
|
||||
_selectedCartonType = _carton.cartonType;
|
||||
_cargoTypes = List.from(_carton.cargoTypes);
|
||||
_isNew = false;
|
||||
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
|
||||
_loadPackages();
|
||||
_getDeliverAddresses();
|
||||
getCartonSize();
|
||||
_getCartonSize();
|
||||
} else {
|
||||
_carton = Carton(
|
||||
cargoTypes: [],
|
||||
@@ -105,9 +106,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_heightController.text = "0";
|
||||
_isNew = true;
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_selectedMixType = mix_delivery;
|
||||
_selectedMixBoxType = mix_delivery;
|
||||
_loadFcsShipments();
|
||||
// _cartons = [Carton(cartonNumber: "A100B-1#3", userName: "Seven 7")];
|
||||
|
||||
// _mixCartons = [
|
||||
// Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"),
|
||||
@@ -192,21 +192,18 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
await addressModel.getDeliveryAddresses(_carton.userID);
|
||||
}
|
||||
|
||||
getCartonSize() {
|
||||
_getCartonSize() {
|
||||
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
|
||||
cartonSizeModel.cartonSizes.forEach((c) {
|
||||
if (c.length == _carton.length &&
|
||||
c.width == _carton.width &&
|
||||
c.height == _carton.height) {
|
||||
print(c.name);
|
||||
// setState(() {
|
||||
// // selectedCatonSize = CartonSize(
|
||||
// // id: c.id,
|
||||
// // name: c.name,
|
||||
// // length: c.length,
|
||||
// // width: c.width,
|
||||
// // height: c.height);
|
||||
// });
|
||||
selectedCatonSize = CartonSize(
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
length: c.length,
|
||||
width: c.width,
|
||||
height: c.height);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -274,7 +271,9 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
final createBtn = LocalButton(
|
||||
textKey: "box.complete.packaging",
|
||||
callBack: _save,
|
||||
callBack: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
|
||||
final saveBtn = LocalButton(
|
||||
@@ -300,62 +299,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select FCS ID");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID =
|
||||
_isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.fcsID = _user?.fcsID;
|
||||
carton.userName = _user?.name;
|
||||
carton.packages =
|
||||
_carton.packages.where((e) => e.isChecked).toList();
|
||||
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
|
||||
carton.deliveryAddress = _carton.deliveryAddress;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
Carton _c = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PackageCartonEditor(carton: carton, isNew: _isNew)),
|
||||
);
|
||||
if (_c == null) return;
|
||||
var cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
Carton _carton = await cartonModel.getCarton(_c.id);
|
||||
_cartons.add(_carton);
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}),
|
||||
onPressed: _addCarton),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -374,16 +318,16 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
Row(
|
||||
children: boxModel.mixTypes.map((e) {
|
||||
children: boxModel.mixBoxTypes.map((e) {
|
||||
return Row(
|
||||
children: [
|
||||
Radio(
|
||||
value: e,
|
||||
groupValue: _selectedMixType,
|
||||
groupValue: _selectedMixBoxType,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_selectedMixType = v;
|
||||
_selectedMixBoxType = v;
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -404,12 +348,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => MixCartonEditor()),
|
||||
);
|
||||
},
|
||||
onPressed: _addMixCarton,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -426,15 +365,15 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
|
||||
if (cargos == null) return;
|
||||
setState(() {
|
||||
_carton.cargoTypes.clear();
|
||||
_carton.cargoTypes.addAll(cargos);
|
||||
_cargoTypes.clear();
|
||||
_cargoTypes.addAll(cargos);
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
final cargoTableBox = CargoTable(
|
||||
isNew: _isNew,
|
||||
cargoTypes: _carton.cargoTypes,
|
||||
cargoTypes: _cargoTypes,
|
||||
onAdd: (c) => _addCargo(c),
|
||||
onRemove: (c) => _removeCargo(c),
|
||||
);
|
||||
@@ -487,7 +426,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(
|
||||
context,
|
||||
"box.info.title",
|
||||
_isNew ? "box.info.title" : "box.edit.title",
|
||||
fontSize: 20,
|
||||
color: primaryColor,
|
||||
),
|
||||
@@ -509,10 +448,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
? [
|
||||
mixcartonTitleBox,
|
||||
Column(
|
||||
children: _getMixCartons(
|
||||
context,
|
||||
this._mixCartons,
|
||||
)),
|
||||
children: _getMixCartons(context, this._mixCartons)),
|
||||
]
|
||||
: [
|
||||
fcsIDBox,
|
||||
@@ -585,19 +521,26 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
);
|
||||
}
|
||||
|
||||
_addCarton(Carton carton) {
|
||||
if (carton == null) return;
|
||||
this._cartons.add(carton);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
|
||||
return cartons.map((c) {
|
||||
return cartons.asMap().entries.map((c) {
|
||||
return InkWell(
|
||||
onTap: () {},
|
||||
onTap: () async {
|
||||
_loadPackages();
|
||||
c.value.packages = _carton.packages;
|
||||
Carton _c = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PackageCartonEditor(carton: c.value, isNew: false)),
|
||||
);
|
||||
if (_c == null) return;
|
||||
cartons.removeWhere((item) => item.id == _c.id);
|
||||
cartons.insert(c.key, _c);
|
||||
setState(() {});
|
||||
},
|
||||
child: CartonRow(
|
||||
key: ValueKey(c.id),
|
||||
box: c,
|
||||
key: ValueKey(c.value.id),
|
||||
box: c.value,
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
@@ -696,81 +639,126 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_addCargo(CargoType cargo) {
|
||||
if (cargo == null) return;
|
||||
setState(() {
|
||||
_carton.cargoTypes.remove(cargo);
|
||||
_carton.cargoTypes.add(cargo);
|
||||
_cargoTypes.remove(cargo);
|
||||
_cargoTypes.add(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCargo(CargoType cargo) {
|
||||
setState(() {
|
||||
_carton.cargoTypes.remove(cargo);
|
||||
_cargoTypes.remove(cargo);
|
||||
});
|
||||
}
|
||||
|
||||
_save() async {
|
||||
// bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
||||
// bool isSmallBag = _selectedCartonType == carton_small_bag;
|
||||
// if (_user == null && (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Please select customer");
|
||||
// return;
|
||||
// }
|
||||
// if (_fcsShipment == null && _isNew) {
|
||||
// showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
// return;
|
||||
// }
|
||||
// if ((_carton.cargoTypes?.length ?? 0) == 0 &&
|
||||
// (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
// return;
|
||||
// }
|
||||
// double l = double.parse(_lengthController.text, (s) => 0);
|
||||
// double w = double.parse(_widthController.text, (s) => 0);
|
||||
// double h = double.parse(_heightController.text, (s) => 0);
|
||||
// if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
|
||||
// showMsgDialog(context, "Error", "Invalid dimension");
|
||||
// return;
|
||||
// }
|
||||
// if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
// return;
|
||||
// }
|
||||
// if (isSmallBag && _mixCarton == null && _isNew) {
|
||||
// showMsgDialog(context, "Error", "Invalid mix carton");
|
||||
// return;
|
||||
// }
|
||||
_addCarton() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select FCS ID");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
// Carton carton = Carton();
|
||||
// carton.id = _carton.id;
|
||||
// carton.cartonType = _selectedCartonType;
|
||||
// carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
// carton.userID = _user?.id;
|
||||
// carton.cargoTypes = _carton.cargoTypes;
|
||||
// carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
// carton.mixCartonID = _mixCarton?.id;
|
||||
// carton.length = l;
|
||||
// carton.width = w;
|
||||
// carton.height = h;
|
||||
// carton.deliveryAddress = _deliveryAddress;
|
||||
// setState(() {
|
||||
// _isLoading = true;
|
||||
// });
|
||||
// try {
|
||||
// CartonModel cartonModel =
|
||||
// Provider.of<CartonModel>(context, listen: false);
|
||||
// if (_isNew) {
|
||||
// await cartonModel.createCarton(carton);
|
||||
// } else {
|
||||
// await cartonModel.updateCarton(carton);
|
||||
// }
|
||||
// Navigator.pop(context, true);
|
||||
// } catch (e) {
|
||||
// showMsgDialog(context, "Error", e.toString());
|
||||
// } finally {
|
||||
// setState(() {
|
||||
// _isLoading = false;
|
||||
// });
|
||||
// }
|
||||
Navigator.pop(context, true);
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.fcsID = _user?.fcsID;
|
||||
carton.userName = _user?.name;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
|
||||
carton.deliveryAddress = _carton.deliveryAddress;
|
||||
|
||||
try {
|
||||
Carton _c = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PackageCartonEditor(carton: carton, isNew: _isNew)),
|
||||
);
|
||||
if (_c == null) return;
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
Carton _carton = await cartonModel.getCarton(_c.id);
|
||||
_cartons.add(_carton);
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
_addMixCarton() async {
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.mixBoxType = _selectedMixBoxType;
|
||||
await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => MixCartonEditor(box: carton)),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages)) {
|
||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
return;
|
||||
}
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
if ((l <= 0 || w <= 0 || h <= 0) && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Invalid dimension");
|
||||
return;
|
||||
}
|
||||
if (_deliveryAddress == null && (isFromPackages)) {
|
||||
showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
return;
|
||||
}
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
carton.cargoTypes = _cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
carton.deliveryAddress = _deliveryAddress;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
await cartonModel.updateCarton(carton);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
|
||||
Reference in New Issue
Block a user