add carton from mix_box & from cargos
This commit is contained in:
@@ -33,9 +33,7 @@ import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'cargo_type_addtion.dart';
|
||||
import 'carton_cargo_table.dart';
|
||||
import 'carton_list_row.dart';
|
||||
import 'carton_row.dart';
|
||||
import 'mix_carton_editor.dart';
|
||||
import 'model/carton_model.dart';
|
||||
import '../carton_size/model/carton_size_model.dart';
|
||||
import 'package_carton_editor.dart';
|
||||
@@ -62,15 +60,23 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
bool _isNew;
|
||||
User _user;
|
||||
String _selectedCartonType;
|
||||
String _selectedMixBoxType;
|
||||
|
||||
double volumetricRatio = 0;
|
||||
double shipmentWeight = 0;
|
||||
FcsShipment _fcsShipment;
|
||||
List<FcsShipment> _fcsShipments;
|
||||
List<Carton> _cartons = [];
|
||||
List<Carton> _mixCartons = [];
|
||||
CartonSize selectedCatonSize;
|
||||
|
||||
//for mix carton
|
||||
List<Carton> _mixCartons = [];
|
||||
String _selectedMixBoxType;
|
||||
|
||||
//for carton from cargos
|
||||
User consignee;
|
||||
User sender;
|
||||
List<Carton> _cartonsForCargos = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -93,9 +99,20 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_cargoTypes = List.from(_carton.cargoTypes);
|
||||
_isNew = false;
|
||||
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
|
||||
_loadPackages();
|
||||
_getDeliverAddresses();
|
||||
_getCartonSize();
|
||||
consignee =
|
||||
User(fcsID: _carton.receiverFCSID, name: _carton.receiverName);
|
||||
sender = User(fcsID: _carton.senderID, name: _carton.senderName);
|
||||
_selectedMixBoxType = _carton.mixBoxType ?? "";
|
||||
this._mixCartons =
|
||||
_carton.mixCartons == null ? [] : List.from(_carton.mixCartons);
|
||||
bool isMixBox = _carton.cartonType == carton_mix_box;
|
||||
bool isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
if (isFromPackages) _loadPackages();
|
||||
|
||||
if (!isMixBox) {
|
||||
_getDeliverAddresses();
|
||||
_getCartonSize();
|
||||
}
|
||||
} else {
|
||||
_carton = Carton(
|
||||
cargoTypes: [],
|
||||
@@ -108,11 +125,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_selectedMixBoxType = mix_delivery;
|
||||
_loadFcsShipments();
|
||||
|
||||
// _mixCartons = [
|
||||
// Carton(cartonNumber: "A100B-1#1", userName: "Seven 7"),
|
||||
// Carton(cartonNumber: "A100B-1#2", userName: "Seven 7"),
|
||||
// ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,8 +200,10 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
_getDeliverAddresses() async {
|
||||
var addressModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
this._deliveryAddresses =
|
||||
await addressModel.getDeliveryAddresses(_carton.userID);
|
||||
bool isFromPackages = _carton.cartonType == carton_from_packages;
|
||||
this._deliveryAddresses = isFromPackages
|
||||
? await addressModel.getDeliveryAddresses(_carton.userID)
|
||||
: await addressModel.getDeliveryAddresses(_carton.receiverID);
|
||||
}
|
||||
|
||||
_getCartonSize() {
|
||||
@@ -216,6 +230,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var boxModel = Provider.of<CartonModel>(context);
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
bool isMixBox = _selectedCartonType == carton_mix_box;
|
||||
|
||||
final shipmentBox = DisplayText(
|
||||
@@ -348,7 +364,11 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: _addMixCarton,
|
||||
onPressed: () async {
|
||||
searchCarton(context, callbackCartonSelect: (c) {
|
||||
_addMixCarton(c);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -405,6 +425,80 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
SizedBox(child: heightBox, width: 80),
|
||||
],
|
||||
);
|
||||
|
||||
final createMixCarton = LocalButton(
|
||||
textKey: _isNew ? "box.mix_carton_btn" : "box.cargo.save.btn",
|
||||
callBack: _creatMixCarton,
|
||||
);
|
||||
|
||||
final consigneefcsIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: consignee != null ? consignee.fcsID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
setState(() {
|
||||
this.consignee = u;
|
||||
});
|
||||
})),
|
||||
],
|
||||
);
|
||||
|
||||
final consigneeNameBox = DisplayText(
|
||||
text: consignee != null ? consignee.name : "",
|
||||
labelTextKey: "processing.consignee.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final consigneeBox = Container(
|
||||
child: Column(
|
||||
children: [
|
||||
consigneefcsIDBox,
|
||||
consigneeNameBox,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final shipperIDBox = Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: sender != null ? sender.fcsID : "",
|
||||
labelTextKey: "processing.fcs.id",
|
||||
icon: FcsIDIcon(),
|
||||
)),
|
||||
IconButton(
|
||||
icon: Icon(Icons.search, color: primaryColor),
|
||||
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
||||
setState(() {
|
||||
this.sender = u;
|
||||
});
|
||||
})),
|
||||
],
|
||||
);
|
||||
|
||||
final shipperNamebox = DisplayText(
|
||||
text: sender != null ? sender.name : "",
|
||||
labelTextKey: "processing.shipper.name",
|
||||
maxLines: 2,
|
||||
iconData: Icons.person,
|
||||
);
|
||||
|
||||
final shipperBox = Container(
|
||||
child: Column(
|
||||
children: [
|
||||
shipperIDBox,
|
||||
shipperNamebox,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -451,29 +545,44 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
children: _getMixCartons(context, this._mixCartons)),
|
||||
]
|
||||
: [
|
||||
fcsIDBox,
|
||||
namebox,
|
||||
CartonPackageTable(
|
||||
packages: _carton.packages,
|
||||
onSelect: (p, checked) {
|
||||
if (checked &&
|
||||
_deliveryAddress != null &&
|
||||
p.deliveryAddress?.id != _deliveryAddress.id) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
p.isChecked = checked;
|
||||
});
|
||||
// _populateDeliveryAddress();
|
||||
},
|
||||
),
|
||||
isFromPackages ? fcsIDBox : Container(),
|
||||
isFromPackages ? namebox : Container(),
|
||||
isFromPackages
|
||||
? CartonPackageTable(
|
||||
packages: _carton.packages,
|
||||
onSelect: (p, checked) {
|
||||
if (checked &&
|
||||
_deliveryAddress != null &&
|
||||
p.deliveryAddress?.id !=
|
||||
_deliveryAddress.id) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
p.isChecked = checked;
|
||||
});
|
||||
// _populateDeliveryAddress();
|
||||
},
|
||||
)
|
||||
: Container(),
|
||||
isFromCargos
|
||||
? Container(
|
||||
padding: const EdgeInsets.only(top: 15),
|
||||
child: Row(
|
||||
children: [
|
||||
Flexible(child: consigneeBox),
|
||||
Flexible(child: shipperBox)
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(),
|
||||
_isNew ? cartonTitleBox : Container(),
|
||||
_isNew
|
||||
? Column(
|
||||
children: _getCartons(
|
||||
context,
|
||||
this._cartons,
|
||||
))
|
||||
context,
|
||||
isFromPackages
|
||||
? this._cartons
|
||||
: this._cartonsForCargos))
|
||||
: Container(),
|
||||
_isNew ? Container() : cargoTableTitleBox,
|
||||
_isNew ? Container() : cargoTableBox,
|
||||
@@ -510,7 +619,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
_isNew ? createBtn : saveBtn,
|
||||
isFromPackages || isFromCargos
|
||||
? _isNew
|
||||
? createBtn
|
||||
: saveBtn
|
||||
: Container(),
|
||||
isMixBox ? createMixCarton : Container(),
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
@@ -525,18 +639,22 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
return cartons.asMap().entries.map((c) {
|
||||
return InkWell(
|
||||
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(() {});
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
if (isFromPackages) {
|
||||
_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.value.id),
|
||||
@@ -548,12 +666,12 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
List<Widget> _getMixCartons(BuildContext context, List<Carton> cartons) {
|
||||
return cartons.map((c) {
|
||||
return InkWell(
|
||||
onTap: () {},
|
||||
child: CartonRow(
|
||||
key: ValueKey(c.id),
|
||||
box: c,
|
||||
),
|
||||
return CartonRow(
|
||||
key: ValueKey(c.id),
|
||||
box: c,
|
||||
onRemove: (carton) {
|
||||
_removeMixCarton(carton);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
@@ -652,12 +770,25 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
_addCarton() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select FCS ID");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
|
||||
if (consignee == null && isFromCargos) {
|
||||
showMsgDialog(context, "Error", "Please select consignee's FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender == null && isFromCargos) {
|
||||
showMsgDialog(context, "Error", "Please select sender's FCS ID");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -669,16 +800,26 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
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();
|
||||
if (isFromPackages) {
|
||||
carton.userID = _user?.id;
|
||||
carton.fcsID = _user?.fcsID;
|
||||
carton.userName = _user?.name;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
carton.receiverID = consignee?.id;
|
||||
carton.receiverFCSID = consignee?.fcsID;
|
||||
carton.receiverName = consignee?.name;
|
||||
carton.senderID = sender?.id;
|
||||
carton.senderFCSID = sender?.fcsID;
|
||||
carton.senderName = sender?.name;
|
||||
}
|
||||
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
|
||||
carton.deliveryAddress = _carton.deliveryAddress;
|
||||
|
||||
try {
|
||||
@@ -691,43 +832,85 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
if (_c == null) return;
|
||||
var cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
Carton _carton = await cartonModel.getCarton(_c.id);
|
||||
_cartons.add(_carton);
|
||||
if (isFromPackages) {
|
||||
_cartons.add(_carton);
|
||||
}
|
||||
|
||||
if (isFromCargos) {
|
||||
_cartonsForCargos.add(_carton);
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
_addMixCarton() async {
|
||||
_addMixCarton(Carton carton) {
|
||||
if (carton == null) return;
|
||||
if (this._mixCartons.any((c) => c.id == carton.id)) return;
|
||||
setState(() {
|
||||
this._mixCartons.add(carton);
|
||||
});
|
||||
}
|
||||
|
||||
_removeMixCarton(Carton carton) {
|
||||
setState(() {
|
||||
this._mixCartons.removeWhere((c) => c.id == carton.id);
|
||||
});
|
||||
}
|
||||
|
||||
_creatMixCarton() async {
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
if ((this._mixCartons?.length ?? 0) == 0) {
|
||||
showMsgDialog(context, "Error", "Expect at least one carton");
|
||||
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)),
|
||||
);
|
||||
carton.mixCartons = this._mixCartons;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await cartonModel.createMixCarton(carton);
|
||||
} else {
|
||||
await cartonModel.updateMixCarton(carton);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_save() async {
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages)) {
|
||||
bool isFromCargos = _selectedCartonType == carton_from_cargos;
|
||||
if ((_cargoTypes?.length ?? 0) == 0 && (isFromPackages || isFromCargos)) {
|
||||
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) {
|
||||
if ((l <= 0 || w <= 0 || h <= 0) && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Invalid dimension");
|
||||
return;
|
||||
}
|
||||
if (_deliveryAddress == null && (isFromPackages)) {
|
||||
if (_deliveryAddress == null && (isFromPackages || isFromCargos)) {
|
||||
showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
return;
|
||||
}
|
||||
@@ -736,8 +919,15 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
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();
|
||||
if (isFromPackages) {
|
||||
carton.userID = _user?.id;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
}
|
||||
if (isFromCargos) {
|
||||
carton.receiverID = consignee?.id;
|
||||
carton.senderID = sender?.id;
|
||||
}
|
||||
|
||||
carton.cargoTypes = _cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
|
||||
Reference in New Issue
Block a user