add mix carton

This commit is contained in:
Sai Naw Wun
2020-10-21 02:59:10 +06:30
parent b87703c693
commit 9aefc585ec
23 changed files with 393 additions and 519 deletions

View File

@@ -100,7 +100,8 @@ class _CargoTypeEditorState extends State<CargoTypeEditor> {
)),
body: Container(
padding: EdgeInsets.all(18),
child: Column(
child: ListView(
shrinkWrap: true,
children: <Widget>[
cargoTypeBox,
rateBox,

View File

@@ -63,6 +63,8 @@ class _CartonEditorState extends State<CartonEditor> {
double shipmentWeight = 0;
FcsShipment _fcsShipment;
List<FcsShipment> _fcsShipments;
Carton _mixCarton;
List<Carton> _mixCartons;
@override
void initState() {
@@ -85,6 +87,7 @@ class _CartonEditorState extends State<CartonEditor> {
_selectedCartonType = _carton.cartonType;
_isNew = false;
_user = User(fcsID: _carton.fcsID, name: _carton.userName);
_loadPackages();
} else {
_carton = Carton(cargoTypes: [], packages: [], cartons: []);
_lengthController.text = "12";
@@ -93,6 +96,7 @@ class _CartonEditorState extends State<CartonEditor> {
_isNew = true;
_selectedCartonType = carton_from_packages;
_loadFcsShipments();
_loadMixCartons();
}
}
@@ -108,25 +112,46 @@ class _CartonEditorState extends State<CartonEditor> {
});
}
_loadMixCartons() async {
if (_fcsShipment == null) return;
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
var mixCartons =
await cartonModel.getMixCartonsByFcsShipment(_fcsShipment.id);
setState(() {
_mixCartons = mixCartons;
});
}
_loadPackages() async {
if (_user == null) return;
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
List<Package> packages = await packageModel.getPackages(_user.id);
String prevCompare;
packages.forEach((p) {
String compare = (p.deliveryAddress?.fullName ?? "") +
(p.deliveryAddress?.phoneNumber ?? "");
if (prevCompare != null && compare == prevCompare) {
p.isChecked = true;
} else {
p.isChecked = false;
}
if (prevCompare == null) {
p.isChecked = true;
prevCompare = compare;
}
});
List<Package> packages = await packageModel.getPackages(
_user.id, [package_processed_status, package_packed_status]);
if (_isNew) {
String prevCompare;
packages.forEach((p) {
String compare = (p.deliveryAddress?.fullName ?? "") +
(p.deliveryAddress?.phoneNumber ?? "");
if (prevCompare != null && compare == prevCompare) {
p.isChecked = true;
} else {
p.isChecked = false;
}
if (prevCompare == null) {
p.isChecked = true;
prevCompare = compare;
}
});
} else {
packages.forEach((p) {
if (_carton.packages.contains(p)) {
p.isChecked = _carton.packages.firstWhere((cp) => cp == p).isChecked;
} else {
p.isChecked = false;
}
});
}
setState(() {
_carton.packages = packages;
@@ -176,12 +201,17 @@ class _CartonEditorState extends State<CartonEditor> {
Widget build(BuildContext context) {
var boxModel = Provider.of<CartonModel>(context);
bool isMixBox = _selectedCartonType == carton_mix_box;
bool isSmallBag = _selectedCartonType == carton_small_bag;
final shipmentBox = DisplayText(
text: _carton.fcsShipmentNumber,
labelTextKey: "box.fcs_shipment_num",
iconData: Ionicons.ios_airplane,
);
final mixCartonNumberBox = DisplayText(
text: _carton.mixCartonNumber,
labelTextKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
);
var fcsShipmentsBox = LocalDropdown<FcsShipment>(
callback: (v) {
setState(() {
@@ -190,6 +220,9 @@ class _CartonEditorState extends State<CartonEditor> {
if (_selectedCartonType == carton_mix_box) {
_loadCartons();
}
if (_selectedCartonType == carton_small_bag) {
_loadMixCartons();
}
},
labelKey: "shipment.pack.fcs.shipment",
iconData: Ionicons.ios_airplane,
@@ -198,6 +231,19 @@ class _CartonEditorState extends State<CartonEditor> {
values: _fcsShipments,
);
var mixCartonsBox = LocalDropdown<Carton>(
callback: (v) {
setState(() {
_mixCarton = v;
});
},
labelKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
display: (u) => u.cartonNumber,
selectedValue: _mixCarton,
values: _mixCartons,
);
final fcsIDBox = Row(
children: <Widget>[
Expanded(
@@ -338,16 +384,19 @@ class _CartonEditorState extends State<CartonEditor> {
cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"),
_isNew ? fcsShipmentsBox : shipmentBox,
isSmallBag
? _isNew ? mixCartonsBox : mixCartonNumberBox
: Container(),
...(isMixBox
? [
CartonMixTable(
cartons: _carton.cartons,
onSelect: (c, check) {
setState(() {
c.isChecked = check;
});
},
)
// CartonMixTable(
// cartons: _carton.cartons,
// onSelect: (c, check) {
// setState(() {
// c.isChecked = check;
// });
// },
// )
]
: [
fcsIDBox,
@@ -368,9 +417,11 @@ class _CartonEditorState extends State<CartonEditor> {
),
cargoTableTitleBox,
cargoTableBox,
LocalTitle(textKey: "box.dimension"),
dimBox,
shipmentWeightBox,
isSmallBag
? Container()
: LocalTitle(textKey: "box.dimension"),
isSmallBag ? Container() : dimBox,
isSmallBag ? Container() : shipmentWeightBox,
LocalTitle(textKey: "box.delivery_address"),
DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
@@ -413,7 +464,9 @@ class _CartonEditorState extends State<CartonEditor> {
}
_save() async {
if (_user == null) {
bool isFromShipment = _selectedCartonType == carton_from_shipments;
bool isSmallBag = _selectedCartonType == carton_small_bag;
if (_user == null && (isFromShipment || isSmallBag)) {
showMsgDialog(context, "Error", "Please select customer");
return;
}
@@ -421,35 +474,40 @@ class _CartonEditorState extends State<CartonEditor> {
showMsgDialog(context, "Error", "Please select FCS shipment");
return;
}
if ((_carton.cargoTypes?.length ?? 0) == 0) {
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) {
if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
showMsgDialog(context, "Error", "Invalid dimension");
return;
}
if (_deliveryAddress == null) {
if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
showMsgDialog(context, "Error", "Invalid delivery address");
return;
}
if (isSmallBag && _mixCarton == null) {
showMsgDialog(context, "Error", "Invalid mix carton");
return;
}
Carton carton = Carton();
carton.id = _carton.id;
carton.cartonType = _selectedCartonType;
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
carton.userID = _user.id;
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;
carton.cartons = _carton.cartons.where((c) => c.isChecked).toList();
setState(() {
_isLoading = true;
});

View File

@@ -55,7 +55,8 @@ class _CartonInfoState extends State<CartonInfo> {
bool isMixBox;
bool isFromShipments;
bool isFromPackage;
bool isFromPackages;
bool isSmallBag;
bool isEdiable;
@override
@@ -72,35 +73,39 @@ class _CartonInfoState extends State<CartonInfo> {
_widthController.addListener(_calShipmentWeight);
_heightController.addListener(_calShipmentWeight);
_updateBoxData();
_loadPackages();
}
_updateBoxData() {
_widthController.text = _box.width.toString();
_heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString();
_cargoTypes = _box.cargoTypes;
_deliveryAddress = _box.deliveryAddress;
isMixBox = _box.cartonType == carton_mix_box;
isFromShipments = _box.cartonType == carton_from_shipments;
isFromPackage = _box.cartonType == carton_from_packages;
isEdiable =
(isMixBox || isFromPackage) && _box.status == carton_packed_status;
if (isFromPackage) {
_loadPackages();
}
isFromPackages = _box.cartonType == carton_from_packages;
isSmallBag = _box.cartonType == carton_small_bag;
isEdiable = !isMixBox &&
(isFromPackages || isSmallBag) &&
_box.status == carton_packed_status;
}
_loadPackages() async {
if (!isFromPackages && !isSmallBag) return;
if (_box.cartonType == carton_from_packages && _box.userID == null) return;
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
List<Package> packages = await packageModel.getPackages(_box.userID);
List<Package> packages = await packageModel.getPackages(_box.userID, [
package_processed_status,
package_packed_status,
package_shipped_status
]);
packages = packages.where((p) => _box.packageIDs.contains(p.id)).toList();
packages.forEach((p) {
if (_box.packageIDs.contains(p.id)) {
p.isChecked = true;
} else {
p.isChecked = false;
}
p.isChecked = true;
});
setState(() {
@@ -219,6 +224,11 @@ class _CartonInfoState extends State<CartonInfo> {
final cargoTableBox = CargoTable(
cargoTypes: _box.cargoTypes,
);
final mixCartonNumberBox = DisplayText(
text: _box.mixCartonNumber,
labelTextKey: "box.mix.carton",
iconData: MaterialCommunityIcons.package,
);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -250,65 +260,68 @@ class _CartonInfoState extends State<CartonInfo> {
]
: [],
),
body: Card(
child: Column(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
Center(child: getCartonNumberStatus(context, _box)),
LocalTitle(textKey: "box.type.title"),
cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"),
shipmentBox,
fcsIDBox,
customerNameBox,
isFromPackage
? CartonPackageTable(
packages: _box.packages,
)
: Container(),
isFromPackage
? Container()
: isFromShipments
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
shipmentBoxTitle,
Divider(
color: Colors.grey[400],
),
shipmentBoxRow
],
)
: _selectedCartonType == "Mix carton"
? CartonMixTable(
cartons: _box.cartons,
onSelect: (c, check) {
setState(() {
c.isChecked = check;
});
},
)
: Container(),
LocalTitle(textKey: "box.cargo.type"),
cargoTableBox,
LocalTitle(textKey: "box.dimension"),
dimBox,
shipmentWeightBox,
LocalTitle(textKey: "box.delivery_address"),
DefaultDeliveryAddress(
body: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
Center(child: getCartonNumberStatus(context, _box)),
LocalTitle(textKey: "box.type.title"),
cartonTypeBox,
LocalTitle(textKey: "box.shipment_info"),
shipmentBox,
isSmallBag ? mixCartonNumberBox : Container(),
isMixBox ? Container() : fcsIDBox,
isMixBox ? Container() : customerNameBox,
isFromPackages || isSmallBag
? CartonPackageTable(
packages: _box.packages,
)
: Container(),
isFromPackages
? Container()
: isFromShipments
? Column(
children: [
LocalTitle(textKey: "box.shipment.boxes"),
shipmentBoxTitle,
Divider(
color: Colors.grey[400],
),
shipmentBoxRow
],
)
: Container(),
// : _selectedCartonType == "Mix carton"
// ? CartonMixTable(
// cartons: _box.cartons,
// onSelect: (c, check) {
// setState(() {
// c.isChecked = check;
// });
// },
// )
// : Container(),
isMixBox ? Container() : LocalTitle(textKey: "box.cargo.type"),
isMixBox ? Container() : cargoTableBox,
...(isFromPackages
? [
LocalTitle(textKey: "box.dimension"),
dimBox,
shipmentWeightBox,
]
: []),
isMixBox
? Container()
: LocalTitle(textKey: "box.delivery_address"),
isMixBox
? Container()
: DefaultDeliveryAddress(
deliveryAddress: _deliveryAddress,
labelKey: "box.delivery_address",
),
SizedBox(
height: 20,
)
]),
)),
],
),
SizedBox(
height: 20,
)
]),
),
),
);
@@ -324,6 +337,7 @@ class _CartonInfoState extends State<CartonInfo> {
var c = await cartonModel.getCarton(widget.box.id);
setState(() {
_box = c;
_updateBoxData();
});
_loadPackages();
}

View File

@@ -7,32 +7,20 @@ import 'package:flutter_icons/flutter_icons.dart';
import 'package:intl/intl.dart';
import 'carton_info.dart';
class CartonListRow extends StatefulWidget {
class CartonListRow extends StatelessWidget {
final Carton box;
const CartonListRow({Key key, this.box}) : super(key: key);
CartonListRow({Key key, this.box}) : super(key: key);
@override
_CartonListRowState createState() => _CartonListRowState();
}
class _CartonListRowState extends State<CartonListRow> {
final double dotSize = 15.0;
Carton _box = new Carton();
final DateFormat dateFormat = new DateFormat("dd MMM yyyy");
@override
void initState() {
super.initState();
_box = widget.box;
}
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(builder: (context) => CartonInfo(box: _box)),
CupertinoPageRoute(builder: (context) => CartonInfo(box: box)),
);
},
child: Container(
@@ -59,7 +47,7 @@ class _CartonListRowState extends State<CartonListRow> {
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
_box.cartonNumber ?? "",
box.cartonNumber ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.black),
),
@@ -67,7 +55,7 @@ class _CartonListRowState extends State<CartonListRow> {
Padding(
padding: const EdgeInsets.only(left: 10.0, top: 10),
child: new Text(
_box.userName ?? "",
box.userName ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.grey),
),
@@ -83,14 +71,14 @@ class _CartonListRowState extends State<CartonListRow> {
children: <Widget>[
Padding(
padding: const EdgeInsets.all(0),
child: getStatus(_box.status == null ? "" : _box.status),
child: getStatus(box.status == null ? "" : box.status),
),
Padding(
padding: const EdgeInsets.only(left: 8.0, top: 5, bottom: 5),
child: Row(
children: <Widget>[
new Text(
"${_box.actualWeight?.toString() ?? ''} lb",
"${box.actualWeight?.toString() ?? ''} lb",
style:
new TextStyle(fontSize: 15.0, color: Colors.grey),
),

View File

@@ -31,45 +31,47 @@ class CartonMixTable extends StatelessWidget {
),
);
final rows = cartons.asMap().entries.map((p) {
return Container(
color: p.value.isChecked
? Colors.grey.withOpacity(0.2)
: Colors.grey[50].withOpacity(0.2),
child: Container(
padding:
EdgeInsets.only(left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == cartons.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Checkbox(
value: p.value.isChecked,
activeColor: primaryColor,
onChanged: (bool check) {
if (onSelect != null) onSelect(p.value, check);
}),
Expanded(
child: new Text(
p.value.cartonNumber ?? "",
style: textStyle,
)),
new Text(
p.value?.actualWeight?.toString() ?? "",
style: textStyle,
final rows = cartons == null
? []
: cartons.asMap().entries.map((p) {
return Container(
color: p.value.isChecked
? Colors.grey.withOpacity(0.2)
: Colors.grey[50].withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == cartons.length - 1
? Colors.white
: Colors.grey[350],
width: 1),
),
),
child: Row(
children: <Widget>[
Checkbox(
value: p.value.isChecked,
activeColor: primaryColor,
onChanged: (bool check) {
if (onSelect != null) onSelect(p.value, check);
}),
Expanded(
child: new Text(
p.value.cartonNumber ?? "",
style: textStyle,
)),
new Text(
p.value?.actualWeight?.toString() ?? "",
style: textStyle,
),
],
),
),
],
),
),
);
}).toList();
);
}).toList();
return Column(
children: [

View File

@@ -55,11 +55,16 @@ class CartonModel extends BaseModel {
});
}
List<String> cartonTypes = [carton_from_packages, carton_mix_box];
List<String> cartonTypes = [
carton_from_packages,
carton_mix_box,
carton_small_bag
];
List<String> cartonTypesInfo = [
carton_from_packages,
carton_mix_box,
carton_from_shipments
carton_from_shipments,
carton_small_bag
];
set selectedIndex(int index) {
@@ -192,6 +197,19 @@ class CartonModel extends BaseModel {
.toList();
}
Future<List<Carton>> getMixCartonsByFcsShipment(String fcsShipmentID) async {
String path = "/$cartons_collection";
var querySnap = await Firestore.instance
.collection(path)
.where("fcs_shipment_id", isEqualTo: fcsShipmentID)
.where("carton_type", isEqualTo: carton_mix_box)
.where("is_deleted", isEqualTo: false)
.getDocuments();
return querySnap.documents
.map((e) => Carton.fromMap(e.data, e.documentID))
.toList();
}
Future<Carton> getCarton(String id) async {
String path = "/$cartons_collection";
var snap = await Firestore.instance.collection(path).document(id).get();