update carton from packages

This commit is contained in:
2021-01-08 17:13:51 +06:30
parent f0662ff1d0
commit 32b8c5ae93
17 changed files with 321 additions and 371 deletions

View File

@@ -123,7 +123,7 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
color: primaryColor,
),
onPressed: () async {
CustomDuty customDuty = await Navigator.of(context).push(
CargoType customDuty = await Navigator.of(context).push(
CupertinoPageRoute(
builder: (context) =>
CustomList(selected: true)));
@@ -143,14 +143,20 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
);
}
_addCustom(CustomDuty customDuty) {
_addCustom(CargoType customDuty) {
if (customDuty == null) return;
if (cargos.any((c) => c.name == customDuty.productType)) return;
if (cargos.any((c) => c.name == customDuty.name)) return;
// setState(() {
// cargos.add(CargoType(
// name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0));
// });
setState(() {
cargos.add(CargoType(
name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0));
customDuty.qty = 1;
customDuty.isChecked = false;
cargos.add(customDuty);
});
}
}

View File

@@ -105,7 +105,9 @@ class _CargoTableState extends State<CargoTable> {
String _t = await showDialog(
context: context,
builder: (_) => DialogInput(
label: "cargo.qty", value: c.qty.toString()));
label: "cargo.qty",
value: c.qty.toString(),
isQty: true));
if (_t == null) return;
setState(() {
@@ -238,10 +240,11 @@ class _CargoTableState extends State<CargoTable> {
child: InkWell(
onTap: () async {
String _t = await showDialog(
context: context,
builder: (_) => DialogInput(
label: "shipment.cargo.total",
value: totalWeight.toStringAsFixed(2)));
context: context,
builder: (_) => DialogInput(
label: "shipment.cargo.total",
value: totalWeight.toStringAsFixed(2)),
);
if (_t == null) return;
setState(() {

View File

@@ -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() {

View File

@@ -109,7 +109,6 @@ class _CartonInfoState extends State<CartonInfo> {
if (c.length == _box.length &&
c.width == _box.width &&
c.height == _box.height) {
print(c.name);
setState(() {
_cartonSizeController.text = c.name;
});

View File

@@ -1,12 +1,15 @@
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/carton/model/carton_model.dart';
import 'package:fcs/pages/carton_search/carton_search.dart';
import 'package:fcs/pages/main/util.dart';
import 'package:fcs/pages/widgets/local_button.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'carton_row.dart';
class MixCartonEditor extends StatefulWidget {
@@ -26,14 +29,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
@override
void initState() {
super.initState();
if (widget.box != null) {
_box = widget.box;
_isNew = false;
} else {
_isNew = true;
_box = Carton(cargoTypes: []);
}
_box = widget.box;
}
@override
@@ -124,5 +120,26 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
});
}
_creatCarton() {}
_creatCarton() {
if ((this._cartons?.length ?? 0) == 0) {
showMsgDialog(context, "Error", "Expect at least one carton");
return;
}
Carton carton = Carton();
carton.id = _box.id;
carton.cartonType = _box.cartonType;
setState(() {
_isLoading = true;
});
try {
CartonModel cartonModel =
Provider.of<CartonModel>(context, listen: false);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}

View File

@@ -57,7 +57,7 @@ class CartonModel extends BaseModel {
}
List<String> cartonTypes = [carton_from_packages, carton_mix_box];
List<String> mixTypes = [mix_delivery, mix_pickup];
List<String> mixBoxTypes = [mix_delivery, mix_pickup];
List<String> cartonTypesInfo = [
carton_from_packages,
carton_mix_box,
@@ -212,7 +212,6 @@ class CartonModel extends BaseModel {
}
Future<void> updateCarton(Carton carton) {
print(carton.id);
return Services.instance.cartonService.updateCarton(carton);
}

View File

@@ -45,6 +45,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<DeliveryAddress> _deliveryAddresses = [];
List<CargoType> _cargoTypes = [];
CartonSize selectedCatonSize;
@override
void initState() {
@@ -65,6 +66,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
_widthCtl.text = _carton.width.toString();
_heightCtl.text = _carton.height.toString();
_deliveryAddress = _carton.deliveryAddress;
_getCartonSize();
}
}
@@ -75,6 +77,22 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
await addressModel.getDeliveryAddresses(_carton.userID);
}
_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) {
selectedCatonSize = CartonSize(
id: c.id,
name: c.name,
length: c.length,
width: c.width,
height: c.height);
}
});
}
@override
Widget build(BuildContext context) {
final lengthBox = LengthPicker(
@@ -105,7 +123,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
],
);
final createBtn = LocalButton(
textKey: "box.new_carton_btn",
textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn",
callBack: _creatCarton,
);
@@ -193,7 +211,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
);
}
CartonSize selectedCatonSize;
Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes =
Provider.of<CartonSizeModel>(context).getCartonSizes;
@@ -307,7 +324,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
carton.userID = _carton.userID;
carton.cargoTypes = _cargoTypes;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
// carton.cartonSizeID = selectedCatonSize?.id;
carton.length = l;
carton.width = w;
carton.height = h;
@@ -323,7 +339,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
Navigator.pop(context, _c);
} else {
await cartonModel.updateCarton(carton);
Navigator.pop(context, carton);
Carton _c = await cartonModel.getCarton(_carton.id);
Navigator.pop(context, _c);
}
} catch (e) {
showMsgDialog(context, "Error", e.toString());